• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Auto regeneration

qx

New Member
Joined
Aug 16, 2016
Messages
13
Reaction score
0
Hi, I'm trying to make it so players never need to eat any food, and they still automatically regenerate health and mana. Anybody know what I can change to make this happen? Thanks.
 
you can use a onLogin script, something like it:
Code:
player:feed(60 * 60 * 60 * 60 * 60)
I never saw it before, then test it.
when the player login always he will be full, I guess.
 
Sorry, but both of your suggestions are terrible. OP is better of using a condition (where ticks is set to -1, and disappears when the player logs out) that is added each time a player logins.

Code:
local regenCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
regenCondition:setTicks(-1)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 2)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 2000)
regenCondition:setParameter(CONDITION_PARAM_MANAGAIN, 2)
regenCondition:setParameter(CONDITION_PARAM_MANATICKS, 2000)

function onLogin(player)
    player:addCondition(regenCondition)
    return true
end
 
Sorry, but both of your suggestions are terrible. OP is better of using a condition (where ticks is set to -1, and disappears when the player logs out) that is added each time a player logins.

Code:
local regenCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
regenCondition:setTicks(-1)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 2)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 2000)
regenCondition:setParameter(CONDITION_PARAM_MANAGAIN, 2)
regenCondition:setParameter(CONDITION_PARAM_MANATICKS, 2000)

function onLogin(player)
    player:addCondition(regenCondition)
    return true
end
and what about "utura" and "utura gran", it don't use the condition_regen ? then my question, if I'm using this script on login and the player use utura, it is not envolved with that?
 
and what about "utura" and "utura gran", it don't use the condition_regen ? then my question, if I'm using this script on login and the player use utura, it is not envolved with that?
They do use CONDITION_REGENERATION, but they are also using sub ID 1 so they wouldn't affect this condition.
 
Sorry, but both of your suggestions are terrible. OP is better of using a condition (where ticks is set to -1, and disappears when the player logs out) that is added each time a player logins.

Code:
local regenCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
regenCondition:setTicks(-1)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 2)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 2000)
regenCondition:setParameter(CONDITION_PARAM_MANAGAIN, 2)
regenCondition:setParameter(CONDITION_PARAM_MANATICKS, 2000)

function onLogin(player)
    player:addCondition(regenCondition)
    return true
end

Wouldn't this get removed if doRemoveConditions is applied onto the player? Not that this happens often, but it does on custom servers. Just wondering. :p
 
Wouldn't this get removed if doRemoveConditions is applied onto the player? Not that this happens often, but it does on custom servers. Just wondering. :p
I don't know why custom servers would remove all conditions from a player, but okay. I had to look this up, but you do have the option to remove persistent conditions when using doRemoveConditions by utilizing the second parameter onlyPersistent (boolean).

A condition is persistent if the following conditions are met:
  • Ticks larger than 0
  • Condition ID equal to CONDITIONID_DEFAULT or Condition ID not equal to CONDITIONID_COMBAT
So this condition would only get removed if you use doRemoveConditions(cid, false). Even if you decide to remove all conditions, you can always reapply the condition as long as you have access to it (hence why it might be good to create a function for cases like this).
 
Is it possible to do something in my food.lua so to make it so I'm always "full"? Because I want the hp/mp ticks to be different per vocation, and I have all that setup in my vocations.xml
 
Code:
local FOODS = {
    [2362] = {5, "Crunch."}, -- carrot
    [2666] = {15, "Munch."}, -- meat
    [2667] = {12, "Munch."}, -- fish
    [2668] = {10, "Mmmm."}, -- salmon
    [2669] = {17, "Munch."}, -- northern pike
    [2670] = {4, "Gulp."}, -- shrimp
    [2671] = {30, "Chomp."}, -- ham
    [2672] = {60, "Chomp."}, -- dragon ham
    [2673] = {5, "Yum."}, -- pear
    [2674] = {6, "Yum."}, -- red apple
    [2675] = {13, "Yum."}, -- orange
    [2676] = {8, "Yum."}, -- banana
    [2677] = {1, "Yum."}, -- blueberry
    [2678] = {18, "Slurp."}, -- coconut
    [2679] = {1, "Yum."}, -- cherry
    [2680] = {2, "Yum."}, -- strawberry
    [2681] = {9, "Yum."}, -- grapes
    [2682] = {20, "Yum."}, -- melon
    [2683] = {17, "Munch."}, -- pumpkin
    [2684] = {5, "Crunch."}, -- carrot
    [2685] = {6, "Munch."}, -- tomato
    [2686] = {9, "Crunch."}, -- corncob
    [2687] = {2, "Crunch."}, -- cookie
    [2688] = {2, "Munch."}, -- candy cane
    [2689] = {10, "Crunch."}, -- bread
    [2690] = {3, "Crunch."}, -- roll
    [2691] = {8, "Crunch."}, -- brown bread
    [2695] = {6, "Gulp."}, -- egg
    [2696] = {9, "Smack."}, -- cheese
    [2787] = {9, "Munch."}, -- white mushroom
    [2788] = {4, "Munch."}, -- red mushroom
    [2789] = {22, "Munch."}, -- brown mushroom
    [2790] = {30, "Munch."}, -- orange mushroom
    [2791] = {9, "Munch."}, -- wood mushroom
    [2792] = {6, "Munch."}, -- dark mushroom
    [2793] = {12, "Munch."}, -- some mushrooms
    [2794] = {3, "Munch."}, -- some mushrooms
    [2795] = {36, "Munch."}, -- fire mushroom
    [2796] = {5, "Munch."}, -- green mushroom
    [5097] = {4, "Yum."}, -- mango
    [6125] = {8, "Gulp."}, -- tortoise egg
    [6278] = {10, "Mmmm."}, -- cake
    [6279] = {15, "Mmmm."}, -- decorated cake
    [6393] = {12, "Mmmm."}, -- valentine's cake
    [6394] = {15, "Mmmm."}, -- cream cake
    [6501] = {20, "Mmmm."}, -- gingerbread man
    [6541] = {6, "Gulp."}, -- coloured egg (yellow)
    [6542] = {6, "Gulp."}, -- coloured egg (red)
    [6543] = {6, "Gulp."}, -- coloured egg (blue)
    [6544] = {6, "Gulp."}, -- coloured egg (green)
    [6545] = {6, "Gulp."}, -- coloured egg (purple)
    [6569] = {1, "Mmmm."}, -- candy
    [6574] = {5, "Mmmm."}, -- bar of chocolate
    [7158] = {15, "Munch."}, -- rainbow trout
    [7159] = {13, "Munch."}, -- green perch
    [7372] = {2, "Yum."}, -- ice cream cone (crispy chocolate chips)
    [7373] = {2, "Yum."}, -- ice cream cone (velvet vanilla)
    [7374] = {2, "Yum."}, -- ice cream cone (sweet strawberry)
    [7375] = {2, "Yum."}, -- ice cream cone (chilly cherry)
    [7376] = {2, "Yum."}, -- ice cream cone (mellow melon)
    [7377] = {2, "Yum."}, -- ice cream cone (blue-barian)
    [7909] = {4, "Crunch."}, -- walnut
    [7910] = {4, "Crunch."}, -- peanut
    [7963] = {60, "Munch."}, -- marlin
    [8112] = {9, "Urgh."}, -- scarab cheese
    [8838] = {10, "Gulp."}, -- potato
    [8839] = {5, "Yum."}, -- plum
    [8840] = {1, "Yum."}, -- raspberry
    [8841] = {1, "Urgh."}, -- lemon
    [8842] = {7, "Munch."}, -- cucumber
    [8843] = {5, "Crunch."}, -- onion
    [8844] = {1, "Gulp."}, -- jalapeño pepper
    [8845] = {5, "Munch."}, -- beetroot
    [8847] = {11, "Yum."}, -- chocolate cake
    [9005] = {7, "Slurp."}, -- yummy gummy worm
    [9114] = {5, "Crunch."}, -- bulb of garlic
    [9996] = {0, "Slurp."}, -- banana chocolate shake
    [10454] = {0, "Your head begins to feel better."}, -- headache pill
    [11246] = {15, "Yum."}, -- rice ball
    [11370] = {3, "Urgh."}, -- terramite eggs
    [11429] = {10, "Mmmm."}, -- crocodile steak
    [12415] = {20, "Yum."}, -- pineapple
    [12416] = {10, "Munch."}, -- aubergine
    [12417] = {8, "Crunch."}, -- broccoli
    [12418] = {9, "Crunch."}, -- cauliflower
    [12637] = {55, "Gulp."}, -- ectoplasmic sushi
    [12638] = {18, "Yum."}, -- dragonfruit
    [12639] = {2, "Munch."}, -- peas
    [13297] = {20, "Crunch."}, -- haunch of boar
    [15405] = {55, "Munch."}, -- sandfish
    [15487] = {14, "Urgh."}, -- larvae
    [15488] = {15, "Munch."}, -- deepling filet
    [16014] = {60, "Mmmm."}, -- anniversary cake
    [18397] = {33, "Munch."}, -- mushroom pie
    [19737] = {10, "Urgh."}, -- insectoid eggs
    [20100] = {15, "Smack."}, -- soft cheese
    [20101] = {12, "Smack."} -- rat cheese
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local food = FOODS[item.itemid]
    if food == nil then
        return false
    end

    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and math.floor(condition:getTicks() / 1000 + food[1]) >= 1200 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are full.")
    else
        player:feed(food[1] * 12)
        player:say(food[2], TALKTYPE_MONSTER_SAY)
        item:remove(1)
    end
    return true
end
 
[EDIT] Ops. I just realized Ninja already made this.... Sorry :P Teach me not to read the entire thread!

Check your data/lib folder. The condition is already there. You have make it so when it's called, to never end, and Ninja already stated how to do so.

Here is a simple auto regeneration code. I quickly made it tonight, not sure if it works. I used the food script as reference.

creaturtescripts/login.lua
Code:
--auto health mana regeneration
   local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
   if condition == nil then
     player:constregen()
   end

lib/core/player.lua
Code:
local pahealCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)

function Player.constregen(self)
   local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
   local vocation = self:getVocation()

   pahealCondition:setTicks(-1)
   pahealCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, vocation:getHealthGainAmount())
   pahealCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, vocation:getHealthGainTicks() * 1000)
   pahealCondition:setParameter(CONDITION_PARAM_MANAGAIN, vocation:getManaGainAmount())
   pahealCondition:setParameter(CONDITION_PARAM_MANATICKS, vocation:getManaGainTicks() * 1000)

   self:addCondition(pahealCondition)
end
 
Last edited:
Add to config.lua
Code:
-- Auto regeneration HP & MP by waqmaz. Set this global variable to "false" if you want to disable auto regeneration in your Open Tibia Server
autoRegeneration = true

In login.lua above:
Code:
registerCreatureEvent(cid, "Mail")
Add:
Code:
registerCreatureEvent(cid, "regenerating")
In creaturescripts.xml under:
Code:
<creaturescripts>
Add:
Code:
<!-- regen -->
<event type="think" name="regenerating" event="script" value="regenerating.lua"/>
In a folder data/creaturescripts/scripts add a lua file called regenerating.lua and put iside that file:
Code:
local function regenerate(cid, HP, MP)

   if isPlayer(cid) then
  
     if not getCreatureCondition(cid, CONDITION_INFIGHT) then
  
       if (getCreatureHealth(cid) < getCreatureMaxHealth(cid)) then
         doCreatureAddHealth(cid, HP)
         print('HP: '..HP)
       end
       if (getCreatureMana(cid) < getCreatureMaxMana(cid)) then
         doCreatureAddMana(cid, MP)
         print('MP: '..MP)
       end
  
     else
       print('You are not regenerating hp or mp, cuz you are in fight!')
       return false
     end

   end

   return true
end

local t = {
  [1] = {nr = 5, hp = 1, mp = 2}, -- MS
  [2] = {nr = 6, hp = 5, mp = 4}, -- ED
  [3] = {nr = 7, hp = 2, mp = 5}, -- RP
  [4] = {nr = 8, hp = 3, mp = 6}, -- EK
}

local timeBetweenAction = 3

function onThink(cid, interval)

   if getConfigValue("autoRegeneration") == true then

     if lastinterval == nil then
      lastInterval = os.time()
     end

     if (os.time() - lastInterval) > timeBetweenAction then

       local players = getPlayersOnline()
       for i=1,#players do
         for i=1,#t do
           if getPlayerVocation(cid) == t[i].nr then
             regenerate(cid, t[i].hp, t[i].mp)
           end
         end
       end

       lastInterval = os.time()

     end

   else
     return false
   end

   return true
end

That code should regenerates HP or MP every 3 seconds while we are not in a fight. It requires to turn it on in config.lua, writing "true".
You can make that function global adding it to 050-function.lua. Just remove local before the function.
It would be nice to specify HP and MP for each vocation in config.lua instead inside that onThink function. Hovever we can set a timeBetweenAction for each vocation in an array too. I think, you can do it easy, looking how my script is done.
Please like this post, if I have helped you. :)
 
Last edited:
if you care about efficiency over memory
Code:
local players = getPlayersOnline()
       for i=1,#players do
is better than
Code:
       for _, cid in ipairs(getPlayersOnline()) do

https://springrts.com/wiki/Lua_Performance#TEST_9:_for-loops

EDIT:
also the for loop for vocation table isnt really needed, you can get vocation number with
Code:
local voc = getPlayerVoc
local vocN = voc%4 >0 and voc% or 4

and if you dont want promotions to have same reg as normal vocs, you can make the table like
Code:
[vocID (1-4)] = {{hp = 2, mp = 2},{hp = 5, mp = 5}}
and do
table[vocN (prev ex)][math.floor(voc/4 (if you have 4 vocs only))]
 
Last edited:
Back
Top