SA-MP Forums Archive
Cmd for 1 Player. - 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: Cmd for 1 Player. (/showthread.php?tid=625353)



Cmd for 1 Player. - aymane123 - 31.12.2016

How to make a command that only 1 player can use it like a roof top only 1 guy can use it ??


Re: Cmd for 1 Player. - SoLetsGO - 31.12.2016

There are several ways to do it. You can either create a player variable for each player which holds the values true or false. So if the value is true for the player then he can use it. A less elegant but at this point faster way to do it is if you just compare the playernames. For example if you are the server owner and you are the only one who can use it and your name is aymane123 then you can do something like that:

PHP код:
COMMAND:yourcommand(playerid,params[]){
   new 
name[MAX_PLAYER_NAME];
   
GetPlayerName(playerid,name,sizeof(name));
   if(
strcmp(name,"aymane123"))return 0;
   
//Your command
   
return 1;




Re: Cmd for 1 Player. - ISmokezU - 31.12.2016

You could also use it for a specific ID

Код:
CMD:test(0,params[]) {//Only ID: 0 could use it.
Edit: ^^


Re: Cmd for 1 Player. - aymane123 - 31.12.2016

tthx guys.


Re: Cmd for 1 Player. - aymane123 - 31.12.2016

any help got this ?
Код:
CMD:gopen( playerid, params[] )
{
   new name[MAX_PLAYER_NAME];
   GetPlayerName(playerid,name,sizeof(name));
   if(strcmp(name,"aymane123"))return 0;
   
	if( isnull( params ) )
	    return SendClientMessage( playerid, -1, "Syntax: /gopen [password]" );
	    
	new szName[24], gate = -1;
	GetPlayerName( playerid, szName, 24 );
	for( new i = 0; i != MAX_GATES; i++ )
		if( GateInfo[i][gCreated] == 1 )
			if( strval( params ) == GateInfo[i][gPassword] )
				{ gate = i; break; }

	if( gate != -1 )
	{
	    if( !IsObjectMoving( GateInfo[gate][gObject] ) )
	    {
	    	if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
			{
   				if( GateInfo[gate][gStatus] == GATE_STATE_CLOSED )
	        	{
				    MoveObject( GateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]-5.3, 7.0 );
					SendClientMessage( playerid, -1, "You opened the gate." );
				}

				else
	    			return SendClientMessage( playerid, -1, "The gate is already open." );
			}

			else
    			return SendClientMessage( playerid, -1, "You're not near any gate." );
        }

       	else
	    	return SendClientMessage( playerid, -1, "You must wait untill the gate has moved." );
	}

	else
	    return SendClientMessage( playerid, -1, "Invalid password." );

	return 1;
}



Re: Cmd for 1 Player. - ISmokezU - 31.12.2016

Errors? does it works? Say Something...


Re: Cmd for 1 Player. - RedRex - 31.12.2016

To make Command Follow this Steps:

1- #include <zcmd>
Код:
2- CMD:teleport(playerid, params[])
{
  SetPlayerPos(playerid, x,y,z)
  SendClientMessage(playerid, -1, "YOU HAVE BEEN TELEPORTER");
  return 1;
}
Hope you understand <3


Re: Cmd for 1 Player. - aymane123 - 31.12.2016

i am not talking about that its too easy and that code when i run it as a FS it compiles with warning and on the server doesnt have any effect.


Re: Cmd for 1 Player. - ISmokezU - 31.12.2016

Quote:
Originally Posted by RedRex
Посмотреть сообщение
To make Command Follow this Steps:

1- #include <zcmd>
Код:
2- CMD:teleport(playerid, params[])
{
  SetPlayerPos(playerid, x,y,z)
  SendClientMessage(playerid, -1, "YOU HAVE BEEN TELEPORTER");
  return 1;
}
Hope you understand <3
Get off the post. he already knows how to make a command

Quote:
Originally Posted by aymane123
Посмотреть сообщение
i am not talking about that its too easy and that code when i run it as a FS it compiles with warning and on the server doesnt have any effect.
I don't really understand what you're saying,it complies with no errors/warnings but it doesn't work ingame right?


Re: Cmd for 1 Player. - SoLetsGO - 31.12.2016

Quote:
Originally Posted by aymane123
Посмотреть сообщение
i am not talking about that its too easy and that code when i run it as a FS it compiles with warning and on the server doesnt have any effect.
Which warning do you have?
Loose Indentation?
If so, you have to get the tabulators right.