• 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 Change the item's load

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Could someone help me with this solution?

Currently when I pick up the item it comes with only one charge, I would like to change it in a way that comes 1500 loads or the load I define.

Using OTG 1.3 Version Premium, 12.40

Lua:
local mounts = {
        [1] = {name = "1500x Veteran Exercise Bow", ID = 39582},
        [2] = {name = "1500x Veteran Exercise Rod", ID = 39583},
        [3] = {name = "1500x Veteran Exercise Wand", ID = 39584},
        [4] = {name = "1500x Veteran Exercise Sword", ID = 39585},
        [5] = {name = "1500x Veteran Exercise Axe", ID = 39586},
        [6] = {name = "1500x Veteran Exercise Club", ID = 39587}
    }
     
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("modalExercise")

    if modalWindowId == 1001 then
        if buttonId == 100 then
            if player:getItemCount(39999) == 0 then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "")
            return false
            end
           
            if choiceId == 0 then
                return false
            end
                       
           
            local pot =  player:addItem(mounts[choiceId].ID)
            local charge = 1500
           
            setItemName(pot, getItemNameById(mounts[choiceId].ID)..' x'..charge)
                       
            player:removeItem(39999, 1)        
            player:getPosition():sendMagicEffect(CONST_ME_GREENSMOKE)
        end
    end
end

Error:
XML:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/modalExercise.lua:onModalWindow
data/creaturescripts/scripts/modalExercise.lua:29: attempt to call global 'getItemNameById' (a nil value)
stack traceback:
        [C]: in function 'getItemNameById'
        data/creaturescripts/scripts/modalExercise.lua:29: in function <data/creaturescripts/scripts/modalExercise.lua:10>
 
Solution
E
Lua:
local mounts = {
        [1] = {name = "1500x Veteran Exercise Bow", ID = 39582},
        [2] = {name = "1500x Veteran Exercise Rod", ID = 39583},
        [3] = {name = "1500x Veteran Exercise Wand", ID = 39584},
        [4] = {name = "1500x Veteran Exercise Sword", ID = 39585},
        [5] = {name = "1500x Veteran Exercise Axe", ID = 39586},
        [6] = {name = "1500x Veteran Exercise Club", ID = 39587}
    }

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("modalExercise")

    if modalWindowId == 1001 then
        if buttonId == 100 then
            if choiceId == 0 then
                return false
            end
            player:addItem(mounts[choiceId].ID, 1500)
        end
    end
end
Lua:
local mounts = {
        [1] = {name = "1500x Veteran Exercise Bow", ID = 39582},
        [2] = {name = "1500x Veteran Exercise Rod", ID = 39583},
        [3] = {name = "1500x Veteran Exercise Wand", ID = 39584},
        [4] = {name = "1500x Veteran Exercise Sword", ID = 39585},
        [5] = {name = "1500x Veteran Exercise Axe", ID = 39586},
        [6] = {name = "1500x Veteran Exercise Club", ID = 39587}
    }

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("modalExercise")

    if modalWindowId == 1001 then
        if buttonId == 100 then
            if choiceId == 0 then
                return false
            end
            player:addItem(mounts[choiceId].ID, 1500)
        end
    end
end
 
Solution
Lua:
local mounts = {
        [1] = {name = "1500x Veteran Exercise Bow", ID = 39582},
        [2] = {name = "1500x Veteran Exercise Rod", ID = 39583},
        [3] = {name = "1500x Veteran Exercise Wand", ID = 39584},
        [4] = {name = "1500x Veteran Exercise Sword", ID = 39585},
        [5] = {name = "1500x Veteran Exercise Axe", ID = 39586},
        [6] = {name = "1500x Veteran Exercise Club", ID = 39587}
    }

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("modalExercise")

    if modalWindowId == 1001 then
        if buttonId == 100 then
            if choiceId == 0 then
                return false
            end
            player:addItem(mounts[choiceId].ID, 1500)
        end
    end
end

Thank you very much, look what I had done,
I didn't know you could set it with the addItem


Lua:
local item = player:addItem(mounts[choiceId].ID)

            item:setAttribute(ITEM_ATTRIBUTE_CHARGES,(1500))
 
Back
Top