Jump to content

[Lua]VIP


Go-piratia

Recommended Posts

--[[

							*###########################################################################*
							#                              -Simple VIP by 7n6.-                         #
							#       If used please give credit or I will break your server Kappa.       #
							#                  (But seriously don't remove credits...)                  #
							*###########################################################################*
	

	
	
	
*******************************************************************************************************************************	
###############################################################################################################################
*******************************************************************************************************************************		
	Installation:
		1) Change VIP.SavePath to your desired save path.
		2) Change VIP.State to the state you wish to add to a VIP player
		3) Add lines to iteminfo
			eg:
				8967	VIP 10 Seconds	n1216	10130016	0	0	0	0	0	0	31	0	0	0	0	0	1	1	1	1	1	0	200	-1,-2,-2,-2	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0	0,0	0,0	0	0	0	0	0	0	0	0	0	AddVIP	0	0	0	0,0	0	0	Use to get VIP
				8968	VIP 1 Day	n1216	10130016	0	0	0	0	0	0	31	0	0	0	0	0	1	1	1	1	1	0	200	-1,-2,-2,-2	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0	0,0	0,0	0	0	0	0	0	0	0	0	0	AddVIP	0	0	0	0,0	0	0	Use to get VIP
				8969	VIP 7 Days	n1216	10130016	0	0	0	0	0	0	31	0	0	0	0	0	1	1	1	1	1	0	200	-1,-2,-2,-2	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0	0,0	0,0	0	0	0	0	0	0	0	0	0	AddVIP	0	0	0	0,0	0	0	Use to get VIP
		4) Adjust VIP.Items to have the ID of the item as the index, and the time in seconds that the item will add upon use as the value
			eg : 
				[8967] = 10,
			Means item 8967 will add 10 seconds to VIP.
		5) Load this file with DoFile()
*******************************************************************************************************************************	
###############################################################################################################################
*******************************************************************************************************************************	


]]
--Create VIP object
VIP = {}
--Declare save path
VIP.SavePath = GetResPath("script/New Extension/Data/VIP.txt")
--State to add to VIP players
VIP.State = 234
--Items to add VIP
--[8967] = 10  : means item 8967 when used gives VIP for 10 seconds
VIP.Items = {
	[8967] = 10,
	[8968] = (60 * 60 * 24),
	[8969] = (7 * 60 * 60 * 24),
}

--Function to create the savefile upon first load
function VIP.Initial(file)
	Table = io.open(file,"r")
	if Table~=nil then 
		io.close(Table) 
	else 
		table.save({},file,"w")
	end
end
VIP.Initial(VIP.SavePath)

--Item function to add to the VIP time.
--If you use a vip item while already vip, it adds to your vip time
function AddVIP(role,Item)
	local PID = GetRoleID(role)
	local ID = GetItemID(Item)
	local Time = VIP.Items[ID]
	local data = table.load(VIP.SavePath,"r")
	if Time ~= nil then
		if VIP.CheckVIP(role) == false then
			data[PID] = VIP.SystemTimeNow()
		end
		data[PID] = data[PID] + Time
	end
	table.save(data,VIP.SavePath,"w")
	AttrRecheck(role)
end

--Function returns true if user is currently vip, false if they are not
function VIP.CheckVIP(role)
	local data = table.load(VIP.SavePath,"r")
	local PID = GetRoleID(role)
	if data[PID] == nil or data[PID] <= VIP.SystemTimeNow() then
		return false
	else
		return true
	end
end

--Hooked on AttrRecheck, so will check each time players stats update
function VIP.AddState(role)
	if VIP.CheckVIP(role) == true then
		AddState(role,role,VIP.State,1,0)
	else
		if GetChaStateLv ( role , VIP.State ) > 0 then
			RemoveState ( role ,  VIP.State )
		end
	end
end

--Returns systemtime in seconds.
function VIP.SystemTimeNow()
	local TimeNow = os.date("*t")
	local Value = os.time{day = TimeNow.day ,month = TimeNow.month,year = TimeNow.year,hour = TimeNow.hour, min = TimeNow.min,sec = TimeNow.sec}
	return Value 
end

Hook:AddPreHook("AttrRecheck",VIP.AddState)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Chat

Chat

Please enter your display name

×
×
  • Create New...