command help
#1

How can i make two command with two space
example : /bank deposit [amount] and /bank withdraw [amount]
Reply
#2

The easiest way is using sscanf (#include <sccanf2>)

string[64];
integer;
if(sscanf(params, "is[64]", integer, variable)) return SendClientMessage(playerid, -1, "ERROR......[parameter 1] [parameter 2]");

Then just use the variables: string, integer ect.
Reply
#3

i dont understands
Reply
#4

Quote:
Originally Posted by JawsPlus
Посмотреть сообщение
i dont understands
Okay, are you using sscanf?
pawn Код:
new string[64]; //defines a string with 64 slots.
new integer; //defines a blank variable with 1 slot.
if(sscanf(params, "is[64]", integer, string)) //params, is parameter (i.e: /command [parameter 1] [parameter 2].
                                //"is[64]", defines the slopes: integer is 'i', string is 's', with 64 slots.
                                // integer and variable, are the variables that were defined.
                                //sscanf is the function which handles it all (simple words).
{
     SendClientMessage(playerid, -1, "ERROR......[parameter 1] [parameter 2]"); //Filter out when invalid parameters don't exist.
}
...then to use it:

pawn Код:
COMMAND:command(playerid, params[])
{
    new string[64];
    new integer;
    if(sscanf(params, "is[64]", integer, string)) //sscanf function is called (called it this for simple explaining).
    {
        SendClientMessage(playerid, -1, "ERROR......[parameter 1] [parameter 2]");
    }
    if(integer == 1) //parameter 1, as it comes FIRST in the sscanf function.
    {
        SendClientMessage(playerid, -1, "You have entered an int of 1, as parameter 1!");
    }
    if(string) //parameter 2, as it comes SECOND in the sscanf function.
    {
        SendClientMessage(playerid, -1, "There is a valid string as parameter 2!");
    }
    return 1;
}
Sorry, I'm a bit tired.
Reply
#5

i make some thing like this but error like this

PHP код:
error 001expected token";"but found "if" 
PHP код:
COMMAND:eventbank(playeridparams[])
{
    new 
money,string[128],str1[100],string1[100];
     if(
sscanf(params"sd[100]","donate",money))return SendClientMessage(playeridCOLOR_RED"[USAGE]:{FFFFFF}/eventbank donate [AMOUNT]");
     {
        if(
money 1000) return SendClientMessage(playerid,    COLOR_RED,"[ERROR]:{FFFFFF}You can donate at least $1000");
        if(
GetPlayerMoney(playerid) < money) return SendClientMessage(playerid,COLOR_RED,"[ERROR]:{FFFFFF} You don't have this money");
        
format(string,sizeof(string),"[EVENT BANK]:{ffffff}%s(%d) have donate $%d to the event bank.",Name(playerid),playerid,money);
        
SendClientMessageToAll(COLOR_YELLOW,string);
        
SetPlayerMoney(playerid,GetPlayerMoney(playerid)-money);
        
eventbank += money;
         return 
1;
    }
    else if(
sscanf(params"sd""withdraw"money))return SendClientMessage(playerid,COLOR_RED"[USAGE]:{FFFFFF}/eventbank withdraw [AMOUNT]");
    {
        
format(str1,sizeof(str1),"[ERROR]:{FFFFFF}There are only $%d in event bank.",eventbank);
        if(
money GetInfo(playerid,"Bank")) return SendClientMessage(playerid,COLOR_RED,str1);
        
format(string,sizeof(string),"[EVENT BANK]:{ffffff}%s(%d) have withdraw $%d from the event bank.",Name(playerid),playerid,money);
        
SendClientMessage(playerid,COLOR_YELLOW,string);
        
eventbank -= money;
        
SetPlayerMoney(playeridGetPlayerMoney(playerid) + money );
        return 
1;
    }
    else if(
sscanf(params,"s","balance"))
    {
        
#pragma unused params
        
format(string1,sizeof(string1),"[EVENTBANK]:{ffffff}There are $%d in event bank",eventbank);
        
SendClientMessage(playerid,COLOR_YELLOW,string1);
        return 
1;
    }
 return 
SendClientMessage(playerid0xff0000AA"[USAGE]:{FFFFFF}/eventbank [donate/withdraw/balance]");

Reply
#6

Which line is the error occurring on? It just means you've missed a ';', at some stage.

I'll reply soon, sorry but it's completely wrong.

EDIT: try this

pawn Код:
removed...wasn't thinking.
Reply
#7

the error is on else if
Reply
#8

You has open an totaly wrong statment, i explain you why:

correct instruction
pawn Код:
if(condition) return [instructions]; //finish statment you can't open a brackets (" { " ) after you declare a return.
Reply
#9

can you give me some example
Reply
#10

Check my post above, edited.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)