Question about ZCMD & SSCANF
#1

How could i possibly do a command for example: /give money (playerid) (amount) or /give key (playerid), im using sscanf, someone tell me please.
Reply
#2

Made it quirckly, just look in both commands and try get their logic's by your self.

pawn Код:
CMD:givemoney(playerid,params[])
{
   new money,people;
   if(sscanf(params,"ud",people,money))return SendClientMessage(playerid,-1,#usage /givemoney [id] [amount]);
   if(!IsPlayerConnected(people)) return SendClientMessage(playerid,-1,#not connected);
   if(playerid == people) return SendClientMessage(playerid,-1,#you can't give money to yourself.);
   GivePlayerMoney(playerid,-money);
   GivePlayerMoney(people,money);
   return 1;
}
new keys[MAX_PLAYERS];
CMD:givekey(playerid,params[])
{
   new people,key;
   if(sscanf(params,"ud",people,keys))return SendClientMessage(playerid,-1,#usage /givekey [id]);
   if(!IsPlayerConnected(people)) return SendClientMessage(playerid,-1,#not connected);
   if(playerid == people) return SendClientMessage(playerid,-1,#you can't give the key to yourself.);
   keys[playerid]-=key;
   keys[people]+=key;
   return 1;
}
Reply
#3

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
Made it quirckly, just look in both commands and try get their logic's by your self.

pawn Код:
CMD:givemoney(playerid,params[])
{
   new money,people;
   if(sscanf(params,"ud",people,money))return SendClientMessage(playerid,-1,#usage /givemoney [id] [amount]);
   if(!IsPlayerConnected(people)) return SendClientMessage(playerid,-1,#not connected);
   if(playerid == people) return SendClientMessage(playerid,-1,#you can't give money to yourself.);
   GivePlayerMoney(playerid,-money);
   GivePlayerMoney(people,money);
   return 1;
}
new keys[MAX_PLAYERS];
CMD:givekey(playerid,params[])
{
   new people,key;
   if(sscanf(params,"ud",people,keys))return SendClientMessage(playerid,-1,#usage /givekey [id]);
   if(!IsPlayerConnected(people)) return SendClientMessage(playerid,-1,#not connected);
   if(playerid == people) return SendClientMessage(playerid,-1,#you can't give the key to yourself.);
   keys[playerid]-=key;
   keys[people]+=key;
   return 1;
}
You misunderstood me. I can do those normal commands easy, but i want to do a command as this:
/give key (playerid)
/give money (playerid) (amount)
/give phone (playerid)
/give...
/give... You see, /give is one command. I hope you understand what do i mean.
Reply
#4

oh, just use the function "strcmp" inside the command /give comparing the params.
Reply
#5

Quote:
Originally Posted by ddnbb
Посмотреть сообщение
You misunderstood me. I can do those normal commands easy, but i want to do a command as this:
/give key (playerid)
/give money (playerid) (amount)
/give phone (playerid)
/give...
/give... You see, /give is one command. I hope you understand what do i mean.
pawn Код:
CMD:give(playerid, params[ ])
{
    if( !strcmp( "key", params, true, 3 ) )
    {
        if( !strlen( params[ 4 ] ) ) return SendClientMessage( playerid, -1, "/give key [playerid]" );
       
        new targetid = strval( params[ 4 ] );
       
        if( !IsPlayerConnected( targetid ) ) return SendClientMessage(playerid, -1, "The target ID is not connected" );
        if( targetid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Invalid player" );
        if( targetid == playerid ) return SendClientMessage( playerid, -1, "You can't give yourself a key!" );

        // your code
    }
    else if( !strcmp( "money", params, true, 5 ) )
    {
        if( !strlen( params[ 6 ] ) ) return SendClientMessage( playerid, -1, "/give money [playerid]" );

        new targetid = strval( params[ 6 ] );

        if( !IsPlayerConnected( targetid ) ) return SendClientMessage(playerid, -1, "The target ID is not connected" );
        if( targetid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Invalid player" );
        if( targetid == playerid ) return SendClientMessage( playerid, -1, "You can't give money to yourself!" );
       
        // your code
    }
// so on
    /*else if( !strmp( "shit", params, true, NUMBER ) )
    {
    }*/

    else
    {
        SendClientMessage( playerid, -1, "/give [key/money/phone]" );
    }
    return 1;
}
Reply
#6

you would need to do it like this"
pawn Код:
CMD:give(playerid,params[])
{
    if(!strcmp(params,"cash ",true,5))//5 is the length of "cash "
    {
        new ID,amount;
        if(sscanf(params[5],"dd",ID,amount))//make sure you have [(the length of "cash ")] after params
        {
            return SendClientMessage(playerid,0xFFAA00AA,"Usage: /give Cash (player ID) (Amount)");
        }
        //code here
        return 1;
    }
    if(!strcmp(params,"keys ",true,5))//5 is the length of "keys "
    {
        new ID;
        if(sscanf(params[5],"d",ID))"dd"//make sure you have [(the length of "keys ")] after params
        {
            return SendClientMessage(playerid,0xFFAA00AA,"Usage: /give Keys (player ID)");
        }
        //code here
        return 1;
    }
    return 0;
}
Reply
#7

Quote:
Originally Posted by MeDaKewlDude
Посмотреть сообщение
you would need to do it like this"
pawn Код:
CMD:give(playerid,params[])
{
    if(!strcmp(params,"cash ",true,5))//5 is the length of "cash "
    {
        new ID,amount;
        if(sscanf(params[5],"dd",ID,amount))//make sure you have [(the length of "cash ")] after params
        {
            return SendClientMessage(playerid,0xFFAA00AA,"Usage: /give Cash (player ID) (Amount)");
        }
        //code here
        return 1;
    }
    if(!strcmp(params,"keys ",true,5))//5 is the length of "keys "
    {
        new ID;
        if(sscanf(params[5],"d",ID))"dd"//make sure you have [(the length of "keys ")] after params
        {
            return SendClientMessage(playerid,0xFFAA00AA,"Usage: /give Keys (player ID)");
        }
        //code here
        return 1;
    }
    return 0;
}
Thanks for the help! +REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)