• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

help me create function i bad in functions xD

beenii

Well-Known Member
Joined
Jul 26, 2010
Messages
586
Solutions
1
Reaction score
58
Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
if isPlayer(attacker) or isMonster(attacker) then

     itemHEAD = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
    itemARMOR = getPlayerSlotItem(cid, CONST_SLOT_ARMOR)
    itemLEGS = getPlayerSlotItem(cid, CONST_SLOT_LEGS)
    itemFEET = getPlayerSlotItem(cid, CONST_SLOT_FEET)
    itemLEFT = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    itemRIGHT = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)


if combat == COMBAT_ICEDAMAGE then
absorb = math.floor(getItemAttribute(itemHEAD.uid, "IceProtec") + getItemAttribute(itemARMOR.uid, "IceProtec") + getItemAttribute(itemLEGS.uid, "IceProtec") + getItemAttribute(itemFEET.uid, "IceProtec")+ getItemAttribute(itemLEFT.uid, "IceProtec") + getItemAttribute(itemRIGHT.uid, "IceProtec"))
doSendMagicEffect(getThingPosition(attacker), CONST_ME_ICEATTACK)
doCreatureAddHealth(attacker, -absorb)
doSendAnimatedText(getThingPosition(attacker), absorb, COLOR_TEAL)
end


if combat == COMBAT_EARTHDAMAGE then
absorb = math.floor(value / 2)
doSendMagicEffect(getThingPosition(attacker), CONST_ME_GREEN_RINGS)
doCreatureAddHealth(attacker, -absorb)
doSendAnimatedText(getThingPosition(attacker), absorb, COLOR_LIGHTGREEN)
end
end
return true
end
end

my script have error because, dont have all items on slots and have valors null on atttributes
need function check all slots have or not items. and if null attrribute return to 0

I found something like, but need modify. need check attributes "EnergyProtec, FireProtec, IceProtec, PhysicalProtec, DeathProtec, EarthProtec, HolyProtec" in next slots:
( CONST_SLOT_HEAD
CONST_SLOT_ARMOR
CONST_SLOT_LEGS
CONST_SLOT_FEET
CONST_SLOT_LEFT
CONST_SLOT_RIGHT )

and give me the sum of an attribute.
--------------------------------------------------------- script base started -----------------------------------
items = {
[2647] = {CONST_SLOT_LEGS, 30},
[2463] = {CONST_SLOT_ARMOR, 30},
[2645] = {CONST_SLOT_FEET, 30},
[2493] = {CONST_SLOT_HEAD, 30},
}

local reflection = 0
for x,i in pairs(items) do
if getPlayerSlotItem(cid, i[1]).itemid == x then
reflection = reflection + i[2]
end
end
 
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 = {}
    local total, absorb, constMe, color = 0, 0, 0, 0

    function onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then

                for slot, const in pairs(slots) do
                    itemSlots[slot] = getPlayerSlotItem(cid, const)
                end
            
                for slot, slottedItem in pairs(itemSlots) do
                    total = total + getItemAttribute(slottedItem.uid, "IceProtec")
                end

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                end


                if combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end
 
Last edited:
i think working xD but

9hjouh.png


in line 22 y change
total = total + getItemAttribute(slottedItem.uid, "IceProtec")
for:
total = getItemAttribute(slottedItem.uid, "IceProtec")

and get this error:
6f6r0h.png


and i try change this in line 26 :
absorb = math.floor(total)
for:
absorb = total

and get this error:
2i0w0u1.png




my original idea is reflect % of damage player recived with enchanted stone i put attributes on ice, fire, earth, etc...:
jq6kox.jpg
 
See if this works
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 attribute = "IceProtec"

    local itemSlots = {}
    local total, absorb, constMe, color = 0, 0, 0, 0

    function onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then

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

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                end


                if combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end
 
The code above is going to give you errors regardless, I am just looking for a list of colors.

ok, if you get any errors just post them here
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 attribute = "IceProtec"

    local itemSlots = {}
    local total, absorb, constMe, color = 0, 0, 0, 0

    function onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then

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

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                elseif combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                else
                    absorb = 0
                    constMe = CONST_ME_NONE
                    color = COLOR_NONE
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, absorb == 0 and absorb or -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end
 
See if this works
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 attribute = "IceProtec"

    local itemSlots = {}
    local total, absorb, constMe, color = 0, 0, 0, 0

    function onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then

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

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                end


                if combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end

yeah its work i go to modify for reflect % :D thanks much bro.

u have idea how send msg to player when items in slot change?
for send states: You have 5% fire, 10% ice Reflection. but only when items in slots change hehe
if it is very difficult, so fine.i very happy with your help bro :)
 
The code above is going to give you errors regardless, I am just looking for a list of colors.

ok, if you get any errors just post them here
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 attribute = "IceProtec"

    local itemSlots = {}
    local total, absorb, constMe, color = 0, 0, 0, 0

    function onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then

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

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                elseif combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                else
                    absorb = 0
                    constMe = CONST_ME_NONE
                    color = COLOR_NONE
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, absorb == 0 and absorb or -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end

broo buggg xD when remove item with protection in slot, reflection dont remove, and duplicate reflection if put item two times.

AND DONT REMOVE WITH LOGOUT AND LOGIN, REMOVE BEFORE RESTARTED SERVER XD ITS CRAZZY THIS BUG HAHA
 
broo buggg xD when remove item with protection in slot, reflection dont remove, and duplicate reflection if put item two times.

AND DONT REMOVE WITH LOGOUT AND LOGIN, REMOVE BEFORE RESTARTED SERVER XD ITS CRAZZY THIS BUG HAHA
ok, well lets change the scope of the variables & table and see what happens
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 onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then
                local attribute = "IceProtec"
                local itemSlots = {}
                local total, absorb, constMe, color = 0, 0, 0, 0
              
                for slot, const in pairs(slots) do
                    itemSlots[slot] = getPlayerSlotItem(cid, const).uid
                end
          
                for slot, slottedItem in pairs(itemSlots) do
                    local temp = getItemAttribute(slottedItem, attribute)
                    total = total + (temp ~= nil and temp or 0 )
                end

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                elseif combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                else
                    absorb = 0
                    constMe = CONST_ME_NONE
                    color = COLOR_NONE
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, absorb == 0 and absorb or -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end
 
okok reflection its working fine. only two small bug.

error in console if player dont have any item in the slots check send this:
2nb58qh.png


and when dont have items with reflection send this:
2d9bvd5.png


need return when damage = 0 hehe
 
Now we're getting somewhere :p
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 onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then
                local attribute = "IceProtec"
                local itemSlots = {}
                local total, absorb, constMe, color = 0, 0, 0, 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)
                    total = total + (temp ~= nil and temp or 0 )
                end

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                elseif combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                else
                    return true
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end
 
Last edited:
Now we're getting somewhere :p
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 onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then
                local attribute = "IceProtec"
                local itemSlots = {}
                local total, absorb, constMe, color = 0, 0, 0, 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)
                    total = total + (temp ~= nil and temp or 0 )
                end

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                elseif combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                else
                    return true
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end

same small bugs xD
 
getPlayerSlotItem(cid, slot).itemid > 0

this u can use for solved error in console when dbug say item no fount no?

and atribute == 0 return true
no'? xD


i add this:
if total == 0 then
return true
end

and solved 1 small bug :p xD
 
for add this elements :

"EnergyProtec"
"FireProtec"
"IceProtec"
"PhysicalProtec"
"DeathProtec"
"EarthProtec"
"HolyProtec"


i need copy this?

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

and change for:

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


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

etc
etc
etc

one for element?

and change:
if combat == COMBAT_ICEDAMAGE then
absorb = math.floor(totalIce)
constMe = CONST_ME_ICEATTACK
color = COLOR_TEAL
elseif combat == COMBAT_EARTHDAMAGE then
absorb = math.floor(totalEarth)
constMe = CONST_ME_GREEN_RINGS
color = COLOR_LIGHTGREEN
 
Now we're getting somewhere :p
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 onStatsChange(cid, attacker, type, combat, value)
        if isPlayer(cid) and type == STATSCHANGE_HEALTHLOSS then
            if isPlayer(attacker) or isMonster(attacker) then
                local attribute = "IceProtec"
                local itemSlots = {}
                local total, absorb, constMe, color = 0, 0, 0, 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)
                    total = total + (temp ~= nil and temp or 0 )
                end

                if combat == COMBAT_ICEDAMAGE then
                    absorb = math.floor(total)
                    constMe = CONST_ME_ICEATTACK
                    color = COLOR_TEAL
                elseif combat == COMBAT_EARTHDAMAGE then
                    absorb = math.floor(value / 2)
                    constMe = CONST_ME_GREEN_RINGS
                    color = COLOR_LIGHTGREEN
                else
                    return true
                end
                doSendMagicEffect(getThingPosition(attacker), constMe)
                doCreatureAddHealth(attacker, -absorb)
                doSendAnimatedText(getThingPosition(attacker), absorb, color)
            end
        end
        return true
    end


how add more elements bro?
 
Back
Top