• 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 onStatsChange - help in the code

Guiaki

Member
Joined
Jan 3, 2011
Messages
137
Reaction score
8
okay, darkhaos gave me the lets say initial part of the code, I changed it all and okay, i'll show you everthing:
Code:
function onStatsChange(cid, attacker, type, combat, value)
	if isPlayer(attacker) then
	if type == STATSCHANGE_HEALTHLOSS then
		if combat == COMBAT_PHYSICALDAMAGE then
			local reset = getReset(attacker)
			local value = (value + value*(reset/5))
		end
	end
	end
	if isMonster(attacker) and isPlayer(cid) then
	if type == STATSCHANGE_HEALTHLOSS then
			if combat == COMBAT_PHYSICALDAMAGE then
				local reset = getReset(cid)
				local value = (value + value*(reset/5))
			end
	end
	end
	return true
end

First thing, the cid / attacker manual

Code:
Player1 x Player2 =
Player1 = attacker
Player2 = cid

Player1 x Monster1 =
Player1 = cid
Monster1 = attacker

Monster1 x Player1 =
Player1 = cid
Monster1 = attacker

Okay, first thing as you can see when a monster attack a player or a player attack a monster cid and attacker are both the same, so if a monster attack a player the action that it will receive wil be the same one as the player attacking a monster, so i needed a function or something that will only do the action if the player are the one attacking, or in other words the monster is the one who is loosing hp.

Second thing, on the code, when its called:
Code:
	if isMonster(attacker) and isPlayer(cid) then
	if type == STATSCHANGE_HEALTHLOSS then
			if combat == COMBAT_PHYSICALDAMAGE then
				local reset = getReset(cid)
				local value = (value + value*(reset/5))
			end
	end
	end

all the things will be only resulting in the monster, if you do like a
Code:
				doCreatureSay(cid, "damage initial "..value.." hitpoints")
				local value = (value + value*(reset/5))
				doCreatureSay(cid, "damage final "..value.." hitpoints")

You will see that even if the player attacks or the monster attacks, it will be always the monster attack value, never the player one, so this needs to take only the damage done by the player.

third thing: MOST IMPORTANT:
when you do like:
Code:
doTargetCombatHealth(attacker, cid, combat, -value, -value, CONST_ME_DRAWBLOOD)

or
Code:
doCreatureAddHealth(cid, -value)

it will do the new damage, but since you are doing a new damage, it automaticly enters in the onStatsChange again, and do a new damage with your new damage, like I did 50 damage to a player and I have 5 resets, it will be done 100 damage, and by that damage it will do a new one that will make it go to 200, after that 400, then 800, etc..

so what i mean: if you attack once, and hit 50, you will kill the target because it goes into a infinite loop inside the script.

can someone help me with all these things?
 
Lua:
function onStatsChange(cid, attacker, type, combat, value)
	local reset = getReset(cid)
	if type == STATSCHANGE_HEALTHLOSS then
		if combat == COMBAT_PHYSICALDAMAGE then
			if reset > 0 then
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Initial damage: " .. value)
				local value = (value + value*((reset/5) + 1))
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Final damage: " .. value)
				doTargetCombatHealth(attacker, cid, COMBAT_PHYSICALDAMAGE, value, value, CONST_ME_DRAWBLOOD)
				return false
			end
		end
	end
	return true
end

I tested and works

Note: I tested it with local reset = getPlayerSoul(cid) because i don't have the function getReset(cid) and i just needed a function that returns a value

The only "problem" is that you won't get the message You lose x hitpoints due on attack by y, just You lose x hitpoints.
 
its not working...
first it doesn't hit the enemy and i already changed to -value.

second, monsters hit will be based in the script as well, i want only to the players scripts be based on that.

last when you hit once it will go into a infinite loop inside the script, because you hit like 10, it will go there do the resets and return like 20, the 20 will be another damage so it will go inside the script again..
---------edit-----------
now its not in the loop anymore, but it still have the monster problem
monsters damage is based on the players which they are attacking resets, which was supposed to be happening only when a player attacks a monster not the opposite
 
Last edited:
BumP, sorry i need it really bad ;x

-------------edit--------------
Code:
doTargetCombatHealth(attacker, cid, COMBAT_UNDEFINEDDAMAGE, -value, -value, CONST_ME_DRAWBLOOD)

will deal the -value to the player, but there is no message popping up that he lost that damage like a red -500 going up when hit and in the server log like Player lost 500 damage due to an attack by player.

so I made this code:

Code:
                                doPlayerSendTextMessage(attacker,MESSAGE_DAMAGE_DEALT,"Player "..getCreatureName(cid).." loses "..value.." hitpoints due to an attack by you.")
				doPlayerSendTextMessage(cid,MESSAGE_DAMAGE_DEALT,"You loose "..value.." hitpoints due to an attack by " .. getCreatureName(attacker))
				doSendAnimatedText(getCreaturePosition(cid), value,TEXTCOLOR_RED)

but it will only appear to attacker and cid, is there a way to do the damage and it shows without getting into a loop?
 
Last edited:
this is the script changed and everthing , it is working 90% for PlayerxPlayer (just the issue that i have in the last post)
Code:
function onStatsChange(cid, attacker, type, combat, value)
	local reset = getReset(cid)
	if isPlayer(attacker) then
	local reset = getReset(attacker)
	if type == STATSCHANGE_HEALTHLOSS then
		if combat == COMBAT_PHYSICALDAMAGE then
			if reset > 0 then
				local value = (value + value*((reset/5)))
				doTargetCombatHealth(attacker, cid, COMBAT_UNDEFINEDDAMAGE, -value, -value, CONST_ME_DRAWBLOOD)
				doPlayerSendTextMessage(attacker,MESSAGE_DAMAGE_DEALT,"Player "..getCreatureName(cid).." loses "..value.." hitpoints due to an attack by you.")
				doPlayerSendTextMessage(cid,MESSAGE_DAMAGE_DEALT,"You loose "..value.." hitpoints due to an attack by " .. getCreatureName(attacker))
				doSendAnimatedText(getCreaturePosition(cid), value,TEXTCOLOR_RED)
				return false
			end
		end
	end
	end
	return true
end

I wanted to add the same thing for monsters because if i take out the isPlayer(attacker), the function will applies to monster, and lets say if a monster attack me pyshical for 100 damage, and i have 5 resets, i'll take twice the damage because of the equation value + value*(reset/5), so i don't want that, i only to work for PLAYER x Monster not MONSTER X Player, how can i do that?
 
you would have to register this for every monster, there was a thread with shorter solution but i can't find it right now
 
even tho i register it for every monster who i could know when they are the one attacking or don't? '-', can't you give me the right direction to try? thanks for helping :D you rock ;p
 
unregister it from login.lua, therefore leaving it registered only for monsters. the player will be 'attacker' and monster will be 'cid'
 
okay but it will still be the same thing, only if when monster attack they become the attacker :S
----edit----
i tested it, and still the same thing, player becomes the cid and the monster is the attacker.

if i want to do something to happen when i a player attacks a monster it doesn't work at all, somebody know why? it all only happens if the monster is the one attacking :S
 
Last edited:
how could that? i UNregistred lol :I

----edit----
ohh got it, i forgot the part to register in monster, ok i will try
 
Okay, I put this in every monster I wanted to work:
<script>
<event name= "ResetDMG"/>
</script>

just before </monster>

I tested it, changed the damage and put a very big one just to make sure it was working, but now I can't make the players say stuff like: doCreatureSay(cid or attacker, "I am cid/attacker) just to know where i can manage to get the script in and make tests.

but even that tho it appears in the console:
[Warning - Monster::Monster] Unknown event name - ResetDMG
and i am sure that i put ResetDMG the name of the event

I made this code, to make a Dual Combo or Triple Combo for my vocation : Monk
Lua:
if isPlayer(attacker) then
	if voc==11 or voc==15 then
		if type == STATSCHANGE_HEALTHLOSS and combat == COMBAT_PHYSICALDAMAGE and getCreatureStorage(attacker, 5) == -1 then
				n = math.random(100)
					if n<25 then
						doCreatureSetStorage(attacker, 5, 1)
						doTargetCombatHealth(attacker, cid, COMBAT_PHYSICALDAMAGE, -value*55, -value*55, CONST_ME_NONE)

						doSendAnimatedText(getCreaturePosition(attacker), "DUAL COMBO",TEXTCOLOR_RED)
						n = math.random(100)
						if n<25 then
							doSendAnimatedText(getCreaturePosition(attacker), "TRIPLE COMBO",TEXTCOLOR_RED)
							doTargetCombatHealth(attacker, cid, COMBAT_PHYSICALDAMAGE, -value, -value, CONST_ME_NONE)
						end
						doCreatureSetStorage(attacker, 5)
					end
		end
	end

This is inside the script Reset Damage.lua, which i named the event ResetDMG, well, it isn't working, I can't know where it doesn't work because i cant make doCreatureSay, or the other talk commands because it is not registered in login.lua, and if i register it in there it wont work against monsters, is something wrong with the script? it doesn't say dual combo or triple combo, or even do the combos, i took out the change of the n, and even that it still don't work ;x
 
Okay, i fixed it all, now when player attacks monster i can do something for they, but now i wanted to make a damage reflect system, and well using the same function i did this
Lua:
if not isMonster(attacker) then
else
	doCreatureSay(attacker, "I am the attacker")
	if getCreatureStorage(cid,989878) == 1 then
		doCreatureAddHealth(attacker, -value*0.30)
	end
end

and well, when the character have the storage 989878 1 (when he cast the spell) it will start to hit the monster as they hit him, but the problem is, as you can see i put the attacker to say i am the attacker, he only say that when he/it use heal, by saying that, if I get hydras, and they start to hit me, when they heal they will be the attacker, but when they attack me they are nothing '-' how can i know when they are the one attacking?
 
Back
Top