• 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 Helpme to finish my script or function

beenii

Well-Known Member
Joined
Jul 26, 2010
Messages
586
Solutions
1
Reaction score
58
HI This code works perfectly
returned good values.
but....

Only have this error in console:
63rfyv.png


This error happens when the character has not any article in its slot.
Here the code:
Code:
local slots = {
        ['head'] = CONST_SLOT_HEAD,
        ['armor'] = CONST_SLOT_ARMOR,
        ['legs'] = CONST_SLOT_LEGS,
        ['feet'] = CONST_SLOT_FEET,
        ['left'] = CONST_SLOT_LEFT,
        ['right'] = CONST_SLOT_RIGHT
    }               
               local itemSlots, total = {}, 0
                for slot, const in pairs(slots) do
                    local hasItemOn = getPlayerSlotItem(cid, const).uid
                    if hasItemOn  then
                        itemSlots[slot] = hasItemOn
                    end
                end

                for slot, slottedItem in pairs(itemSlots) do
                local temp = getItemAttribute(slottedItem, 'IceProtec')
                total = total + (temp ~= nil and temp or 0 )
                end

// here check values returns and works fine. only is error in console xD
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ice: "..total..".")






AND I try creating this function, but only returns me the value of a slot:

Code:
function getPlayerProtection(cid, attribute)  
        local slots = {
        ['head'] = CONST_SLOT_HEAD,
        ['armor'] = CONST_SLOT_ARMOR,
        ['legs'] = CONST_SLOT_LEGS,
        ['feet'] = CONST_SLOT_FEET,
        ['left'] = CONST_SLOT_LEFT,
        ['right'] = CONST_SLOT_RIGHT
    }  
   
               local itemSlots, total = {}, 0
                for slot, const in pairs(slots) do
                    local hasItemOn = getPlayerSlotItem(cid, const).uid
                    if hasItemOn  then
                        itemSlots[slot] = hasItemOn
                    end
                end
 
                for slot, slottedItem in pairs(itemSlots) do
                    local temp = getItemAttribute(slottedItem, attribute)
                   return  total + (temp ~= nil and temp or 0 )
                end
                end

for use:
getPlayerProtection(cid, 'IceProtec')

and same error in console anil value xD!
 
Last edited:
but of course that is your code. and much thanks for the progress. only is small detail error in console xD!
and yes this not the full script, because now that's all I need. only returns attribs
 
i remplace :

if hasItemOn then
to:
if hasItemOn ~= 0 then

and console error was fixed. Now I seek to create a function with this code, someone could help me?
 

Here only returned one value xD
not if I'll be approaching xD

Code:
function getPlayerProtection(cid, attribute)   
          local slots = {
        ['head'] = CONST_SLOT_HEAD,
        ['armor'] = CONST_SLOT_ARMOR,
        ['legs'] = CONST_SLOT_LEGS,
        ['feet'] = CONST_SLOT_FEET,
        ['left'] = CONST_SLOT_LEFT,
        ['right'] = CONST_SLOT_RIGHT
    }                
                local itemSlots, total = {}, 0
                for slot, const in pairs(slots) do
                    local hasItemOn = getPlayerSlotItem(cid, const).uid
                    if hasItemOn ~= 0  then
                        itemSlots[slot] = hasItemOn
                    end
                end

                for slot, slottedItem in pairs(itemSlots) do
                local temp = getItemAttribute(slottedItem, attribute)
                return temp ~= nil and temp or 0
                end
                end

//
getPlayerProtection(cid, 'IceProtec')
 
Code:
local slots = {
        ['head'] = CONST_SLOT_HEAD,
        ['armor'] = CONST_SLOT_ARMOR,
        ['legs'] = CONST_SLOT_LEGS,
        ['feet'] = CONST_SLOT_FEET,
        ['left'] = CONST_SLOT_LEFT,
        ['right'] = CONST_SLOT_RIGHT
    }           
   
      local itemSlots, total = {}, 0

function getPlayerProtection(cid, param)

    
                for slot, const in pairs(slots) do
                    local hasItemOn = getPlayerSlotItem(cid, const).uid
                    if hasItemOn ~= 0  then
                        itemSlots[slot] = hasItemOn
                    end
                end
  
                for slot, slottedItem in pairs(itemSlots) do
                local temp = getItemAttribute(slottedItem, param)
                total = total + (temp ~= nil and temp or 0 )
                end
return total
    end


solved.
 
Back
Top