• 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 1.X+ automatic recognition from premium to free tfs 1.5 772

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
883
Solutions
7
Reaction score
123
Location
Brazil
YouTube
caruniawikibr
hi, I would like to know how do I configure the player when it is premium and free, and it relogs free, born in Thais for example. like in tibia global
 
Solution
You can try with this:

data/scripts/onlosspremium.lua
Lua:
local storage = 88888
local defaultCity = "Thais"

local creatureEvent = CreatureEvent("onLossPremium")

function creatureEvent.onLogin(player)
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, player:isPremium() and 1 or 0)
    end
    if player:getPremiumEndsAt() < os.time() then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local thais = Town(defaultCity)
            player:setTown(thais)
            local thaisPos = thais:getTemplePosition()...
You mean when premium ends then player gets teleported to Thais onLogin?
Something like this?
Lua:
if player:getPremiumEndsAt() < os.time() then
    local town = Town(Yourtownid)
    player:setTown(town)
    local templePosition = town:getTemplePosition()
    player:teleportTo(templePosition)
    templePosition:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
end
 
how do i add here?

Lua:
function onLogin(player)
    local serverName = configManager.getString(configKeys.SERVER_NAME)
    local loginStr = "Welcome to " .. serverName .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format("Your last visit in %s: %s.", serverName, os.date("%d %b %Y %X", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(PlayerStorageKeys.promotion)
        if value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end
    

    -- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    player:registerEvent("TasksOnKill")
    player:registerEvent("SvargrondArenaKill")
    return true
end
 
Lua:
function onLogin(player)
    local serverName = configManager.getString(configKeys.SERVER_NAME)
    local loginStr = "Welcome to " .. serverName .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr =
            string.format("Your last visit in %s: %s.", serverName, os.date("%d %b %Y %X", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(PlayerStorageKeys.promotion)
        if value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end
    if player:getPremiumEndsAt() < os.time() then
        local town = Town(Yourtownid)
        player:setTown(town)
        local templePosition = town:getTemplePosition()
        player:teleportTo(templePosition)
        templePosition:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
    end

    -- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    player:registerEvent("TasksOnKill")
    player:registerEvent("SvargrondArenaKill")
    return true
end
 
You mean when premium ends then player gets teleported to Thais onLogin?
Something like this?
Lua:
if player:getPremiumEndsAt() < os.time() then
    local town = Town(Yourtownid)
    player:setTown(town)
    local templePosition = town:getTemplePosition()
    player:teleportTo(templePosition)
    templePosition:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
end
The problem is: the player will be teleported everytime he login or no?

You need to set a storage to know if the player already has the town set or not like

If playerstorage ~= 1 and premiumtimend < time_now then
setstorage(1)
 
The problem is: the player will be teleported everytime he login or no?
I think he'll get teleported every time he login as long as he is not premium.
Can't think of any other way to do it, Maybe setting a storage and check if player doesn't have it then teleport him?
@bpm91 If he got teleported every time then add this
Lua:
player:setStorageValue(yourstoragehere, 1)
and change this from
Lua:
if player:getPremiumEndsAt() < os.time() then
to
Lua:
if player:getPremiumEndsAt() < os.time() and player:getStorageValue(yourstoragehere) ~= 1 then
But then you'll have to remove the storage when player buys premium in your NPC, Talkaction, Action or any other script the player is able to obtain premium through, Using something like this.
Lua:
player:setStorageValue(yourstoragehere, -1)
 
Last edited:
I think he'll get teleported every time he login as long as he is not premium.
Can't think of any other way to do it, Maybe setting a storage and check if player doesn't have it then teleport him?
@bpm91 If he got teleported every time then add this
Lua:
player:setStorageValue(yourstoragehere, 1)
and change this from
Lua:
if player:getPremiumEndsAt() < os.time() then
to
Lua:
if player:getPremiumEndsAt() < os.time() and player:getStorageValue(yourstoragehere) ~= 1 then
But then you'll have to remove the storage when player buys premium in your NPC, Talkaction, Action or any other script the player is able to obtain premium through, Using something like this.
Lua:
player:setStorageValue(yourstoragehere, -1)
Simple add another storage while the player is premium, like:
If premiumtime > time_now and playerstorage ~= 0 then
Setstorage(0)

Remember to use the same storageid in "player is premium" and "player is free", changing only the value
 
You can try with this:

data/scripts/onlosspremium.lua
Lua:
local storage = 88888
local defaultCity = "Thais"

local creatureEvent = CreatureEvent("onLossPremium")

function creatureEvent.onLogin(player)
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, player:isPremium() and 1 or 0)
    end
    if player:getPremiumEndsAt() < os.time() then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local thais = Town(defaultCity)
            player:setTown(thais)
            local thaisPos = thais:getTemplePosition()
            player:teleportTo(thaisPos)
            thaisPos:sendMagicEffect(CONST_ME_TELEPORT)
        end
    elseif player:getStorageValue(storage) == 0 then
        player:setStorageValue(storage, 1)
    end
    return true
end

creatureEvent:register()
 
Solution
You can try with this:

data/scripts/onlosspremium.lua
Lua:
local storage = 88888
local defaultCity = "Thais"

local creatureEvent = CreatureEvent("onLossPremium")

function creatureEvent.onLogin(player)
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, player:isPremium() and 1 or 0)
    end
    if player:getPremiumEndsAt() < os.time() then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local thais = Town(defaultCity)
            player:setTown(thais)
            local thaisPos = thais:getTemplePosition()
            player:teleportTo(thaisPos)
            thaisPos:sendMagicEffect(CONST_ME_TELEPORT)
        end
    elseif player:getStorageValue(storage) == 0 then
        player:setStorageValue(storage, 1)
    end
    return true
end

creatureEvent:register()
Thinking about non-vocations(rookgaard), can you change to work only if player has a vocation? Or even to teleport non-vocations to rookgaard temple and pvocations to Thais.

Anyway, thanks for your help and work.
 
You can try with this:

data/scripts/onlosspremium.lua
Lua:
local storage = 88888
local defaultCity = "Thais"

local creatureEvent = CreatureEvent("onLossPremium")

function creatureEvent.onLogin(player)
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, player:isPremium() and 1 or 0)
    end
    if player:getPremiumEndsAt() < os.time() then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local thais = Town(defaultCity)
            player:setTown(thais)
            local thaisPos = thais:getTemplePosition()
            player:teleportTo(thaisPos)
            thaisPos:sendMagicEffect(CONST_ME_TELEPORT)
        end
    elseif player:getStorageValue(storage) == 0 then
        player:setStorageValue(storage, 1)
    end
    return true
end

creatureEvent:register()

as the friend mentioned above, a premium player in rook would fall into thais without vocation. but how to solve this?
 
as the friend mentioned above, a premium player in rook would fall into thais without vocation. but how to solve this?

Lua:
local storage = 88888
local defaultCity = "Thais"

local creatureEvent = CreatureEvent("onLossPremium")
function creatureEvent.onLogin(player)
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, player:isPremium() and 1 or 0)
    end
    if player:getPremiumEndsAt() < os.time() then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local city = Town(player:getVocation():getId() ~= 0 and defaultCity or "Rookgard")
            player:setTown(city)
            local cityPos = city:getTemplePosition()
            player:teleportTo(cityPos)
            cityPos:sendMagicEffect(CONST_ME_TELEPORT)
        end
    elseif player:getStorageValue(storage) == 0 then
        player:setStorageValue(storage, 1)
    end
    return true
end

creatureEvent:register()
 
WOrk 100% ty tyty ty <3

Is it possible to set an outfit free account? for example, if it's a man, the outfit is 130, if it's a woman, the outfit is 138.
so when the person leaves the premium pro free he will be born with free account clothes
 
Last edited:
Lua:
local storage = 88888
local defaultCity = "Thais"
local noVocationCity = "Rookgaard"
local defaultOutfit = {138, 130}

local creatureEvent = CreatureEvent("onLossPremium")

function creatureEvent.onLogin(player)
    if configManager.getBoolean(configKeys.FREE_PREMIUM) or player:hasFlag(PlayerFlag_IsAlwaysPremium) then
        return true
    end

    local isPremium = player:getPremiumEndsAt() >= os.time()
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, isPremium and 1 or 0)
    end
    if not isPremium then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local town = Town(player:getVocation():getId() ~= 0 and defaultCity or noVocationCity)
            player:setTown(town)
            local townPos = town:getTemplePosition()
            player:teleportTo(townPos)
            townPos:sendMagicEffect(CONST_ME_TELEPORT)
            local outfit = player:getOutfit()
            outfit.lookType = defaultOutfit[player:getSex()]
            player:setOutfit(outfit)
        end
    elseif player:getStorageValue(storage) == 0 then
        player:setStorageValue(storage, 1)
    end
    return true
end

creatureEvent:register()
 
Lua:
local storage = 88888
local defaultCity = "Thais"
local noVocationCity = "Rookgaard"
local defaultOutfit = {138, 130}

local creatureEvent = CreatureEvent("onLossPremium")

function creatureEvent.onLogin(player)
    if configManager.getBoolean(configKeys.FREE_PREMIUM) or player:hasFlag(PlayerFlag_IsAlwaysPremium) then
        return true
    end

    local isPremium = player:getPremiumEndsAt() >= os.time()
    if player:getStorageValue(storage) == -1 then
        player:setStorageValue(storage, isPremium and 1 or 0)
    end
    if not isPremium then
        if player:getStorageValue(storage) == 1 then
            player:setStorageValue(storage, 0)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your premium time has expired.")
            local town = Town(player:getVocation():getId() ~= 0 and defaultCity or noVocationCity)
            player:setTown(town)
            local townPos = town:getTemplePosition()
            player:teleportTo(townPos)
            townPos:sendMagicEffect(CONST_ME_TELEPORT)
            local outfit = player:getOutfit()
            outfit.lookType = defaultOutfit[player:getSex()]
            player:setOutfit(outfit)
        end
    elseif player:getStorageValue(storage) == 0 then
        player:setStorageValue(storage, 1)
    end
    return true
end

creatureEvent:register()
tytyty @Sarah Wesker this part of the outfit he takes the original gender of the character and sends it? or do I need to say "if it's male or if it's female, change to x outfit?
 
Last edited:
@Diarreamental
Tested in TFS 1.5 Nekiro 7.72

In player.cpp (look for death), before
C:
 //PASTE CODE HEREEEEEEEEEEEEEEEEEEEEEE <<<<<<<<<<<<<<
   } else {
        setSkillLoss(true);

Paste this code, where I write to do above:
C:
        // Teleport players from mainland back to rookgaard
        if (g_config.getBoolean(ConfigManager::GLOBAL_ROOKSYSTEM)) {
            if (vocation->getId() != VOCATION_NONE && level <= static_cast<uint32_t>(g_config.getNumber(ConfigManager::ROOKGAARD_LEVEL_THRESHOLD))) {
                Town* rookTown = g_game.map.towns.getTown(g_config.getNumber(ConfigManager::ROOKGAARD_TOWN));
                if (rookTown) {
                    // Restart stats
                    level = 1;
                    experience = 0;
                    levelPercent = 0;
                    capacity = 40000; //400oz
                    health = 150;
                    healthMax = 150;
                    mana = 0;
                    manaMax = 0;
                    magLevel = 0;
                    magLevelPercent = 0;
                    manaSpent = 0;
                    setVocation(0);

                    // Restart skills
                    for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { //for each skill
                        skills[i].level = 10;
                        skills[i].tries = 0;
                        skills[i].percent = 0;
                    }

                    // Restart town
                    setTown(rookTown);
                    loginPosition = getTemplePosition();

                    // Restart first items
                    addStorageValue(30017, 1);

                    // Restart items
                    for (int32_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; slot++)
                    {
                        Item* item = inventory[slot];
                        if (item) {
                            g_game.internalRemoveItem(item, item->getItemCount());
                        }
                    }
                } else {
                    std::cout << "[Warning - Player:death] Rookgaard teletransportation is enabled, rookgaard town does not exist." << std::endl;
                }
            }
        }


in configmanager.cpp:
after:
C:
boolean[PLAYER_CONSOLE_LOGS] = getGlobalBoolean(L, "showPlayerLogInConsole", true);
Paste:
C:
    boolean[GLOBAL_ROOKSYSTEM] = getGlobalBoolean(L, "rookSystem", false); /*Enable rookgaard system*/

after:
C:
    integer[DEPOT_PREMIUM_LIMIT] = getGlobalNumber(L, "depotPremiumLimit", 10000);
Paste:
C:
    integer[ROOKGAARD_TOWN] = getGlobalNumber(L, "rookTown", 1); /*Rook town id */
    integer[ROOKGAARD_LEVEL_THRESHOLD] = getGlobalNumber(L, "levelToRook", 5); /*level to be teleported back to rook */


in configmanager.h:
after:
C:
PLAYER_CONSOLE_LOGS,
Paste:
C:
GLOBAL_ROOKSYSTEM, /*Rooksystem*/

after:
C:
            IP_NUM,
Paste:
C:
            ROOKGAARD_LEVEL_THRESHOLD, /*Level to rook */
            ROOKGAARD_TOWN, /*rookgaard town */


in config.lua, paste:
Lua:
rookSystem = true
rookTown = 1
levelToRook = 5


in firstitems.lua in creaturescripts.
where is:
Lua:
    if player:getLastLoginSaved() == 0 then

change to:
Lua:
    if player:getLastLoginSaved() == 0 or player:getStorageValue(30017) == 1 then
        player:setStorageValue(30017, 0) -- reset storage for first items


Compile and test
 
Last edited:
Back
Top