try thisjust for formula with vocation like knight have one formula and sorcerer have another one formula
local config = {
-- [{min_level, max_level}] = regen per second
[{100, 250}] = {
-- [vocation id] = {formula}
[1] = {lvl = 1, mlvl = 0.7},
[2] = {lvl = 1, mlvl = 0.5},
[3] = {lvl = 1, distance = 0.7},
[4] = {lvl = 1, sword = 0.3, axe = 0.3, club = 0.3}
},
-- last max_level must be math.huge
[{250, math.huge}] = {
-- [vocation id] = {formula}
[1] = {lvl = 1, mlvl = 0.7},
[2] = {lvl = 1, mlvl = 0.5},
[3] = {lvl = 1, distance = 0.7},
[4] = {lvl = 1, sword = 0.3, axe = 0.3, club = 0.3}
},
}
function onThink(interval...
local level = getPlayerLevel(cid)
if level < 100 then
return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
heal_amount = 100
elseif level >= 250 then
heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
return true
elseif current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
local heal_amount = getPlayerLevel(cid)
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
return true
elseif current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
Not sure which one you wanted.
Put either of these into whatever script you are wanting to use the 'regeneration' for.
from level A to B heal X amount.
heal LEVEL amountLua:local level = getPlayerLevel(cid) if level < 100 then return true end local heal_amount = 0 if level >= 100 and level <= 249 then heal_amount = 100 elseif level >= 250 then heal_amount = 250 end local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid) if current_health == max_health then return true elseif current_health + heal_amount > max_health then heal_amount = max_health - current_health end doCreatureAddHealth(cid, heal_amount)
Lua:local heal_amount = getPlayerLevel(cid) local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid) if current_health == max_health then return true elseif current_health + heal_amount > max_health then heal_amount = max_health - current_health end doCreatureAddHealth(cid, heal_amount)
Show full script, and picture of console?this dont work @Xikini i got error on console startup attempt to compare bolean with number!!!
local level = getPlayerLevel(cid)
if level < 100 then
return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
heal_amount = 100
elseif level >= 250 then
heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
return true
elseif current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
<event type="healthchange" name="HealthRegeneration" script="HealthRegeneration.lua" />
Not sure which one you wanted.
Put either of these into whatever script you are wanting to use the 'regeneration' for.
from level A to B heal X amount.
heal LEVEL amountLua:local level = getPlayerLevel(cid) if level < 100 then return true end local heal_amount = 0 if level >= 100 and level <= 249 then heal_amount = 100 elseif level >= 250 then heal_amount = 250 end local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid) if current_health == max_health then return true elseif current_health + heal_amount > max_health then heal_amount = max_health - current_health end doCreatureAddHealth(cid, heal_amount)
Lua:local heal_amount = getPlayerLevel(cid) local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid) if current_health == max_health then return true elseif current_health + heal_amount > max_health then heal_amount = max_health - current_health end doCreatureAddHealth(cid, heal_amount)
Show full script, and picture of console?
local level = getPlayerLevel(cid)
if level < 100 then
return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
heal_amount = 100
elseif level >= 250 then
heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
return true
elseif current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
@Xikini I get the same error as the threadstarter.
"Attempt to compare boolean with number".
This is the script I added to HealthRegeneration.lua
local level = getPlayerLevel(cid)
if level < 100 then
return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
heal_amount = 100
elseif level >= 250 then
heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
return true
elseif current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
---------
I added it into creaturescripts.xml
<event type="healthchange" name="HealthRegeneration" script="HealthRegeneration.lua" />
The lua file HealthRegeneration.Lua is in the creaturescripts/scripts folder.
I use this
Lua:local level = getPlayerLevel(cid) if level < 100 then return true end local heal_amount = 0 if level >= 100 and level <= 249 then heal_amount = 100 elseif level >= 250 then heal_amount = 250 end local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid) if current_health == max_health then return true elseif current_health + heal_amount > max_health then heal_amount = max_health - current_health end doCreatureAddHealth(cid, heal_amount)
At GlobalEvent with interval 6000
<globalevent name="regen" interval="2000" event="script" value="regen.lua"/>
function onThink(cid, interval, lastExecution)
for _, cid in ipairs(getPlayersOnline()) do
local level = getPlayerLevel(cid)
if level < 100 then
return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
heal_amount = 100
elseif level >= 250 then
heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health < max_health then
if current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
end
end
return true
end
Oh, that's because you both are supposed to add it to an existing script, not use the partial script as-is.
If you want it specifically for a global event, I suppose you can loop through all of the players online to grab the cid's of everyone based on an interval.
something like this. (0.4 interval is in seconds I think, so set 2000 to 2 instead)
XML:<globalevent name="regen" interval="2000" event="script" value="regen.lua"/>
Lua:function onThink(cid, interval, lastExecution) for _, cid in ipairs(getPlayersOnline()) do local level = getPlayerLevel(cid) if level < 100 then return true end local heal_amount = 0 if level >= 100 and level <= 249 then heal_amount = 100 elseif level >= 250 then heal_amount = 250 end local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid) if current_health < max_health then if current_health + heal_amount > max_health then heal_amount = max_health - current_health end doCreatureAddHealth(cid, heal_amount) end end return true end
Like I said in my previous post, if you are using tfs 0.4, it does interval in seconds.I think its working now, with your finishing addition to the top of the script and adding it to globalevents instead of creaturescripts has left me with no error !
I have not tried it out ingame yet but I believe it work because I understand your lua code. Thank you!
EDIT: I tried using a char ingame with lvl 250 and there was no health regen at all. Your script looks like it should work, but it doesn't for my server =/ There's no errors but there is no regen.
I'm using TFS 1.2 not 0.4 actually. Is there a need for a totally different script? I tried with 2000 and with 2.Like I said in my previous post, if you are using tfs 0.4, it does interval in seconds.
2000 seconds = 33.3 minutes (ultra slow regen. )
Change interval to something lower. (like 2)
I'm not sure.I'm using TFS 1.2 not 0.4 actually. Is there a need for a totally different script? I tried with 2000 and with 2.
local config = {
-- [{min_level, max_level}] = regen per second
[{100, 250}] = 100,
-- last max_level must be math.huge
[{250, math.huge}] = 250
}
function onThink(interval, lastExecution)
for _, player in pairs(Game.getPlayers()) do
for range, regen in pairs(config) do
local level = player:getLevel()
-- level matches between range found from config
if level >= range[1] and level < range[2] then
player:addHealth(regen)
break
end
end
end
return true
end
<globalevent name="regen" interval="1000" script="regen.lua" />
I think you can't use return, otherwise it will only heal the first person it finds.made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones
save this as regen.lua in data/globalevents/scripts
Lua:local config = { -- [{min_level, max_level}] = regen per second [{100, 250}] = 100, -- last max_level must be math.huge [{250, math.huge}] = 250 } function onThink(interval, lastExecution) for _, player in pairs(Game.getPlayers()) do for range, regen in pairs(config) do local level = player:getLevel() -- level matches between range found from config if level >= range[1] and level < range[2] then player:addHealth(regen) return end end end end
add this in globalevents.xml
XML:<globalevent name="regen" interval="1000" script="regen.lua" />
right, forgot this was onThink for a secondI think you can't use return, otherwise it will only heal the first person it finds.
made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones
save this as regen.lua in data/globalevents/scripts
Lua:local config = { -- [{min_level, max_level}] = regen per second [{100, 250}] = 100, -- last max_level must be math.huge [{250, math.huge}] = 250 } function onThink(interval, lastExecution) for _, player in pairs(Game.getPlayers()) do for range, regen in pairs(config) do local level = player:getLevel() -- level matches between range found from config if level >= range[1] and level < range[2] then player:addHealth(regen) break end end end end
add this in globalevents.xml
XML:<globalevent name="regen" interval="1000" script="regen.lua" />
error:made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones
save this as regen.lua in data/globalevents/scripts
Lua:local config = { -- [{min_level, max_level}] = regen per second [{100, 250}] = 100, -- last max_level must be math.huge [{250, math.huge}] = 250 } function onThink(interval, lastExecution) for _, player in pairs(Game.getPlayers()) do for range, regen in pairs(config) do local level = player:getLevel() -- level matches between range found from config if level >= range[1] and level < range[2] then player:addHealth(regen) break end end end end
add this in globalevents.xml
XML:<globalevent name="regen" interval="1000" script="regen.lua" />
[Error - GlobalEvents::think] Failed to executre event: PerLevelRegenHp
my bad, edited the script in my previous post and it works now (i tested it)I can see the scripting logic in this one too, but.. just like the last script, its not working and with no errors. Any other options? lol I'm using tfs 1.2
What version of tfs did you script this for? Because maybe I'll switch my ot server if its a higher version. I need to be able to script stuff.
work, thanks one question how to check if player food > 0 ?my bad, edited the script in my previous post and it works now (i tested it)
because you didn't edit the level ranges in the config, if you want it to work on your level 7 character you need to make a new range or edit the first level range minimum to level 1 like thisnot works, no error but no regen i set interval as 1 but my knight sample lvl7 no get health + 100 each sec
local config = {
-- [{min_level, max_level}] = regen per second
[{1, 250}] = 100,
-- last max_level must be math.huge
[{250, math.huge}] = 250
}