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

TFS 0.X infinite premium account untill the player is logged in

dragon1155

Member
Joined
Mar 5, 2010
Messages
128
Reaction score
5
Hi, ive been struggling with this for hours. My project is based on a premium account, so the problem is that as long as the player is online the premium account does not expire. Ive tried diffrent functions, but it doesnt change anything - the player has to relog to update his premium account status.
This is a big problem because I have many NPCs that use the
Lua:
getPlayerPremiumDays
or
Lua:
isPremium
functions, plus some spells is premium only.
i tried doing something with the
Lua:
doRemoveCreature(cid)
but its doesnt work. maybe I just don't know how to do it.
i added this code to login.lua, and it works fine, but it does not solve the main problem, it only prevents you from staying in the premium zone:

if isPremium(cid) then
setPlayerStorageValue(cid, 10203, 1)
elseif ((getPlayerStorageValue(cid, 10203)) == 1) then
setPlayerStorageValue(cid, 10203, 0)
doTeleportThing(cid, config.templePosition, true)
doPlayerSetTown(cid, 1)
doSendMagicEffect(getCreaturePosition(cid), 10)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your premium account has expired.")
end
TFS 0.4 protocol 8.6. Any ideas? Thank you in advance for help
 
Hi, ive been struggling with this for hours. My project is based on a premium account, so the problem is that as long as the player is online the premium account does not expire. Ive tried diffrent functions, but it doesnt change anything - the player has to relog to update his premium account status.
This is a big problem because I have many NPCs that use the
Lua:
getPlayerPremiumDays
or
Lua:
isPremium
functions, plus some spells is premium only.
i tried doing something with the
Lua:
doRemoveCreature(cid)
but its doesnt work. maybe I just don't know how to do it.
i added this code to login.lua, and it works fine, but it does not solve the main problem, it only prevents you from staying in the premium zone:


TFS 0.4 protocol 8.6. Any ideas? Thank you in advance for help
//doRemoveCreature(cid[, forceLogout = true])

after doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your premium account has expired.")
put doRemoveCreature(cid, true)
 
Like i said, i tried but it didnt help :/ The player does not log out when premium ends,, but if he logs out/logs in on his own, this error appears in the console:
Code:
[18:22:11.949] [Error - CreatureScript Interface]
[18:22:11.953] data/creaturescripts/scripts/login.lua:onLogin
[18:22:11.956] Description:
[18:22:11.958] (LuaInterface::luaDoRemoveCreature) Creature not found

edit:
this eliminated this error, but it does not change the fact that when the premium expires, the player still has it until he logs out (the function does not seem to work and nothing happens when the premium expires)

Lua:
if isPremium(cid) then
setPlayerStorageValue(cid, 10203, 1)
elseif ((getPlayerStorageValue(cid, 10203)) == 1) then
setPlayerStorageValue(cid, 10203, 0)
doTeleportThing(cid, config.templePosition, true)
doPlayerSetTown(cid, 1)
doSendMagicEffect(getCreaturePosition(cid), 10)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your premium account has expired.")
    elseif isPlayer(cid) == TRUE then
        doRemoveCreature(cid, true)
    end
 
Last edited:
you should instead compare it with os.time with like onThink function instead of the storage value. after logging in you could query that every 60 seconds or 15 minutes or player save within some time.
i discovered using globalevents that premium days are removed even if the player is online, so i guess checking if a player has premium wont help, because if he has 0 days and is logged in he can still use premium privileges. maybe some random logging out the player once a day? or a global server restart once a day? idk :l
 
well as I mentioned you can query them at player save by checking the os.time with storage like an exhaustion. but definately server restart once a day is way to go all you have to do is setup globalevent for time and do GAMESTATE_CLOSED and delay maybe clean map and GAMESTATE_OPEN this will relog eevery character present.
 
well as I mentioned you can query them at player save by checking the os.time with storage like an exhaustion. but definately server restart once a day is way to go all you have to do is setup globalevent for time and do GAMESTATE_CLOSED and delay maybe clean map and GAMESTATE_OPEN this will relog eevery character present.
i tried doing it the way you mentioned but it didnt work. I probably did something wrong and gave up, finally made a simple script to close the gameworld and reopen it after a minute (with map clean and save) and it actually does its job ;p
 
i realized that this solution would be the best because it is related to one more very important thing: the house also has to be removed when the premium ends and the player has to relog

Code:
globalevents\scripts\closeopen.lua

Lua:
local timetoclosee = 10




function onTime()
return prepareShutdown(math.abs(math.ceil(timetoclosee)))
end




function prepareShutdown(minutes)
if(minutes <= 0) then
addEvent(global, 10*1000)
addEvent(executeClean, 10*3000)
addEvent(open, 10*6000)
return false
end




if(minutes == 1) then
doBroadcastMessage("Server is going down in " .. minutes .. " minute, please log out now. You will be able to log in again within a minute.")
elseif(minutes <= 3) then
doBroadcastMessage("Server is going down in " .. minutes .. " minutes, please log out.")
else
doBroadcastMessage("Server is going down in " .. minutes .. " minutes.")
end




shutdownEvent = addEvent(prepareShutdown, 60000, minutes - 1)
return true
end




function global()
    doSetGameState(GAMESTATE_CLOSED)
end




function executeClean()
    doCleanMap()
end




function open()
    doSetGameState(GAMESTATE_NORMAL)
end

btw, i also have a small problem with houses, but maybe I will create another thread for this

@edit: however, the problem was trivial, i just forgot to add a function that checks is the player has a house. with this globalevent above, this script works very well. I'll post it in case someone needs it:

creaturescripts.xml
Lua:
<event type="login" name="PremiumCheck" event="script" value="premiumcheck.lua"/>

Lua:
function onLogin(cid)
local pos = {x = 1002, y = 999, z = 7}
local storage = 10203
local house = getHouseByPlayerGUID(getPlayerGUID(cid))


   if getPlayerStorageValue(cid, storage) <= 0 and getPlayerPremiumDays(cid) >= 1 then
      setPlayerStorageValue(cid, storage, 1)
   end


   if getPlayerPremiumDays(cid) >= 1 then
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have "..getPlayerPremiumDays(cid).." days of premium account left.")
   else
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have a premium account.")
   end
 
   if getPlayerStorageValue(cid, storage) >= 1 and getPlayerPremiumDays(cid) <= 0 then
      doTeleportThing(cid, pos)
      doPlayerSendTextMessage(cid, 25, "Your premium account has expired.")
      setPlayerStorageValue(cid, storage, -1)
      doSendMagicEffect(getPlayerPosition(cid), 10)
      end
     
      if getPlayerStorageValue(cid, storage) >= -1 and getPlayerPremiumDays(cid) <= 0 and getHouseByPlayerGUID(getPlayerGUID(cid)) then
      setHouseOwner(house, 0)
   end
 return true
end

i guess the premium case can be considered completely finished, but i dont know how to mark the post as a solution xD
btw2: if anything can be improved, please give me suggestions ;p
 
Last edited:

Similar threads

Back
Top