• 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 Items for advance on each vocation.

shayenek

New Member
Joined
Jun 20, 2013
Messages
40
Reaction score
1
Location
Poland
Hello guys. I need some help creating script that gives item, different for every vocation, for advance in level. Example: on lvl 20 knight will get spike sword, on lvl 30 fire sword, druid/sorc will get rod/wand for lvl 19 at lvl 19 and then on level 33 will get rod/wand for 33lvl. Paladin some spears or bow + arrows. I tried to use this script http://otland.net/threads/reward-for-each-single-vocation-onadvance.153115/ but it doesnt work for me. So I want to ask if you guys could make something like that for me.

Edit. Forgot to mention. I use TFS 1.0.
 
Code:
local c = {
   [{1,5}] = {
     [15] = {itemid = 2160, count = 1, storage = 99963},
     [30] = {itemid = 2160, count = 3, storage = 99964},
     [45] = {itemid = 2160, count = 5, storage = 99965}
   },
   [{2,6}] = {
     [15] = {itemid = 2160, count = 1, storage = 99963},
     [30] = {itemid = 2160, count = 3, storage = 99964},
     [45] = {itemid = 2160, count = 5, storage = 99965}
   },
   [{3,7}] = {
     [15] = {itemid = 2160, count = 1, storage = 99963},
     [30] = {itemid = 2160, count = 3, storage = 99964},
     [45] = {itemid = 2160, count = 5, storage = 99965}
   },
   [{4,8}] = {
     [15] = {itemid = 2160, count = 1, storage = 99963},
     [30] = {itemid = 2160, count = 3, storage = 99964},
     [45] = {itemid = 2160, count = 5, storage = 99965}
   }
}

function onAdvance(cid, skill, oldlevel, newlevel)
     if skill ~= SKILL_LEVEL then
         return true
     end

     for voc, x in pairs(c) do
         if isInArray(voc, getPlayerVocation(cid)) then
             for level, z in pairs(x) do
                 if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
                     doPlayerAddItem(cid, z.itemid, z.count)
                     local item = getItemDescriptions(z.itemid)
                     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..(z.count == 1 and item.article or z.count).." "..(z.count == 1 and item.name or item.plural)..".")
                     doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
                     setPlayerStorageValue(cid, z.storage, 1)
                 end
             end
         end
     end
     return true
end
 
Just tested it with TFS 1.0
Lj5N2J.png

LUpC5z.png

Works fine for me. This is how I added it.
creaturescripts.xml
Code:
<event type="advance" name="Advance" script="advance.lua"/>
login.lua
Code:
player:registerEvent("Advance")
 
I just got one from a different post, but this one looks more advanced and good. But I dont wanna edit again xD!
 
Yeah, you're right. My bad. I did typo in login.lua with event. Thanks for help.

Edit. Last question. How do I edit this to give 2 or even 3 different items for one level advance? For example, paladin level 20: bow + 100 arrows.
 
Last edited:
sO1MUT.png

Code:
local c = {
   [{1,5}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   },
   [{2,6}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   },
   [{3,7}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   },
   [{4,8}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   }
}

function onAdvance(cid, skill, oldlevel, newlevel)
     if skill ~= SKILL_LEVEL then
         return true
     end

     for voc, x in pairs(c) do
         if isInArray(voc, getPlayerVocation(cid)) then
             for level, z in pairs(x) do
                 if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
                     local text = ""
                     for v = 1, #z.items do
                         count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
                         local ret = ", "
                         if v == 1 then
                             ret = ""
                         elseif v == #z.items then
                             ret = " and "
                         end
                         text = text .. ret
                         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
                         doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
                     end
                     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
                     doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
                     setPlayerStorageValue(cid, z.storage, 1)
                 end
             end
         end
     end
     return true
end
 
Hmm.. idk if i did something wrong, but i did not recieve any items, nor were there any errors in my console.

Code:
local c = {
   [{1,5}] = {
     [13] = {items = {{itemid = 2186, count = 1}}, storage = 20046},
     [19] = {items = {{itemid = 2185, count = 1}}, storage = 20047},
     [20] = {items = {{itemid = 2160, count = 2}}, storage = 20048},
     [22] = {items = {{itemid = 8911, count = 1}}, storage = 20049},
     [25] = {items = {{itemid = 7620, count = 30}}, storage = 20050},
     [26] = {items = {{itemid = 2181, count = 1}}, storage = 20051},
     [50] = {items = {{itemid = 2160, count = 5}}, storage = 20052},
     [100] = {items = {{itemid = 2160, count = 10}}, storage = 20053}
   },
   [{2,6}] = {
     [13] = {items = {{itemid = 2191, count = 1}}, storage = 20054},
     [19] = {items = {{itemid = 2188, count = 1}}, storage = 20055},
     [20] = {items = {{itemid = 2160, count = 2}}, storage = 20056},
     [22] = {items = {{itemid = 8921, count = 1}}, storage = 20057},
     [25] = {items = {{itemid = 7620, count = 30}}, storage = 20058},
     [26] = {items = {{itemid = 2189, count = 1}}, storage = 20059},
     [50] = {items = {{itemid = 2160, count = 5}}, storage = 20060},
     [100] = {items = {{itemid = 2160, count = 10}}, storage = 20061}
   },
   [{3,7}] = {
     [20] = {items = {{itemid = 2160, count = 2}}, storage = 20062},
     [25] = {items = {{itemid = 7620, count = 20}, {itemid = 7618, count = 20}, {itemid = 7378, count = 1}}, storage = 20063},
     [50] = {items = {{itemid = 2160, count = 5}}, storage = 20064},
     [100] = {items = {{itemid = 2160, count = 10}}, storage = 20065}
   },
   [{4,8}] = {
     [20] = {items = {{itemid = 2160, count = 2}}, storage = 20066},
     [25] = {items = {{itemid = 7618, count = 30}, {itemid = 2518, count = 1}}, storage = 20067},
     [50] = {items = {{itemid = 2160, count = 5}}, storage = 20068},
     [100] = {items = {{itemid = 2160, count = 10}}, storage = 20069}
   }
}

function onAdvance(cid, skill, oldlevel, newlevel)
     if skill ~= SKILL_LEVEL then
         return true
     end

     for voc, x in pairs(c) do
         if isInArray(voc, getPlayerVocation(cid)) then
             for level, z in pairs(x) do
                 if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
                     local text = ""
                     for v = 1, #z.items do
                         count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
                         local ret = ", "
                         if v == 1 then
                             ret = ""
                         elseif v == #z.items then
                             ret = " and "
                         end
                         text = text .. ret
                         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
                         doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
                     end
                     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
                     doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
                     setPlayerStorageValue(cid, z.storage, 1)
                 end
             end
         end
     end
     return true
end




EDIT - im an idoit, just realized this is for 1.0. I'm using 0.3.6, is there one for this version?
 
can't get this to work for tfs 1.0 no errors on console.

i used the correctiosn you posted for tfs 1.0
Code:
local c = {
   [{1,5}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   },
   [{2,6}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   },
   [{3,7}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   },
   [{4,8}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
   }
}

function onAdvance(cid, skill, oldlevel, newlevel)
     if skill ~= 8 then
         return true
     end

     local player = Player(cid)
     for voc, x in pairs(c) do
         if isInArray(voc, player:getVocation():getId()) then
             for level, z in pairs(x) do
                 if newlevel >= level and player:getStorageValue(z.storage) ~= 1 then
                     local text = ""
                     for v = 1, #z.items do
                         count, info = z.items[v].count, ItemType(z.items[v].itemid)
                         local ret = ", "
                         if v == 1 then
                             ret = ""
                         elseif v == #z.items then
                             ret = " and "
                         end
                         text = text .. ret
                         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
                         player:addItem(z.items[v].itemid, z.items[v].count)
                     end
                     player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
                     player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
                     player:setStorageValue(z.storage, 1)
                 end
             end
         end
     end
     return true
end
 
proposal to update only one Storage

Code:
local storage = 25000
local c = {
   [{1,5}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 1},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 2},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 3}
   },
   [{2,6}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 1},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 2},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 3}
   },
   [{3,7}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 1},
     [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 2},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 3}
   },
   [{4,8}] = {
     [15] = {items = {{itemid = 2160, count = 1}}, storage = 1},
     [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 2},
     [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 3}
   }
}

function onAdvance(cid, skill, oldlevel, newlevel)
     if skill ~= SKILL_LEVEL then
         return true
     end

     for voc, x in pairs(c) do
         if isInArray(voc, getPlayerVocation(cid)) then
             for level, z in pairs(x) do
                 if newlevel >= level and getPlayerStorageValue(cid, storage) <= z.storage then
                     local text = ""
                     for v = 1, #z.items do
                         count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
                         local ret = ", "
                         if v == 1 then
                             ret = ""
                         elseif v == #z.items then
                             ret = " and "
                         end
                         text = text .. ret
                         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
                         doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
                     end
                     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
                     doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
                     setPlayerStorageValue(cid, storage, z.storage)
                 end
             end
         end
     end
     return true
end
 
Back
Top