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

Error Script | Premium_Ends_At - TFS 1.3

nanduzenho

Member
Joined
Mar 21, 2021
Messages
191
Solutions
1
Reaction score
16
GitHub
nanduzenho
Good morning, I don't know what else to do. My TFS 1.3 doesn't have the premium_ends_at function, so the script when the premium account ends doesn't work, I don't know what else to do. I tried this procedure but was unsuccessful. I would like your help, because without this script I cannot deliver premium to the player.

I opened other threads with other errors in an attempt to solve this one, but I got no response from the community. Please someone help me!

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
 
Solution
X
Can someone edit for me? The script is teleporting all players to the temple when logging in, accounts free and premium, it would only be the player who ended the premium, please!!!!!

LUA:
local TOWN_ID = 2

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

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

    if premDays and premDays > 0 then
        local town = Town(TOWN_ID)
        player:setTown(town)

        local templePosition = town:getTemplePosition()
        player:teleportTo(templePosition)...
I think you use premdays instead of premium_ends_at?
premium_ends_at stores the timestamp when premium expires, premdays stores remaining days of premium. So if premdays is 0, then you do not have premium.

LUA:
local TOWN_ID = 2

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

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

    if premDays and premDays > 0 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 think you use premdays instead of premium_ends_at?
premium_ends_at stores the timestamp when premium expires, premdays stores remaining days of premium. So if premdays is 0, then you do not have premium.

LUA:
local TOWN_ID = 2

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

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

    if premDays and premDays > 0 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
It worked, but the character goes back to the temple every time he relogs, the right thing would be just once
 
Then use a storage value to determine premium state and only trigger the code when the storage value mismatches with current state.
 
Can someone edit for me? The script is teleporting all players to the temple when logging in, accounts free and premium, it would only be the player who ended the premium, please!!!!!

LUA:
local TOWN_ID = 2

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

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

    if premDays and premDays > 0 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
 
Can someone edit for me? The script is teleporting all players to the temple when logging in, accounts free and premium, it would only be the player who ended the premium, please!!!!!

LUA:
local TOWN_ID = 2

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

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

    if premDays and premDays > 0 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
Adding a storage value, to know if the player town was reset previously, so that it only get's reset once.

LUA:
local premiumResetStorage = 45055
local TOWN_ID = 2

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

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

    -- no premium
    if premDays and premDays < 1 then
        -- if player's town has not been reset
        if player:getStorageValue(premiumResetStorage) ~= 1 then
            local town = Town(TOWN_ID)
            player:setTown(town)
            
            local templePosition = town:getTemplePosition()
            player:teleportTo(templePosition)
            templePosition:sendMagicEffect(CONST_ME_TELEPORT)
    
            player:setStorageValue(premiumResetStorage, 1)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
        end
        
    -- has premium
    elseif premDays and premDays > 0 then
        if player:getStorageValue(premiumResetStorage) ~= -1 then
            player:setStorageValue(premiumResetStorage, -1)
        end
    end

    return true
end
 
Last edited by a moderator:
Solution
Adding a storage value, to know if the player town was reset previously, so that it only get's reset once.

LUA:
local premiumResetStorage = 45055
local TOWN_ID = 2

function onLogin(cid)
    local player = Player(cid)
 
    local resultId = db.storeQuery("SELECT [ICODE]premdays[/ICODE] FROM [ICODE]accounts[/ICODE] WHERE [ICODE]id[/ICODE] = " .. player:getAccountId())

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

    -- no premium
    if premDays and premDays < 1 then
        -- if player's town has not been reset
        if player:getStorageValue(premiumResetStorage) ~= 1 then
            local town = Town(TOWN_ID)
            player:setTown(town)
          
            local templePosition = town:getTemplePosition()
            player:teleportTo(templePosition)
            templePosition:sendMagicEffect(CONST_ME_TELEPORT)
  
            player:setStorageValue(premiumResetStorage, 1)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
        end
      
    -- has premium
    elseif premDays and premDays > 0 then
        if player:getStorageValue(premiumResetStorage) ~= -1 then
            player:setStorageValue(premiumResetStorage, -1)
        end
    end

    return true
end/code]


I'll try!
 
Adding a storage value, to know if the player town was reset previously, so that it only get's reset once.

LUA:
local premiumResetStorage = 45055
local TOWN_ID = 2

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

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

    -- no premium
    if premDays and premDays < 1 then
        -- if player's town has not been reset
        if player:getStorageValue(premiumResetStorage) ~= 1 then
            local town = Town(TOWN_ID)
            player:setTown(town)
           
            local templePosition = town:getTemplePosition()
            player:teleportTo(templePosition)
            templePosition:sendMagicEffect(CONST_ME_TELEPORT)
   
            player:setStorageValue(premiumResetStorage, 1)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sua premium acabou!")
        end
       
    -- has premium
    elseif premDays and premDays > 0 then
        if player:getStorageValue(premiumResetStorage) ~= -1 then
            player:setStorageValue(premiumResetStorage, -1)
        end
    end

    return true
end
Could be possible to the same script add function to check if house is guild house too, when player loses premium and send items to the depot? And maybe a day before warn house owner or leader/guild members?
 
Back
Top