[SOLVED] Sub-Command (playerid or range)? -
RayBiH - 18.12.2016
So my question is this:
I made a command that gives money to a player. Now that works fine (/givemoney [playerid] [money])
But i want to make it so I can type /giveweapon [playerid/range] [money]
So, I know how to do it with two options, example /giveweapon [range/all] [money], but how do I do it with both playerid/name and range, can't figure it out.
Thanks.
Re: Sub-Command (playerid or range)? -
Konstantinos - 18.12.2016
Something like this:
pawn Code:
new id, Float: range, money;
if (!sscanf(params, "fi", range, money))
{
// code..
}
else if (!sscanf(params, "ri", id, money))
{
// code..
}
else SendClientMessage(playerid, -1, "Usage: /giveweapon [playerid/range] [money]");
Re: Sub-Command (playerid or range)? -
RayBiH - 18.12.2016
Quote:
Originally Posted by Konstantinos
Something like this:
pawn Code:
new id, Float: range, money;
if (!sscanf(params, "fi", range, money)) { // code.. } else if (!sscanf(params, "ri", id, money)) { // code.. } else SendClientMessage(playerid, -1, "Usage: /giveweapon [playerid/range] [money]");
|
Thanks, repped
Re: Sub-Command (playerid or range)? -
SickAttack - 18.12.2016
Quote:
Originally Posted by Konstantinos
Something like this:
pawn Code:
new id, Float: range, money;
if (!sscanf(params, "fi", range, money)) { // code.. } else if (!sscanf(params, "ri", id, money)) { // code.. } else SendClientMessage(playerid, -1, "Usage: /giveweapon [playerid/range] [money]");
|
Not quite conventional since people don't usually use decimals/floating point numbers. But a pretty clever solution.
You should make it like /cmd -r 5 5000 and /cmd -p 5 5000, -r for range, -p for player. But just a small detail I'd consider.
Re: Sub-Command (playerid or range)? -
Konstantinos - 18.12.2016
Quote:
Originally Posted by SickAttack
Not quite conventional since people don't usually use decimals/floating point numbers. But a pretty clever solution.
You should make it like /cmd -r 5 5000 and /cmd -p 5 5000, -r for range, -p for player. But just a small detail I'd consider.
|
I realized that and it's quite tricky because even an integer is a valid float (as parameter) and a float is a valid player's name (10.5 for example). Without a 3rd parameter, it will be very difficult to detect what exactly the value is supposed to be.
Re: Sub-Command (playerid or range)? -
Duco - 19.12.2016
Unable to test this as I'm not near my computer, but how you could do it is as SickAttack suggested.
Which I believe can go as followed:
Code:
new selector[2], target, weapon, Float:radius;
if (sscanf(params, "s[2]ii", selector, target, weapon)
{
if (!strcmp(selector, "-r") // checks if the selector that was given equals -r
{
radius = float(target); // turns the integer (target) into a float
//insert radius give code
}
else if (!strcmp(selector, "-p") // checks if the selector that was given equals -p
{
//insert player give code
}
else // if neither of the checks were positive
{
//sytax message (/giveweapon [-p / -r] [target] [weapon])
}
}
else
{
//sytax message (/giveweapon [-p / -r] [target] [weapon])
}
Only problem with this code is that you can't use a player's name, only their ID. But besides that it should work in theory.
Re: Sub-Command (playerid or range)? -
RayBiH - 19.12.2016
Thanks all, but no help needed with the range, I only needed to know how to make the command work with both playerid and range (I used strcmp for subcommands).
Re: Sub-Command (playerid or range)? -
OneDay - 19.12.2016
PHP Code:
if (!sscanf(params, "'all'i", money)) {
}
else if (!sscanf(params, "p<->up< >ui", lowPlayer, highPlayer, money)) {
}
else if (!sscanf(params, "ui", playerid, money)) {
}
/givemoney all 1000
/givemoney 5-9 1000
/givemoney OneDay 1000