Scripting Help
#1

Hi, When I type /spectate .. I want it to save player position and then If I type /specoff and it will set the player's position to the saved position.Can someone help me to do it? I don't know how to.Please Help . Here's my spectate and specoff codes :





Код:
dcmd_spectate(playerid,params[])
{
	new string[128];
	new ID;
	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;
	}
	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);

	IsBeingSpectated[SpectatingPlayer[playerid]] =0;
	SpectatingPlayer[playerid] =-1;
	return 1;
}
Reply
#2

use

pawn Код:
new Float:x , Float:y, Float:z;

dcmd_spectate(playerid,params[])
{
    new string[128];
    new ID;
    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;
    }
    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;
        GetPlayerPos(playerid, x, y, z);
    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);

    IsBeingSpectated[SpectatingPlayer[playerid]] =0;
    SpectatingPlayer[playerid] =-1;
        SetPlayerPos(playerid, x,  y, z);
    return 1;
}
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)