• 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 Reflect System Help

Tegardee

The Boss
Joined
Jun 18, 2014
Messages
106
Reaction score
0
Location
Brazil
hello guys, I have a MOD of Reflect System in my Server.

The MOD is: When a player buy an Item on the Shop, the player receive that item with some % of Reflect. The problem of the MOD is, when a player attack another player that uses this item with some % of Reflect, the Reflect don't works. I really need help on this.

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Reflect System" version="0.1" author="Aluccard" contact="" enabled="yes">

<event type="login" name="regReflectDamage" event="script"><![CDATA[
function onLogin(cid)
registerCreatureEvent(cid,"ReflectDamage")
return true
end
]]></event>

<event type="statschange" name="ReflectDamage" event="script"><![CDATA[

local slotPos = {CONST_SLOT_NECKLACE, CONST_SLOT_FEET, CONST_SLOT_RING}

function onStatsChange(cid, attacker, type, combat, value)
    if isCreature(cid) == true and isCreature(attacker) == true then
        if (type == STATSCHANGE_HEALTHLOSS or (getCreatureCondition(cid, CONDITION_MANASHIELD) and type == STATSCHANGE_MANALOSS)) then
          if combat ~= COMBAT_HEALING then
            local reflectPercent = 0
            local dmg = value
            local playerPos = getCreaturePosition(cid)
            local attackerPos = getCreaturePosition(attacker)

            for i = 1, #slotPos do
                if getPlayerSlotItem(cid, slotPos).uid > 1 then
                    if getItemReflectPercent(getPlayerSlotItem(cid, slotPos).uid) then
                        reflectPercent = reflectPercent + getItemReflectPercent(getPlayerSlotItem(cid, slotPos).uid)
                    end
                end
            end

            if reflectPercent > 0 then
                dmg = math.ceil(-value*((100-reflectPercent)/100))
                if (dmg < 0) then
                    doCreatureAddHealth(cid, dmg)
                    doSendAnimatedText(playerPos, -dmg, COLOR_RED)
                    doSendMagicEffect(playerPos, 0)
                else
                    doSendMagicEffect(playerPos, 3)
                end

                dmg = math.ceil(-value*(reflectPercent/100))
                if (dmg < 0) then
                    doCreatureAddHealth(attacker, dmg)
                    doSendAnimatedText(attackerPos, -dmg, COLOR_RED)
                    doSendDistanceShoot(playerPos, attackerPos, CONST_ANI_SMALLHOLY)
                end
            else
                return true
            end
          end
        end
    end
    return true
end
]]>
</event>
</mod>

I use TFS 0.4 r.3777.
 
Try this:

Paste it only after
<event type="statschange" name="ReflectDamage" event="script"><![CDATA[
Code:
local slotPos = {CONST_SLOT_NECKLACE, CONST_SLOT_FEET, CONST_SLOT_RING}

function onStatsChange(cid, attacker, type, combat, value)
    if isCreature(cid) == true and isCreature(attacker) == true then
        if (type == STATSCHANGE_HEALTHLOSS or (getCreatureCondition(cid, CONDITION_MANASHIELD) and type == STATSCHANGE_MANALOSS)) then
            if combat ~= COMBAT_HEALING then
                local reflectPercent = 0
                local dmg = value
                local playerPos = getCreaturePosition(cid)
                local attackerPos = getCreaturePosition(attacker)
               
                for i = 1, #slotPos do
                    if getPlayerSlotItem(cid, slotPos[i]).uid > 1 then
                        if getItemReflectPercent(getPlayerSlotItem(cid, slotPos[i]).uid) then
                            reflectPercent = reflectPercent + getItemReflectPercent(getPlayerSlotItem(cid, slotPos[i]).uid)
                        end
                    end
                end
               
                if reflectPercent > 0 then
                    dmg = math.ceil(-value*((100-reflectPercent)/100))
                    if (dmg < 0) then
                        doCreatureAddHealth(cid, dmg)
                        doSendAnimatedText(playerPos, -dmg, COLOR_RED)
                        doSendMagicEffect(playerPos, 0)
                    else
                        doSendMagicEffect(playerPos, 3)
                    end
                   
                    dmg = math.ceil(-value*(reflectPercent/100))
                    if (dmg < 0) then
                        doCreatureAddHealth(attacker, dmg)
                        doSendAnimatedText(attackerPos, -dmg, COLOR_RED)
                        doSendDistanceShoot(playerPos, attackerPos, CONST_ANI_SMALLHOLY)
                    end
                else
                    return true
                end
            end
        end
    end
    return true
end
 
hey man, can you adjust the script?

because if the attacking player have the condition of "utamo vita", the reflect hit remove of the hp, I want to remove the mp.
 
Try:
Code:
local slotPos = {CONST_SLOT_NECKLACE, CONST_SLOT_FEET, CONST_SLOT_RING}

function onStatsChange(cid, attacker, type, combat, value)
    if isCreature(cid) == true and isCreature(attacker) == true then
        if (type == STATSCHANGE_HEALTHLOSS or (getCreatureCondition(cid, CONDITION_MANASHIELD) and type == STATSCHANGE_MANALOSS)) then
            if combat ~= COMBAT_HEALING then
                local reflectPercent = 0
                local dmg = value
                local playerPos = getCreaturePosition(cid)
                local attackerPos = getCreaturePosition(attacker)
              
                for i = 1, #slotPos do
                    if getPlayerSlotItem(cid, slotPos[i]).uid > 1 then
                        if getItemReflectPercent(getPlayerSlotItem(cid, slotPos[i]).uid) then
                            reflectPercent = reflectPercent + getItemReflectPercent(getPlayerSlotItem(cid, slotPos[i]).uid)
                        end
                    end
                end
              
                if reflectPercent > 0 then
                    dmg = math.ceil(-value*((100-reflectPercent)/100))
                    if (dmg < 0) then
                        if getCreatureCondition(cid, CONDITION_MANASHIELD) then
                            doCreatureAddMana(cid, dmg)
                            doSendAnimatedText(playerPos, -dmg, COLOR_BLUE)
                            doSendMagicEffect(playerPos, 0)
                        else
                            doCreatureAddHealth(cid, dmg)
                            doSendAnimatedText(playerPos, -dmg, COLOR_RED)
                            doSendMagicEffect(playerPos, 0)
                        end
                    else
                        doSendMagicEffect(playerPos, 3)
                    end
                  
                    dmg = math.ceil(-value*(reflectPercent/100))
                    if (dmg < 0) then
                        if getCreatureCondition(attacker, CONDITION_MANASHIELD) then
                            doCreatureAddMana(attacker, dmg)
                            doSendAnimatedText(attackerPos, -dmg, COLOR_BLUE)
                            doSendMagicEffect(attackerPos, 0)
                        else
                            doCreatureAddHealth(attacker, dmg)
                            doSendAnimatedText(attackerPos, -dmg, COLOR_RED)
                            doSendDistanceShoot(playerPos, attackerPos, CONST_ANI_SMALLHOLY)
                        end
                    end
                else
                    return true
                end
            end
        end
    end
    return true
end
 
Try:
Code:
local slotPos = {CONST_SLOT_NECKLACE, CONST_SLOT_FEET, CONST_SLOT_RING}

function onStatsChange(cid, attacker, type, combat, value)
    if isCreature(cid) == true and isCreature(attacker) == true then
        if (type == STATSCHANGE_HEALTHLOSS or (getCreatureCondition(cid, CONDITION_MANASHIELD) and type == STATSCHANGE_MANALOSS)) then
            if combat ~= COMBAT_HEALING then
                local reflectPercent = 0
                local dmg = value
                local playerPos = getCreaturePosition(cid)
                local attackerPos = getCreaturePosition(attacker)
             
                for i = 1, #slotPos do
                    if getPlayerSlotItem(cid, slotPos[i]).uid > 1 then
                        if getItemReflectPercent(getPlayerSlotItem(cid, slotPos[i]).uid) then
                            reflectPercent = reflectPercent + getItemReflectPercent(getPlayerSlotItem(cid, slotPos[i]).uid)
                        end
                    end
                end
             
                if reflectPercent > 0 then
                    dmg = math.ceil(-value*((100-reflectPercent)/100))
                    if (dmg < 0) then
                        if getCreatureCondition(cid, CONDITION_MANASHIELD) then
                            doCreatureAddMana(cid, dmg)
                            doSendAnimatedText(playerPos, -dmg, COLOR_BLUE)
                            doSendMagicEffect(playerPos, 0)
                        else
                            doCreatureAddHealth(cid, dmg)
                            doSendAnimatedText(playerPos, -dmg, COLOR_RED)
                            doSendMagicEffect(playerPos, 0)
                        end
                    else
                        doSendMagicEffect(playerPos, 3)
                    end
                 
                    dmg = math.ceil(-value*(reflectPercent/100))
                    if (dmg < 0) then
                        if getCreatureCondition(attacker, CONDITION_MANASHIELD) then
                            doCreatureAddMana(attacker, dmg)
                            doSendAnimatedText(attackerPos, -dmg, COLOR_BLUE)
                            doSendMagicEffect(attackerPos, 0)
                        else
                            doCreatureAddHealth(attacker, dmg)
                            doSendAnimatedText(attackerPos, -dmg, COLOR_RED)
                            doSendDistanceShoot(playerPos, attackerPos, CONST_ANI_SMALLHOLY)
                        end
                    end
                else
                    return true
                end
            end
        end
    end
    return true
end



hi have RevScripts?
 
hi have RevScripts?
 
Back
Top