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

Lua Offline Training Error.

Doss Aaa

New Member
Joined
Oct 14, 2013
Messages
48
Reaction score
4
Location
Poland
How to fix that?

5af542d76ba4c639a918baccb287351f.png
 
In order for us to help you in any way, you would need to post the contents of data\creaturescripts\scripts\others\offlinetraining.lua here.

Can you also give us the TFS version you are using?
 
Tells you right in the console, your using a function getOfflineTrainingSkill that doesn't exist on your server.
 
But the problem is it exist... I even checked in my compilimg src.
Im using tfs 1.2 compiled by self with cast system.
This lua from offlinetraining is using this function and claiming it doesnt exist wwhen it exist. I can give u soirce from my tfs.

Code:
function onLogin(player)
    local lastLogout = player:getLastLogout()
    local offlineTime = lastLogout ~= 0 and math.min(os.time() - lastLogout, 86400 * 21) or 0
    local offlineTraining_Skill = player:getOfflineTrainingSkill()
    if offlineTrainingSkill == -1 then
        player:addOfflineTrainingTime(offlineTime * 1000)
        return true
    end

    player:setOfflineTrainingSkill(-1)

    if offlineTime < 600 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must be logged out for more than 10 minutes to start offline training.")
        return true
    end

    local trainingTime = math.max(0, math.min(offlineTime, math.min(43200, player:getOfflineTrainingTime() / 1000)))
    player:removeOfflineTrainingTime(trainingTime * 1000)

    local remainder = offlineTime - trainingTime
    if remainder > 0 then
        player:addOfflineTrainingTime(remainder * 1000)
    end

    if trainingTime < 60 then
        return true
    end

    local text = "During your absence you trained for"
    local hours = math.floor(trainingTime / 3600)
    if hours > 1 then
        text = string.format("%s %d hours", text, hours)
    elseif hours == 1 then
        text = string.format("%s 1 hour", text)
    end

    local minutes = math.floor((trainingTime % 3600) / 60)
    if minutes ~= 0 then
        if hours ~= 0 then
            text = string.format("%s and", text)
        end

        if minutes > 1 then
            text = string.format("%s %d minutes", text, minutes)
        else
            text = string.format("%s 1 minute", text)
        end
    end

    text = string.format("%s.", text)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text)

    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    local topVocation = not promotion and vocation or promotion

    local updateSkills = false
    if isInArray({SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE}, offlineTrainingSkill) then
        local modifier = topVocation:getAttackSpeed() / 1000
        updateSkills = player:addOfflineTrainingTries(offlineTrainingSkill, (trainingTime / modifier) / (offlineTrainingSkill == SKILL_DISTANCE and 4 or 2))
    elseif offlineTrainingSkill == SKILL_MAGLEVEL then
        local gainTicks = topVocation:getManaGainTicks() * 2
        if gainTicks == 0 then
            gainTicks = 1
        end

        updateSkills = player:addOfflineTrainingTries(SKILL_MAGLEVEL, trainingTime * (vocation:getManaGainAmount() / gainTicks))
    end

    if updateSkills then
        player:addOfflineTrainingTries(SKILL_SHIELD, trainingTime / 4)
    end

    return true
end

Code:
player->loginPosition.x = result->getNumber<uint16_t>("posx");
    player->loginPosition.y = result->getNumber<uint16_t>("posy");
    player->loginPosition.z = result->getNumber<uint16_t>("posz");

    player->lastLoginSaved = result->getNumber<time_t>("lastlogin");
    player->lastLogout = result->getNumber<time_t>("lastlogout");

    player->offlineTrainingTime = result->getNumber<int32_t>("offlinetraining_time") * 1000;
    player->offlineTrainingSkill = result->getNumber<int32_t>("offlinetraining_skill");

Tibia client: 10.78
 
Last edited by a moderator:
there is an inconsistency in your script
line 4, this variable offlineTraining_Skill isn't used anywhere
Code:
local offlineTraining_Skill = player:getOfflineTrainingSkill()
change it to this & it should resolve your problem.. hopefully :p
Code:
local offlineTrainingSkill = player:getOfflineTrainingSkill()
 
Since you compiled it yourself, this should be easy.
Ensure player.h has this
Code:
int32_t getOfflineTrainingSkill() const {
return offlineTrainingSkill;
}
Ensure luascript.cpp has this
Code:
registerMethod("Player", "getOfflineTrainingSkill", LuaScriptInterface::luaPlayerGetOfflineTrainingSkill);
and this
Code:
int LuaScriptInterface::luaPlayerGetOfflineTrainingSkill(lua_State* L)
{
// player:getOfflineTrainingSkill()
Player* player = getUserdata<Player>(L, 1);
if (player) {
lua_pushnumber(L, player->getOfflineTrainingSkill());
} else {
lua_pushnil(L);
}
return 1;
}
The error means the method doesn't exist on the Player class. If it has all of the above and still does not work, then something else is very wrong.

player->loginPosition.x = result->getNumber<uint16_t>("posx"); player->loginPosition.y = result->getNumber<uint16_t>("posy"); player->loginPosition.z = result->getNumber<uint16_t>("posz"); player->lastLoginSaved = result->getNumber<time_t>("lastlogin"); player->lastLogout = result->getNumber<time_t>("lastlogout"); player->offlineTrainingTime = result->getNumber<int32_t>("offlinetraining_time") * 1000; player->offlineTrainingSkill = result->getNumber<int32_t>("offlinetraining_skill");
In addition, this just means that the player attribute offlineTrainingSkill on the player is set upon login. This does not mean that the function to CHECK the value exists.
 
Back
Top