@496815 I took your code, changed a bit to this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
print("x")
if getPlayerStorageValue(attacker, 15600) == 1 then
print("y")
local multiplier = 500
doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
end
end
return true
end
Declarated as: <event type="statschange" name="dmg" event="script" value="damage.lua"/>
Added to login.lua: registerCreatureEvent(cid,'dmg')
There are no errors in terminal, also there isn't any printed x or y, moreover when this script is enabled server crashes after killing any monster.
You've created an infinite loop.
You attack monster for 1 damage.
Script enables, and deals 1 damage, and puts a new damage through the system for 500 damage.
Script enables, and deals 500 damage, and puts a new damage through the system for 250000 damage.
Script enables, and deals 250000 damage, and puts a new damage through the system for 125000000 damage.
Script enables,.....
You can do this many ways, but I'll do it simple, so you understand what you'll want to do.
Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
print("x")
if getPlayerStorageValue(attacker, 15600) == 1 then
print("y")
setPlayerStorageValue(attacker, 15600, 2)
local multiplier = 500
doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
return false
elseif getPlayerStorageValue(attacker, 15600) == 2 then
print("z")
setPlayerStorageValue(attacker, 15600, 1)
return true
end
end
return true
end
You attack monster for 1 damage.
Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 2, sends 500 damage through the system, and returns the initial damage as false.
Script enables, and checks player storage.
Script detects you have storage value 2.
Script changes storage value to 1, deals 500 damage to target.
x
y
x
z
--------
The problem with the above method (1/10000 chance to happen) is if your system get's too many commands at once, it will sometimes flop the order of the issued damages, as it assumes all damage is true by default, and is not going to be modified, since within the script, it only checks true/false, as values cannot be returned as a different value.
In these cases some of your damages may get skewed to be stronger or weaker then they are supposed to be, as the damages will have been multiplied twice, or not multiplied at all.
Scenario
You attack monster(1) for 1 damage.
You attack monster(2) for 2 damage.
Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 2, sends 500 damage through the system against monster(1), and returns the initial damage as false.
Script enables, and checks player storage.
Script detects you have storage value 2.
Script changes storage value to 1, deals 2 damage to monster(2).
-- This damage should never go through before monster(1)'s damage has fully finished, but it has flopped in front for reasons unknown.
Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 2, sends 250000 damage through the system against monster(1), and returns the initial damage as false.
Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 1, deals 250000 damage to monster(1).
-----
In this scenario, Monster(1) got multiplied twice, and Monster(2) did not receive any multiplier.
-----------
Instead of using storage flopping, you can use a global table to store the false/true damages for each creature in the world, however that's beyond my scripting capabilities.
I have an example on my home computer, but I'm not currently home, and could not explain it to you, even if I had the example with me to post.
That being said, if the multipliers aren't crazy amounts like 500x and instead something like 1.5-3x you'll likely never notice the scenario's above, even if you were looking for them.
Good luck!
Xikini