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

Player rooked problem tfs1.2

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
151
Reaction score
9
when player loses his level 5 on mainland he is sent to rookgaard, with level 1 and all skills 10, all correctly

but my problem is with firstitems, he is not coming back with the firstitems again, I do not know why

My First Items.lua
Lua:
function onLogin(player)
    if player:getLastLoginSaved() <= 0 then
        -- Items
        if player:getSex() == PLAYERSEX_FEMALE then
            player:addItem(3562, 1, true, -1, CONST_SLOT_ARMOR)
        else
            player:addItem(3561, 1, true, -1, CONST_SLOT_ARMOR)
        end
        player:addItem(3270, 1, true, -1, CONST_SLOT_LEFT)
        player:addItem(2920, 1, true, -1, CONST_SLOT_RIGHT)
        
        local container = Game.createItem(2853, 1)
        container:addItem(3585, 1)
        
        player:addItemEx(container, true, CONST_SLOT_BACKPACK)
    
        -- Default Outfit
        if player:getSex() == PLAYERSEX_FEMALE then
            player:setOutfit({lookType = 136, lookHead = 78, lookBody = 68, lookLegs = 58, lookFeet = 95})
        else
            player:setOutfit({lookType = 128, lookHead = 78, lookBody = 68, lookLegs = 58, lookFeet = 95})
        end
        
        local town = Town("Rookgaard")
        player:teleportTo(town:getTemplePosition())
        player:setTown(town)
        player:setDirection(DIRECTION_SOUTH)
    end
    return true
end

This is the part of code on Player.cpp
C++:
// Teleport newbies to newbie island
        if (g_config.getBoolean(ConfigManager::TELEPORT_NEWBIES)) {
            if (getVocationId() != VOCATION_NONE && level <= static_cast<uint32_t>(g_config.getNumber(ConfigManager::NEWBIE_LEVEL_THRESHOLD))) {
                Town* newbieTown = g_game.map.towns.getTown(g_config.getNumber(ConfigManager::NEWBIE_TOWN));
                if (newbieTown) {
                    // Restart stats
                    level = 1;
                    experience = 0;
                    levelPercent = 0;
                    capacity = 340;
                    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(newbieTown);
                    loginPosition = getTemplePosition();

                    // Restart first items
                    lastLoginSaved = 0;
                    lastLogout = 0;

                    // 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] Newbie teletransportation is enabled, newbie town does not exist." << std::endl;
                }
            }
        }
    }

I don't understand because in code have
lastLoginSaved = 0;
lastLogout = 0;

anyone know why not work?
 
Solution
Yes, maybe create a OR hasBeenRooked onLogin, but this need check when the player lose level 6 to 5 and check if player is not (no vocation) because this can't work with (no vocation character) and think is better disable the lastLoginSaved = 0;
lastLogout = 0; on sources, but idk how to edit my onLogin script to add hasBeenRooked there.

What you could do for simplicity sake is make an onDeath() event script and have it write a quest/storage variable (or something like that) to the character, if the character dies while being level 6 and has low enough EXP to trigger a de-level to 5. Then just add a check for that quest variable to onLogin(). It should be a lot easier to check for a quest variable set by lua, in lua, than having...
When exactly does this part of Player.cpp trigger? My guess is that onLogin for some reason happens first, before lastLoginSaved is reset, which is why only changes included in Player.cpp work as intended. If that's the case, you'd actually get the starting equipment when you relog with the rooked character.
 
One solution would be to simply edit your onLogin() to include an OR where it validates, to check for "hasBeenRooked" or something.
Then you simply change your Players.cpp to add hasBeenRooked and then disconnect the player at the end of changing the player, which should force them to relogin and thus re-execute the onLogin() lua script.
 
One solution would be to simply edit your onLogin() to include an OR where it validates, to check for "hasBeenRooked" or something.
Then you simply change your Players.cpp to add hasBeenRooked and then disconnect the player at the end of changing the player, which should force them to relogin and thus re-execute the onLogin() lua script.

Yes, maybe create a OR hasBeenRooked onLogin, but this need check when the player lose level 6 to 5 and check if player is not (no vocation) because this can't work with (no vocation character) and think is better disable the lastLoginSaved = 0;
lastLogout = 0; on sources, but idk how to edit my onLogin script to add hasBeenRooked there.
 
Yes, maybe create a OR hasBeenRooked onLogin, but this need check when the player lose level 6 to 5 and check if player is not (no vocation) because this can't work with (no vocation character) and think is better disable the lastLoginSaved = 0;
lastLogout = 0; on sources, but idk how to edit my onLogin script to add hasBeenRooked there.

What you could do for simplicity sake is make an onDeath() event script and have it write a quest/storage variable (or something like that) to the character, if the character dies while being level 6 and has low enough EXP to trigger a de-level to 5. Then just add a check for that quest variable to onLogin(). It should be a lot easier to check for a quest variable set by lua, in lua, than having to mess with adding custom lua functions to check for the hasBeenRooked internal variable done in CPP.

Something like...

Lua:
onDeath(player)
    if (player.level == 6 AND player.exp <= 6969) then
        player.writeQuestProgress(4444, 1)
    end
end

onLogin(player)
    if (player.getLastLoginSaved() <= 0 OR player.getQuestProgress(4444) == 1)
        player.GiveNewbItems()
        player.setTown(Rookgard)
    end
end
 
Last edited:
Solution
as they said, use storage values or create a new value at players data, this will check if you are in rook or nay, this way you could check with the last login and if he has been rooked.
 
Back
Top