SA-MP Forums Archive
Command unworking - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Command unworking (/showthread.php?tid=642854)



Command unworking - Droxx - 08.10.2017

I got this spectate command not working..when i type it nothing happenes..

Код:
CMD:spec(playerid, params[])
{
	if (pInClass[playerid])
	{
	    return 1;
	}

	if (! IsPlayerAdmin(playerid) && pStats[playerid][userAdmin] < 1)
	{
	    return SendClientMessage(playerid, COLOR_TOMATO, "You must be admin level 1+ to use this command.");
	}

    new targetid;
    if (sscanf(params, "u", targetid))
	{
		return SendClientMessage(playerid, COLOR_THISTLE, "USAGE: /spec [player]");
	}

	if (targetid == playerid)
	{
		return SendClientMessage(playerid, COLOR_TOMATO, "You can't spectate to yourself.");
	}

	if (! IsPlayerConnected(targetid))
	{
		return SendClientMessage(playerid, COLOR_TOMATO, "The specified player is not conected.");
	}

	if (pInClass[targetid] && GetPlayerState(targetid) == PLAYER_STATE_SPECTATING)
	{
		return SendClientMessage(playerid, COLOR_TOMATO, "The specified player is not spawned.");
	}

	PlayerSpectatePlayer(playerid, targetid);

	new buf[150];
	format(buf, sizeof(buf), "You are now spectating %s(%i).", ReturnPlayerName(targetid), targetid);
	SendClientMessage(playerid, COLOR_DODGER_BLUE, buf);
	SendClientMessage(playerid, COLOR_DODGER_BLUE, "You can type /specoff when you wish to stop spectating.");
    return 1;
}



Re: Command unworking - Kane - 08.10.2017

You need to TogglePlayerSpectating before PlayerSpecPlayer.


Re: Command unworking - Droxx - 08.10.2017

Like this??
Код:
CMD:spec(playerid, params[])
{
	if (pInClass[playerid])
	{
	    return 1;
	}

	if (! IsPlayerAdmin(playerid) && pStats[playerid][userAdmin] < 1)
	{
	    return SendClientMessage(playerid, COLOR_TOMATO, "You must be admin level 1+ to use this command.");
	}

    new targetid;
    if (sscanf(params, "u", targetid))
	{
		return SendClientMessage(playerid, COLOR_THISTLE, "USAGE: /spec [player]");
	}

	if (targetid == playerid)
	{
		return SendClientMessage(playerid, COLOR_TOMATO, "You can't spectate to yourself.");
	}

	if (! IsPlayerConnected(targetid))
	{
		return SendClientMessage(playerid, COLOR_TOMATO, "The specified player is not conected.");
	}

	if (pInClass[targetid] && GetPlayerState(targetid) == PLAYER_STATE_SPECTATING)
	{
		return SendClientMessage(playerid, COLOR_TOMATO, "The specified player is not spawned.");
	}
	
    TogglePlayerSpectating(playerid, true);
	PlayerSpectatePlayer(playerid, targetid);

	new buf[150];
	format(buf, sizeof(buf), "You are now spectating %s(%i).", ReturnPlayerName(targetid), targetid);
	SendClientMessage(playerid, COLOR_DODGER_BLUE, buf);
	SendClientMessage(playerid, COLOR_DODGER_BLUE, "You can type /specoff when you wish to stop spectating.");
    return 1;
}
EDIT:
Fixed thank you.