cocacola13
Member
Have problem this code is not work im
i need wand + wand + 150 tokens to upgrade wand and mana leech +1% and hp leech +1 and max value is 20% but i can't create it
update have problem:
i need wand + wand + 150 tokens to upgrade wand and mana leech +1% and hp leech +1 and max value is 20% but i can't create it
Lua:
local function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local requiredTokens = 150
local wandID = 7429
local leverID = 10559
local maxLevel = 20
local hpLeechIncrement = 1
local manaLeechIncrement = 1
if item:getId() == leverID and player:getOnlineTokens() >= requiredTokens then
local wands = {}
local wandCount = 0
for _, item in ipairs(player:getItems()) do
if item:getId() == wandID then
table.insert(wands, item)
wandCount = wandCount + 1
end
end
if wandCount >= 2 then
local wand = wands[1]
local hpLeech = wand:getExtraParam(ITEM_PARAM_HEALTHLEECH)
local manaLeech = wand:getExtraParam(ITEM_PARAM_MANALEECH)
if hpLeech < maxLevel or manaLeech < maxLevel then
hpLeech = math.min(hpLeech + hpLeechIncrement, maxLevel)
manaLeech = math.min(manaLeech + manaLeechIncrement, maxLevel)
wand:setExtraParam(ITEM_PARAM_HEALTHLEECH, hpLeech)
wand:setExtraParam(ITEM_PARAM_MANALEECH, manaLeech)
player:removeItem(leverID, 1)
player:removeOnlineTokens(requiredTokens)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The lever has consumed 150 online tokens and upgraded the wand with 1% mana leech and 1% hp leech.")
wands[2]:remove(1) -- Remove the second wand from the player's inventory
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "The wand is already at its maximum upgrade level.")
end
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need two identical wands to upgrade them.")
end
end
return true
end
local testAction = Action()
testAction.actionid = 3500 -- Action ID for the lever
testAction.func = onUse
testAction:register()
Post automatically merged:
update have problem:
Lua:
data/lib/compat/compat.lua:92: bad argument #1 to 'rawset' (table expected, got userdata)
stack traceback:
[C]: at 0x55c9ba11ae5e
[C]: in function 'rawset'
data/lib/compat/compat.lua:92: in function '__newindex'
/home/*****/data/scripts/lever.lua:40: in main chunk
[C]: in function 'reload'
data/talkactions/scripts/reload.lua:81: in function <data/talkactions/scripts/reload.lua:59>
> lever.lua [error]
Last edited: