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

Solved Voc ID 9 fast soul regen

Nevalopo

Demigod
Joined
Jul 21, 2008
Messages
5,165
Reaction score
68
Location
Sweden, Landskrona
Hi! I have a little problem with my soul regen script for voc 9 this is what i have so far:

Code:
local vocations,max_soul = {{9}},{200}
function onThink(interval, lastExecution, thinkInterval)
    for _, cid in ipairs(getPlayersOnline()) do
        local maxsoul = isInArray(vocations[1],getPlayerVocation(cid)) and max_soul[1] or max_soul[2]
        if getPlayerSoul(cid) < maxsoul then
            doPlayerAddSoul(cid, 1)
        end
    end
    return TRUE
end

It's working fine and regens soul but im getting spammed error whenever i login with another char

This is the error im getting:


UihmEqN.png


Anyone have ideas where i gone wrong in the script?

Also, Running 0.4 tfs
 
max_soul[2] is nil, since there is no second value in the table max_soul.
If there are just 2 values you don't need to use tables. I assume it should only be added for players with vocation id 9?
Then you can just do this.
Code:
if getPlayerVocation(cid) == 9 and getPlayerSoul(cid) < 200 then
 
max_soul[2] is nil, since there is no second value in the table max_soul.
If there are just 2 values you don't need to use tables. I assume it should only be added for players with vocation id 9?
Then you can just do this.
Code:
if getPlayerVocation(cid) == 9 and getPlayerSoul(cid) < 200 then

So just simple like this?

Code:
function onThink(interval, lastExecution)
if getPlayerVocation(cid) == 9 and getPlayerSoul(cid) < 200 then
            doPlayerAddSoul(cid, 1)
        end
        end

Then im getting error
29ymKRw.png
 
Instead of this.
Code:
if getPlayerSoul(cid) < maxsoul then

You can remove the local maxsoul line and the tables at the top since they are not used anymore.
 
Instead of this.
Code:
if getPlayerSoul(cid) < maxsoul then

You can remove the local maxsoul line and the tables at the top since they are not used anymore.

Thanks! It's working fine now without errors. The script itself is still really messy but it works and i don't dare clean it up with my 0 knowledge of lua.

If anyone ever wants a soul regen script here it is working:

Code:
local vocations,max_soul = {{9}},{200}
function onThink(interval, lastExecution, thinkInterval)
    for _, cid in ipairs(getPlayersOnline()) do
        local maxsoul = isInArray(vocations[1],getPlayerVocation(cid)) and max_soul[1] or max_soul[2]
        if getPlayerVocation(cid) == 9 and getPlayerSoul(cid) < 200 then
            doPlayerAddSoul(cid, 1)
        end
    end
    return TRUE
end
 
You can remove this
Code:
local vocations,max_soul = {{9}},{200}
And this
Code:
local maxsoul = isInArray(vocations[1],getPlayerVocation(cid)) and max_soul[1] or max_soul[2]
All 3 variables are not used anymore in the script so it's not needed.
A variable is basicly just a name you give for certain values/strings or tables.
For example
Code:
local amount = 10
Every time you use amount in the script, it will mean 10, so writing amount somewhere will be the same as writing 10. It it usually used to make a script shorter or more easy to edit.
 
You can remove this
Code:
local vocations,max_soul = {{9}},{200}
And this
Code:
local maxsoul = isInArray(vocations[1],getPlayerVocation(cid)) and max_soul[1] or max_soul[2]
All 3 variables are not used anymore in the script so it's not needed.
A variable is basicly just a name you give for certain values/strings or tables.
For example
Code:
local amount = 10
Every time you use amount in the script, it will mean 10, so writing amount somewhere will be the same as writing 10. It it usually used to make a script shorter or more easy to edit.


Thanks! Here is optimized code for anyone who wants:
Code:
function onThink(interval, lastExecution, thinkInterval)
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerVocation(cid) == 9 and getPlayerSoul(cid) < 200 then
            doPlayerAddSoul(cid, 1)
        end
    end
    return TRUE
end
 
Why do you not edit soul regn, in vocations.xml

Alsoci would use creaturescript in thin and check player voc onLogin and then register the event. Instead of checking all players.
 
Back
Top