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

Send player to temple when pacc ends for tfs 1.1

You need three creature scripts for this system. Global variable can be moved to data/global.lua if it's needed. Also, login and logout events can be merged with default versions of it.

Here is list of creature scripts (you have to create file for it in correct place and add records to data/creaturescripts/creaturescripts.xml).
  • login event
Code:
if lastPremiumStatus == nil then
    lastPremiumStatus = {}
end

function onLogin(player)
    lastPremiumStatus[player:getId()] = player:isPremium()

    player:registerEvent("{{think-event-name}}")
    return true
end
  • logout event
Code:
function onLogout(player)
    local playerId = player:getId()
    if lastPremiumStatus[playerId] ~= nil then
        lastPremiumStatus[playerId] = nil
    end
    return true
end
  • think event
Code:
function onThink(creature, interval)
    local player = creature:getPlayer()
    if not player then
        return
    end

    local playerId = player:getId()
    local status = player:isPremium()
    if lastPremiumStatus[playerId] and not status then
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:teleportTo(player:getTown():getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    end
    lastPremiumStatus[playerId] = status
end
 
@oddake, nice job. But the global table i did not understand why you created it.

What i've done, is check if the premium day is the last day. Then we add the premium check think event. Instead of checking everyday, when the player still have e.x 30 days prem.


Add this inside login.lua:
Code:
    if player:getPremiumDays() == 1 then
        player:registerEvent("PremiumCheck")
    end

Go inside creaturescripts.xml and paste this line:
Code:
<event type="think" name="CheckPremium" script="checkPremium.lua" />

Now create a new lua and name it "checkPremium" and paste the code below:
Code:
function onThink(player, interval)
    if player:isPremium() then
        return true
    end
   
    local position = player:getTown():getTemplePosition()
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
    player:unregisterEvent("CheckPremium")
end
 
why not check it with onlogin? there is really no need to check it with onthink (besides being resource intensive) and I think it is useless since the premium status only gets updated when logging in/out (at least it is like that in rl tibia)
 
We have to check while player is online. Since the player can login when it's mby 10min prem left.

Also the code i made should not be resource intensive, since it check the last day of prem.
 
Back
Top