Text only in vehicle?
#1

How can I make if players are talking/writing in vehicle only driver and every passenger in that vehicle will receive message?
Reply
#2

I looked over this and it should work fine, credits to Shidony
pawn Код:
if(strcmp(cmd,"/cw",true)==0)
    {
    if(IsSpawned[playerid] == 0) {
    SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
    return 1;
    }
    if(!IsPlayerInAnyVehicle(playerid)) {
    SendClientMessage(playerid, COLOR_ERROR, "You not in any vehicle. You cannot use this command");
    return 1;
    }
   
    if(strlen(cmdtext) <= 4) {
    SendClientMessage(playerid,COLOR_ERROR,"USAGE: /cw (msg)");
    return 1;
    }
    new cwhisperid = GetPlayerVehicleID(playerid);
    new output[150];
    new pname[24];
    GetPlayerName(playerid, pname, 24);
    strmid(output,cmdtext,3,strlen(cmdtext));
    format(string, sizeof(string), "(CAR WHISPER): %s(%d) %s",pname,playerid,output);
    printf("%s", string);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(IsPlayerInAnyVehicle(i))
    {
    if(GetPlayerVehicleID(i) == cwhisperid)
    {
    format(string, sizeof(string), "(CAR WHISPER): %s(%d) %s",pname,playerid,output);
    SendClientMessage(i,COLOR_YELLOW,string);
    }
    }
    }
    return 1;
    }
Reply
#3

This helped me unintentionally I am new to using format (im a noob) and just realized I could make simple chat channels with it :O
Reply
#4

Okay but I'm working with OnPlayerText and vehicle windows (open/close) if windows are open we can see text if windows are closed - this supposed to be for vehicle message only (passengers and driver) but I can see my text and from a guy that is writing, but passengers can't see my text neither their own text, here is the code what I've made:

pawn Код:
public OnPlayerText(playerid, text[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name, sizeof(Name));
    new string[256];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInVehicle(i, vehicleid))
            {
                if(Carinfo[vehicleid][VehWin] == 0) // closed
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
                    {
                        format(string, sizeof(string), "Driver %s: %s",Name,text);
                        SendClientMessage(i,-1,string);
                        return 0;
                    }
                    else
                    {
                        format(string, sizeof(string), "Passenger %s: %s",Name,text);
                        SendClientMessage(i,-1,string);
                        return 0;
                    }
                }
                if(Carinfo[vehicleid][VehWin] == 1) // opened
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
                    {
                        format(string, sizeof(string), "Driver %s: %s",Name,text);
                        ProxDetector(8.0, playerid, string, COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE); // Radius need to be checked..
                        return 0;
                    }
                    else
                    {
                        format(string, sizeof(string), "Passenger %s: %s",Name,text);
                        ProxDetector(8.0, playerid, string, COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE); // Radius need to be checked..
                        return 0;
                    }
                }
            }
        }
    }
    return 1;
}
So I want to make if windows are closed and players are talking inside of the car, only they will see text.. how to fix that?

Thanks for help in advance!
Reply
#5

Still didn't solved this, anyone please?
Reply
#6

Use the search button next time, Jesus. I posted this literally 30 minutes ago.

Source:
http://forum.sa-mp.com/showthread.ph...58#post2923858

Quote:
Originally Posted by Mionee
https://sampforum.blast.hk/showthread.php?tid=79709

Something like this (using zcmd and sscanf):

pawn Код:
CMD:carmsg(playerid, params[])
{
    new string[128], text[100];
       
    if(sscanf(params, "s[100]", text)) return SendClientMessage(playerid, -1, "USAGE: /carmsg [text]");

    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInVehicle(i, GetPlayerVehicleID(playerid)))
            {
                format(string, sizeof(string), "[%s]: %s", GetPlayerName(playerid, string, sizeof(string)), text);
                SendClientMessage(i, -1, string);
                return 1;
            }
        }
    }
    return 1;
}
Reply
#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
#8

I'll just make it simple for you.

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new str[150], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name)), car = GetPlayerVehicleID(playerid);
        format(str, sizeof(str), "%s(%d) [CAR]: %s", name, playerid, text);
        for(new i = 0; i < MAX_PLAYERS; i++) //Foreach recommended.
        {
            if(!IsPlayerConnected(i)) continue;
            if(!IsPlayerInVehicle(i, car)) continue;
            SendClientMessage(i, 0xFFFF00FF, str);
        }
    }
    else //They aren't in a car...
    {
        //Rest of code...
    }
    return 0;
}
Reply
#9

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
I'll just make it simple for you.

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new str[150], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name)), car = GetPlayerVehicleID(playerid);
        format(str, sizeof(str), "%s(%d) [CAR]: %s", name, playerid, text);
        for(new i = 0; i < MAX_PLAYERS; i++) //Foreach recommended.
        {
            if(!IsPlayerConnected(i)) continue;
            if(!IsPlayerInVehicle(i, car)) continue;
            SendClientMessage(i, 0xFFFF00FF, str);
        }
    }
    else //They aren't in a car...
    {
        //Rest of code...
    }
    return 0;
}
Sorry for late response but this one isn't working I mean I can't see chat when I'm not in car and I'm writing..
Reply
#10

Then you haven't anything to the 'else' statement.
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new str[150], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name)), car = GetPlayerVehicleID(playerid);
        format(str, sizeof(str), "%s(%d) [CAR]: %s", name, playerid, text);
        for(new i = 0; i < MAX_PLAYERS; i++) //Foreach recommended.
        {
            if(!IsPlayerConnected(i)) continue;
            if(!IsPlayerInVehicle(i, car)) continue;
            SendClientMessage(i, 0xFFFF00FF, str);
        }
    }
    else return 1;
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)