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

Premium ended Return to temple and become resident city TFS 1.3

nanduzenho

Member
Joined
Mar 21, 2021
Messages
187
Solutions
1
Reaction score
15
GitHub
nanduzenho
Good morning, anyone know why it's not working?

Lua:
local STORAGE_PREMIUM = PremiumDays
local TEMPLE_ID = 2

function onLogin(cid)
    local player = Player(cid)

    if player:getPremiumDays() < 1 and player:getStorageValue(PremiumDays) > 0 then
        player:setStorageValue(PremiumDays, 0)
        player:teleportTo(Town(TEMPLE_ID):getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:setTown(TEMPLE_ID)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
    end

    return true
end
 
Probably this
Lua:
local STORAGE_PREMIUM = PremiumDays
Unless you have PremiumDays specified somewhere you are calling a nil value there.
Also you aren't even using STORAGE_PREMIUM in your code.

Find out what the storage value for premium days and do
Lua:
local PremiumDays = 1111
Change 1111 for whatever your storage value for premium days is.
 
Probably this
Lua:
local STORAGE_PREMIUM = PremiumDays
Unless you have PremiumDays specified somewhere you are calling a nil value there.
Also you aren't even using STORAGE_PREMIUM in your code.

Find out what the storage value for premium days and do
Lua:
local PremiumDays = 1111
Change 1111 for whatever your storage value for premium days is.
setTown(TEMPLE_ID) doesn't work either
 
Probably this
Lua:
local STORAGE_PREMIUM = PremiumDays
Unless you have PremiumDays specified somewhere you are calling a nil value there.
Also you aren't even using STORAGE_PREMIUM in your code.

Find out what the storage value for premium days and do
Lua:
local PremiumDays = 1111
Change 1111 for whatever your storage value for premium days is.
Dont work =/
 
My server is getPremDays
If your function is 'getPremDays' then you're not using TFS 1.3. So if you want accurate help you should find out what server you're actually using.

Also when you write this, you should keep in mind that if a player has already logged in once before since losing premium, we should not keep teleporting them to the free account temple every login. We should compare last premium day timestamp with last logout timestamp and determine that way if they should be teleported or not.

That said you can try this, its untested and not even sure if the function/database variables are right but it'll hopefully get you on the right track. If it doesnt work check for errors because the database variables might throw some.

Lua:
local TOWN_ID = 2

function onLogin(cid)
    local player = Player(cid)
  
    local resultId = db.storeQuery("SELECT `premium_ends_at` FROM `accounts` WHERE `id` = " .. player:getAccountId())

    local premiumEnd = false
    if resultId ~= false then
        premiumEnd = result.getNumber(resultId, "premium_ends_at")
        result.free(resultId)
    end

    if premiumEnd and (os.time() > premiumEnd) and (player:getLastLogout() < premiumEnd) then
        local town = Town(TOWN_ID) 
        player:setTown(town)

        local templePosition = town:getTemplePosition()
        player:teleportTo(templePosition)
        templePosition:sendMagicEffect(CONST_ME_TELEPORT)

        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
    end

    return true
end
 
If your function is 'getPremDays' then you're not using TFS 1.3. So if you want accurate help you should find out what server you're actually using.

Also when you write this, you should keep in mind that if a player has already logged in once before since losing premium, we should not keep teleporting them to the free account temple every login. We should compare last premium day timestamp with last logout timestamp and determine that way if they should be teleported or not.

That said you can try this, its untested and not even sure if the function/database variables are right but it'll hopefully get you on the right track. If it doesnt work check for errors because the database variables might throw some.

Lua:
local TOWN_ID = 2

function onLogin(cid)
    local player = Player(cid)
 
    local resultId = db.storeQuery("SELECT `premium_ends_at` FROM `accounts` WHERE `id` = " .. player:getAccountId())

    local premiumEnd = false
    if resultId ~= false then
        premiumEnd = result.getNumber(resultId, "premium_ends_at")
        result.free(resultId)
    end

    if premiumEnd and (os.time() > premiumEnd) and (player:getLastLogout() < premiumEnd) then
        local town = Town(TOWN_ID)
        player:setTown(town)

        local templePosition = town:getTemplePosition()
        player:teleportTo(templePosition)
        templePosition:sendMagicEffect(CONST_ME_TELEPORT)

        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
    end

    return true
end
I will test and then confirm if it worked, thank you bro
 
If your function is 'getPremDays' then you're not using TFS 1.3. So if you want accurate help you should find out what server you're actually using.

Also when you write this, you should keep in mind that if a player has already logged in once before since losing premium, we should not keep teleporting them to the free account temple every login. We should compare last premium day timestamp with last logout timestamp and determine that way if they should be teleported or not.

That said you can try this, its untested and not even sure if the function/database variables are right but it'll hopefully get you on the right track. If it doesnt work check for errors because the database variables might throw some.

Lua:
local TOWN_ID = 2

function onLogin(cid)
    local player = Player(cid)
 
    local resultId = db.storeQuery("SELECT `premium_ends_at` FROM `accounts` WHERE `id` = " .. player:getAccountId())

    local premiumEnd = false
    if resultId ~= false then
        premiumEnd = result.getNumber(resultId, "premium_ends_at")
        result.free(resultId)
    end

    if premiumEnd and (os.time() > premiumEnd) and (player:getLastLogout() < premiumEnd) then
        local town = Town(TOWN_ID)
        player:setTown(town)

        local templePosition = town:getTemplePosition()
        player:teleportTo(templePosition)
        templePosition:sendMagicEffect(CONST_ME_TELEPORT)

        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
    end

    return true
end
Didn't work, just like the other script, just nothing happens, I don't know what's wrong =/
 
This thread is confusing.

Lua:
if player:getPremiumEndsAt() < os.time() then
    print("Players' premium is ended.")
else
    print("Player still has premium.")
end
 
I don't know what's going on, the script just doesn't work, there's no error in .exe
So if nothing is printing to console, there are no errors.. then the script isn't being called at all.

That makes me believe that the login event is not registered to players.
 
My server is getPremDays
I mean after this response idk what to think, that's why I went with a query that can be interchanged with lastDay instead of premium_ends_at to work for tfs 1.2.

You didn't respond to what exact distribution you have, seems you didn't read my whole reply. No one is going to be able to help you until you help yourself man.
 
I mean after this response idk what to think, that's why I went with a query that can be interchanged with lastDay instead of premium_ends_at to work for tfs 1.2.

You didn't respond to what exact distribution you have, seems you didn't read my whole reply. No one is going to be able to help you until you help yourself man.
My server doesn't have the premium_ends_at function, do you have any solution for that?
 
Back
Top