Suicide
#1

Why can't I check if a player suicided (fell of a building, burned in fire etc.) with killerid == INVALID_PLAYER_ID ?
I don't know what I'm doing wrong.
Here's my onplayerdeath callback:

PHP код:

public OnPlayerDeath(playeridkilleridreason)
{
    new 
msg[144];
    
    if(
PlayerInfo[playerid][pAdminDuty] == && PlayerInfo[playerid][pDuel] == 0)
    {
        
SetPlayerHealth(playerid100);
        new 
Float:XFloat:YFloat:ZFloat:angle;
        new 
skin;
        
skin GetPlayerSkin(playerid);
        
GetPlayerPos(playeridXYZ);
        
GetPlayerFacingAngle(playeridangle);
        
SetSpawnInfo(playeridADUTYskinXYZangle000000);
        
ClearAnimations(playerid);
    }
    
    if(
reason != 50)
    {
        if(
PlayerInfo[killerid][pDuel] == && PlayerInfo[playerid][pDuel] == 1)
        {
            
SetPlayerHealth(killerid0.0);
            
SetTimerEx("duelend"100false"ii"killeridplayerid);
            
SetPlayerTeam(playeridPlayerInfo[playerid][pLastTeam]);
            
SetPlayerTeam(killeridPlayerInfo[killerid][pLastTeam]);
            
gTeam[playerid] = PlayerInfo[playerid][pLastTeam];
            
gTeam[killerid] = PlayerInfo[killerid][pLastTeam];
            
format(msg,sizeof(msg), "%s has won the duel!"UnderscoreToSpaceName(killerid));
            
SendClientMessage(playeridCOLORNOTIFmsg);
             
SendClientMessage(killeridCOLORNOTIFmsg);
             
PlayerInfo[playerid][pJustDied] = 1;
             
duelcount--;
        }
        else if(
PlayerInfo[playerid][pHunted] == 1)
        {
            if(
killerid == INVALID_PLAYER_ID)
            {
                
format(msg,sizeof(msg),"Rest in peace %s, as he died in a tragic accident."UnderscoreToSpaceName(playerid));
                
SendClientMessageToAll(COLORNOTIFmsg);
                
ForceClassSelection(playerid);
                
PlayerInfo[playerid][pHunted] = 0;
                
huntcount--;
                return 
1;
            }
            
            new 
td[MAX_PLAYER_NAME 16];
             
format(td,sizeof(td),"killed by: %s",UnderscoreToSpaceName(killerid));
            
PlayerTextDrawSetString(playeridkilledby1[playerid], td);
            
PlayerTextDrawShow(playeridkilledby1[playerid]);
            
PlayerTextDrawShow(playeridkilledby2[playerid]);
            
PlayerTextDrawShow(playeridkilledby3[playerid]);
            
            
TextDrawHideForPlayer(playerid,TeamFBI);
            
TextDrawHideForPlayer(playerid,TeamGROVE);
            
TextDrawHideForPlayer(playerid,TeamBALLAS);
            
TextDrawHideForPlayer(playerid,TeamAL);
            
TextDrawHideForPlayer(playerid,TeamVAGOS);
            
TextDrawHideForPlayer(playerid,TeamLSPD);
            
TextDrawHideForPlayer(playerid,FPS[playerid]);
            
TextDrawHideForPlayer(playerid,Ping[playerid]);
            
            if(
killerid != INVALID_PLAYER_IDSetPlayerScore(killeridGetPlayerScore(killerid) + 100);
            
GivePlayerMoney(killerid20000);
            
format(msgsizeof(msg), "%s has killed hunted %s and gained +100 score and $20,000 cash!"UnderscoreToSpaceName(killerid), UnderscoreToSpaceName(playerid));
            
SendClientMessageToAll(COLORNOTIFmsg);
            
ForceClassSelection(playerid);
            
PlayerInfo[playerid][pHunted] = 0;
            
PlayerInfo[playerid][pJustDied] = 1;
            
huntcount--;
        }
        else
        {
            if(
killerid == INVALID_PLAYER_ID) return 0;
            if(
PlayerInfo[killerid][pDuel] == 1) return 0;
            if(
PlayerInfo[playerid][pDuel] == 1) return 0;
            if(
PlayerInfo[playerid][pHunted] == 1) return 0;
            if(
PlayerInfo[killerid][pAdminDuty] == 1) return 0;
            if(
PlayerInfo[playerid][pAdminDuty] == 1) return SpawnPlayer(playerid);
            
TogglePlayerSpectating(playerid1);
             
PlayerSpectatePlayer(playeridkillerid);
             new 
td[MAX_PLAYER_NAME 16];
             
format(td,sizeof(td),"killed by: %s",UnderscoreToSpaceName(killerid));
            
PlayerTextDrawSetString(playeridkilledby1[playerid], td);
            
PlayerTextDrawShow(playeridkilledby1[playerid]);
            
PlayerTextDrawShow(playeridkilledby2[playerid]);
             
PlayerTextDrawShow(playeridkilledby3[playerid]);
            
TextDrawHideForPlayer(playerid,TeamFBI);
            
TextDrawHideForPlayer(playerid,TeamGROVE);
            
TextDrawHideForPlayer(playerid,TeamBALLAS);
            
TextDrawHideForPlayer(playerid,TeamAL);
            
TextDrawHideForPlayer(playerid,TeamVAGOS);
            
TextDrawHideForPlayer(playerid,TeamLSPD);
            
TextDrawHideForPlayer(playerid,FPS[playerid]);
            
TextDrawHideForPlayer(playerid,Ping[playerid]);
            
GameTextForPlayer(playerid"~n~~n~~n~~n~~n~~n~~n~~n~~w~respawning in 5..."15003);
            
PlayerTextDrawShow(playeridrespawning[playerid]);
            
SetTimerEx("respawn1"10000"i"playerid);
             
SetPlayerScore(killeridGetPlayerScore(killerid) + 5);
            
GivePlayerMoney(killerid2500);
            
SendClientMessage(killeridCOLORNOTIF"You have gained +5 score and $2500 for killing an opponent!");
            
SendDeathMessage(killerid,playerid,reason);
            
PlayerState[playerid][pTazer] = 0;
            
PlayerState[playerid][pCuffed] = 0;
            
PlayerState[playerid][pDetained] = 0;
            
PlayerState[playerid][pGettingDragged] = 0;
            
PlayerState[playerid][pDraggedBy] = INVALID_PLAYER_ID;
            
PlayerState[playerid][pTazed] = 0;
            
PlayerInfo[playerid][pJustDied] = 1;
            
PlayerInfo[killerid][pKills]++;
            
PlayerInfo[playerid][pDeaths]++;
            
ServerInfo[Kills]++;
            
ServerInfo[Deaths]++;
            
//ServerInfo[SScore]+=5;
            
if(gTeam[killerid] == FBI) ++Score[FBI];
            if(
gTeam[killerid] == LSPD) ++Score[LSPD];
            if(
gTeam[killerid] == AL) ++Score[AL];
            if(
gTeam[killerid] == GROVE) ++Score[GROVE];
            if(
gTeam[killerid] == VAGOS) ++Score[VAGOS];
            if(
gTeam[killerid] == BALLAS) ++Score[BALLAS];
            
UpdateScore();
        }
    }
    
    if(
reason == 50)
    {
        if(
PlayerInfo[playerid][pAdminDuty] == || PlayerInfo[killerid][pAdminDuty] == 1) return 0;
        
format(msgsizeof(msg), "%s has been jailed for heliblading %s."UnderscoreToSpaceName(killerid), UnderscoreToSpaceName(playerid));
        
SendClientMessageToAll(COLORLIGHTRED,msg);
        
SendClientMessage(killeridCOLORLIGHTRED"You have been jailed for heliblading. Time: 1 hour.");
        
SetPlayerInterior(killeridJAIL_INT);
        
SetPlayerVirtualWorld(killeridJAIL_VW);
        
loadingobj(killerid);
        new 
rand random(sizeof(AdminPrisonFloat));
        
SetPlayerPos(killeridAdminPrisonFloat[rand][0], AdminPrisonFloat[rand][1], AdminPrisonFloat[rand][2]);
        
ResetPlayerWeapons(killerid);
        
GameTextForPlayer(killerid"~w~Welcome to ~n~~r~Admin Prison"50003);
        
PlayerState[killerid][pAdmJail] = 1;
        
PlayerState[killerid][pAdmJailTime] = 3600;
        
SetPlayerColor(killeridCOLORPRISON);
        
SetPlayerSkin(killerid8);
        
SetPlayerFacingAngle(killerid180);
        
SetCameraBehindPlayer(killerid);
    }
    
    if(
GetPlayerWeapon(killerid) == reason)
    {
        new 
IP[16];
        
GetPlayerIp(playeridIPsizeof(IP));
        
SendClientMessage(playeridCOLORRED"You have been automatically banned for fake killing.");
        
format(msg,sizeof(msg),"AdmBan: %s (IP - %s) has been automatically banned for fake killing."UnderscoreToSpaceName(playerid), IP);
        
ABroadcast(COLORLIGHTREDmsg1);
        
SetTimerEx("FakeKillKick"1000"i"playerid);
        
PlayerInfo[playerid][pBanned] = 1;
        
AddBan(IP);
        
Log("logs/bans.txt"msg);
    }
    return 
1;

Reply
#2

Bump
Reply
#3

Probably because you still have out-of-bounds errors. You are not checking if killerid is, in fact, valid before using it as an array index.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Probably because you still have out-of-bounds errors. You are not checking if killerid is, in fact, valid before using it as an array index.
Yeah I sometimes get array index out of bounds in the console, how to fix this?
Reply
#5

Fix:

You have to put if(killerid == INVALID_PLAYER_ID) on the top of the callback, otherwise it won't work.

Otherwise, thanks Vince!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)