Scripting Help
#3

The code above will work aslong as you are the only player able to spectate people. Else use my code.
pawn Код:
enum Oldpos
{
Float:PosX,
Float:PosY,
Float:PosZ,
Int,
VW
}
new OldPos[MAX_PLAYERS][Oldpos];

dcmd_spectate(playerid,params[])
{
    new string[128], ID, Float:X, Float:Y, Float:Z;
    if(sscanf(params,"u",ID))
    {
        SendClientMessage(playerid,COLOR_ERROR,"USAGE: /spectate (Player Name/ID)");
        return 1;
    }
    if(!IsPlayerConnected(ID))
    {
        format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot spectate them.",ID);
        SendClientMessage(playerid,COLOR_ERROR,string);
        return 1;
    }
    if(IsSpawned[playerid] != 1)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You must be alive and spawned in order to be able to use this command.");
        return 1;
    }
    if(playerid == ID)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You cannot spectate yourself, how could that even be possible?");
        return 1;
    }
    if(IsSpawned[ID] != 1)
    {
        format(string,sizeof(string),"%s(%d) is not spawned. You cannot place spectate dead people ..",PlayerName(ID),ID);
        SendClientMessage(playerid,COLOR_ERROR,string);
        return 1;
    }
    GetPlayerPos(playerid, X, Y, Z);
    OldPos[playerid][PosX] = X;
    OldPos[playerid][PosY] = Y;
    OldPos[playerid][PosZ] = Z;
    OldPos[playerid][Int] = GetPlayerInterior(playerid);
    OldPos[playerid][VW] = GetPlayerVirtualWorld(playerid);
    if(IsPlayerInAnyVehicle(ID))
    {
        new vehid = GetPlayerVehicleID(ID);
        TogglePlayerSpectating(playerid, 1);
        PlayerSpectateVehicle(playerid, vehid);
        SetPlayerInterior(playerid,GetPlayerInterior(ID));
        SpectatingPlayer[playerid] =ID;
        IsBeingSpectated[ID] =1;
        return 1;
    }
    TogglePlayerSpectating(playerid, 1);
    PlayerSpectatePlayer(playerid, ID);
    SetPlayerInterior(playerid,GetPlayerInterior(ID));
    SpectatingPlayer[playerid] =ID;
    IsBeingSpectated[ID] =1;
    return 1;
}

dcmd_specoff(playerid,params[])
{
    #pragma unused params
    if(SpectatingPlayer[playerid] == -1)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You are not spectating a player. How can you spectating them?");
        return 1;
    }
    TogglePlayerSpectating(playerid,0);
    SetPlayerPos(playerid, OldPos[playerid][PosX], OldPos[playerid][PosY], OldPos[playerid][PosZ]);
    SetPlayerInterior(playerid, OldPos[playerid][Int]);
    SetPlayerVirtualWorld(playerid, OldPos[playerid][VW]);
    IsBeingSpectated[SpectatingPlayer[playerid]] =0;
    SpectatingPlayer[playerid] =-1;
    return 1;
}
This will do it for sure even tough I haven't tested the code ( Because I don't have the DCMD includes ) but I know it will work and do the thing you asked.

Best regards,
Jesse
Reply


Messages In This Thread
Scripting Help - by Michael_Cruise - 14.06.2012, 05:46
Respuesta: Scripting Help - by Chris1337 - 14.06.2012, 05:56
Re: Scripting Help - by jessejanssen - 14.06.2012, 06:02

Forum Jump:


Users browsing this thread: 1 Guest(s)