SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   Need help with // command (https://forum.sa-mp.com/showthread.php?t=666805)

Edvukas 26/05/2019 11:53 AM

Need help with // command
 
Hello, how can I make command // where I can chat with other? I have command with strcmp but I need better variant

OtimoJogo 26/05/2019 12:07 PM

Re: Need help with // command
 
Could you post your command? That way we can improve on it.

Edvukas 26/05/2019 12:15 PM

Re: Need help with // command
 
Code:

if(strcmp(cmdtext, "//", true, 2) == 0 && PlayerDB[playerid][Loaded]) // If the player isn't an admin, the command is not available to them
    {
        if(PlayerDB[playerid][MutedPlayer] > 0)
            {
        new string[144];
        SendClientMessage(playerid, RED, "! You can't use that command right now.);
        return 1;
            }
        if(strlen(cmdtext) == 2) // The player typed '//' without any text!
        {
            SendClientMessage(playerid, WHITE,"* Use // [text]");

            return 0;
        }
        new string[152];
        format(string, sizeof(string), "[VIP CHAT] %s: %s", Nick(playerid), text[2]);

        foreach(new i : Player)
        {
            if(PlayerDB[i][LoggedIn] == 1 && PlayerDB[i][Loaded] == 1 && PlayerDB[i][VIP] > 0)
            {
                SendClientMessage(i, -1, string);
            }
        }
        return 0; // Return 0 here means that no other ZCMD command will be executed!
    }


OtimoJogo 26/05/2019 12:48 PM

Re: Need help with // command
 
pawn Code:
new cmd[128];
    new idx;
    new tmp[128];
    cmd = strtok(cmdtext, idx);

    if(strcmp(cmdtext, "/message", true) == 0 && PlayerDB[playerid][Loaded])
    {
        if(PlayerDB[playerid][MutedPlayer] > 0)
        {
          SendClientMessage(playerid, RED, "! You can't use that command right now.);
          return 1;
        }

        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_RED, "
Use: /message [message]");
        }

        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COLOR_RED, "
enter a message.");
        }

        new string[152];
        format(string, sizeof(string), "
[VIP CHAT] %s: %s", Nick(playerid), result);

        foreach(new i : Player)
        {
            if(PlayerDB[i][LoggedIn] == 1 && PlayerDB[i][Loaded] == 1 && PlayerDB[i][VIP] > 0)
            {
                SendClientMessage(i, -1, string);
            }
        }
        return 0; // Return 0 here means that no other ZCMD command will be executed!
    }
   
   //puts this out of the callback OnPlayerCommandText()
  strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
   }

I made it here in the rush, see if it works out. Anything post the error here.


All times are GMT. The time now is 08:44 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.