Sure, Easy. I'll write the code and explain it:
pawn Код:
CMD:airchat
(playerid, params
[]) // airchat is the name of the command, you can change it to whatever you want.{new text
[126];
// text is a string variableif(sscanf2
(params,
"s", text
)) return SendClientMessage
(playerid, COLOR,
"Usage: /airchat [text]");
// if the player didn't enter the string parameter (text) then you will send him a message showing him how to use the commandif(pInfo
[playerid
][pilot
] == 0 || pInfo
[playerid
][helicopter
] == 0) // Your enum could be different, from mine. I used pInfo though.return SendClientMessage
(playerid, COLOR,
"You need to be a pilot/helicopter to use this radio!");
// If he's not a pilot, then he can't use the radioelse{ // He will now be able to use the radionew pilotname
[MAX_PLAYER_NAME
], pilotrank
[25], msg
[144];
// pilotname is the name of the player using the radio, pilotrank is the rank of the pilot. { According to your rank system }, msg[144] is the mesage that will be sent to all players.format(msg,
sizeof(msg
),
"[RADIO] %s %s : %s", pilotrank, GetPlayerName
(playerid, pilotname,
sizeof(pilotname
)), text
);
SendClientMessageToAir
(COLOR, msg
);
// Send The Message ONLY to Air Units, which we will define.}return 1;
// When returning 1, it prevents the server from sending "Unknown Message"}// Now, we need to define SendClientMessageToAir, which will Send Message ONLY to pilots/Helicopters.forward SendClientMessageToAir
(COLOR, text
[144]);
// Forward the function. Learn more here --> https://sampwiki.blast.hk/wiki/Public_functionspublic SendClientMessageToAir
(COLOR, text
[144]) // Name of the function{new i;
// integer Variable, which will be used as the player IDsfor(i
= 0; i
< MAX_PLAYERS; i
++) // i = 0 at first, begging to check from player ID 0 until the Last player (MAX_PLAYERS){if(IsPlayerConnected
(i
)) // Checks if the player is connected.{if(pInfo
[i
][pilot
] !=0 || pInfo
[i
][helicopter
] != 0) // Checks if the player is an air unit (helicopter or pilot) --> AGAIN! Use your own enum, it could be different from the one I'm using.{SendClientMessage
(i, COLOR, text
);
// Send Every Person who is a pilot this message}}}return 1;
}
Hope that helps! --> Ask me if you have any questions.
+rep if it did