OnPlayerDeath
#1

Hello Guyz ! I have a problem !


Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	if( IsPlayerAnyClanMember(playerid) && IsPlayerAnyClanMember(killerid) )
	{
	new clanquery[300];
	format(clanquery, sizeof(clanquery), "UPDATE clans SET clankills = %d WHERE clanname = '%s'", GetClanKills(GetPlayerClan(killerid)) + 1, GetPlayerClan(killerid));
  	db_query( Database, clanquery );
	format(clanquery, sizeof(clanquery), "UPDATE clans SET clandeaths = %d WHERE clanname = '%s'", GetClanDeaths(GetPlayerClan(playerid)) + 1, GetPlayerClan(playerid));
 	db_query( Database, clanquery );
	}

	// SendDeathMessage(killerid, playerid, reason);
	 KillingSpree{ playerid } = 0;

	 if ( KillingSpree{ killerid } != bKillingSpree{ killerid } )
	 {
	 ++KillingSpree{ killerid };
	 }
	 else
	 {
	 ++KillingSpree{ killerid };
	 ++bKillingSpree{ killerid };
	 }
	 format( stringgg, sizeof( stringgg ), "~r~~d~~d~~d~Killing Spree: ~h~~g~%d", KillingSpree{ killerid } );
	 GameTextForPlayer( killerid, stringgg, 3000, 5 );
     new string[1000];

    if(GetPlayerScore(killerid) == 5) // Amount of required kills to get rank 1 *Baby Killa'*
    {
        GetPlayerName(killerid, string, sizeof(string) );
        format(string, sizeof(string), ">> %s advanced to rank *Baby Killa'* by killing %d players", string, GetPlayerScore(killerid) );
        SendClientMessageToAll(COLOR_LIGHTBLUE, string);
        pRank[playerid] = 1;
    }
     else if(GetPlayerScore(killerid) == 25) // Amount of required kills to get rank 2 *Soldier*
	{
	    GetPlayerName(killerid, string, sizeof(string) );
        format(string, sizeof(string), ">> %s advanced to rank *Soldier* by killing %d players", string, GetPlayerScore(killerid));
        SendClientMessageToAll(COLOR_LIGHTBLUE, string);
        pRank[playerid] = 2;
	}
	 else if(GetPlayerScore(killerid) == 50) // Amount of required kills to get rank 3 *Gangsta'*
	{
        GetPlayerName(killerid, string, sizeof(string) );
	    format(string, sizeof(string), ">> %s advanced to rank *Gangsta'* by killing %d players", string, GetPlayerScore(killerid));
	    SendClientMessageToAll(COLOR_LIGHTBLUE, string);
	    pRank[playerid] = 3;
	}
	 else if(GetPlayerScore(killerid) == 150) // Amount of required kills to get rank 4 *Underboss*
	{
	    GetPlayerName(killerid, string, sizeof(string) );
        format(string, sizeof(string), ">> %s advanced to rank *UnderBoss* by killing %d players", string, GetPlayerScore(killerid));
        SendClientMessageToAll(COLOR_LIGHTBLUE, string);
	    pRank[playerid] = 4;
	}
	 else if(GetPlayerScore(killerid) == 300) // Amount of required kills to get rank 5 *Tha' Boss*
	{
	    GetPlayerName(killerid, string, sizeof(string) );
	    format(string, sizeof(string), ">> %s advanced to rank *The Boss* by killing %d players", string, GetPlayerScore(killerid));
	    SendClientMessageToAll(COLOR_LIGHTBLUE, string);
	    pRank[playerid] = 5;
	}
	#if defined USE_STATS
    ++PlayerInfo[playerid][Deaths];
	#endif
    InDuel[playerid] = 0;
    
    //Race
 	if(Joined[playerid] == true)
    {
		JoinCount--;
		Joined[playerid] = false;
		DestroyVehicle(CreatedRaceVeh[playerid]);
		DisablePlayerRaceCheckpoint(playerid);
		TextDrawHideForPlayer(playerid, Text:RaceInfo[playerid]);
		CPProgess[playerid] = 0;
		KillTimer(InfoTimerRace[playerid]);
		#if defined RACE_IN_OTHER_WORLD
		SetPlayerVirtualWorld(playerid, 0);
		#endif
	}
	//
   	if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
	{
		#if defined USE_STATS
		++PlayerInfo[killerid][Kills];
	    #endif
	if(InDuel[playerid] == 1) && InDuel[killerid] == 1)
		{
			GameTextForPlayer(playerid,"Loser !",3000,3);
			GameTextForPlayer(killerid,"Winner !",3000,3);
			InDuel[killerid] = 0;
			SetPlayerPos(killerid, 0.0, 0.0, 0.0);
			SpawnPlayer(killerid);
		}
		else if(InDuel[playerid] == 1) && InDuel[killerid] == 0)
		{
			GameTextForPlayer(playerid,"Loser !",3000,3);
		}
	}

	#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(InSumo[playerid] == 1)
	{
		DestroyVehicle(SumoCar[playerid]);
	    SumoPlayers--;
		InSumo[playerid] = 0;
		new strec[256];
	    format(strec, sizeof(strec), "{FF5A00}%s {FFFFFF}a pierdut la competitia Sumo cu Phoenix!", PlayerName2(playerid));
	    SendClientMessageToAll(0x6495EDAA,strec);
	    if(SumoPlayers == 1)
	    {
		    for(new i = 0; i < GetMaxPlayers(); i++)
		    {
			    if(InSumo[i] == 1)
			    {
				    format(strec, sizeof(strec), "{FF5A00}%s {FFFFFF}a castigat competitia Sumo cu Phoenix! {FF5A00}+%d {FFFFFF}Coins si {FF5A00}+%d$", PlayerName2(i),ScoreWin,CashWin);
					SendClientMessageToAll(0x6495EDAA,string);
					pInfo[ i ][Coins] += ScoreWin;
					GivePlayerMoney(i,CashWin);
					SumoPlayers = 0;
					SumoStarted = 0;
					new Float:x,Float:y,Float:z;
					GetPlayerPos(i,x,y,z);
					SetPlayerPos(i,x,y,z+1);
					DestroyVehicle(SumoCar[i]);
					SetTimerEx("SpawnPP",1000,0,"i",i);
					TogglePlayerControllable(i,1);
					InSumo[i] = 0;
			    }
		    }
	    }
	}

	return 1;
}
Код:
 [22:16:27] [debug] Run time error 4: "Array index out of bounds"
[22:16:27] [debug]  Accessing element at index 65535 past array upper bound 499
[22:16:27] [debug] AMX backtrace:
[22:16:27] [debug] #0 0006c428 in public OnPlayerDeath () from LoS.amx
Can you help me ! I will give REP ++ ! Thanks
Reply
#2

You need to check if the killerid is valid or not
pawn Код:
if(killerid != INVALID_PLAYER_ID) {
//execute code
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)