[Solved]Whats wrong with my pilot chat?
#1

Please tell me whats wrong with my script, when i type /pit says Usage: /p (Text).
And when i type /p Hello in a air vehicle, it says nothing, it doesnt even send a empty message.
Please tell me whats wrong with it
pawn Код:
//At Top
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

//The Command
dcmd_p(playerid,params[])
{
  new vehicleid;
  if(strlen(params) == 0) return SendClientMessage(playerid, red, "Usage: /p (Text)");
  for (new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i)) continue;
    vehicleid = GetPlayerVehicleID(i);
    switch(GetVehicleModel(vehicleid))
    {
      case 417 ,425, 447, 592, 577, 511, 512,
      593, 520, 553, 476, 519, 460, 513, 548,
      487, 488, 497, 563, 469:
      {
        new string[128];
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, sizeof(pName));
        format(string,sizeof(string),"Pilot Chat: %s: %s",pName, params);
        SendClientMessage(i, green, string);
      }
    }
    return 1;
  }
  return 1;
}

//At OnPlayerCommandText
dcmd(p,1,cmdtext);
Reply
#2

Try this:

pawn Код:
//At Top
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
forward Car();

//The Command
dcmd_p(playerid,params[])
{
    if(strlen(params) == 0) return SendClientMessage(playerid, red, "Usage: /p (Text)");
    for (new i = 0; i < GetMaxPlayers(); i++)
    {
        if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))
        {
            Car();
        }
        return 1;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(p,1,cmdtext);
    return 1;
}

public Car()
{
    new vehicleid;
    vehicleid = GetPlayerVehicleID(i);
    switch(GetVehicleModel(vehicleid))
    {
        case 417 ,425, 447, 592, 577, 511, 512,
        593, 520, 553, 476, 519, 460, 513, 548,
        487, 488, 497, 563, 469:
        {
            new string[128];
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(playerid, pName, sizeof(pName));
            format(string,sizeof(string),"Pilot Chat: %s: %s",pName, params);
            SendClientMessage(i, green, string);
        }
        default: return SendClientMessage(playerid,COLOR_RED,"[ERROR]: You must be in a valid vehicle!.");
    }
    return 1;
}
Reply
#3

Theres something wrong with the public Car() function.
pawn Код:
C:\Documents and Settings\Administratцr\Skrivbord\Server\filterscripts\admin.pwn(7202) : error 017: undefined symbol "i"
C:\Documents and Settings\Administratцr\Skrivbord\Server\filterscripts\admin.pwn(7211) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administratцr\Skrivbord\Server\filterscripts\admin.pwn(7212) : error 017: undefined symbol "params"
C:\Documents and Settings\Administratцr\Skrivbord\Server\filterscripts\admin.pwn(7213) : error 017: undefined symbol "i"
C:\Documents and Settings\Administratцr\Skrivbord\Server\filterscripts\admin.pwn(7215) : error 017: undefined symbol "playerid"
Pawn compiler 3.2.3664      Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
Reply
#4

pawn Код:
public Car(playerid)
{
    for(new i = 0; i<MAX_PLAYERS;i++)
    {
        new vehicleid;
        vehicleid = GetPlayerVehicleID(i);
        switch(GetVehicleModel(vehicleid))
        {
            case 417 ,425, 447, 592, 577, 511, 512,
            593, 520, 553, 476, 519, 460, 513, 548,
            487, 488, 497, 563, 469:
            {
                new string[128];
                new pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pName, sizeof(pName));
                format(string,sizeof(string),"Pilot Chat: %s: %s",pName, params);
                SendClientMessage(i, green, string);
            }
            default: return SendClientMessage(playerid,COLOR_RED,"[ERROR]: You must be in a valid vehicle!.");
        }
    }
    return 1;
}
Use that for the public car() function, it should fix a few errors, not all I think...

And, change this part:
pawn Код:
if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))
{
Car();
}
into this:
pawn Код:
if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))
{
Car(playerid);
}
Reply
#5

Please try to remake my command from the code i gave you.
pawn Код:
//At Top
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

//The Command
dcmd_p(playerid,params[])
{
  new vehicleid;
  if(strlen(params) == 0) return SendClientMessage(playerid, red, "Usage: /p (Text)");
  for (new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i)) continue;
    vehicleid = GetPlayerVehicleID(i);
    switch(GetVehicleModel(vehicleid))
    {
      case 417 ,425, 447, 592, 577, 511, 512,
      593, 520, 553, 476, 519, 460, 513, 548,
      487, 488, 497, 563, 469:
      {
        new string[128];
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, sizeof(pName));
        format(string,sizeof(string),"Pilot Chat: %s: %s",pName, params);
        SendClientMessage(i, green, string);
      }
    }
    return 1;
  }
  return 1;
}

//At OnPlayerCommandText
dcmd(p,1,cmdtext);
Reply
#6

Bump
Reply
#7

Found your bug, you had a return one inside of your for loop. /facepalm

Quote:
Originally Posted by [NWA
Hannes ]
pawn Код:
for (new i = 0; i < GetMaxPlayers(); i++)
  {
    //...
    return 1;
  }
  return 1;
}

I also changed a few things:
So I added a check for the player being in the right vehicle type.
There were also some very bad innificiencies which i took care of too. (No point recreating the same string, and calling the same functions repeatedly for all players)

pawn Код:
dcmd_p(playerid,params[])
{
  new vehicleid;
  if(strlen(params) == 0) return SendClientMessage(playerid, red, "Usage: /p (Text)");
  switch(GetVehicleModel(GetPlayerVehicleID(playerid)))
  {
    case 417 ,425, 447, 592, 577, 511, 512,
    593, 520, 553, 476, 519, 460, 513, 548,
    487, 488, 497, 563, 469:{}
    default:SendClientMessage(playerid, red, "You must be in a pilot vehicle to use this command");
  }
  new string[128];
  new pName[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pName, sizeof(pName));
  format(string,sizeof(string),"Pilot Chat: %s: %s",pName, params);
  for (new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i)) continue;
    vehicleid = GetPlayerVehicleID(i);
    switch(GetVehicleModel(vehicleid))
    {
      case 417 ,425, 447, 592, 577, 511, 512,
      593, 520, 553, 476, 519, 460, 513, 548,
      487, 488, 497, 563, 469:
        SendClientMessage(i, green, string);
    }
  }
  return 1;
}
Reply
#8

Thanks, I just tested it, It works 100%
Thank you very much
Reply
#9

Np.

You understood the efficiency issue?
Recognizing things like that will make your server faster
Reply
#10

What you did is very slow on low-bandwith computers.
GetMaxPlayers() doing this thing;
1. Connecting FTP.
2. Reading server.cfg.
3. Taking the 'maxplayers' value from the file.
4. Closing the FTP Connection.

This will take at least 5 seconds.

I think you better replace 'GetMaxPlayers()' in the loop, by the default server maxplayers value.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)