• 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 [1.X] Soul gain while standing on tile

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
897
Solutions
21
Reaction score
427
Location
Santiago - Chile
Hi! I wonder if you can help me again at this one :). Would like to request a tile that makes the player gain soul after "x" seconds. The only thing I was able to found for this Traning monk regen Soul (https://otland.net/threads/traning-monk-regen-soul.274492/) but it has a problem that OP mentions. The idea is to allow players to gain soul while training, since runemaking is a essential feature for the gameplay. I use TFS 1.4 downgraded by nekiro (8.60). If it does requiere source edit I can test too. Thanks in advance!
 
Solution
Thanks for the answer @Silba. I still have a doubt. Since the old manner to add soul in 0.X was for example: doPlayerAddSoul(cid, 4), how do I indicate the amount of soul won + addTime value. Something like:

Lua:
player:addSoul(config.addTime, 4)

This will work? Where "4" indicates the ammount of soul earned. For example, to make the player win "4" soul every "1" minute. Thanks in advance, Regards!

Edit: Another thing, wouldn't this work?
Code:
player:setSoul(player:getSoul() + config.addTime)

To get player soul and add the configured value to the current soul?
In the code I sent you, it adds soul at the same interval as stamina(because it's in the same function) and then adds the same amount of soul as stamina...

Loney

🇲🇽
Senator
Premium User
Joined
Jul 23, 2012
Messages
1,975
Solutions
20
Reaction score
194
Location
MX
You can experiment with these two to get an idea:
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
897
Solutions
21
Reaction score
427
Location
Santiago - Chile
Thanks @Loney honestly i'm bad scripting but I can read lua at least. The second thread you added seems to be a good solution, trying to give more information, I can say that the function
Lua:
player:addSoul(number)
Must be used, and merged in a script like this stamina tile example:
Lua:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 1,
}

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(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You will receive "..config.addTime.." minute of stamina every "..config.timeToAdd.." minutes while you are in this room.")
        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

Considering the thread is a request I will be really gratefull if someone can do this merge for me, I would love to do it but i'm definitely bad coding. Still don't know if source edit must be involved on this. Thanks in advance, regards!
 

Silba

is stephany, the josh wife
Premium User
Joined
Aug 22, 2013
Messages
364
Solutions
5
Reaction score
273
Thanks @Loney honestly i'm bad scripting but I can read lua at least. The second thread you added seems to be a good solution, trying to give more information, I can say that the function
Lua:
player:addSoul(number)
Must be used, and merged in a script like this stamina tile example:
Lua:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 1,
}

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(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You will receive "..config.addTime.." minute of stamina every "..config.timeToAdd.." minutes while you are in this room.")
        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

Considering the thread is a request I will be really gratefull if someone can do this merge for me, I would love to do it but i'm definitely bad coding. Still don't know if source edit must be involved on this. Thanks in advance, regards!
easy and dirty way is to put it inside the addStamina function then the player will gain soul every time the player gains stamina, you should be able to modify this with ease to suit your needs.

Lua:
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:addSoul(config.addTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You received "..config.addTime.." minutes of stamina and "..config.addTime.." soul points.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
897
Solutions
21
Reaction score
427
Location
Santiago - Chile
easy and dirty way is to put it inside the addStamina function then the player will gain soul every time the player gains stamina, you should be able to modify this with ease to suit your needs.

Lua:
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:addSoul(config.addTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You received "..config.addTime.." minutes of stamina and "..config.addTime.." soul points.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end
Thanks for the answer @Silba. I still have a doubt. Since the old manner to add soul in 0.X was for example: doPlayerAddSoul(cid, 4), how do I indicate the amount of soul won + addTime value. Something like:

Lua:
player:addSoul(config.addTime, 4)

This will work? Where "4" indicates the ammount of soul earned. For example, to make the player win "4" soul every "1" minute. Thanks in advance, Regards!

Edit: Another thing, wouldn't this work?
Code:
player:setSoul(player:getSoul() + config.addTime)

To get player soul and add the configured value to the current soul?
 
Last edited:

Silba

is stephany, the josh wife
Premium User
Joined
Aug 22, 2013
Messages
364
Solutions
5
Reaction score
273
Thanks for the answer @Silba. I still have a doubt. Since the old manner to add soul in 0.X was for example: doPlayerAddSoul(cid, 4), how do I indicate the amount of soul won + addTime value. Something like:

Lua:
player:addSoul(config.addTime, 4)

This will work? Where "4" indicates the ammount of soul earned. For example, to make the player win "4" soul every "1" minute. Thanks in advance, Regards!

Edit: Another thing, wouldn't this work?
Code:
player:setSoul(player:getSoul() + config.addTime)

To get player soul and add the configured value to the current soul?
In the code I sent you, it adds soul at the same interval as stamina(because it's in the same function) and then adds the same amount of soul as stamina also because I used the same value of config.addTime which is defined here:
local config = {
timeToAdd = 3,
addTime = 1,
}
so player:addSoul(config.addtime) is the same as player:addSoul(1) in this case. You do not need to get the amount of soul first since you are not setting the soul but are adding it on top of the already existing soul. I don't know why the stamina stuff is like that.

If you want it to have it's own config and it's own interval we just need to modify the existing config and copy the stamina function and then add the new function to the onStepIn:


Lua:
local config = {
    staminaInterval = 6, -- minutes
    soulInterval = 6,
    addStamina = 1,
    addSoul = 1,
}

staminaEvents = {}
soulEvents = {}

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.addStamina)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You received "..config.addStamina.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.staminaInterval * 60 * 1000, cid)
end

local function addSoul(cid)
    local player = Player(cid)
    if not player then
        stopEvent(soulEvents[cid])
        soulEvents[cid] = nil
        return true
    end
    player:addSoul(config.addSoul)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You received "..config.addSoul.." soul points.")
    soulEvents[cid] = addEvent(addSoul, config.soulInterval * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You will receive "..config.addStamina.." minutes of stamina every "..config.staminaInterval.." minutes while you are in this room.")
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Trainer Recovery]: You will receive "..config.addSoul.." soul points every "..config.soulInterval.." minutes while you are in this room.")
        staminaEvents[creature:getId()] = addEvent(addStamina, config.staminaInterval * 60 * 1000, creature:getId())
        soulEvents[creature:getId()] = addEvent(addSoul, config.soulInterval * 60 * 1000, creature:getId())
    end
    return true
end

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

I believe this should work if the original script also worked. I have not tested this.
Renamed the config too since it was very confusing.
 
Last edited:
Solution
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
897
Solutions
21
Reaction score
427
Location
Santiago - Chile
@Silba this was exactly was I was looking for. Did minor testings can't be sure 100% if all is ok, but got it running on the server awaiting for feed, overall, I think it works perfectly. Thanks a lot!!!!!!!! Regards :D
 
Top