OnPlayerDeath gets stuck.
#1

Hi, I've encountered a strange problem with my OnPlayerDeath, if there is player who died by a INVALID_PLAYER_ID for example if an admin does /sethp 0 0, he will spawn at 0,0,0 and be in the CJ skin..

It stopped when I removed this code under, it looks like it's crashing it somehow, if a player gets killed by a normal player with or without hit, it works fine, but if a player gets killed by a INVALID_PLAYER_ID, it bugs.

Код:
if (AcceptedHit[playerid] == killerid && CharacterData[playerid][pBounty])
	{
	    printf("OnPlayerDeath: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	    new string[128];
	    for(new i = 1; i < MAX_FACTIONS; i++)
		{
			if(FactionData[i][fac_Taken] == 1 && FactionData[i][fac_Type] == FAC_TYPE_HITMEN)
	    	{
	    	    format(string, sizeof(string),"Hitman %s has failed the contract on %s and lost $%d.", PlayerRPName(playerid), PlayerRPName(killerid), CharacterData[killerid][pBounty]/2);
				SendFactionMessage(i, YELLOW, string);
	    	}
	    }
		format(string, sizeof(string),"You have killed a hitman and gained $%d, the contract on your head has been removed.", CharacterData[killerid][pBounty]/2);
		SendClientMessage(killerid, YELLOW, string);
	    CharacterData[playerid][pFailedHits] ++;
	    //PlayerJustDied[playerid] = 1;
	    GiveMoney(playerid, -CharacterData[killerid][pBounty]/2);
	    GiveMoney(killerid, CharacterData[killerid][pBounty]/2);
	    AcceptedHit[playerid] = 999;
	    CharacterData[killerid][pBounty] = 0;
	    printf("OnPlayerDeath: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	}
Reply
#2

Try this and see what happens:
pawn Код:
if (killerid != INVALID_PLAYER_ID && AcceptedHit[playerid] == killerid && CharacterData[playerid][pBounty])
Reply
#3

The same! Tried this before!
Reply
#4

Put a print after each line of code and see where it stops printing
Reply
#5

Код:
printf("OnPlayerDeath debug 1: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
 	if (killerid != INVALID_PLAYER_ID && AcceptedHit[playerid] == killerid && CharacterData[playerid][pBounty])
	{
	    printf("OnPlayerDeath: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	    new string[128];
	    for(new i = 1; i < MAX_FACTIONS; i++)
		{
			if(FactionData[i][fac_Taken] == 1 && FactionData[i][fac_Type] == FAC_TYPE_HITMEN)
	    	{
	    	    format(string, sizeof(string),"Hitman %s has failed the contract on %s and lost $%d.", PlayerRPName(playerid), PlayerRPName(killerid), CharacterData[killerid][pBounty]/2);
				SendFactionMessage(i, YELLOW, string);
	    	}
	    }
		format(string, sizeof(string),"You have killed a hitman and gained $%d, the contract on your head has been removed.", CharacterData[killerid][pBounty]/2);
		SendClientMessage(killerid, YELLOW, string);
	    CharacterData[playerid][pFailedHits] ++;
	    //PlayerJustDied[playerid] = 1;
	    GiveMoney(playerid, -CharacterData[killerid][pBounty]/2);
	    GiveMoney(killerid, CharacterData[killerid][pBounty]/2);
	    AcceptedHit[playerid] = 999;
	    CharacterData[killerid][pBounty] = 0;
	    printf("OnPlayerDeath: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	}
	printf("OnPlayerDeath debug 2: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	if (AcceptedHit[killerid] == playerid && killerid != INVALID_PLAYER_ID)
	{
	    printf("OnPlayerDeath debug 3: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	    new witness, Float:KilledPos[3], string[128], bounty = CharacterData[playerid][pBounty]/2;
	    GetPlayerPos(playerid, KilledPos[0], KilledPos[1], KilledPos[2]);
	    foreach (Player, i)
		{
	    	if(IsPlayerInRangeOfPoint(i, 10.0, KilledPos[0], KilledPos[1], KilledPos[2]))
    		{
	       		if(i != playerid && i != killerid)
        		{
        		    witness ++;
        		}
	    	}
		}
	    PlayerJustDied[playerid] = 1;
	    format(string, sizeof(string),"You have been critically injured by a hitman and lost $%d.", CharacterData[playerid][pBounty]/2);
		SendClientMessage(playerid, YELLOW, string);
		for(new i = 1; i < MAX_FACTIONS; i++)
		{
			if(FactionData[i][fac_Taken] == 1 && FactionData[i][fac_Type] == FAC_TYPE_HITMEN)
	    	{
	    	    format(string, sizeof(string), "Hitman %s has successfully assassinated %s with a %s and collected $%d, %d witnesses.",PlayerRPName(killerid), PlayerRPName(playerid), WeaponName(GetPlayerWeapon(killerid)), CharacterData[playerid][pBounty]/2,witness);
				SendFactionMessage(i, YELLOW, string);
	    	}
	    }
	    GiveMoney(playerid, -bounty);
	    GiveMoney(killerid, bounty);
	    AcceptedHit[killerid] = 999;
	    CharacterData[playerid][pBounty] = 0;
	    CharacterData[killerid][pCompletedHits] ++;
	}
	printf("OnPlayerDeath debug 3: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
Debug;

[19:44:59] OnPlayerDeath debug 1: 0 | 65535 | 255 | 999
[19:44:59] OnPlayerDeath debug 2: 0 | 65535 | 255 | 999
[19:44:59] [death] Jihad_Warrior died 255
Reply
#6

pawn Код:
if (AcceptedHit[killerid] == playerid && killerid != INVALID_PLAYER_ID)
    {
        new witness, Float:KilledPos[3], string[128], bounty = CharacterData[playerid][pBounty]/2;
        GetPlayerPos(playerid, KilledPos[0], KilledPos[1], KilledPos[2]);
        print("1");
        foreach (Player, i)
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, KilledPos[0], KilledPos[1], KilledPos[2]))
            {
                if(i != playerid && i != killerid)
                {
                    witness ++;
                }
            }
        }
        print("2");
        PlayerJustDied[playerid] = 1;
        print("3");
        format(string, sizeof(string),"You have been critically injured by a hitman and lost $%d.", CharacterData[playerid][pBounty]/2);
        print("4");
        SendClientMessage(playerid, YELLOW, string);
        print("5");
        for(new i = 1; i < MAX_FACTIONS; i++)
        {
            if(FactionData[i][fac_Taken] == 1 && FactionData[i][fac_Type] == FAC_TYPE_HITMEN)
            {
                format(string, sizeof(string), "Hitman %s has successfully assassinated %s with a %s and collected $%d, %d witnesses.",PlayerRPName(killerid), PlayerRPName(playerid), WeaponName(GetPlayerWeapon(killerid)), CharacterData[playerid][pBounty]/2,witness);
                SendFactionMessage(i, YELLOW, string);
            }
        }
        print("6");
        GiveMoney(playerid, -bounty);
        print("7");
        GiveMoney(killerid, bounty);
        print("8");
        AcceptedHit[killerid] = 999;
        print("9");
        CharacterData[playerid][pBounty] = 0;
        print("10");
        CharacterData[killerid][pCompletedHits] ++;
        print("11");
    }
You need to go deeper, we've already come to the conclusion that this part of the code doesn't execute
Reply
#7

Code:
Код:
printf("OnPlayerDeath debug 1: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	printf("OnPlayerDeath: Debug 1");
 	if (killerid != INVALID_PLAYER_ID && AcceptedHit[playerid] == killerid && CharacterData[playerid][pBounty])
	{
	    printf("OnPlayerDeath: Debug 2");
	    new string[128];
	    for(new i = 1; i < MAX_FACTIONS; i++)
		{
			if(FactionData[i][fac_Taken] == 1 && FactionData[i][fac_Type] == FAC_TYPE_HITMEN)
	    	{
	    	    format(string, sizeof(string),"Hitman %s has failed the contract on %s and lost $%d.", PlayerRPName(playerid), PlayerRPName(killerid), CharacterData[killerid][pBounty]/2);
				SendFactionMessage(i, YELLOW, string);
	    	}
	    }
	    printf("OnPlayerDeath: Debug 3");
		format(string, sizeof(string),"You have killed a hitman and gained $%d, the contract on your head has been removed.", CharacterData[killerid][pBounty]/2);
		SendClientMessage(killerid, YELLOW, string);
	    CharacterData[playerid][pFailedHits] ++;
	    //PlayerJustDied[playerid] = 1;
	    printf("OnPlayerDeath: Debug 4");
	    GiveMoney(playerid, -CharacterData[killerid][pBounty]/2);
	    GiveMoney(killerid, CharacterData[killerid][pBounty]/2);
	    AcceptedHit[playerid] = 999;
	    printf("OnPlayerDeath: Debug 5");
	    CharacterData[killerid][pBounty] = 0;
	    printf("OnPlayerDeath: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	    printf("OnPlayerDeath: Debug 6");
	}
	printf("OnPlayerDeath: Debug 7");
	if (AcceptedHit[killerid] == playerid && killerid != INVALID_PLAYER_ID)
	{
	    printf("OnPlayerDeath: Debug 8");
	    printf("OnPlayerDeath debug 3: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
	    new witness, Float:KilledPos[3], string[128], bounty = CharacterData[playerid][pBounty]/2;
	    GetPlayerPos(playerid, KilledPos[0], KilledPos[1], KilledPos[2]);
	    foreach (Player, i)
		{
	    	if(IsPlayerInRangeOfPoint(i, 10.0, KilledPos[0], KilledPos[1], KilledPos[2]))
    		{
	       		if(i != playerid && i != killerid)
        		{
        		    witness ++;
        		}
	    	}
		}
		printf("OnPlayerDeath: Debug 9");
	    PlayerJustDied[playerid] = 1;
	    format(string, sizeof(string),"You have been critically injured by a hitman and lost $%d.", CharacterData[playerid][pBounty]/2);
		SendClientMessage(playerid, YELLOW, string);
		for(new i = 1; i < MAX_FACTIONS; i++)
		{
			if(FactionData[i][fac_Taken] == 1 && FactionData[i][fac_Type] == FAC_TYPE_HITMEN)
	    	{
	    	    format(string, sizeof(string), "Hitman %s has successfully assassinated %s with a %s and collected $%d, %d witnesses.",PlayerRPName(killerid), PlayerRPName(playerid), WeaponName(GetPlayerWeapon(killerid)), CharacterData[playerid][pBounty]/2,witness);
				SendFactionMessage(i, YELLOW, string);
	    	}
	    }
	    GiveMoney(playerid, -bounty);
	    GiveMoney(killerid, bounty);
	    AcceptedHit[killerid] = 999;
	    CharacterData[playerid][pBounty] = 0;
	    CharacterData[killerid][pCompletedHits] ++;
	    printf("OnPlayerDeath: Debug 10");
	}
	printf("OnPlayerDeath: Debug 11");
	printf("OnPlayerDeath debug 3: %d | %d | %d | %d", playerid, killerid, reason, AcceptedHit[playerid]);
The strangest thing is this occures when I /sethp 0 0 myself, this shouldn't be even called cuz there was no hitman involved.
Reply
#8

Show me the part of your serverlog where a player dies. That's the reason i added the prints, to see the last print to know where it stops
Reply
#9

[19:56:16] OnPlayerDeath debug 1: 0 | 65535 | 255 | 999
[19:56:16] OnPlayerDeath: Debug 1
[19:56:16] OnPlayerDeath: Debug 7
[19:56:16] [death] Jihad_Warrior died 255

It crashes after the 7
Reply
#10

Put in more prints after 7 to know more precisely where your code stops
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)