• 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 LUA scripting function; onAdvance

dysodium

New Member
Joined
Aug 11, 2024
Messages
2
Reaction score
0
I am very new to scripting on OT tibia servers... date of start, yesterday. I am currenctly working on xp-ganing systems and rebirth systems and I am wondering if onAdvance functions has to have getPlayerStorageValue to work, becuase I have tried a lot of different onAdvance if statement scripts but the only ones that work are those who use getPlayerStorageValue.

Is there another way to write a functional script without getPlayerStorageValue or is it needed?

Reference script; working:
function onAdvance(cid, skill, oldlevel, newlevel)

if(getPlayerStorageValue(cid, 60362) ~= 1 and skill == SKILL__LEVEL and newlevel >= 45) then
doPlayerAddItem(cid, 2152, 50)
setPlayerStorageValue(cid, 60362, 1)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_RED)
local message = "You have received 15 crystal coins for reaching level 45."
doCreatureSay(cid, message, TALKTYPE_ORANGE_1)
doPlayerSendTextMessage(cid, 19, "You have received 50 platinum coins for reaching level 45.")
end
return TRUE
end

Reference script; not working:
function onAdvance(cid, skill, oldlevel, newlevel)

if 1 == 1 then
doPlayerAddItem(cid, 2152, 50)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_RED)
local message = "You have received 15 crystal coins for reaching level 45."
doCreatureSay(cid, message, TALKTYPE_ORANGE_1)
doPlayerSendTextMessage(cid, 19, "You have received 50 platinum coins for reaching level 45.")
end
return TRUE
end
 
I am very new to scripting on OT tibia servers... date of start, yesterday. I am currenctly working on xp-ganing systems and rebirth systems and I am wondering if onAdvance functions has to have getPlayerStorageValue to work, becuase I have tried a lot of different onAdvance if statement scripts but the only ones that work are those who use getPlayerStorageValue.

Is there another way to write a functional script without getPlayerStorageValue or is it needed?

Reference script; working:
function onAdvance(cid, skill, oldlevel, newlevel)

if(getPlayerStorageValue(cid, 60362) ~= 1 and skill == SKILL__LEVEL and newlevel >= 45) then
doPlayerAddItem(cid, 2152, 50)
setPlayerStorageValue(cid, 60362, 1)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_RED)
local message = "You have received 15 crystal coins for reaching level 45."
doCreatureSay(cid, message, TALKTYPE_ORANGE_1)
doPlayerSendTextMessage(cid, 19, "You have received 50 platinum coins for reaching level 45.")
end
return TRUE
end

Reference script; not working:
function onAdvance(cid, skill, oldlevel, newlevel)

if 1 == 1 then
doPlayerAddItem(cid, 2152, 50)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_RED)
local message = "You have received 15 crystal coins for reaching level 45."
doCreatureSay(cid, message, TALKTYPE_ORANGE_1)
doPlayerSendTextMessage(cid, 19, "You have received 50 platinum coins for reaching level 45.")
end
return TRUE
end
Here's an example i use:

LUA:
local storage = 3746
local levelReward = {
   [1] = {30, 2160, 1, "crystal coin"},
   [2] = {60, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
   [3] = {100, 2160, 5, "crystal coins"}, -- level, itemID, item_amount, item_name
   [4] = {150, 2160, 10, "crystal coins"},
   [5] = {200, 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
   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, ExtremeOT has sent " .. table_count .. " " .. levelReward[i][4] .. " as a reward for level " .. table_level .. " to your location!")
           setPlayerStorageValue(cid, storage, table_level)       
           break
       end
   end

   return true
end

U need to keep some information in a storage to validate the "new level", you must have to add to avoid some bugs in code. In my code, if i dont keep storage, player can receive money getting level 30, dying and back to 29 and get money again at level 30.
 
Aha ok, so I do have to have storage for onAdvance to work? I am just using another type of script for referance to see if what I want to do works. I do not want to create a levelreward system. I just want to cap the experience to a specific number so that the character cannot level any further than a specific number. I have checked with stages and you can indeed put a number in there to stop gaining experience after a specific level. But if you do somehow level beyond that point of entry... you will be higher than the "cap".

My question for this is if I can create a script without the use of storage.
 
Back
Top