• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Simple VIP system

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
219
Location
Sweden
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:
I thought you ceased to release your scripts?

Anyway, nice work.
 
thank for releasing is, but i get a error in my ot, is 0.3.2

Code:
[23/03/2009 17:25:42] Lua Script Error: [CreatureScript Interface] 
[23/03/2009 17:25:42] data/creaturescripts/scripts/login.lua:onLogin

[23/03/2009 17:25:42] luaGetPlayerStorageValue(). Player not found

[23/03/2009 17:25:42] Lua Script Error: [CreatureScript Interface] 
[23/03/2009 17:25:42] data/creaturescripts/scripts/login.lua:onLogin

[23/03/2009 17:25:42] luaSetPlayerStorageValue(). Player not found

and my onLogin Script are:

PHP:
function onLogin(cid)
	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		for i = PLAYERLOSS_EXPERIENCE, PLAYERLOSS_ITEMS do
			doPlayerSetLossPercent(cid, i, loss)
		end
	end

	local isVIP = getPlayerVIPTime(cid)
	local vipDays = getPlayerVIPDays(cid)
	if isVIP >= 1 then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You Have: " ..vipDays.. " left.")
		doPlayerUpdateVIPTime(cid)
		else
			doPlayerUpdateVIPTime(cid)
	return TRUE
end
	
	registerCreatureEvent(cid, "Mail")
	registerCreatureEvent(cid, "GuildMotd")
	registerCreatureEvent(cid, "PlayerDeath")
	doPlayerUpdateLastLogin(cid)
	return TRUE
end
 
All bugs fixed. Please re-copy the functions.

Here's fix of your code:
Code:
    local vipDays = getPlayerVIPDays(cid)
    if vipDays >= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You Have: " ..vipDays.. " left.")
        doPlayerUpdateVIPTime(cid)
    end

You must ALWAYS update last login. And now you are returning TRUE so it won't update the last login. Simply remove the else (as I did for you).
 
Last edited:
Updated few functions and added how exactly you should implent this system. I will later give you the ability to choose whether you want it to be for a whole account or for a single player.


I thought you ceased to release your scripts?

Anyway, nice work.

Yes indeed, but I do like releasing functions/systems :)
 
Last edited:
i make this simple script for test the days and give me the same error of onLogin

PHP:
function onSay(cid, words, param)
	doPlayerAddVIPDays(cid, 30)
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "VIp Funcionando")
	return TRUE
end

is for "return TRUE"???
 
Well I updated the functions before so it should work if you just re-copy them as I said.
 
Back
Top