11.08.2012, 19:23
How could i possibly do a command for example: /give money (playerid) (amount) or /give key (playerid), im using sscanf, someone tell me please.
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;
}
Made it quirckly, just look in both commands and try get their logic's by your self.
pawn Код:
|
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. |
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;
}
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;
}
you would need to do it like this"
pawn Код:
|