• 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 Advance Scripts - Money & Health and Mana FULL on level up

Loth Gena

Roxeria 8.60 Developer
Joined
Feb 5, 2014
Messages
245
Reaction score
23
Location
UK
Hi all, i tried to search but couldn't find any working scripts for my needs.

Im using TFS 0.3.6 (V8.2) Tibia Client 8.60

Im looking for 2 scripts (think they go in creaturescripts folder);
First script to add money for level (3cc at 30lvl, 5cc at 50lvl and 10cc at 100lvl). With storage so that when a player dies he cannot get the money again for advancing on the same level.

Second script is every time a player levels up, his health and mana goes back to full.

Any help will be much appreciated, thank you
 
Solution
Hehe, Thanks, but there seems to be 1 more issue :D i get no errors this time, but, after level 30, players get money on every level (31, 32, 33, and so on) it keeps saying congratulations for reaching level 30
Maybe I was drunk writing this script. lmfao
Lua:
setPlayerStorageValue(cid, storage)
Lua:
setPlayerStorageValue(cid, storage, table_level)
Hi all, i tried to search but couldn't find any working scripts for my needs.

Im using TFS 0.3.6 (V8.2) Tibia Client 8.60

Im looking for 2 scripts (think they go in creaturescripts folder);
First script to add money for level (3cc at 30lvl, 5cc at 50lvl and 10cc at 100lvl). With storage so that when a player dies he cannot get the money again for advancing on the same level.

Second script is every time a player levels up, his health and mana goes back to full.

Any help will be much appreciated, thank you

Lua:
local levelReward = {
    [30] = 3,
    [50] = 5,
    [100] = 10
}

function onAdvance(cid, skill, oldLevel, newLevel)
    doCreatureAddHealth(cid, getCreatureHealth(cid))
    doCreatureAddMana(cid, getCreatureMana(cid))

    for k, v in pairs(levelReward) do
        if newLevel == k and getPlayerStorageValue(cid, 3746) < k then
            doPlayerAddItem(cid, 2160, v, TRUE)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations, you\'ve received "..v.." crystal coins as a reward for level "..k..".")
      
            setPlayerStorageValue(cid, 3746, k)
        end
    end
    return true
end

Something like this should work. Untested though so let me know how it goes.
 
change
Lua:
    doCreatureAddHealth(cid, getCreatureHealth(cid))
    doCreatureAddMana(cid, getCreatureMana(cid))
to
Lua:
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
    doCreatureAddMana(cid, getCreatureMaxMana(cid))
 
Just wanting to point out that if a player levels up from 29 to 31, skipping level 30, they will miss out on the level 30 reward with the current script.
If they can't level up that fast, then no need to worry about changing the script.
 
Oops, only just realized the script includes mana and health gain :D everything works with "Max" health and mana, thank you all for replies.
And @Xikini thats a good point, is there anything i could add to the script to prevent that? or is this a case of having a new script
 
Oops, only just realized the script includes mana and health gain :D everything works with "Max" health and mana, thank you all for replies.
And @Xikini thats a good point, is there anything i could add to the script to prevent that? or is this a case of having a new script
Well, if you want something a bit more advanced, I created a similar script awhile ago in my thread. Xikini's Free Scripting Service. [0.3.7 & (0.3.6/0.4)]

If you only want 1 item like above script, then you just want to loop through a slightly different table.
(I couldn't help add a bit more functionality to the script though. Sorry about that.)
Lua:
local storage = 3746
local levelReward = {
   [1] = {10, 2160, 1, "crystal coin"},
   [2] = {30, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
   [3] = {50, 2160, 5, "crystal coins"}, -- level, itemID, item_amount, item_name
   [4] = {100, 2160, 10, "crystal coins"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
   -- this is to make sure that the players skill is actually increasing
   -- it's also to check that it's their level that is increasing, and not their fisting skill or something
   if skill ~= SKILL__LEVEL or oldlevel >= newLevel then
       return true
   end

   doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
   doCreatureAddMana(cid, getCreatureMaxMana(cid))

   for i = 1, levelReward do
       local table_level = levelReward[i][1]
       if newLevel >= table_level and table_level > getPlayerStorageValue(cid, storage) then
           local table_count = levelReward[i][3]
           doPlayerAddItem(cid, levelReward[i][2], table_count, true)
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations, system has sent " .. table_count .. " " .. levelReward[i][4] .. " as a reward for level " .. table_level .. " to your location!")
           setPlayerStorageValue(cid, storage)
           break
       end
   end

   return true
end
 
Well, if you want something a bit more advanced, I created a similar script awhile ago in my thread. Xikini's Free Scripting Service. [0.3.7 & (0.3.6/0.4)]

If you only want 1 item like above script, then you just want to loop through a slightly different table.
(I couldn't help add a bit more functionality to the script though. Sorry about that.)
Lua:
local storage = 3746
local levelReward = {
   [1] = {10, 2160, 1, "crystal coin"},
   [2] = {30, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
   [3] = {50, 2160, 5, "crystal coins"}, -- level, itemID, item_amount, item_name
   [4] = {100, 2160, 10, "crystal coins"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
   -- this is to make sure that the players skill is actually increasing
   -- it's also to check that it's their level that is increasing, and not their fisting skill or something
   if skill ~= SKILL__LEVEL or oldlevel >= newLevel then
       return true
   end

   doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
   doCreatureAddMana(cid, getCreatureMaxMana(cid))

   for i = 1, levelReward do
       local table_level = levelReward[i][1]
       if newLevel >= table_level and table_level > getPlayerStorageValue(cid, storage) then
           local table_count = levelReward[i][3]
           doPlayerAddItem(cid, levelReward[i][2], table_count, true)
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations, system has sent " .. table_count .. " " .. levelReward[i][4] .. " as a reward for level " .. table_level .. " to your location!")
           setPlayerStorageValue(cid, storage)
           break
       end
   end

   return true
end

Mmm doesn't seem to work, i get an error in the console every time a player levels up. No money given and no max mana or health, here is the code:
Code:
[04/01/2018 19:51:19] [Error - CreatureScript Interface]
[04/01/2018 19:51:19] data/creaturescripts/scripts/reward.lua:onAdvance
[04/01/2018 19:51:19] Description:
[04/01/2018 19:51:19] data/creaturescripts/scripts/reward.lua:12: attempt to compare number with nil
[04/01/2018 19:51:19] stack traceback:
[04/01/2018 19:51:19]     data/creaturescripts/scripts/reward.lua:12: in function <data/creaturescripts/scripts/reward.lua:9>
 
Mmm doesn't seem to work, i get an error in the console every time a player levels up. No money given and no max mana or health, here is the code:
Code:
[04/01/2018 19:51:19] [Error - CreatureScript Interface]
[04/01/2018 19:51:19] data/creaturescripts/scripts/reward.lua:onAdvance
[04/01/2018 19:51:19] Description:
[04/01/2018 19:51:19] data/creaturescripts/scripts/reward.lua:12: attempt to compare number with nil
[04/01/2018 19:51:19] stack traceback:
[04/01/2018 19:51:19]     data/creaturescripts/scripts/reward.lua:12: in function <data/creaturescripts/scripts/reward.lua:9>
change
Lua:
if skill ~= SKILL__LEVEL or oldlevel >= newLevel then
Lua:
if skill ~= SKILL__LEVEL or oldLevel >= newLevel then
 
change
Lua:
if skill ~= SKILL__LEVEL or oldlevel >= newLevel then
Lua:
if skill ~= SKILL__LEVEL or oldLevel >= newLevel then
Thanks, mana and health work now, but get another error when a player levels up;
Code:
[05/01/2018 08:29:52] [Error - CreatureScript Interface]
[05/01/2018 08:29:52] data/creaturescripts/scripts/reward.lua:onAdvance
[05/01/2018 08:29:52] Description:
[05/01/2018 08:29:52] data/creaturescripts/scripts/reward.lua:19: 'for' limit must be a number
[05/01/2018 08:29:52] stack traceback:
[05/01/2018 08:29:52]     data/creaturescripts/scripts/reward.lua:19: in function <data/creaturescripts/scripts/reward.lua:9>
 
Thanks, mana and health work now, but get another error when a player levels up;
Code:
[05/01/2018 08:29:52] [Error - CreatureScript Interface]
[05/01/2018 08:29:52] data/creaturescripts/scripts/reward.lua:onAdvance
[05/01/2018 08:29:52] Description:
[05/01/2018 08:29:52] data/creaturescripts/scripts/reward.lua:19: 'for' limit must be a number
[05/01/2018 08:29:52] stack traceback:
[05/01/2018 08:29:52]     data/creaturescripts/scripts/reward.lua:19: in function <data/creaturescripts/scripts/reward.lua:9>
zzzz these stupid small mistakes.
Lua:
for i = 1, levelReward do
Lua:
for i = 1, #levelReward do
 
zzzz these stupid small mistakes.
Lua:
for i = 1, levelReward do
Lua:
for i = 1, #levelReward do
Hehe, Thanks, but there seems to be 1 more issue :D i get no errors this time, but, after level 30, players get money on every level (31, 32, 33, and so on) it keeps saying congratulations for reaching level 30
 
Also i removed the level 10 1cc reward, not sure if thats why i get this issue.. but here is what i changed it to:
Lua:
   [1] = {30, 2160, 1, "crystal coin"},
   [2] = {50, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
   [3] = {100, 2160, 10, "crystal coins"}, -- level, itemID, item_amount, item_name
 
Hehe, Thanks, but there seems to be 1 more issue :D i get no errors this time, but, after level 30, players get money on every level (31, 32, 33, and so on) it keeps saying congratulations for reaching level 30
Maybe I was drunk writing this script. lmfao
Lua:
setPlayerStorageValue(cid, storage)
Lua:
setPlayerStorageValue(cid, storage, table_level)
 
Solution
You got the answer, but some people might need some more features, like items in a backpack, only for vocation, or for the specified skill.

That's why I made a mod for TFS 0.3/0.4, like 7 years ago.

https://raw.githubusercontent.com/slawkens/tfs-mods/master/advance-reward.xml

Just copy it into your mods/ dir, and configure as you wish. You can add rewards for skills, levels, magic level, backpack items, custom broadcast messages, custom callback.

You can also add health/mana to full-on advance, where you configure it as follows:
Lua:
{skill = SKILL__LEVEL, level = 1, storage = 0, message = false,
   callback = function(cid, reward)
      doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
      doCreatureAddMana(cid, getCreatureMaxMana(cid))
      return true
   end
},
 
You got the answer, but some people might need some more features, like items in a backpack, only for vocation, or for the specified skill.

That's why I made a mod for TFS 0.3/0.4, like 7 years ago.

https://raw.githubusercontent.com/slawkens/tfs-mods/master/advance-reward.xml

Just copy it into your mods/ dir, and configure as you wish. You can add rewards for skills, levels, magic level, backpack items, custom broadcast messages, custom callback.

You can also add health/mana to full-on advance, where you configure it as follows:
Lua:
{skill = SKILL__LEVEL, level = 1, storage = 0, message = false,
   callback = function(cid, reward)
      doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
      doCreatureAddMana(cid, getCreatureMaxMana(cid))
      return true
   end
},
Thanks i will save that, will be useful if i come up with something :)
 
Back
Top