whats this?
#1

pawn Код:
public OnPlayerDeath(playerid,killerid,reason)
{
    pInfo[playerid][Deaths] ++;
    pInfo[killerid][Kills] ++;
    if(IsBeingSpeced[playerid] == 1)
    {
        foreach(Player,i)
        {
            if(spectatorid[i] == playerid)
            {
                TogglePlayerSpectating(i,false);
            }
        }
    }
    return 1;
}
can somebody tell me what is this ?

pawn Код:
public OnPlayerDeath(playerid,killerid,reason)
{
    if(IsBeingSpeced[playerid] == 1)
    {
        foreach(Player,i)
        {
            if(spectatorid[i] == playerid)
            {
                TogglePlayerSpectating(i,false);
            }
        }
    }
    return 1;
}
Reply
#2

When a player dies, if people are spectating the player who died then it will disable the spectating mode and the spectators will respawn. However, there are few mistakes with both of them.

pawn Код:
pInfo[killerid][Kills] ++;
If a killer is not valid - that means a player died by nobody (falling, explosion etc.) then it will pass INVALID_PLAYER_ID and that will cause index out of bounds (runtime error). It will stop whatever code you have or it will crash the server. You need to check first if the killer is valid player.

pawn Код:
if(killerid != INVALID_PLAYER_ID) pInfo[killerid][Kills] ++;
Also those who spectate the player who died since it will respawn them and take them off the spectating mode - you need to reset the variables (they will spectate none).
pawn Код:
spectatorid[i] = INVALID_PLAYER_ID;
TogglePlayerSpectating(i,false);
And since nobody will spectate the player who died, the player is simply not being spectated so you'll need to reset it as well.
pawn Код:
// at the end
IsBeingSpeced[playerid] = 0;
There are ways to make the code much better; for example, if IsBeingSpeced uses only 0,1 then it can be a boolean (false/true) and using char makes it even better. Anyways, these are not important for now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)