Making a command in car only
#1

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;
  }
Reply
#2

https://sampwiki.blast.hk/wiki/IsPlayerInAnyVehicle
Reply
#3

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;
  }
Reply
#4

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"?
Reply
#5

Код:
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.");
Reply
#6

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

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?
Reply
#8

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

-- I think
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)