• 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 [TFS 1.0] Stamina gain when Training on "monks"

trustjah

Newbie
Joined
Jan 22, 2009
Messages
126
Solutions
6
Reaction score
14
Location
Belgium
Anyone knows how to get this rolling on TFS 1.0?

LUA:
addSta = {}
local config = {
timeToAdd = 3, --
addTime = 5, --
}

local function addStamina(cid)
    if not isPlayer(cid) then
        addSta[cid] = nil
    return true
    end
    player:setStamina(cid, getStamina(cid) + config.addTime)
    player:sendTextMessage(cid, 25, "You received "..config.addTime.." minutes of stamina.")
    addSta[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(cid)
    if isPlayer(cid) then
        addSta[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
    end
return true
end

function onStepOut(cid)
    if isPlayer(cid) then
        stopEvent(addSta[cid])
        addSta[cid] = nil
    end
return true
end

i've tried some things here and there but i'm too stupid to figure this out.
 
Last edited by a moderator:
Solution
@Xeraphus still getting an error here,

Argument 3 unsafe,
C in function 'addEvent'
because you were using the wrong function arguments
LUA:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 5,
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return true
    end
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(25, "You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        staminaEvents[creature:getId()] =...
LUA:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 5,
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(attSta[cid])
        staminaEvents[cid] = nil
        return true
    end
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(25, "You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(cid)
    if isPlayer(cid) then
        staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
    end
    return true
end

function onStepOut(cid)
    if isPlayer(cid) then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
    end
    return true
end
 
@Xeraphus still getting an error here,

Argument 3 unsafe,
C in function 'addEvent'
because you were using the wrong function arguments
LUA:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 5,
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return true
    end
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(25, "You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        staminaEvents[creature:getId()] = addEvent(addStamina, config.timeToAdd * 60 * 1000, creature:getId())
    end
    return true
end

function onStepOut(creature)
    if creature:isPlayer() then
        stopEvent(staminaEvents[creature:getId()])
        staminaEvents[creature:getId()] = nil
    end
    return true
end
 
Solution
because you were using the wrong function arguments
LUA:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 5,
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(attSta[cid])
        staminaEvents[cid] = nil
        return true
    end
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(25, "You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        staminaEvents[creature:getId()] = addEvent(addStamina, config.timeToAdd * 60 * 1000, creature:getId())
    end
    return true
end

function onStepOut(creature)
    if creature:isPlayer() then
        stopEvent(staminaEvents[creature:getId()])
        staminaEvents[creature:getId()] = nil
    end
    return true
end

also, there is no broadcast when i step on the tile now, any idea why that is?
 
also, there is no broadcast when i step on the tile now, any idea why that is?
there never was a broadcast when you stepped on the tile, only when you gained stamina
it might be because you used the wrong message type though
use MESSAGE_INFO_DESCR instead of 25 in player:sendTextMessage
please don't ever use numbers, instead use the constants provided to make it more understandable what you're using since no one memorizes the numbers
https://otland.net/threads/tfs-1-x-enums.225588/
 
Back
Top