SA-MP Forums Archive
Making a command in car only - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Making a command in car only (/showthread.php?tid=126668)



Making a command in car only - jesuschristlordandsavior - 09.02.2010

Ok so for my trucking server I am making a CB radio command. I got it working but I would like to know how to make it so you can only use/hear it in a vehicle.

Command code:
Код:
	if(!strcmp(cmdtext, "/cb", true, 3))
  {
    if(!cmdtext[3])return SendClientMessage(playerid, 0xFF9900AA, "USAGE: /cb [Text]");
    new str[128];
    GetPlayerName(playerid, str, sizeof(str));
    format(str, sizeof(str), "*(CB Radio)%s: %s", str, cmdtext[4]);
    SendClientMessageToAll(0x9ACD32AA, str);
    return 1;
  }



Re: Making a command in car only - Correlli - 09.02.2010

https://sampwiki.blast.hk/wiki/IsPlayerInAnyVehicle


Re: Making a command in car only - akis_tze - 09.02.2010

now this cmd can be used only in vehicle
Код:
if(!strcmp(cmdtext, "/cb", true, 3))
  {
  	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || (GetPlayerState(playerid) == PLAYER_STATE_PASSENGER))
  	{
		    if(!cmdtext[3])return SendClientMessage(playerid, 0xFF9900AA, "USAGE: /cb [Text]");
		    new str[128];
		    GetPlayerName(playerid, str, sizeof(str));
		    format(str, sizeof(str), "*(CB Radio)%s: %s", str, cmdtext[4]);
		    SendClientMessageToAll(0x9ACD32AA, str);
	  }
    return 1;
  }



Re: Making a command in car only - jesuschristlordandsavior - 09.02.2010

Quote:
Originally Posted by KotZ
now this cmd can be used only in vehicle
Код:
if(!strcmp(cmdtext, "/cb", true, 3))
  {
  	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || (GetPlayerState(playerid) == PLAYER_STATE_PASSENGER))
  	{
		    if(!cmdtext[3])return SendClientMessage(playerid, 0xFF9900AA, "USAGE: /cb [Text]");
		    new str[128];
		    GetPlayerName(playerid, str, sizeof(str));
		    format(str, sizeof(str), "*(CB Radio)%s: %s", str, cmdtext[4]);
		    SendClientMessageToAll(0x9ACD32AA, str);
	  }
    return 1;
  }
Ah that worked perfect! Where in that code would I make it so if someone isn't in the car it says "You must be in a Vehicle to use this command"?


Re: Making a command in car only - ray187 - 09.02.2010

Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || (GetPlayerState(playerid) == PLAYER_STATE_PASSENGER))
  	{
		    if(!cmdtext[3])return SendClientMessage(playerid, 0xFF9900AA, "USAGE: /cb [Text]");
		    new str[128];
		    GetPlayerName(playerid, str, sizeof(str));
		    format(str, sizeof(str), "*(CB Radio)%s: %s", str, cmdtext[4]);
		    SendClientMessageToAll(0x9ACD32AA, str);
	  } else 
		    SendClientMessage(playerid, 0x9ACD32AA,"This command can only be used inside a vehicle.");



Re: Making a command in car only - Correlli - 09.02.2010

pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
  // player is in any vehicle, execute the other code..
}
else
{
  // player is not in any vehicle, send him the message.
}



Re: Making a command in car only - jesuschristlordandsavior - 09.02.2010

Thank you all

But I have one last problem. People who are not in cars can still see the CB text although they can not use the command. How would I fix that?


Re: Making a command in car only - IcyBlight - 09.02.2010

I think you should do a MAX_PLAYERS loop to check who's in a vehicle and do SendClientMessage(i, COLOR, "text");

-- I think