[HELP] Multiple inputs per command
#1

Probably a stupid question, just pretty new at coding in PAWN. How would I set up a script such that if I type
Код:
/am Hello, this is a message
it would send that message to everyone on the server?

Like I know
Код:
if (strcmp("/adminmessage", cmdtext, true) == 0 || strcmp(cmdtext,"/am",true)==0)
{
     //Code Here
     return 1;
}
but I don't know how to grab everything after the command and set it as a variable.
Reply
#2

https://sampwiki.blast.hk/wiki/SendClientMessageToAll

Quote:

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp(cmdtext, "/msgall", true) == 0)
{
// Send a message to everyone.
SendClientMessageToAll(0xDEEE20FF, "Hello.");
return 1;
}
return 0;
}

If you have zcmd

pawn Код:
CMD:am(playerid, params[]
{
    new string[128];
    if(isnull(params)) return SendClientMessage(playerid, -1, "USAGE: /am [message]");
    format(string, sizeof(string), "%s", params);
    SendClientMessageToAll(COLOR_LIGHTBLUE, string);
    return 1;
}
Else

pawn Код:
if (strcmp("/adminmessage", cmdtext, true) == 0 || strcmp(cmdtext,"/am",true)==0)
{
     new string[128];
     format(string, sizeof(string), "%s", params);
     SendClientMessageToAll(COLOR_LIGHTBLUE, string);
     return 1;
}
Reply
#3

Thanks, but what if I want to use 3 inputs, like the next example
Код:
/w [id] [message]
How would I store the "id" they entered in one string, and the message they entered in a different one. How do I install zcmd if that is what I need?
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=91354 - That's for ZCMD
Place this in your includes.
All you do is put #include <zcmd> at the top of your scripts.

This is a zcmd command.
Now keep in mind this is just a base for a /w command.

You need to identify the id
new id;

As well as the message
new message[128];
The [128] is the size of the string.

pawn Код:
CMD:w(playerid, params[])
{
    new
        message[128],
        id,
        szPlayerName[MAX_PLAYER_NAME],
        szMessage[128];

    if(sscanf(params, "us[128]", id, message)) {
        SendClientMessage(playerid, -1, "USAGE: /w [playerid] [message]");
    }
    else
    {
        if(IsPlayerConnected(id))
        {
            if(playerid != id)
            {
                GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);

                format(szMessage, sizeof(szMessage), "Whisper from %s: %s", szPlayerName, message);
                SendClientMessage(id, -1, szMessage);

                GetPlayerName(id, szPlayerName, MAX_PLAYER_NAME);

                format(szMessage, sizeof(szMessage), "Whisper sent to %s: %s", szPlayerName, message);
                SendClientMessage(playerid, -1, szMessage);
            }
            else
            {
                SendClientMessage(playerid, -1, "You cannot whisper to yourself!");
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "The specified player ID is either not connected or has not authenticated.");
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by [TC]XxJuggaloxX
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/SendClientMessageToAll
pawn Код:
if (strcmp("/adminmessage", cmdtext, true) == 0 || strcmp(cmdtext,"/am",true)==0)
{
     new string[128];
     format(string, sizeof(string), "%s", params);
     SendClientMessageToAll(COLOR_LIGHTBLUE, string);
     return 1;
}
This gives me the following error
Код:
F:\SAMP\gamemodes\naterp.pwn(146) : error 017: undefined symbol "params"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#6

Sorry, I can't help you with that very much xD I am only good with zcmd. The params does need to be changed though. Also, Can you please reply to your message.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)