• 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 Equipment from Level Advance

Kodak

Member
Joined
Jun 7, 2007
Messages
36
Reaction score
6
So I wrote this script using some info I found here on the forums.
In theory, it should work as,
If Level 20 & No storage value then
If Knight/Elite Knight then
If Axe > then Sword & Club, give axe weapon
Else if Sword > Axe & Club then give sword weapon
Else if Club > Sword & Axe then give club weapon

If Sorc/MS then give Wand
If Druid/ED then give Rod
If Paladin/RP then give spear,
along with adding storage and a message with each.

Currently it only sets storage value, and sets it to 62, no 1 for some reason, with no weapon given or message shown.

Figure another set of eyes would help. Used as a creature script:

Lua:
function onAdvance(cid, oldLevel, newLevel)
    if getPlayerLevel(cid) >= 20 and getPlayerStorageValue(cid, 8141) == -1 then
        if player:getVocation() == 4 or player:getVocation() == 8 then
                if player:getSkillLevel(cid, SKILL_AXE) > player:getSkillLevel(cid, SKILL_SWORD) and player:getSkillLevel(cid, SKILL_AXE) > player:getSkillLevel(cid, SKILL_CLUB) then
                            player:addItem(2429, 1)
                            player:addStorage(8141, 1)
                            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have received a barbarian axe. Thank you for playing.")
                elseif player:getSkillLevel(cid, SKILL_CLUB) > player:getSkillLevel(cid, SKILL_SWORD) and player:getSkillLevel(cid, SKILL_CLUB) > player:getSkillLevel(cid, SKILL_AXE) then
                            player:addItem(2423, 1)
                            player:addStorage(8141, 1)
                            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have received a clarical mace. Thank you for playing.")
                elseif  player:getSkillLevel(cid, SKILL_SWORD) > player:getSkillLevel(cid, SKILL_CLUB) and player:getSkillLevel(cid, SKILL_SWORD) > player:getSkillLevel(cid, SKILL_AXE) then
                            player:addItem(2383, 1)
                            player:addStorage(8141, 1)
                            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have received a spike sword. Thank you for playing.")
                end
           
        elseif player:getVocation() == 1 or player:getVocation() == 5 then
                    player:addItem(2189, 1)
                    player:addStorage(8141, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have received a wand of cosmic energy. Thank you for playing.")
        elseif player:getVocation() == 2 or player:getVocation() == 6 then
                    player:addItem(2185, 1)
                    player:addStorage(8141, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have received a necrotic rod. Thank you for playing.")
        elseif player:getVocation() == 3 or player:getVocation() == 7 then
                    player:addItem(2429, 1)
                    player:addStorage(8141, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have received a hunting spear. Thank you for playing.")                   
           

        end
    end
return true
end





function onLogin(player)
    player:registerEvent("onadvance_reward3")
    return true
end
 
Solution
the script is entirely wrong, you're mixing 0.x with 1.x scripting style
you're trying to use player but there is no player defined because you rewrote it in the function parameters as cid
all player methods do not need cid, so player:getSkillLevel(cid, skill) is wrong because there's already a player object, no need for cid
player:getSkillLevel(skill)
also player:getVocation() returns a vocation userdata, use player:getVocation():getId()
rename cid to player in onAdvance params
remove all cases of cid where you use a player method
change getPlayerLevel, getPlayerStorageValue, doPlayerSendTextMessage with player:getLevel(), player:getStorageValue(xxx), player:sendTexMessage(type, msg)
the script is entirely wrong, you're mixing 0.x with 1.x scripting style
you're trying to use player but there is no player defined because you rewrote it in the function parameters as cid
all player methods do not need cid, so player:getSkillLevel(cid, skill) is wrong because there's already a player object, no need for cid
player:getSkillLevel(skill)
also player:getVocation() returns a vocation userdata, use player:getVocation():getId()
rename cid to player in onAdvance params
remove all cases of cid where you use a player method
change getPlayerLevel, getPlayerStorageValue, doPlayerSendTextMessage with player:getLevel(), player:getStorageValue(xxx), player:sendTexMessage(type, msg)
 
Solution
I didn't actually read your post but here's my script that I have for 1.3.
Lua:
local c = {
   [{1,5}] = { -- sorcerer
     [13] = {items = {{itemid = 2191, count = 1}}, storage = 40950},
    [15] = {items = {{itemid = 2152, count = 20}}, 40951},
    [18] = {items = {{itemid = 2315, count = 25}}, storage = 40960},---BIG STORAGE
     [19] = {items = {{itemid = 2188, count = 1}}, storage = 40952},
     [22] = {items = {{itemid = 8921, count = 1}}, storage = 40953},
     [26] = {items = {{itemid = 2189, count = 1}}, storage = 40954},
    [30] = {items = {{itemid = 2152, count = 50}}, storage = 40955},
     [33] = {items = {{itemid = 2187, count = 1}}, storage = 40956},
     [37] = {items = {{itemid = 8920, count = 1}}, storage = 40957},
     [42] = {items = {{itemid = 8922, count = 1}}, storage = 40958},
    [50] = {items = {{itemid = 2160, count = 2}}, storage = 40959}
   },
   [{2,6}] = { -- druid
     [13] = {items = {{itemid = 2186, count = 1}}, storage = 40950},
    [15] = {items = {{itemid = 2152, count = 20}}, 40951},
    [18] = {items = {{itemid = 2288, count = 25}}, storage = 40960},---BIG STORAGE
     [19] = {items = {{itemid = 2185, count = 1}}, storage = 40952},
     [22] = {items = {{itemid = 8911, count = 1}}, storage = 40953},
     [26] = {items = {{itemid = 2181, count = 1}}, storage = 40954},
    [30] = {items = {{itemid = 2152, count = 50}}, storage = 40955},
     [33] = {items = {{itemid = 2183, count = 1}}, storage = 40956},
     [37] = {items = {{itemid = 8912, count = 1}}, storage = 40957},
     [42] = {items = {{itemid = 8910, count = 1}}, storage = 40958},
    [50] = {items = {{itemid = 2160, count = 2}}, storage = 40959}
   },
   [{3,7}] = { -- paladin
     [12] = {items = {{itemid = 2389, count = 5}}, storage = 40950},
    [15] = {items = {{itemid = 2152, count = 20}}, 40951},
     [16] = {items = {{itemid = 2389, count = 10}}, storage = 40952},
    [17] = {items = {{itemid = 2295, count = 25}}, storage = 40959}, ---BIG STORAGE
     [20] = {items = {{itemid = 3965, count = 10}}, storage = 40953},
     [25] = {items = {{itemid = 7378, count = 10}}, storage = 40954},
     [30] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}, {itemid = 2152, count = 50}}, storage = 40955},
     [35] = {items = {{itemid = 7364, count = 100}}, storage = 40956},
     [40] = {items = {{itemid = 7365, count = 100}}, storage = 40957},
    [50] = {items = {{itemid = 2160, count = 2}}, storage = 40958},
   },
   [{4,8}] = { -- knight
     [15] = {items = {{itemid = 2409, count = 1}, {itemid = 2265, count = 25}, {itemid = 2152, count = 20}}, storage = 40950},
     [30] = {items = {{itemid = 2392, count = 1}, {itemid = 2152, count = 50}}, storage = 40951},
     [40] = {items = {{itemid = 2407, count = 1}, {itemid = 2160, count = 1}}, storage = 40952},
    [50] = {items = {{itemid = 2160, count = 2}}, storage = 40953}
   }
}

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_EVENT_ADVANCE, "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

XML:
<event type="advance" name="AdvanceReward" script="levelup.lua"/>

Lua:
player:registerEvent("AdvanceReward")
 
Back
Top