Stop spectating crashes server
#1

For some reason, sometimes, not always, if someone types /stopspec it will crash the server.

pawn Код:
COMMAND:spectate(playerid, params[])
{
    if(GetPVarInt(playerid, "Admin") > 0 || GetPVarInt(playerid, "Helper") == 1)
    {
        new targetid, string[128];
        if(sscanf(params, "u", targetid)) SendUsage(playerid, "USAGE: /spectate [targetid]");
        else
        {
            if(IsPlayerConnected(targetid))
            {
                if(GetPVarInt(playerid, "Spectating") == 0)
                {
                    SetPVarInt(playerid, "SWorld", GetPlayerVirtualWorld(playerid));
                    SetPVarInt(playerid, "SInt", GetPlayerInterior(playerid));
                    new Float:x, Float:y, Float:z;
                    GetPlayerPos(playerid, x, y, z);
                    SetPVarFloat(playerid, "SX", x); SetPVarFloat(playerid, "SY", y); SetPVarFloat(playerid, "SZ", z);
                }
                SpawnPlayer(playeird);
                TogglePlayerSpectating(playerid, 1);
                SetPlayerInterior(playerid, GetPlayerInterior(targetid));
                SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(targetid));
                if(IsPlayerInAnyVehicle(targetid)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(targetid));
                else PlayerSpectatePlayer(playerid, targetid);
                SendClientMessage(playerid, COLOR_WHITE, "Type '/stopspec' to stop spectating.");
                format(string, 128, "ADMIN: %s(%d) is spectating %s(%d)", PlayerName(playerid), playerid, PlayerName(targetid), targetid);
                SendAdminMessage(string);
                SetPVarInt(playerid, "Spectating", 1);
            }
            else
            {
                SendClientMessage(playerid, COLOR_WHITE, "ERROR: That player is not connected.");
            }
        }
    }
    else SendErrorMessage(playerid);
    return 1;
}
ALTCOMMAND:spec->spectate;

COMMAND:stopspec(playerid, params[])
{
    if(GetPVarInt(playerid, "Admin") > 0 || GetPVarInt(playerid, "Helper") == 1)// && GetPVarInt(playerid, "AdminLogged"))
    {
        if(GetPVarInt(playerid, "Spectating") == 1)
        {
            TogglePlayerSpectating(playerid, 0);
        }
    }
    else SendErrorMessage(playerid);
    return 1;
}
Under OnPlayerSpawn
pawn Код:
if(GetPVarInt(playerid, "Spectating") == 1)
    {
        DeletePVar(playerid, "Spectating");
        SetPlayerVirtualWorld(playerid, GetPVarInt(playerid, "SWorld"));
        SetPlayerInterior(playerid, GetPVarInt(playerid, "SInt"));
        SetPlayerPosEx(playerid, GetPVarFloat(playerid, "SX"), GetPVarFloat(playerid, "SY"), GetPVarFloat(playerid, "SZ"));
    }
What could be going wrong that is making my server freeze/crash?
Reply
#2

Код:
 else SendErrorMessage(playerid);
Maybe try

Код:
 else return SendErrorMessage(playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)