• 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!

Helpme to finish my script only have bad returns please.

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

//
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!
 
The problem is that your executer is running with the NPM encryption which doesn't function very well with .LUA scripts. Therefore you are getting the error you showed us, what I'd recommend is to start using HXQ encryption instead of the NPM encryption since it would be better for this script, and obviously also future scripts.
 
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?
 
Well if you did not change the encryption management, you're going to have to think about switching the dual connecter from the very bottom of the source code. This will matter in so many ways, and change the way your server will execute all the scripts, making it run approximately 10 times smoother, and would also understand more functions instead of getting unnecessary errors.
 
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
 
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
And here it is tabbed correctly.
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
 
That will become one large total after a while.

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
}

function getPlayerProtection(cid, param)
    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, param)
        total = total + (temp ~= nil and temp or 0 )
    end
    return total
end
 
Here is the final version.
for use with other attributes.

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
    }         
function getPlayerProtection(cid, param, tipo)
      local itemSlots, tipo = {}, 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, param)
                tipo = tipo + (temp ~= nil and temp or 0 )
                end
return tipo
    end


//
local icePRO = getPlayerProtection(cid, 'IceProtec', ice)
local firePRO = getPlayerProtection(cid, 'FireProtec',fire)

//
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ice: "..icePRO.."% Fire: "..firePRO.."%.")
 
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 currentProtection = {}
function getPlayerProtection(cid, param)
    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, param)
        total = total + (temp ~= nil and temp or 0 )
    end
    param = param:sub(1, 1):upper() .. param:sub(2, #param)
    currentProtection[#currentProtection + 1] = param .. " protection: " .. total .. "% "
    return total, doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, table.concat(currentProtection) .. ".")
end
 
Last edited:
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 currentProtection = {}
function getPlayerProtection(cid, param)
    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, param)
        total = total + (temp ~= nil and temp or 0 )
    end
    param = param:sub(1,1):upper()
    currentProtection[#currentProtection + 1] = param .. " protection:" .. total .. "% "
    return total, doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, table.concat(currentProtection) .. ".")
end


i recived :
33dw7de.png


but text is only for test.
my script system is Here:

first compile:
Code:
https://otland.net/threads/doabsorbcombatpercentage-getcombatpercentageabsorbed.114409/


It is a bit long but my script is working XD!


Code:
function onThink(cid)

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
    }            
function getPlayerProtection(cid, param, tipo)
      local itemSlots, tipo = {}, 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, param)
                tipo = tipo + (temp ~= nil and temp or 0 )
                end
return tipo
    end
   
   
local icePRO = getPlayerProtection(cid, 'IceProtec', ice) --1
local firePRO = getPlayerProtection(cid, 'FireProtec',fire)    --2
local energyPRO = getPlayerProtection(cid, 'EnergyProtec', energy) --3
local physicalPRO = getPlayerProtection(cid, 'PhysicalProtec', physical) --4
local deathPRO = getPlayerProtection(cid, 'DeathProtec', death) --5
local earthPRO = getPlayerProtection(cid, 'EarthProtec', earth) --6
local holyPRO = getPlayerProtection(cid, 'HolyProtec', holy) --7

local storageCheck = 61610


if icePRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_ICEDAMAGE, icePRO) --1
iceMSG = " [Ice: "..icePRO.."%]"
else
iceMSG = ""
end

if firePRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_FIREDAMAGE, firePRO) --2
fireMSG = " [Fire: "..firePRO.."%]"
else
fireMSG = ""
end

if energyPRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_ENERGYDAMAGE, energyPRO) --3
energyMSG = " [Energy: "..energyPRO.."%]"
else
energyMSG = ""
end

if physicalPRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_PHYSICALDAMAGE, physicalPRO) -- 4
physicalMSG = " [Physical: "..physicalPRO.."%]"
else
physicalMSG = ""
end

if deathPRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_DEATHDAMAGE, deathPRO) --5
deathMSG = " [Death: "..deathPRO.."%]"
else
deathMSG = ""
end

if earthPRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_EARTHDAMAGE, earthPRO) --6
earthMSG = " [Earth: "..earthPRO.."%]"
else
earthMSG = ""
end

if holyPRO > 0 then   
doAbsorbCombatPercentage(cid, COMBAT_HOLYDAMAGE, holyPRO) --7
holyMSG = " [Holy: "..holyPRO.."%]"
else
holyMSG = ""
end

local sumATT = icePRO + firePRO + energyPRO + physicalPRO + deathPRO + earthPRO + holyPRO

if sumATT == 0 then
outMSG = " 0%"
else
outMSG = ""
end

if getPlayerStorageValue(cid,storageCheck) ~= sumATT then -- for send msg if change stats.
setPlayerStorageValue(cid,storageCheck,sumATT)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your current Protection: "..iceMSG..""..fireMSG..""..energyMSG..""..physicalMSG..""..deathMSG..""..earthMSG..""..holyMSG..""..outMSG..".")
end
    return true
end
 
Last edited:
I updated so it attaches the whole word instead of just the 1st letter, sorry bout that :p

thank you very much for all your time :p

I'm happy to finish this protection system xD!

i dont know if my code is the most efficient, but for now works perfectly :)

your code to check attributes in each slot was essential Codex NG.
without your code, my code has ended more than a thousand lines :p

i love all xD!
 

Similar threads

Back
Top