A Question
#1

I've seen these types of commands on other servers and I was wondering how to do it myself. Commands where it is like for example /buy 1-5 and if I type either 1-5 it will give me the item or if I type something else it will say "Use /buy [1-5]. Can someone please tell me how I would go about doing this using the default if(strcmp type commands.
Reply
#2

This should work. It's untested:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);
   
    if(!strcmp(cmdtext, "/buy", true))
    {
        new tmp[128];
        tmp = strtok(cmdtext, idx);
        new option = strval(tmp);
       
        switch(option)
        {
            case 0:
            {
                SendClientMessage(playerid, COLOR_YELLOW, "Use /buy [1-5]");
            }
            case 1:
            {
                //if they type /buy 1
            }
            case 2:
            {
                //if they type /buy 2
            }
            case 3:
            {
                //if they type /buy 3
            }
            case 4:
            {
                //if they type /buy 4
            }
            case 5:
            {
                //if they type /buy 5
            }
            default:
            {
                SendClientMessage(playerid, COLOR_RED, "(INFO) You have selected an invalid item! (1-5)");
            }

        }
       
        return 1;
    }
   
    return 0;
}
Reply
#3

I'll try it out.
Reply
#4

Here is the script I have.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);

if(!strcmp(cmdtext, "/radio", true))
{
    if(Audio_IsClientConnected(playerid))
    {
        new tmp[128];
        tmp = strtok(cmdtext, idx);
        new option = strval(tmp);

        switch(option)
        {
            case 0:
            {
                SendClientMessage(playerid, COLOR_YELLOW, "Use /startradio [1-6] [0 = off]");
            }
            case 1:
            {
                if(StreamID[playerid] > 0)
                {
                    Audio_Stop(playerid, StreamID[playerid]);
                    SendClientMessage(playerid, COLOR_YELLOW, "Radio Switched Off.");
                    StreamID[playerid] = 0;
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: You're not currently listening to any streams!");
                }
            }
            case 2:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 1;
                Audio_PlayStreamed(playerid, "http://listen.di.fm/public5/trance.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Trance.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - Listen to the hottest, freshest Trance music from around the globe!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 3:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 2;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/club.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Club Sounds.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - The hottest club and dance tunes 24/7!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 4:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 3;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/dubstep.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Dubstep.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - The sounds of dubstep all day long!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 5:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 4;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/classictrance.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Classic Trance.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - The sounds of classic trance all day long!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 6:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 5;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/drumandbass.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - DnB.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - Tasty assortment to satisfy your Drum n' Bass needs.", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 7:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 6;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/house.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - House.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - Silky, sexy, deep house music straight from the heart of New York City!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            default:
            {
                SendClientMessage(playerid, COLOR_YELLOW, "Use /startradio [1-6] [0 = off]");
            }
            return 1;
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: You are not connected to the audio server.");
        SendClientMessage(playerid, COLOR_YELLOW, "You may need to install the audio client, please visit the forums.");
        return 1;
    }
and here are the errors that I am getting
Код:
F:\Documents\Drifting Roaches\Server\Drifting Roaches\gamemodes\DR-Gamemode.pwn(3281) : warning 202: number of arguments does not match definition
F:\Documents\Drifting Roaches\Server\Drifting Roaches\gamemodes\DR-Gamemode.pwn(4186) : error 047: array sizes do not match, or destination array is too small
F:\Documents\Drifting Roaches\Server\Drifting Roaches\gamemodes\DR-Gamemode.pwn(4209) : error 047: array sizes do not match, or destination array is too small
F:\Documents\Drifting Roaches\Server\Drifting Roaches\gamemodes\DR-Gamemode.pwn(4290) : error 002: only a single statement (or expression) can follow each "case"
F:\Documents\Drifting Roaches\Server\Drifting Roaches\gamemodes\DR-Gamemode.pwn(4290) : warning 215: expression has no effect
F:\Documents\Drifting Roaches\Server\Drifting Roaches\gamemodes\DR-Gamemode.pwn(8303) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Reply
#5

Can you please provide which line is which?
Reply
#6

Here is the script that I am trying to do. Basically if a player types /radio [0-6] a radio station will come on and if they type 0 then the radio will turn off. Here is all the code of the command.
Код:
if(!strcmp(cmdtext, "/radio", true))
{
    if(Audio_IsClientConnected(playerid))
    {
        new tmp[128];
        tmp = strtok(cmdtext, idx);
        new option = strval(tmp);

        switch(option)
        {
            case 0:
            {
                SendClientMessage(playerid, COLOR_YELLOW, "Use /startradio [1-6] [0 = off]");
            }
            case 1:
            {
                if(StreamID[playerid] > 0)
                {
                    Audio_Stop(playerid, StreamID[playerid]);
                    SendClientMessage(playerid, COLOR_YELLOW, "Radio Switched Off.");
                    StreamID[playerid] = 0;
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: You're not currently listening to any streams!");
                }
            }
            case 2:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 1;
                Audio_PlayStreamed(playerid, "http://listen.di.fm/public5/trance.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Trance.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - Listen to the hottest, freshest Trance music from around the globe!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 3:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 2;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/club.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Club Sounds.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - The hottest club and dance tunes 24/7!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 4:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 3;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/dubstep.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Dubstep.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - The sounds of dubstep all day long!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 5:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 4;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/classictrance.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - Classic Trance.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - The sounds of classic trance all day long!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 6:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 5;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/drumandbass.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - DnB.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - Tasty assortment to satisfy your Drum n' Bass needs.", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            case 7:
            {
                if(StreamID[playerid] > 0) Audio_Stop(playerid, StreamID[playerid]);
                StreamID[playerid] = 6;
                Audio_PlayStreamed(playerid, "http://www.di.fm/wma/house.asx", false, false, true);
                SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: Now playing: Digitally Imported - House.");
                SetPlayerChatBubble(playerid, "I am now listening to !!DIGITALLY IMPORTED!! - Silky, sexy, deep house music straight from the heart of New York City!", COLOR_LIGHTBLUE, 25.0, 10000);
                return 1;
            }
            default:
            {
                SendClientMessage(playerid, COLOR_YELLOW, "Use /startradio [1-6] [0 = off]");
            }
            return 1;
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Audio Bot: You are not connected to the audio server.");
        SendClientMessage(playerid, COLOR_YELLOW, "You may need to install the audio client, please visit the forums.");
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)