SA-MP Forums Archive
OnPlayerDeath Weird Problem [REP+] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerDeath Weird Problem [REP+] (/showthread.php?tid=597135)



OnPlayerDeath Weird Problem [REP+] - SecretBoss - 27.12.2015

Hello,

I faced a very weird problem on my server, OnPlayerDeath callback doesn't return correct killerid and reason I tried to debug it and every statement is called I have also putted a print message and got the following results

Code
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	Server(playerid, "OnPlayerDeathCalled");
	printf("playerid: %d killerid: %d reason: %d", playerid, killerid, reason);
        return 1;
}
Output:
Код:
[04:07:49] playerid: 0 killerid: 65535 reason: 255
That printed when my friend killed me^

I tried to run nativechecker and crashdetect but nothing printed, also I don't think that code is needed because I debugged every statement and everything worked properly, any help would very appreciated


EDIT:
Problem is fixed, fix is here


Re: OnPlayerDeath Weird Problem [REP+] - lucamsx - 27.12.2015

I think you need to check if killerid is valid.
Код:
if(killerid != INVALID_PLAYER_ID)
{
//your stuff
}



Re: OnPlayerDeath Weird Problem [REP+] - SecretBoss - 27.12.2015

Quote:
Originally Posted by lucamsx
Посмотреть сообщение
I think you need to check if killerid is valid.
Код:
if(killerid != INVALID_PLAYER_ID)
{
//your stuff
}
65535 means you killed yourself, OnPlayerDeath returns 65535 when its called even if someone else killed me, also I have this check for killerid, SendDeathMessage already checks for it, so it's not needed


Re: OnPlayerDeath Weird Problem [REP+] - lucamsx - 27.12.2015

But theres no need of usage of invalid id check in SendDeathMessage. 65535 is a valid parameter in this function.
Maybe try putting this check somewhere else?


Re: OnPlayerDeath Weird Problem [REP+] - SecretBoss - 27.12.2015

Quote:
Originally Posted by lucamsx
Посмотреть сообщение
But theres no need of usage of invalid id check in SendDeathMessage. 65535 is a valid parameter in this function.
Maybe try putting this check somewhere else?
It means that player has killed his self, I think that there is a problem with fake kill system, I am looking for it now


EDIT: problem still exists it wasn't fake kill system


Re: OnPlayerDeath Weird Problem [REP+] - PrO.GameR - 27.12.2015

Quote:
Originally Posted by SecretBoss
Посмотреть сообщение
Hello,

I faced a very weird problem on my server, OnPlayerDeath callback doesn't return correct killerid and reason I tried to debug it and every statement is called I have also putted a print message and got the following results

Code
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	Server(playerid, "OnPlayerDeathCalled");
	printf("playerid: %d killerid: %d reason: %d", playerid, killerid, reason);
        return 1;
}
Output:
Код:
[04:07:49] playerid: 0 killerid: 65535 reason: 255
That printed when my friend killed me^

I tried to run nativechecker and crashdetect but nothing printed, also I don't think that code is needed because I debugged every statement and everything worked properly, any help would very appreciated
Got a custom damage system ? Probably yes, that causes it, you set the player's HP to 0, he dies by your hand (code) not the default sa-mp damage therefore it's a suicide.
You should make checks under your custom damage.


Re: OnPlayerDeath Weird Problem [REP+] - SecretBoss - 27.12.2015

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
Got a custom damage system ? Probably yes, that causes it, you set the player's HP to 0, he dies by your hand (code) not the default sa-mp damage therefore it's a suicide.
You should make checks under your custom damage.
You are right, I added some checks but I can't get player's reaason


Re: OnPlayerDeath Weird Problem [REP+] - PrO.GameR - 27.12.2015

Here is a suggestion, When you kill him with setting his HP to 0, Call the Onplayerdeath yourself and trash the default OnPlayerDeath

Edit: I had the same problem and found the solution before, but was too lazy to add it to my script, I went ahead and added it right now, it should work in theory (Don't really have anyone around to test it right now, but you go ahead and test now)
use this for your custom damage deaths CallLocalFunction("OnPlayerDeath","iii",playerid,i ssuerid,weaponid);
and this in first line of OnPlayerDeath if(reason==255) return 1;


Re: OnPlayerDeath Weird Problem [REP+] - SpriTe - 27.12.2015

I have same problem, when I kill my friend with m4, reason of onplayerdeath is 255.


Re: OnPlayerDeath Weird Problem [REP+] - SecretBoss - 27.12.2015

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
Here is a suggestion, When you kill him with setting his HP to 0, Call the Onplayerdeath yourself and trash the default OnPlayerDeath (so trash it whenever it's reason 255)
I use it on OnPlayerTakeDamage, I can take issuerid as the killerid and playerid, what about for reason, it will return invalid reason (255) something I don't want?

Nice idea I will test it now