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

If online 1 hour

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,394
Reaction score
162
IF player is online 30 min he gets message "your soul has been Refilled by gods becouse you play ! in another 30 min your soul will be refilled again !" with this message player gets 200 soul recieves
i use 0.4

Thannks in advance , Sorry for broken english :)
 
Last edited:
Should the soul be refilled every 30 min always?
You can do this with addEvent, add this in login.lua (the function above function onLogin).
Code:
function addTimedSoul(cid)
   if not isPlayer(cid) then
     return true
   end
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your soul has been Refilled by gods because you play ! In another 30 min your soul will be refilled again !")
   doPlayerAddSoul(cid, 200)
   addEvent(addTimedSoul, 30 * 60 * 1000, cid)
end

addEvent(addTimedSoul, 30 * 60 * 1000, cid)
 
Should the soul be refilled every 30 min always?
You can do this with addEvent, add this in login.lua (the function above function onLogin).
Code:
function addTimedSoul(cid)
   if not isPlayer(cid) then
     return true
   end
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your soul has been Refilled by gods because you play ! In another 30 min your soul will be refilled again !")
   doPlayerAddSoul(cid, 200)
   addEvent(addTimedSoul, 30 * 60 * 1000, cid)
end

addEvent(addTimedSoul, 30 * 60 * 1000, cid)
i added this script to login.lua but it aint working.
do i need add registered event in login.lua
what about creatuscripts.xml ? :)
 
i added this script to login.lua but it aint working.
do i need add registered event in login.lua
what about creatuscripts.xml ? :)
If you add it to login.lua you do not need to register it anywhere.

Show us the script so we can see how you added it.

This should be placed inside the onLogin function:
Code:
addEvent(addTimedSoul, 30 * 60 * 1000, cid)
 
Should the soul be refilled every 30 min always?
You can do this with addEvent, add this in login.lua (the function above function onLogin).
Code:
function addTimedSoul(cid)
   if not isPlayer(cid) then
     return true
   end
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your soul has been Refilled by gods because you play ! In another 30 min your soul will be refilled again !")
   doPlayerAddSoul(cid, 200)
   addEvent(addTimedSoul, 30 * 60 * 1000, cid)
end

addEvent(addTimedSoul, 30 * 60 * 1000, cid)
not sure about older TFS versions, but in TFS 1.x it would cause stack overflow.

I use outside variable to stop the stack overflow.

local stackOverflow = false
function()
if stackOverflow then return end
stackOverflow = true
addEvent(function(), stackOverflow = false end, 1000)
 
not sure about older TFS versions, but in TFS 1.x it would cause stack overflow.

I use outside variable to stop the stack overflow.

local stackOverflow = false
function()
if stackOverflow then return end
stackOverflow = true
addEvent(function(), stackOverflow = false end, 1000)
outside?
 
not sure about older TFS versions, but in TFS 1.x it would cause stack overflow.

I use outside variable to stop the stack overflow.

local stackOverflow = false
function()
if stackOverflow then return end
stackOverflow = true
addEvent(function(), stackOverflow = false end, 1000)

What?

Limos' script is fine, it shouldn't cause any problem; it should infinitely loop for duration the server is online.
Red
 
What?

Limos' script is fine, it shouldn't cause any problem; it should infinitely loop for duration the server is online.
Red
Interesting, just tested, it works.
However there has been lot of problems for me when I don't make the stackOverflow thing when I use addEvent to execute same function again from inside the function itself.

So far I assumed it tries to check the return value from the event what comes from event and then keeps repeating itself, because the checking never ends.
No clue now how come this works and previous attempts I have done did not.
Still I will continue to use a variable to escape function, before it actually needs to execute the addEvent again
 
Interesting, just tested, it works.
However there has been lot of problems for me when I don't make the stackOverflow thing when I use addEvent to execute same function again from inside the function itself.

So far I assumed it tries to check the return value from the event what comes from event and then keeps repeating itself, because the checking never ends.
No clue now how come this works and previous attempts I have done did not.
Still I will continue to use a variable to escape function, before it actually needs to execute the addEvent again
If you have a recursive function that is GUARANTEED to end you should use proper tail calls to prevent stackoverflow (if you can there are times you can't use it, read about it in the link)
However Limos script has nothing to do with stackoverflow or tail calls, its using addEvents to call the function again after some time.

You can read about it here: https://www.lua.org/pil/6.3.html
 
Should the soul be refilled every 30 min always?
You can do this with addEvent, add this in login.lua (the function above function onLogin).
Code:
function addTimedSoul(cid)
   if not isPlayer(cid) then
     return true
   end
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your soul has been Refilled by gods because you play ! In another 30 min your soul will be refilled again !")
   doPlayerAddSoul(cid, 200)
   addEvent(addTimedSoul, 30 * 60 * 1000, cid)
end

addEvent(addTimedSoul, 30 * 60 * 1000, cid)
If you add it to login.lua you do not need to register it anywhere.

Show us the script so we can see how you added it.

This should be placed inside the onLogin function:
Code:
addEvent(addTimedSoul, 30 * 60 * 1000, cid)
Hey its not working had error then i put in login.lua funcion onlogin
add event.
Callback parameter should be a function


now i did like this this but it aint working
soulgift.lua
Code:
function addTimedSoul(cid)
   if not isPlayer(cid) then
     return true
   end
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your soul has been Refilled by 50 by gods because you play ! In another 60 min your soul will be refilled again !")
   doPlayerAddSoul(cid, 50)
   addEvent(addTimedSoul, 1 * 60 * 1000, cid)
end
is it 1 hour ?
on login.lua
registerCreatureEvent(cid, "SoulGift")

creaturescripts.xml
<event type="addTimedSoul" name="SoulGift" event="script" value="soulgift.lua"/>

error
PHP:
[20:22:30.797] [Error - CreatureEvent::configureEvent] No valid type for creature event.addTimedSoul
[20:22:30.797] [Warning - BaseEvents::loadFromXml] Cannot configure an event
 
Hey its not working had error then i put in login.lua funcion onlogin
add event.
Callback parameter should be a function


now i did like this this but it aint working
soulgift.lua
Code:
function addTimedSoul(cid)
   if not isPlayer(cid) then
     return true
   end
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your soul has been Refilled by 50 by gods because you play ! In another 60 min your soul will be refilled again !")
   doPlayerAddSoul(cid, 50)
   addEvent(addTimedSoul, 1 * 60 * 1000, cid)
end
is it 1 hour ?
on login.lua
registerCreatureEvent(cid, "SoulGift")

creaturescripts.xml
<event type="addTimedSoul" name="SoulGift" event="script" value="soulgift.lua"/>

error
PHP:
[20:22:30.797] [Error - CreatureEvent::configureEvent] No valid type for creature event.addTimedSoul
[20:22:30.797] [Warning - BaseEvents::loadFromXml] Cannot configure an event
God damn. Post your login.lua
nobody cares about your custom scripts that may be inside.
 
God damn. Post your login.lua
nobody cares about your custom scripts that may be inside.
why do you think i care ?
login.lua
PHP:
local config = {
    loginMessage = getConfigValue('loginMessage')
}

function onLogin(cid)
    if getCreatureName(cid) == "Account Manager" then
        doRemoveCreature(cid)
        return true
    end
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) and getPlayerVocation(cid) ~= 0 then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
        setPlayerStorageValue(cid, 65535, -1)
        setPlayerStorageValue(cid, 788989, -1)
    end
   
        local buffs = {CONDITION_HASTE, CONDITION_ATTRIBUTES, CONDITION_REGENERATION}
    for i = 1,#buffs do
        if hasCondition(cid, buffs[i]) then
            doRemoveCondition(cid, buffs[i])
        end
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit warfarian."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid, "Idle")
    registerCreatureEvent(cid, "antirain")
    registerCreatureEvent(cid, "SoulGift")
    return true
end
 

Similar threads

Back
Top