SA-MP Forums Archive
Crashdetecter detects a error on PlayerDeath - 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: Crashdetecter detects a error on PlayerDeath (/showthread.php?tid=626113)



Crashdetecter detects a error on PlayerDeath - ThatFag - 10.01.2017

hello there, i was randomly checking my server logos and i found this error but i couldnt figure out whats wrong with it so im asking for your help.


Error.
Код HTML:
[13:43:14] [debug] Run time error 4: "Array index out of bounds"
[13:43:14] [debug]  Attempted to read/write array element at index 65535 in array of size 50
[13:43:14] [debug] AMX backtrace:
[13:43:14] [debug] #0 0006a944 in public OnPlayerDeath (playerid=2, killerid=65535, reason=255) at ./assets/no.pwn:9902
[13:43:14] [death] Eazy_Compton died 255
Line 9902
Код HTML:
if(PlayerTemp[killerid][isevent])
whole script
Код HTML:
if(PlayerTemp[killerid][isevent])
		{
		    PlayerLoop(i)
		    {
		        if(!PlayerTemp[i][isevent]) continue;
		       SendClientMSG(i, COLOR_YELLOW, "..: [EVENT]: %s has killed %s with a %s (Distance: %dm):..", RPName(killerid), RPName(playerid), aWeaponNames[reason], GetDistanceBetweenPlayers(playerid, killerid));
                OnPlayerKillSpree(killerid);
		    }
		    if(PlayerTemp[killerid][isevent] == 5)
		    {
				shipkills[killerid] += 1;
			}
			PlayerTemp[playerid][isevent] = 0;
			return 1;
		}



Re: Crashdetecter detects a error on PlayerDeath - jlalt - 10.01.2017

65535 is invalid player id value so simple do below checks to avoid crash
PHP код:
if(killerid MAX_PLAYERS && IsPlayerConnected(killerid)) 
so it will be:

PHP код:
if(killerid MAX_PLAYERS && IsPlayerConnected(killerid) && PlayerTemp[killerid][isevent])
        {
            
PlayerLoop(i)
            {
                if(!
PlayerTemp[i][isevent]) continue;
               
SendClientMSG(iCOLOR_YELLOW"..: [EVENT]: %s has killed %s with a %s (Distance: %dm):.."RPName(killerid), RPName(playerid), aWeaponNames[reason], GetDistanceBetweenPlayers(playeridkillerid));
                
OnPlayerKillSpree(killerid);
            }
            if(
PlayerTemp[killerid][isevent] == 5)
            {
                
shipkills[killerid] += 1;
            }
            
PlayerTemp[playerid][isevent] = 0;
            return 
1;
        } 



Re: Crashdetecter detects a error on PlayerDeath - justinnater - 10.01.2017

Change it to
if(PlayerTemp[killerid][isevent] && IsPlayerConnected(killerid))

If the person dies by another reason than another person, the killerid will return a non valid value like that.


Re: Crashdetecter detects a error on PlayerDeath - jlalt - 10.01.2017

Quote:
Originally Posted by justinnater
Посмотреть сообщение
Change it to
if(PlayerTemp[killerid][isevent] && IsPlayerConnected(killerid))

If the person dies by another reason than another person, the killerid will return a non valid value like that.
you're checking if player is connected after checking if he is in event, so there won't be any effect at all.
right code would be:
PHP код:
if(IsPlayerConnected(killerid) && PlayerTemp[killerid][isevent]) 



Re: Crashdetecter detects a error on PlayerDeath - ThatFag - 10.01.2017

Thanks to you both , ill check it repped +