20.11.2009, 18:02
Hello, I just started to work on my new Game Mode, and it has been awhile since I was active on this forum. I decided to use zcmd with sscanf for my commands but I have one question about more complex commands like:
My question is basicly this.
Is this the right usage of sscanf with zcmd (see example command) or is there another better way to use it. Don't get me wrong, the command works fine but this is my first time working with sscanf and zcmd and I just want to know if I'm doing it right.
Example:
Thank you...
Code:
/safe put/take gun/drugs/money amount
My question is basicly this.
Is this the right usage of sscanf with zcmd (see example command) or is there another better way to use it. Don't get me wrong, the command works fine but this is my first time working with sscanf and zcmd and I just want to know if I'm doing it right.
Example:
pawn Code:
COMMAND:safe(playerid, params[])
{
new string[64],
option[4],
item[5],
amount[5];
sscanf(params, "sss", option, item, amount);
if (isnull(option))
{
SendClientMessage(playerid, COLOR_WHITE, " USAGE: /safe <option>");
SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: Put, Take");
return 1;
}
if (!strcmp(option, "put"))
{
if (isnull(item))
{
SendClientMessage(playerid, COLOR_WHITE, " USAGE: /safe put <option>");
SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: Gun, Drugs, Money");
return 1;
}
if (!strcmp(item, "gun"))
{
new ammo = strval(amount),
weapon = GetPlayerWeapon(playerid);
if (isnull(amount) || !IsNumeric(amount))
{
SendClientMessage(playerid, COLOR_WHITE, " USAGE: /safe put gun <ammo>");
return 1;
}
if (weapon == 0)
{
SendClientMessage(playerid, COLOR_WHITE, " ERROR: No weapon found in your hands.");
return 1;
}
if (ammo > GetPlayerAmmo(playerid))
{
SendClientMessage(playerid, COLOR_WHITE, " ERROR: You don't have that much bullets.");
return 1;
}
GivePlayerWeapon(playerid, weapon, -ammo);
format(string, sizeof(string), "You have put weapon %s with %d bullets in the safe !", WeaponNames[weapon], ammo);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
else if (!strcmp(item, "drugs"))
{
// Code for the drugs...
}
else if (!strcmp(item, "money"))
{
// Code for the money...
}
}
else if (!strcmp(option, "take"))
{
if (isnull(item))
{
SendClientMessage(playerid, COLOR_WHITE, " USAGE: /safe take <option>");
SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: Gun, Drugs, Money");
return 1;
}
if (!strcmp(item, "gun"))
{
// Code for the gun...
}
else if (!strcmp(item, "drugs"))
{
// Code for the drugs...
}
else if (!strcmp(item, "money"))
{
// Code for the money...
}
}
return 1;
}