• 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 [Help] I can´t make this script :C

exanime

I´m learning Lua
Joined
Oct 24, 2011
Messages
40
Reaction score
3
Location
Bogota, Colombia
I did this code, nevertheless this mistake gives me, not that parameter to put in the line 13 or in the function slott:getActionId ()???
It helps please

my script TFS 1.3

Lua:
local ids = {
    {thing = "Legendary", chance = 2, itemID = 2475, actionID = 45115, armor = 3, speed = 10, extradefense = 3}, --2%
    {thing = "Bound", chance = 15, itemID = 2475, actionID = 45114, armor = 3, speed = 10, extradefense = 3}, --13%
    {thing = "Normal", chance = 100, itemID = 2475, actionID = 45113, armor = 3, speed = 10, extradefense = 3} --85%
}
--player:getSlotItem(CONST_SLOT_HEAD)
--item:getActionId()
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function onEquip(player, item, slot)
for _, t in ipairs(ids) do
local slott = player:getSlotItem(CONST_SLOT_HEAD)
local slot_actionid = slott:getActionId()
if t.actionID == slot_actionid then --compare actionID with actionID on head slot
item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense)
item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor)
local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed)
player:addCondition(speedCondition)
item:setAttribute("description", "+ ".. t.armor .." Armor")
item:setAttribute("description", "+ ".. t.speed .." Speed")
item:setAttribute("description", "+ ".. t.extradefense .." Extradefense")
end --end if
end --end for
return true --return value
end -- end function
---------------------------------------------------------------------------
--///////////////////////////////////////////////////////////////////////--
---------------------------------------------------------------------------
function onDeEquip(player, item, slot)
for _, t in ipairs(ids) do
local slott = player:getSlotItem(CONST_SLOT_HEAD)
local slot_actionid = slott:getActionId()
if t.actionID == slot_actionid then
item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense * 0)
item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor * 0)
local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed * 0)
player:addCondition(speedCondition)
item:removeAttribute("description", "+ ".. t.armor .." Armor")
item:removeAttribute("description", "+ ".. t.speed .." Speed")
item:removeAttribute("description", "+ ".. t.extradefense .." Extradefense")
end --end if
end --end for
return true --return value
end--end function
---------------------------------------------------------------------------
---------------------------------------------------------------------------


I get this error
83327035585a6a2d16b7e2b404d1b094o.png
 
Last edited by a moderator:
Solution
Retrieving your head slot item inside the loop sounds uneccesary.
slot_actionid should be set after you confirm that the slott exist.
Lua:
local ids = {
    {thing = "Legendary", chance = 2, itemID = 2475, actionID = 45115, armor = 3, speed = 10, extradefense = 3}, --2%
    {thing = "Bound", chance = 15, itemID = 2475, actionID = 45114, armor = 3, speed = 10, extradefense = 3}, --13%
    {thing = "Normal", chance = 100, itemID = 2475, actionID = 45113, armor = 3, speed = 10, extradefense = 3} --85%
}
--player:getSlotItem(CONST_SLOT_HEAD)
--item:getActionId()
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function onEquip(player...
Retrieving your head slot item inside the loop sounds uneccesary.
slot_actionid should be set after you confirm that the slott exist.
Lua:
local ids = {
    {thing = "Legendary", chance = 2, itemID = 2475, actionID = 45115, armor = 3, speed = 10, extradefense = 3}, --2%
    {thing = "Bound", chance = 15, itemID = 2475, actionID = 45114, armor = 3, speed = 10, extradefense = 3}, --13%
    {thing = "Normal", chance = 100, itemID = 2475, actionID = 45113, armor = 3, speed = 10, extradefense = 3} --85%
}
--player:getSlotItem(CONST_SLOT_HEAD)
--item:getActionId()
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function onEquip(player, item, slot)
    local slott = player:getSlotItem(CONST_SLOT_HEAD)
    if slott ~= nil then
        local slot_actionid = slott:getActionId()
        for _, t in ipairs(ids) do
            if t.actionID == slot_actionid then --compare actionID with actionID on head slot
                item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense)
                item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor)
                local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed)
                player:addCondition(speedCondition)
                item:setAttribute("description", "+ ".. t.armor .." Armor")
                item:setAttribute("description", "+ ".. t.speed .." Speed")
                item:setAttribute("description", "+ ".. t.extradefense .." Extradefense")
            end --end if
        end --end for
    end -- end slott check
    return true --return value
end -- end function
---------------------------------------------------------------------------
--///////////////////////////////////////////////////////////////////////--
---------------------------------------------------------------------------
function onDeEquip(player, item, slot)
    local slott = player:getSlotItem(CONST_SLOT_HEAD)
    if slott ~= nil then
        local slot_actionid = slott:getActionId()
        for _, t in ipairs(ids) do
            if t.actionID == slot_actionid then
                item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense * 0)
                item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor * 0)
                local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed * 0)
                player:addCondition(speedCondition)
                item:removeAttribute("description", "+ ".. t.armor .." Armor")
                item:removeAttribute("description", "+ ".. t.speed .." Speed")
                item:removeAttribute("description", "+ ".. t.extradefense .." Extradefense")
            end --end if
        end --end for
    end -- end slott check
    return true --return value
end--end function
---------------------------------------------------------------------------
---------------------------------------------------------------------------
If slott:getActionId returns an item uid, you may need to initialize the item by inserting it into an Item() object before retrieving its action id.
 
Last edited:
Retrieving your head slot item inside the loop sounds uneccesary.
slot_actionid should be set after you confirm that the slott exist.
Lua:
local ids = {
    {thing = "Legendary", chance = 2, itemID = 2475, actionID = 45115, armor = 3, speed = 10, extradefense = 3}, --2%
    {thing = "Bound", chance = 15, itemID = 2475, actionID = 45114, armor = 3, speed = 10, extradefense = 3}, --13%
    {thing = "Normal", chance = 100, itemID = 2475, actionID = 45113, armor = 3, speed = 10, extradefense = 3} --85%
}
--player:getSlotItem(CONST_SLOT_HEAD)
--item:getActionId()
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function onEquip(player, item, slot)
    local slott = player:getSlotItem(CONST_SLOT_HEAD)
    if slott ~= nil then
        local slot_actionid = slott:getActionId()
        for _, t in ipairs(ids) do
            if t.actionID == slot_actionid then --compare actionID with actionID on head slot
                item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense)
                item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor)
                local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed)
                player:addCondition(speedCondition)
                item:setAttribute("description", "+ ".. t.armor .." Armor")
                item:setAttribute("description", "+ ".. t.speed .." Speed")
                item:setAttribute("description", "+ ".. t.extradefense .." Extradefense")
            end --end if
        end --end for
    end -- end slott check
    return true --return value
end -- end function
---------------------------------------------------------------------------
--///////////////////////////////////////////////////////////////////////--
---------------------------------------------------------------------------
function onDeEquip(player, item, slot)
    local slott = player:getSlotItem(CONST_SLOT_HEAD)
    if slott ~= nil then
        local slot_actionid = slott:getActionId()
        for _, t in ipairs(ids) do
            if t.actionID == slot_actionid then
                item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense * 0)
                item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor * 0)
                local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed * 0)
                player:addCondition(speedCondition)
                item:removeAttribute("description", "+ ".. t.armor .." Armor")
                item:removeAttribute("description", "+ ".. t.speed .." Speed")
                item:removeAttribute("description", "+ ".. t.extradefense .." Extradefense")
            end --end if
        end --end for
    end -- end slott check
    return true --return value
end--end function
---------------------------------------------------------------------------
---------------------------------------------------------------------------
If slott:getActionId returns an item uid, you may need to initialize the item by inserting it into an Item() object before retrieving its action id.
You didn't really solve his problem though. I believe slot will still be empty considering you are able to return false to prevent the equipping of the item (I assume at least).

More likely he's supposed to use the "item" variable provided in the function arguments.

Lua:
local ids = {
    {thing = "Legendary", chance = 2, itemID = 2475, actionID = 45115, armor = 3, speed = 10, extradefense = 3}, --2%
    {thing = "Bound", chance = 15, itemID = 2475, actionID = 45114, armor = 3, speed = 10, extradefense = 3}, --13%
    {thing = "Normal", chance = 100, itemID = 2475, actionID = 45113, armor = 3, speed = 10, extradefense = 3} --85%
}

function onEquip(player, item, slot)
    for _, t in ipairs(ids) do
        if t.actionID == item:getActionId() then --compare actionID with actionID on head slot
            item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense)
            item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor)

            local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed)
            player:addCondition(speedCondition)

            item:setAttribute("description", "+ ".. t.armor .." Armor")
            item:setAttribute("description", "+ ".. t.speed .." Speed")
            item:setAttribute("description", "+ ".. t.extradefense .." Extradefense")
            return true
        end
    end
    return true
end

function onDeEquip(player, item, slot)
    for _, t in ipairs(ids) do
        if t.actionID == item:getActionId() then
            item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, 0)
            item:setAttribute(ITEM_ATTRIBUTE_ARMOR, 0)

            local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, 0)
            player:addCondition(speedCondition)

            item:removeAttribute("description")
            item:removeAttribute("description", "+ ".. t.speed .." Speed")
            item:removeAttribute("description", "+ ".. t.extradefense .." Extradefense")
            return true
        end
    end
    return true
end

I'm doubtful about the way he used setAttribute and removeAttribute. But I did not modify it because I'm unsure how it works. Although I guess 90% chance that he's used it wrong.

So I will include an alternative version on how I think it should work regarding the attributes:
Lua:
local ids = {
    {thing = "Legendary", chance = 2, itemID = 2475, actionID = 45115, armor = 3, speed = 10, extradefense = 3}, --2%
    {thing = "Bound", chance = 15, itemID = 2475, actionID = 45114, armor = 3, speed = 10, extradefense = 3}, --13%
    {thing = "Normal", chance = 100, itemID = 2475, actionID = 45113, armor = 3, speed = 10, extradefense = 3} --85%
}

function onEquip(player, item, slot)
    for _, t in ipairs(ids) do
        if t.actionID == item:getActionId() then --compare actionID with actionID on head slot
            item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, t.extradefense)
            item:setAttribute(ITEM_ATTRIBUTE_ARMOR, t.armor)

            local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, t.speed)
            player:addCondition(speedCondition)

            item:setAttribute("description", ("+ %d Armor\n+ %d Speed\n+ %d Extradefense"):format(t.armor, t.speed, t.extradefense))
            return true
        end
    end
    return true
end


function onDeEquip(player, item, slot)
    for _, t in ipairs(ids) do
        if t.actionID == item:getActionId() then
            item:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, 0)
            item:setAttribute(ITEM_ATTRIBUTE_ARMOR, 0)

            local speedCondition = player:setParameter(CONDITION_PARAM_SPEED, 0)
            player:addCondition(speedCondition)

            item:removeAttribute("description")
            return true
        end
    end
    return true
end
 
Last edited by a moderator:
Solution
I don't th

You didn't really solve his problem though. I believe slot will still be empty considering you are able t8 return false to prevent the equipping of the item (I assume at least).

More likely he's supposed to use the "item" variable provided in the function paramerers.

Haha yeah, I saw a few flaws in his code and lost focus.
There is a slot param in the onEquip and onDeEquip functions, use that to identify that the event matches CONST_SLOT_HEAD. (Not sure what the best way to compare it is). This is not neccesary for helmets though, only helmets can be equipped and de-equipped from that slot. So if it is only a helmet itemid linked to this script in the .xml file then I guess its fine. (Unless return true breaks this behavior)
And use the item param instead of loading it from the player.
And return false to keep executing default functionality. (I think)
 
Last edited:
Haha yeah, I saw a few flaws in his code and lost focus.
There is a slot param in the onEquip and onDeEquip functions, use that to identify that the event matches CONST_SLOT_HEAD. (Not sure what the best way to compare it is).
And use the item param instead of loading it from the player.
And return false to keep executing default functionality. (I think)
I'm not too sure about the return values. Either way, unless he uses classic slots he won't need to compare slot types, but it would be the safest thing to do nonetheless.
 
Back
Top