Text only in vehicle?
#7

Your code is also wrong, Mionee!

pawn Код:
CMD:carmsg(playerid, params[])
{
    new string[128], text[100];
       
    if(sscanf(params, "s[100]", text)) return SendClientMessage(playerid, -1, "USAGE: /carmsg [text]"); // first of all, you don't need to use sscanf here

    for(new i = 0; i < MAX_PLAYERS; i ++) // secondly, you shouldn't use a for() loop here; you should encourage other people to use foreach (or y_iterate, same thing)
    {
        if(IsPlayerConnected(i)) // not needed if you use foreach
        {
            if(IsPlayerInVehicle(i, GetPlayerVehicleID(playerid))) // this is wrong, too; don't use GetPlayerVehicleID(playerid) more than once if you don't have to!
            {
                format(string, sizeof(string), "[%s]: %s", GetPlayerName(playerid, string, sizeof(string)), text);
                SendClientMessage(i, -1, string);
                return 1; // this ends the loop, so only one player is going to get the message
            }
        }
    }
    return 1;
}

// correct code:

CMD:carmsg(playerid, params[])
{
    new
        szName[MAX_PLAYER_NAME],
        szString[128],
        vehicleID = GetPlayerVehicleID(playerid);
   
    if(isnull(params)) return SendClientMessage(playerid, -1, "SYNTAX: /carmsg [text]");
    if(vehicleID == 0) return SendClientMessage(playerid, -1, "You aren't in a vehicle, bruh!");
   
    GetPlayerName(playerid, szName, sizeof(szName));
    format(szString, sizeof(szString), "[%s]: %s", szName, params);
   
    foreach(new i : Player)
    {
        if(IsPlayerInVehicle(i, vehicleID)) SendClientMessage(i, -1, szString);
    }
    return 1;
}
@OP: Port the code to use it with OnPlayerText; you won't learn if we do it for you!
Reply


Messages In This Thread
Text only in vehicle? - by Lajko1 - 20.02.2014, 21:48
Re: Text only in vehicle? - by Flake. - 21.02.2014, 00:50
Re: Text only in vehicle? - by Aerotactics - 21.02.2014, 06:18
Re: Text only in vehicle? - by Lajko1 - 21.02.2014, 17:15
Re: Text only in vehicle? - by Lajko1 - 21.02.2014, 21:34
Re: Text only in vehicle? - by Dignity - 21.02.2014, 21:50
Re: Text only in vehicle? - by Scenario - 21.02.2014, 22:20
Re: Text only in vehicle? - by Threshold - 21.02.2014, 23:49
Re: Text only in vehicle? - by Lajko1 - 27.02.2014, 14:25
Re: Text only in vehicle? - by Threshold - 27.02.2014, 22:04

Forum Jump:


Users browsing this thread: 5 Guest(s)