Sub-Command (playerid or range)?
#1

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.
Reply
#2

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]");
Reply
#3

Quote:
Originally Posted by Konstantinos
View Post
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
Reply
#4

Quote:
Originally Posted by Konstantinos
View Post
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.
Reply
#5

Quote:
Originally Posted by SickAttack
View Post
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.
Reply
#6

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.
Reply
#7

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).
Reply
#8

PHP Code:
if (!sscanf(params"'all'i"money)) {
}
else if (!
sscanf(params"p<->up< >ui"lowPlayerhighPlayermoney)) {
}
else if (!
sscanf(params"ui"playeridmoney)) {

/givemoney all 1000
/givemoney 5-9 1000
/givemoney OneDay 1000
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)