Crashdetect OnPlayerDeath SAMP
#1

Hello there i have problem in my onplayerdeath script i dont know but but crashdetect said

Quote:

[21:06:25] [debug] Run time error 4: "Array index out of bounds"
[21:06:25] [debug] Accessing element at index 65535 past array upper bound 129
[21:06:25] [debug] AMX backtrace:
[21:06:25] [debug] #0 003f93e8 in public FC_OnPlayerDeath () from HighSpeedDriversmm3rev7.amx
[21:06:25] [debug] #1 native CallLocalFunction () [00473f40] from samp-server.exe
[21:06:25] [debug] #2 0001223c in public OnPlayerDeath () from HighSpeedDriversmm3rev7.amx
[21:06:25] [death] semara died 255

here is the script
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	//killerid != playerid && playerid != killerid &&
    SendDeathMessage(killerid, playerid, reason);
	GameTextForPlayer(playerid, "~r~Wasted", 2000, 5);
	if(killerid != INVALID_PLAYER_ID)
	{
		PlayerInfo[playerid][Deaths]++;
		PlayerInfo[killerid][Kills]++;
	}
	if(PlayerInfo[playerid][JoinedEvent] == true)
	{
	    PlayerInfo[playerid][JoinedEvent] = false;
		foreach(Player, i)
		{
		    if(PlayerInfo[i][AdminLevel] >= 1)
		    {
				new name[MAX_PLAYER_NAME], string[128];
				GetPlayerName(playerid, name, sizeof(name));
				format(string, sizeof(string), "%s has died in the event", name);
		        SendClientMessage(i, COLOR_RED, string);
			}
		}
	}
	if(PlayerInfo[killerid][World] != DMWorldID && PlayerInfo[playerid][JoinedEvent] == false && PlayerInfo[killerid][World] != TDMWorldID && PlayerInfo[killerid][World] != FreeroamID)
	{
	    if(killerid != INVALID_PLAYER_ID)
	    {
	        if(PlayerInfo[killerid][MaxDMWarnings] == 3)
			{
			    new name[MAX_PLAYER_NAME], string[160];
			    GetPlayerName(killerid, name, sizeof(name));
			    format(string, sizeof(string), "SERVER-KICK: %s (Reason: killing people outside the Deathmatch World) Warning: 3/3", name);
			    SendClientMessageToAll(BANNEDMESSAGE, string);
			    return Kick(killerid);
			}
		    else if(PlayerInfo[killerid][MaxDMWarnings] != 3)
		    {
				new name[MAX_PLAYER_NAME];
				new string[160];
				GetPlayerName(killerid, name, sizeof(name));
				PlayerInfo[killerid][MaxDMWarnings]++;
				format(string, sizeof(string), "SERVER-WARN: %s (Reason: killing people outside the Deathmatch World) Warning: %d/3", name, PlayerInfo[killerid][MaxDMWarnings]);
				SendClientMessageToAll(BANNEDMESSAGE, string);
			    GameTextForPlayer(killerid, "~r~HEY! you may not kill people outside the DM World!!!", 5000, 5);
				cmd_kill(killerid, "");
			}
		}
		else return 1;
	}
	else if(PlayerInfo[killerid][World] == DMWorldID || PlayerInfo[killerid][World] == TDMWorldID || PlayerInfo[killerid][World] == FreeroamID)
	{
	    if(killerid != INVALID_PLAYER_ID)
	    {
	    	GivePlayerMoney(killerid, 2500);
			SetPlayerScore(killerid, GetPlayerScore(killerid) + 2);
 			GameTextForPlayer(killerid, "~r~you earned $2500 and 2 Score for killing an opponent", 2000, 5);
 			PlayerInfo[killerid][KillingSpree]++;
			if(PlayerInfo[killerid][KillingSpree] == 3)
			{
				new string[128], kname[MAX_PLAYER_NAME];
				GetPlayerName(killerid, kname, sizeof(kname));
				format(string, sizeof(string), "%s is starting to Own People! he has a Killing Spree of 3 and earned $5000 and 4 Score", kname);
				GivePlayerMoney(killerid, 5000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+4);
				foreach(Player, i)
				{
				    SendClientMessage(i, PLAYERCOLOR_AQUA, string);
				}
			}
			else if(PlayerInfo[killerid][KillingSpree] == 6)
			{
			    new string[128], kname[MAX_PLAYER_NAME];
				GetPlayerName(killerid, kname, sizeof(kname));
				format(string, sizeof(string), "%s is the Killer!! he has a Killing Spree of 6 and earned $10000 and 8 Score", kname);
				GivePlayerMoney(killerid, 10000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+8);
				foreach(Player, i)
				{
				    SendClientMessage(i, PLAYERCOLOR_AQUA, string);
				}
			}
			else if(PlayerInfo[killerid][KillingSpree] == 10)
			{
			    new string[128], kname[MAX_PLAYER_NAME];
				GetPlayerName(killerid, kname, sizeof(kname));
				format(string, sizeof(string), "%s is Unstoppable!!! he has a Killing Spree of 10 and earned $15000 and 10 Score", kname);
				GivePlayerMoney(killerid, 15000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+10);
				foreach(Player, i)
				{
				    SendClientMessage(i, PLAYERCOLOR_AQUA, string);
				}
			}
			else if(PlayerInfo[killerid][KillingSpree] == 15)
			{
			    new string[128], kname[MAX_PLAYER_NAME];
				GetPlayerName(killerid, kname, sizeof(kname));
				format(string, sizeof(string), "%s is the GodKiller!!!! he has a Killing Spree of 15 and earned $20000 and 15 Score", kname);
				GivePlayerMoney(killerid, 20000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+15);
				foreach(Player, i)
				{
				    SendClientMessage(i, PLAYERCOLOR_AQUA, string);
				}
			}
			else if(PlayerInfo[killerid][KillingSpree] == 20)
			{
			    new string[128], kname[MAX_PLAYER_NAME];
				GetPlayerName(killerid, kname, sizeof(kname));
				format(string, sizeof(string), "%s is the Master!!!!! he has a Killing Spree of 20 and earned $30000 and 20 Score", kname);
				GivePlayerMoney(killerid, 30000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+20);
				foreach(Player, i)
				{
				    SendClientMessage(i, PLAYERCOLOR_AQUA, string);
				}
			}
			else if(PlayerInfo[killerid][KillingSpree] == 30)
			{
			    new string[128], kname[MAX_PLAYER_NAME];
				GetPlayerName(killerid, kname, sizeof(kname));
				format(string, sizeof(string), "%s is the Ultimate Killer!!!!! he has a Killing Spree of 30 and earned $50000 and 30 Score", kname);
				GivePlayerMoney(killerid, 50000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+30);
				foreach(Player, i)
				{
				    SendClientMessage(i, PLAYERCOLOR_AQUA, string);
				}
			}
			if(PlayerInfo[playerid][KillingSpree] == 3)
			{
				GivePlayerMoney(killerid, 5000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+4);
				SendClientMessage(killerid, COLOR_ORANGE, "you have killed someone with a killing spree of 3 and earned $5000 and 4 Score");
			}
			else if(PlayerInfo[playerid][KillingSpree] == 6)
			{
				GivePlayerMoney(killerid, 10000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+8);
				SendClientMessage(killerid, PLAYERCOLOR_AQUA, "you have killed someone with a killing spree of 6 and earned $10000 and 8 Score");
			}
			else if(PlayerInfo[playerid][KillingSpree] == 10)
			{
				GivePlayerMoney(killerid, 15000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+10);
				SendClientMessage(killerid, PLAYERCOLOR_AQUA, "you have killed someone with a killing spree of 10 and earned $15000 and 10 Score");
			}
			else if(PlayerInfo[playerid][KillingSpree] == 15)
			{
				GivePlayerMoney(killerid, 20000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+15);
				SendClientMessage(killerid, PLAYERCOLOR_AQUA, "you have killed someone with a killing spree of 15 and earned $20000 and 15 Score");
			}
			else if(PlayerInfo[playerid][KillingSpree] == 20)
			{
				GivePlayerMoney(killerid, 30000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+20);
				SendClientMessage(killerid, PLAYERCOLOR_AQUA, "you have killed someone with a killing spree of 20 and earned $30000 and 20 Score");
			}
			else if(PlayerInfo[playerid][KillingSpree] == 30)
			{
				GivePlayerMoney(killerid, 50000);
				SetPlayerScore(killerid, GetPlayerScore(killerid)+25);
				SendClientMessage(killerid, PLAYERCOLOR_AQUA, "you have killed someone with a killing spree of 30 and earned $50000 and 25 Score");
			}
		}
		else return 1;
	}
	return 1;
}
plss help if there is a problem

sry for my bad english
Reply
#2

You need check killerid here
if(PlayerInfo[killerid][World] != DMWorldID ...

!= INVALID_PLAYER_ID
Reply
#3

You used "killerid" in the array and then you checked if they're not invalid players. I improved few things (fixed the run time error, declaring variables out of loop and using switch for kill spree, no need for foreach when SendClientMessageToAll sends the message to all players itself, you forgot to reset the playerid's kill spree and a few others):
PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    
SendDeathMessage(killeridplayeridreason);
    
GameTextForPlayer(playerid"~r~Wasted"20005);
    
PlayerInfo[playerid][Deaths]++;
    if(
PlayerInfo[playerid][JoinedEvent] == true)
    {
        
PlayerInfo[playerid][JoinedEvent] = false;
        new 
name[MAX_PLAYER_NAME], string[64];
        foreach(
Playeri)
        {
            if(
PlayerInfo[i][AdminLevel] >= 1)
            {
                
GetPlayerName(playeridnamesizeof(name));
                
format(stringsizeof(string), "%s has died in the event"name);
                
SendClientMessage(iCOLOR_REDstring);
            }
        }
    }
    if(
killerid != INVALID_PLAYER_ID)
    {
        
PlayerInfo[killerid][Kills]++;
        if(
PlayerInfo[killerid][World] != DMWorldID && PlayerInfo[playerid][JoinedEvent] == false && PlayerInfo[killerid][World] != TDMWorldID && PlayerInfo[killerid][World] != FreeroamID)
        {
            if(
PlayerInfo[killerid][MaxDMWarnings] == 3)
            {
                new 
name[MAX_PLAYER_NAME], string[144];
                
GetPlayerName(killeridnamesizeof(name));
                
format(stringsizeof(string), "SERVER-KICK: %s (Reason: killing people outside the Deathmatch World) Warning: 3/3"name);
                
SendClientMessageToAll(BANNEDMESSAGEstring);
                return 
Kick(killerid);
            }
            else
            {
                new 
name[MAX_PLAYER_NAME];
                new 
string[144];
                
GetPlayerName(killeridnamesizeof(name));
                
PlayerInfo[killerid][MaxDMWarnings]++;
                
format(stringsizeof(string), "SERVER-WARN: %s (Reason: killing people outside the Deathmatch World) Warning: %d/3"namePlayerInfo[killerid][MaxDMWarnings]);
                
SendClientMessageToAll(BANNEDMESSAGEstring);
                
GameTextForPlayer(killerid"~r~HEY! you may not kill people outside the DM World!!!"50005);
                
cmd_kill(killerid"");
            }
        }
        else if(
PlayerInfo[killerid][World] == DMWorldID || PlayerInfo[killerid][World] == TDMWorldID || PlayerInfo[killerid][World] == FreeroamID)
        {
            
GivePlayerMoney(killerid2500);
            
SetPlayerScore(killeridGetPlayerScore(killerid) + 2);
            
GameTextForPlayer(killerid"~r~you earned $2500 and 2 Score for killing an opponent"20005);
            
PlayerInfo[killerid][KillingSpree]++;
            new 
string[128], kname[MAX_PLAYER_NAME];
            
GetPlayerName(killeridknamesizeof(kname));
            switch (
PlayerInfo[killerid][KillingSpree])
            {
                case 
3:
                {
                    
format(stringsizeof(string), "%s is starting to Own People! he has a Killing Spree of 3 and earned $5000 and 4 Score"kname);
                    
GivePlayerMoney(killerid5000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+4);
                    
SendClientMessageToAll(PLAYERCOLOR_AQUAstring);
                }
                case 
6:
                {
                    
format(stringsizeof(string), "%s is the Killer!! he has a Killing Spree of 6 and earned $10000 and 8 Score"kname);
                    
GivePlayerMoney(killerid10000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+8);
                    
SendClientMessageToAll(PLAYERCOLOR_AQUAstring);
                }
                case 
10:
                {
                    
format(stringsizeof(string), "%s is Unstoppable!!! he has a Killing Spree of 10 and earned $15000 and 10 Score"kname);
                    
GivePlayerMoney(killerid15000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+10);
                    
SendClientMessageToAll(PLAYERCOLOR_AQUAstring);
                }
                case 
15:
                {
                    
format(stringsizeof(string), "%s is the GodKiller!!!! he has a Killing Spree of 15 and earned $20000 and 15 Score"kname);
                    
GivePlayerMoney(killerid20000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+15);
                    
SendClientMessageToAll(PLAYERCOLOR_AQUAstring);
                }
                case 
20:
                {
                    
format(stringsizeof(string), "%s is the Master!!!!! he has a Killing Spree of 20 and earned $30000 and 20 Score"kname);
                    
GivePlayerMoney(killerid30000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+20);
                    
SendClientMessageToAll(PLAYERCOLOR_AQUAstring);
                }
                case 
30:
                {
                    
format(stringsizeof(string), "%s is the Ultimate Killer!!!!! he has a Killing Spree of 30 and earned $50000 and 30 Score"kname);
                    
GivePlayerMoney(killerid50000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+30);
                    
SendClientMessageToAll(PLAYERCOLOR_AQUAstring);
                }
            }
            switch (
PlayerInfo[playerid][KillingSpree])
            {
                case 
3:
                {
                    
GivePlayerMoney(killerid5000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+4);
                    
SendClientMessage(killeridCOLOR_ORANGE"you have killed someone with a killing spree of 3 and earned $5000 and 4 Score");
                }
                case 
6:
                {
                    
GivePlayerMoney(killerid10000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+8);
                    
SendClientMessage(killeridPLAYERCOLOR_AQUA"you have killed someone with a killing spree of 6 and earned $10000 and 8 Score");
                }
                case 
10:
                {
                    
GivePlayerMoney(killerid15000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+10);
                    
SendClientMessage(killeridPLAYERCOLOR_AQUA"you have killed someone with a killing spree of 10 and earned $15000 and 10 Score");
                }
                case 
15:
                {
                    
GivePlayerMoney(killerid20000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+15);
                    
SendClientMessage(killeridPLAYERCOLOR_AQUA"you have killed someone with a killing spree of 15 and earned $20000 and 15 Score");
                }
                case 
20:
                {
                    
GivePlayerMoney(killerid30000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+20);
                    
SendClientMessage(killeridPLAYERCOLOR_AQUA"you have killed someone with a killing spree of 20 and earned $30000 and 20 Score");
                }
                case 
30:
                {
                    
GivePlayerMoney(killerid50000);
                    
SetPlayerScore(killeridGetPlayerScore(killerid)+25);
                    
SendClientMessage(killeridPLAYERCOLOR_AQUA"you have killed someone with a killing spree of 30 and earned $50000 and 25 Score");
                }
            }
            
PlayerInfo[playerid][KillingSpree] = 0;
        }
    }
    return 
1;

Reply
#4

Urgh the code is killing my eyes. I also made a few additional adjustments:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(killerid, playerid, reason);
    GameTextForPlayer(playerid, "~r~Wasted", 2000, 5);
    if(!PlayerInfo[playerid][JoinedEvent])
    {
        PlayerInfo[playerid][Deaths]++;
        if(killerid != INVALID_PLAYER_ID)
        {
            new kname[MAX_PLAYER_NAME], string[144];
            GetPlayerName(killerid, kname, sizeof(kname));
            PlayerInfo[killerid][Kills]++;
            if(PlayerInfo[killerid][World] != DMWorldID && PlayerInfo[killerid][World] != TDMWorldID && PlayerInfo[killerid][World] != FreeroamID)
            {
                PlayerInfo[killerid][MaxDMWarnings]++;
                if(PlayerInfo[killerid][MaxDMWarnings] >= 3)
                {
                    format(string, sizeof(string), "SERVER-KICK: %s (Reason: killing people outside the Deathmatch World) Warning: 3/3", kname);
                    SendClientMessageToAll(BANNEDMESSAGE, string);
                    return Kick(killerid);
                }
                else
                {
                    format(string, sizeof(string), "SERVER-WARN: %s (Reason: killing people outside the Deathmatch World) Warning: %d/3", kname, PlayerInfo[killerid][MaxDMWarnings]);
                    SendClientMessageToAll(BANNEDMESSAGE, string);
                    GameTextForPlayer(killerid, "~r~HEY! You may not kill people outside the DM World!!!", 5000, 5);
                    cmd_kill(killerid, "");
                }
            }
            else
            {
                GivePlayerMoney(killerid, 2500);
                new
                    sc = GetPlayerScore(killerid),
                    bonuscash = 0,
                    bonusscore = 0
                ;
                SetPlayerScore(killerid, sc + 2);
                sc += 2;
                GameTextForPlayer(killerid, "~r~You earned $2500 and 2 Score for killing an opponent", 2000, 5);
                PlayerInfo[killerid][KillingSpree]++;
                switch(PlayerInfo[killerid][KillingSpree])
                {
                    case 3: format(string, sizeof(string), "%s is starting to Own People! He has a Killing Spree of 3 and earned $5000 and 4 Score", kname), bonuscash = 5000, bonusscore = 4;
                    case 6: format(string, sizeof(string), "%s is the Killer!! He has a Killing Spree of 6 and earned $10000 and 8 Score", kname), bonuscash = 10000, bonusscore = 8;
                    case 10: format(string, sizeof(string), "%s is Unstoppable!!! He has a Killing Spree of 10 and earned $15000 and 10 Score", kname), bonuscash = 15000, bonusscore = 10;
                    case 15: format(string, sizeof(string), "%s is the GodKiller!!!! He has a Killing Spree of 15 and earned $20000 and 15 Score", kname), bonuscash = 20000, bonusscore = 15;
                    case 20: format(string, sizeof(string), "%s is the Master!!!!! He has a Killing Spree of 20 and earned $30000 and 20 Score", kname), bonuscash = 30000, bonusscore = 20;
                    case 30: format(string, sizeof(string), "%s is the Ultimate Killer!!!!! He has a Killing Spree of 30 and earned $50000 and 30 Score", kname), bonuscash = 50000, bonusscore = 30;
                }
                if(bonuscash || bonusscore)
                {
                    GivePlayerMoney(killerid, bonuscash);
                    SetPlayerScore(killerid, sc + bonusscore);
                    sc += bonusscore;
                    SendClientMessageToAll(PLAYERCOLOR_AQUA, string);
                    bonuscash = 0, bonusscore = 0;
                }
                switch(PlayerInfo[playerid][KillingSpree])
                {
                    case 0 .. 2: bonuscash = 0, bonusscore = 0;
                    case 3 .. 5: bonuscash = 5000, bonusscore = 4;
                    case 6 .. 9: bonuscash = 10000, bonusscore = 8;
                    case 10 .. 14: bonuscash = 15000, bonusscore = 10;
                    case 15 .. 19: bonuscash = 20000, bonusscore = 15;
                    case 20 .. 29: bonuscash = 30000, bonusscore = 20;
                    default: bonuscash = 50000, bonusscore = 25;
                }
                if(bonuscash || bonusscore)
                {
                    GivePlayerMoney(killerid, bonuscash);
                    SetPlayerScore(killerid, sc + bonusscore);
                    format(string, sizeof(string), "You have killed someone with a killing spree of %d and earned $%d and %d Score", PlayerInfo[playerid][KillingSpree], bonuscash, bonusscore);
                    SendClientMessage(killerid, COLOR_ORANGE, string);
                }
                PlayerInfo[playerid][KillingSpree] = 0;
            }
        }
    }
    else
    {
        new name[MAX_PLAYER_NAME], string[48];
        GetPlayerName(playerid, name, sizeof(name));
        PlayerInfo[playerid][JoinedEvent] = false;
        format(string, sizeof(string), "%s has died in the event", name);
        foreach(new i : Player)
        {
            if(!PlayerInfo[i][AdminLevel]) continue;
            SendClientMessage(i, COLOR_RED, string);
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)