HI Este código funciona perfeitamente retornado bons valores. mas ....
Só tenho esse erro no console:
Este erro acontece quando o personagem não tem nenhum artigo na respectiva ranhura. Aqui, o código:
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
//
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ice: "..total..".")
E eu tento criar esta função, mas só me retorna o valor de um slot:
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
para uso:
getPlayerProtection(cid, 'IceProtec')
e mesmo erro no valor de nulo em consola