Você disse que ele retorna o valor que você solicita, que o problema mesmo é este erro no console, para tirar isto basta substituir:
if hasItemOn then
Por:
if hasItemOn ~= 0 then
Senão ele irá fazer a busca mesmo você não tendo o item e resultará neste erro em seu console. Caso ainda precise de mais ajuda, solicito que poste o link do tópico com download do servidor que você está usando.





info
Grupo: Artesão
Registrado: 10/11/11
Posts: 118
Reputação: +2
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 ) endE 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 endpara uso:
getPlayerProtection(cid, 'IceProtec')
e mesmo erro no valor de nulo em consola