Command without " / "
#1

Everytime I make a command like:

dcmd_lol

it is automatically like: /lol

How can I put it for be a single character? Like Im trying to do a chat group, and wanted the single character:


pawn Код:
&
dcmd or strcmp
Reply
#2

Try with:
if(strcmp(cmd, "test", true) ==0 )
{
return 1;
}

or use OnPlayerText....

if(text[0] == '&')
{

}
Reply
#3

You can't do it in OnPlayerCommandText, as it is only called when there is a / as the first character.

You need to do it in OnPlayerText, like DRIFT_HUNTER has shown an example of comparing the first character of the text string to the AND character.

Also you should remember that strcmp is not a command processor, it is merely for comparing strings, it would seem you suggested it was a command processor in your post . On the other hand, dcmd is specifically for commands, however you would not be able to use dcmd either for this function, as it uses OnPlayerCommandText, which is only called when you add a / as the first character
Reply
#4

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
You can't do it in OnPlayerCommandText, as it is only called when there is a / as the first character.

You need to do it in OnPlayerText, like DRIFT_HUNTER has shown an example of comparing the first character of the text string to the AND character.

Also you should remember that strcmp is not a command processor, it is merely for comparing strings, it would seem you suggested it was a command processor in your post . On the other hand, dcmd is specifically for commands, however you would not be able to use dcmd either for this function, as it uses OnPlayerCommandText, which is only called when you add a / as the first character
But can you help me fixing it? It's like: If player team is 0, returns a message. Else, if player team is more or equal to 1, send the message for all online members of same team. Here my code:

pawn Код:
if(text[0] = '&')
    {
    new string[128];
    new string2[128];
    new name[30];
    GetPlayerName(playerid, name, 30);
    format(string, sizeof(string),"GROUP: %s [ID:%d]: %s", name, playerid, text[1]);
    //if (sscanf(text[1], "s[128]",string2)) SendClientMessage(playerid, cinza, "/c <texto>");
    if(GetPlayerTeam(playerid) == 0) return SendClientMessage(playerid, cinza, "Vocк nгo tem grupo ainda!");
    foreach (Player, i)
    {
      if(GetPlayerTeam(playerid) == GetPlayerTeam(i))
      {
        SendClientMessage(i, agua, string);
      }
     
    }
   
    return 0;
    }
Reply
#5

pawn Код:
//OnPlayerText
if(text[0]=='&')
{
      text[0]='/';
      CallLocalFunction("OnPlayerCommandText", "is", playerid, text);
      return 0;
}
or am I wrong?
Reply
#6

Removed. My bad - wrong section of code
Reply
#7

pawn Код:
if(text[0]=='&')
{
      OnPlayerCommandText(playerid, "/example");
      return 0;
}
Reply
#8

Quote:
Originally Posted by cynic
Посмотреть сообщение
pawn Код:
if(text[0]=='&')
{
      OnPlayerCommandText(playerid, "/example");
      return 0;
}
This wouldnt work... - OnPlayerCommand is a "public" but publics cannot be run in other publics, Only functions can.

This would work, however

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[0] == '&')
    {
        new pName[MAX_PLAYER_NAME], string[64];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "%s: lol", pName); //You could use SAMP 0.3c's colour embedding to make it look better
        SendClientMessage(playerid, COLOUR, string);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)