Step 1: Check if player in vehicle and store the vehicleid.
Step 2: A player-loop. Step 3: Check if the value of the loop is in the same vehicle: IsPlayerInVehicle or if GetPlayerVehicleID matches. Step 4: If they are, send the message. |
// check if player is not in vehicle and return an error..
// format the text you're going to send to passengers/driver of vehicle
new vehicleid = GetPlayerVehicleID(playerid);
for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if (IsPlayerInVehicle(i, vehicleid))
{
SendClientMessage(i, color_here, message_here);
}
}
CMD:r(playerid, params[])
{
new
string[144];
format(string, sizeof(string), "%s: %s", GetPlayerName(playerid), params);
SendPlayerMessage(playerid, 20.0, string, 0xAFAFAFAA, 0xAFAFAFAA, 0xAFAFAFAA, 0xAFAFAFAA, 0xAFAFAFAA);
return 1;
}
SendPlayerMessage(playerid, Float:radius, const text[], color1, color2, color3, color4, color5)
{
foreach(new i : Player)
{
if(IsPlayerInAnyVehicle(i))
{
if(IsNearPlayer(i, playerid, radius / 16))
{
SendClientMessage(i, color1, text);
}
else if(IsNearPlayer(i, playerid, radius / 8))
{
SendClientMessage(i, color2, text);
}
else if(IsNearPlayer(i, playerid, radius / 4))
{
SendClientMessage(i, color3, text);
}
else if(IsNearPlayer(i, playerid, radius / 2))
{
SendClientMessage(i, color4, text);
}
else if(IsNearPlayer(i, playerid, radius))
{
SendClientMessage(i, color5, text);
}
}
}
}
IsNearPlayer(playerid, targetid, Float:radius)
{
new
Float:x,
Float:y,
Float:z;
GetPlayerPos(targetid, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, radius, x, y, z) && GetPlayerInterior(playerid) == GetPlayerInterior(targetid) && GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(targetid))
{
return 1;
}
return 0;
}