Lua:
function getPlayerLastLogin(cid)
local lastLogin = getPlayerStorageValue(cid, 45345)
if(lastLogin < 0) then
doPlayerUpdateLastLogin(cid)
return os.time()
end
return lastLogin
end
function doPlayerUpdateLastLogin(cid)
setPlayerStorageValue(cid, 45345, os.time())
end
function getPlayerVIPTime(cid)
local VIPTime = getPlayerStorageValue(cid, 3434)
if(VIPTime < 0) then
setPlayerStorageValue(cid, 3434, 0)
return 0
end
return VIPTime
end
function getPlayerVIPDays(cid)
return math.ceil(getPlayerVIPTime(cid) / (24 * 60 * 60))
end
function doPlayerAddVIPTime(cid, addTime)
setPlayerStorageValue(cid, 3434, math.max(0, getPlayerVIPTime(cid) + addTime))
end
function doPlayerAddVIPDays(cid, days)
doPlayerAddVIPTime(cid, days * 24 * 60 * 60)
end
function doPlayerUpdateVIPTime(cid)
if(getPlayerVIPTime(cid) > 0) then
local delta = os.time() - getPlayerLastLogin(cid)
doPlayerAddVIPTime(cid, -delta)
return TRUE
end
return FALSE
end
Now you will put in BOTTOM of login.lua this code:
Lua:
doPlayerUpdateLastLogin(cid)
And somewhere (maybe top, but not below above code) in login.lua place this:
Lua:
doPlayerUpdateVIPTime(cid) -- Returns TRUE if any time was removed (if he had any VIP), FALSE otherwise.
Example of login.lua:
Lua:
function onLogin(cid)
if(doPlayerUpdateVIPTime(cid) == TRUE) then
local VIPDays = getPlayerVIPDays(cid)
if(VIPDays > 0) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have " .. VIPDays .. " days of VIP left.")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your VIP time has expired.")
end
end
doPlayerUpdateLastLogin(cid) -- This MUST be below doPlayerUpdateVIPTime. Otherwise it will not update VIP time properly.
end
Then u have these function u can use:
Lua:
doPlayerAddVIPDays(cid, days) -- example doPlayerAddVIPDays(cid, 10) add 10 days to player...
getPlayerVIPDays(cid) -- this return how many DAYS he have...
-- ALSO u can use time, to add seconds of VIP...
doPlayerAddVIPTime(cid, time) -- example doPlayerAddVIPTime(cid, 5 * 60 * 60) this add 5 hour VIP...
getPlayerVIPTime(cid) -- this tell how many VIP time in SECONDS not days player have.
You can also make a global event set to like each minute and it will remove 1 minute of the time using:
Lua:
function onThink(interval)
for _, cid in ipairs(getPlayersOnline()) do
doPlayerAddVIPTime(cid, -interval) -- "interval" is a parameter for onThink globalevent, so it should automatically remove 60 seconds.
end
return TRUE
end
Last edited: