debug fix OnPlayerDeath [+rep for helper]
#1

I get these error codes in server logs when a player dies. How can i fix it? I have no idea. Please help me.

Код:
[17:23:51] [debug] Run time error 4: "Array index out of bounds"
[17:23:51] [debug]  Attempted to read/write array element at index 65535 in array of size 1000
[17:23:51] [debug] AMX backtrace:
[17:23:51] [debug] #0 0003a854 in ?? (0, 65535, 255) from gamemode.amx
[17:23:51] [debug] #1 00005794 in public OnPlayerDeath (0, 65535, 255) from gamemode.amx
[17:23:51] [death] Potato died 255

Here is my OnPlayerDeath
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
 	SendDeathMessage(killerid, playerid, reason);
 	cVeh[playerid] = 0;
 	if(H_PlayerUsingLoopingAnim[playerid])
    {
    H_PlayerUsingLoopingAnim[playerid] = 0;
    }
    PlayerInfo[playerid][Spawned] = 0;
    PlayerInfo[playerid][Deaths]++;
	if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
	{
		PlayerInfo[killerid][Kills]++;
	}
	#if defined ENABLE_SPEC
	for(new x=0; x<MAX_PLAYERS; x++)
	    if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && PlayerInfo[x][SpecID] == playerid)
	       AdvanceSpectate(x);
	#endif
    if(GetPVarInt(playerid,"dmtime") == 1)
	{
	SetPlayerScore(killerid,GetPlayerScore(killerid)+1);
	GivePlayerMoney(killerid,1200);
	SetPlayerScore(playerid,GetPlayerScore(playerid)-1);
	GivePlayerMoney(killerid,-1200);
	GameTextForPlayer(playerid,"~r~-1 score~n~-$1200",5000,1);
	GameTextForPlayer(killerid,"~g~+1 score~n~+$1200",5000,1);
	}
	if(GetPVarInt(playerid,"InDeathMatch") == 1)
	{
	SetPlayerScore(killerid,GetPlayerScore(killerid)+1);
	GivePlayerMoney(killerid,1200);
	SetPlayerScore(playerid,GetPlayerScore(playerid)-1);
	GivePlayerMoney(killerid,-1200);
	GameTextForPlayer(playerid,"~r~-1 score~n~-$1200",5000,1);
	GameTextForPlayer(killerid,"~g~+1 score~n~+$1200",5000,1);
	}
	if(Minigamer_{playerid} == true)
	{
		if(inProgress > 1)
		{
			Iter_Remove(_Minigamer, playerid);
			Minigamer_{playerid} = false;
			if( Iter_Count(_Minigamer) < 2)
			{
			    foreach(_Minigamer, i) MinigameWinner(i);
			}
		}
		else
		{
			SendClientMessage(playerid, LIME, "Your sign up for Don't Get Wet minigame has been cancelled.");
			Iter_Remove(_Minigamer, playerid);
			Minigamer_{playerid} = false;
		}
	}
	if(InvitedDuel[killerid] == true)
    {
        new Float:healthkiller;
        new namekiller[24],namedeather[24];
        GetPlayerName(killerid, namekiller, 24);
        GetPlayerName(playerid, namedeather, 24);
        GetPlayerHealth(killerid,healthkiller);
        format(Dstring, sizeof(Dstring), "[DUEL]>> %s has won duel on %s [%0.0f off armour and health]",namekiller,namedeather,healthkiller);
        SendClientMessageToAll(0xF600F6AA, Dstring);
        PlayerDuelsWons[killerid]++;
        InvitedDuel[killerid] = false;
        InvitedDuel[playerid] = false;
        IdDuel[playerid] = playerid;
        IdDuel[killerid] = killerid;
        UsingArena = false;
        healthkiller = 0;
        SpawnPlayer(killerid);
    }
	return 1;
}
Thank you
Reply
#2

killerid returns INVALID_PLAYER_ID if the player does not exist (the player who died was not killed). INVALID_PLAYER_ID is defined as 65535.

Nowhere in your callback you check if killerid is a valid ID, so it tries to apply the functions to the ID 65535 and gives you that error.

EDIT: You're checking if it's valid but only for one function, apply the check to the rest of things that involve killerid.
Reply
#3

Quote:
Originally Posted by Troydere
Посмотреть сообщение
killerid returns INVALID_PLAYER_ID if the player does not exist (the player who died was not killed). INVALID_PLAYER_ID is defined as 65535.

Nowhere in your callback you check if killerid is a valid ID, so it tries to apply the functions to the ID 65535 and gives you that error.
How can I fix this thing?
+repped
Reply
#4

You can check if killerid is not INVALID_PLAYER_ID in every function you need to call for killerid.

As an example:

PHP код:
if(killerid != INVALID_PLAYER_ID && InvitedDuel[killerid] == true
Reply
#5

Quote:
Originally Posted by Troydere
Посмотреть сообщение
You can check if killerid is not INVALID_PLAYER_ID in every function you need to call for killerid.

As an example:

PHP код:
if(killerid != INVALID_PLAYER_ID && InvitedDuel[killerid] == true
Thank you . Ill try to fix this thing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)