Crashdetecter detects a error on PlayerDeath
#1

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;
		}
Reply
#2

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;
        } 
Reply
#3

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.
Reply
#4

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]) 
Reply
#5

Thanks to you both , ill check it repped +
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)