• 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!

Lua [TFS 0.X] Send player to temple after VIP expires

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Good morning people, everything fine?

I'm trying to create a creaturescript that validates the player's VIP time (onLogin), if the time has expired, it sends the player to the temple of TownID 1. Could you help me to create this script? Below are the functions to validate my VIP system.

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if query:getID() == -1 then
    return func("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. getPlayerAccountId(cid) ..", ".. key ..", ".. value ..")")
  end
  return func("UPDATE `account_storage` SET `value` = ".. value .." WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
end

function isVIP(cid)
  return getAccountVIP(cid) > 0
end

function getAccountVIP(cid)
  return (getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() > 0) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() or 0
end

function setAccountVIP(cid, days)
  return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (60 * 60 * 24 * days) + (getAccountVIP(cid) > 0 and  getAccountVIP(cid) or 0))
end

Something like this:

Lua:
function onLogin(cid)
if isVIP(cid) == false then
    doTeleportThing(cid, TownID1)
    return true
end

Its not working.
 
Last edited:
Solution
Have an ideia, but still not working, no errors in console:

XML:
    <creatureevent type="login" name="vipover" event="script" value="vipover.lua"/>
Lua:
function onLogin(cid)
    if isVIP(cid) == true then
        setPlayerStorageValue(cid, 830009, 1)
    elseif getPlayerStorageValue(cid, 830009) > 0 and isVIP(cid) == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
        setPlayerStorageValue(cid, 830009, -1)
        doTeleportThing(cid, getTownTemplePosition(TownID1))
        doPlayerSetTown(cid, 1)
    end
    return true
end
Post automatically merged:

nvm, works in this way:

Lua:
function onLogin(cid)
pos = {x=160, y=54, z=7}...
My only suggestion:

Your functions are fine, I just cut them down a bit to make them look prettier.
Lua:
function getAccountVIP(cid)
    return math.max(0, getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time())
end

function setAccountVIP(cid, days)
    return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (days * 86400) + getAccountVIP(cid))
end

Respect to login, maybe:
Lua:
function onLogin(cid)
    if not isVIP(cid) then
        doTeleportThing(cid, getTownTemplePosition(TownID1))
    end
    return true
end
 
My only suggestion:

Your functions are fine, I just cut them down a bit to make them look prettier.
Lua:
function getAccountVIP(cid)
    return math.max(0, getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time())
end

function setAccountVIP(cid, days)
    return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (days * 86400) + getAccountVIP(cid))
end

Respect to login, maybe:
Lua:
function onLogin(cid)
    if not isVIP(cid) then
        doTeleportThing(cid, getTownTemplePosition(TownID1))
    end
    return true
end
A problem came to my mind that I hadn't realized yet: if I do this, everyone who is not a VIP will be teleported to the temple when they relog, which would be bad. Is there any way to put a validator, where only the player who was VIP and now is no longer teleported? And one time?
 
Have an ideia, but still not working, no errors in console:

XML:
    <creatureevent type="login" name="vipover" event="script" value="vipover.lua"/>
Lua:
function onLogin(cid)
    if isVIP(cid) == true then
        setPlayerStorageValue(cid, 830009, 1)
    elseif getPlayerStorageValue(cid, 830009) > 0 and isVIP(cid) == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
        setPlayerStorageValue(cid, 830009, -1)
        doTeleportThing(cid, getTownTemplePosition(TownID1))
        doPlayerSetTown(cid, 1)
    end
    return true
end
Post automatically merged:

nvm, works in this way:

Lua:
function onLogin(cid)
pos = {x=160, y=54, z=7}
    if isVIP(cid) == true then
        setPlayerStorageValue(cid, 830009, 1)
    elseif getPlayerStorageValue(cid, 830009) > 0 and isVIP(cid) == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
        setPlayerStorageValue(cid, 830009, -1)
        doTeleportThing(cid,pos)
        doPlayerSetTown(cid,1)
    end
    return true
end
 
Last edited:
Have an ideia, but still not working, no errors in console:

XML:
    <creatureevent type="login" name="vipover" event="script" value="vipover.lua"/>
Lua:
function onLogin(cid)
    if isVIP(cid) == true then
        setPlayerStorageValue(cid, 830009, 1)
    elseif getPlayerStorageValue(cid, 830009) > 0 and isVIP(cid) == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
        setPlayerStorageValue(cid, 830009, -1)
        doTeleportThing(cid, getTownTemplePosition(TownID1))
        doPlayerSetTown(cid, 1)
    end
    return true
end
Post automatically merged:

nvm, works in this way:

Lua:
function onLogin(cid)
pos = {x=160, y=54, z=7}
    if isVIP(cid) == true then
        setPlayerStorageValue(cid, 830009, 1)
    elseif getPlayerStorageValue(cid, 830009) > 0 and isVIP(cid) == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
        setPlayerStorageValue(cid, 830009, -1)
        doTeleportThing(cid,pos)
        doPlayerSetTown(cid,1)
    end
    return true
end
A cleaner way.

Lua:
function onLogin(cid)
    if not isVIP(cid) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) ~= -1 then
        setAccountStorage(cid, VIP_ACCOUNT_STORAGE, -1)
        doPlayerSetTown(cid, 1)
        doTeleportThing(cid, getTownTemplePosition(1))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
    end
    return true
end
 
Solution
A cleaner way.

Lua:
function onLogin(cid)
    if not isVIP(cid) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) ~= -1 then
        setAccountStorage(cid, VIP_ACCOUNT_STORAGE, -1)
        doPlayerSetTown(cid, 1)
        doTeleportThing(cid, getTownTemplePosition(1))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your VIP time is over, renew to continue enjoying all the VIP benefits.")
    end
    return true
end
Thanks Xiki.
 
Back
Top