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

Tegardee

The Boss
Joined
Jun 18, 2014
Messages
106
Reaction score
0
Location
Brazil
Hi guys, I am having a problem with system of reflection of Aluccard, I installed everything correctly according to warrant in the tutorial, but every time that I will attack a player, an error in distro:
2rnkms9.jpg


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

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

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

local slotPos = {CONST_SLOT_NECKLACE, CONST_SLOT_FEET, CONST_SLOT_RING}

function onStatsChange(cid, attacker, type, combat, value)
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]]>
</event>
</mod>

How can Ifixed it? Thank very much.
 
Last edited:
You can add this above doCreatureAddHealth(attacker, dmg)
Code:
if isCreature(attacker) then
Then close the if statement with end under doSendDistanceShoot(playerPos, attackerPos, CONST_ANI_SMALLHOLY).
 
Change
Code:
local attackerPos = getCreaturePosition(attacker)
To
Code:
local attackerPos = getCreaturePosition(cid)
if isCreature(attacker) then
   attackerPos = getCreaturePosition(attacker)
end
 
thanks man, you fixed this system, but another error, It is not necessary to image.

[24/06/2014 08:47:42] [Error - CreatureEvent::executeStatsChange] Call stack overflow.
[24/06/2014 08:47:42] [Error - CreatureEvent::executeStatsChange] Call stack overflow.
[24/06/2014 08:47:42] [Error - CreatureEvent::executeStatsChange] Call stack overflow.
[24/06/2014 08:47:42] [Error - CreatureEvent::executeStatsChange] Call stack overflow.
[24/06/2014 08:47:42] [Error - CreatureEvent::executeStatsChange] Call stack overflow.
 
You missed two isCreature and return true at end of function!
Also you missed most important thing! Your script is reflecting mana and health regeneration! Even it's reflecting your spells like haste...
You have to declare correct type of statsChange!

You was using ex. haste and script was trying to reflect it, but was unable to read how much it dealt damage becouse value was equal to nil. Same with passive regeneration while your character is fed.

Also, you have to edit this code. Becouse this spell is bugged. Your server will crash if two players will use this reflect spell and then one of them attack the other.

This one will works, unless you did an bug inside the code.

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 == 1 or type == 3 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
    return true
end

To read (you should save it somewhere):
Code:
onStatsChange(cid, attacker, type, combat, value)

cid -- attacked or healed creature

attacker -- attacker or healer

type -- type of stat change
     STATSCHANGE_HEALTHGAIN = 0
     STATSCHANGE_HEALTHLOSS = 1
     STATSCHANGE_MANAGAIN = 2
     STATSCHANGE_MANALOSS = 3

combat -- type of combat
     COMBAT_NONE = 0
     COMBAT_PHYSICALDAMAGE = 1
     COMBAT_ENERGYDAMAGE = 2
     COMBAT_EARTHDAMAGE = 4
     COMBAT_POISONDAMAGE = 4
     COMBAT_FIREDAMAGE = 8
     COMBAT_UNDEFINEDDAMAGE = 16
     COMBAT_LIFEDRAIN = 32
     COMBAT_MANADRAIN = 64
     COMBAT_HEALING = 128
     COMBAT_DROWNDAMAGE = 256
     COMBAT_ICEDAMAGE = 512
     COMBAT_HOLYDAMAGE = 1024
     COMBAT_DEATHDAMAGE = 2048

value -- amount of healing or damage
 
Last edited:
sorry a long time the topic but.

@UP now don't have problems on the script, but the system don't reflect the damage.

why the problem?
 
Like i said in the other topic:

Change this
Code:
 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

To:
Code:
 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
andu forgot slotPos
 
Back
Top