[COMMAND] /spec
#1

Код:
CMD:spec(playerid, params[])
{
	new giveplayerid, Float:x, Float:y, Float:z;
	if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
	if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, -1, "USAGE: /spec [playerid/partofname/off]");
	if(strcmp(params, "off", true) == 0)
	{
		SetPVarInt(playerid, "SpecOff", 1);
		TogglePlayerSpectating(playerid, false);
		SetCameraBehindPlayer(playerid);
		SetPlayerPos(playerid, x, y, z);
		spec[playerid] = -1;
		return 1;
	}
	if(!IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player specified.");
	if(IsPlayerInAnyVehicle(giveplayerid))
	{
		GetPlayerPos(playerid, x, y, z);
		TogglePlayerSpectating(playerid, true);
		new carid = GetPlayerVehicleID(giveplayerid);
		PlayerSpectateVehicle(playerid, carid);
		SetPlayerInterior(playerid, GetPlayerInterior(giveplayerid));
		SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(giveplayerid));
		spec[playerid] = giveplayerid;
	}
		else
	{
	    GetPlayerPos(playerid, x, y, z);
		TogglePlayerSpectating(playerid, true);
		PlayerSpectatePlayer(playerid, giveplayerid);
		SetPlayerInterior(playerid, GetPlayerInterior(giveplayerid));
		SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(giveplayerid));
		spec[playerid] = giveplayerid;
	}
	return 1;
}
/spec off telerports the executer to blueberry for some odd reason... No compiling errors...
Reply
#2

Yeah, you have to save the old position of playerid in a global variable. If you type '/spec off', it'll re-create giveplayerid, x, y, z. So x, y, and z will be 0 and that's why you spawn in Blueberry.
Reply
#3

Quote:
Originally Posted by MartinSwag
Посмотреть сообщение
Yeah, you have to save the old position of playerid in a global variable. If you type '/spec off', it'll re-create giveplayerid, x, y, z. So x, y, and z will be 0 and that's why you spawn in Blueberry.
Thats what this is xD

Код:
    GetPlayerPos(playerid, x, y, z);
		TogglePlayerSpectating(playerid, true);
		PlayerSpectatePlayer(playerid, giveplayerid);
		SetPlayerInterior(playerid, GetPlayerInterior(giveplayerid));
		SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(giveplayerid));
		spec[playerid] = giveplayerid;
Reply
#4

Quote:
Originally Posted by BarFix
Посмотреть сообщение
Thats what this is xD

Код:
    GetPlayerPos(playerid, x, y, z);
		TogglePlayerSpectating(playerid, true);
		PlayerSpectatePlayer(playerid, giveplayerid);
		SetPlayerInterior(playerid, GetPlayerInterior(giveplayerid));
		SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(giveplayerid));
		spec[playerid] = giveplayerid;
Well, x, y and z are local variables which don't exist outside of the command.
Код:
CMD:spec(playerid, params[])
{
	new giveplayerid, Float:x, Float:y, Float:z;
Create some global variables at the top of your script:
Код:
new Float:specPos[MAX_PLAYERS][3], specInt[MAX_PLAYERS], specVW[MAX_PLAYERS];

//Old position, int and vw of the admin.
GetPlayerPos(playerid, SpecPos[playerid][0], SpecPos[playerid][1], SpecPos[playerid][2]);
specInt[playerid] = GetPlayerInterior(playerid);
specVW[playerid] = GetPlayerVirtualWorld(playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)