sscanf
#1

Hi, I'm creating an event system, but the problem is that my server crashes when I try to set the event's weapon. How could I make it work? I see that it's done totally wrong. I've never made commands that can do many things so it's a little bit confusing.
Here's the command:
Код:
CMD:event(playerid, params[])
{
	new type[12];
	
	if (PlayerInfo[playerid][pAdmin] < 3)
		return SendClientMessage(playerid, COLOR_RED, "You are not allowed to use this command.");
		
	if (sscanf(params, "s[12]", type))
		return SendClientMessage(playerid, COLOR_GREY, "USAGE: /event [create/destroy/open/close/start/stop/spawn/respawning/weapon]");

	if (!strcmp(type, "create", true))
	{
		EventInfo[Created] = true;
		EventInfo[SpawnHealth] = 100.0;
		SendClientMessage(playerid, COLOR_YELLOW, "[ADMIN]: {FFFFFF}You have created an event.");
		return 1;
	}	
	else if (!strcmp(type, "weapon", true))
	{
		if (!EventInfo[Created])
			return SendClientMessage(playerid, COLOR_RED, "There are no active events (type /event create to create one).");
			
		new slot, weaponid, ammo;
		
		if (sscanf(params, "ddd", slot, weaponid, ammo))
			return SendClientMessage(playerid, COLOR_GREY, "USAGE: /event weapon [slot] [weaponid] [ammo]");
			
		if (slot < 0 || slot > 12)
			return SendClientMessage(playerid, COLOR_RED, "Invalid slot specified (valid are 0 to 12).");
			
		if (weaponid < 0 || weaponid > 46)
			return SendClientMessage(playerid, COLOR_RED, "You have specified an invalid weapon ID.");
			
		if (slot != GetWeaponSlot(weaponid))
			return SendClientMessageEx(playerid, COLOR_RED, "This weapon can't be put in this slot (put in %d instead).", GetWeaponSlot(weaponid));
			
		if (ammo < 1)
			return SendClientMessage(playerid, COLOR_RED, "The amount of ammo must be at least 1.");
			
		EventInfo[Weapon][slot] = weaponid;
		EventInfo[WeaponAmmo][slot] = ammo;
	}
	else SendClientMessage(playerid, COLOR_GREY, "USAGE: /event [create/destroy/open/close/start/stop/spawn/respawning/weapon]");
	return 1;
}
Reply
#2

Put curly braces and the data type in the second usage of sscanf.

if (sscanf(params, "{s[7]}ddd", slot, weaponid, ammo))
Reply
#3

I don't know if it's better, but I'm doing like this:
PHP код:
CMD:set(playeridparams[])
{
    if(
pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playeridfalse);
    new
        
parametre[30+'\0'],
        
scmd[50];

    if(
sscanf(params"s[30]S()[130]"parametrescmd)) return SCM(playeridLBLUE"/set [money - score - kills - death - skin - vhp - v(irtual)w(orld) - int(erior)]");

    if(!
strcmp(parametre"money"))
    {
... 
Reply
#4

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Put curly braces and the data type in the second usage of sscanf.

if (sscanf(params, "{s[7]}ddd", slot, weaponid, ammo))
Doesn't work at all now. :P
Reply
#5

Try this;

PHP код:
CMD:event(playeridparams[])
{
    new 
type[12], optional[64];
    if (
PlayerInfo[playerid][pAdmin] < 3)
        return 
SendClientMessage(playeridCOLOR_RED"You are not allowed to use this command.");
    if (
sscanf(params"s[12]S()[64]"typeoptional))
        return 
SendClientMessage(playeridCOLOR_GREY"USAGE: /event [create/destroy/open/close/start/stop/spawn/respawning/weapon]");
    if (!
strcmp(type"create"true))
    {
        
EventInfo[Created] = true;
        
EventInfo[SpawnHealth] = 100.0;
        
SendClientMessage(playeridCOLOR_YELLOW"[ADMIN]: {FFFFFF}You have created an event.");
        return 
1;
    }
    else if (!
strcmp(type"weapon"true))
    {
        if (!
EventInfo[Created])
            return 
SendClientMessage(playeridCOLOR_RED"There are no active events (type /event create to create one).");
        new 
slotweaponidammo;
        if (
sscanf(optional"ddd"slotweaponidammo))
            return 
SendClientMessage(playeridCOLOR_GREY"USAGE: /event weapon [slot] [weaponid] [ammo]");
        if (
slot || slot 12)
            return 
SendClientMessage(playeridCOLOR_RED"Invalid slot specified (valid are 0 to 12).");
        if (
weaponid || weaponid 46)
            return 
SendClientMessage(playeridCOLOR_RED"You have specified an invalid weapon ID.");
        if (
slot != GetWeaponSlot(weaponid))
            return 
SendClientMessageEx(playeridCOLOR_RED"This weapon can't be put in this slot (put in %d instead)."GetWeaponSlot(weaponid));
        if (
ammo 1)
            return 
SendClientMessage(playeridCOLOR_RED"The amount of ammo must be at least 1.");
        
EventInfo[Weapon][slot] = weaponid;
        
EventInfo[WeaponAmmo][slot] = ammo;
    }
    else 
SendClientMessage(playeridCOLOR_GREY"USAGE: /event [create/destroy/open/close/start/stop/spawn/respawning/weapon]");
    return 
1;

Reply
#6

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
Try this;

PHP код:
CMD:event(playeridparams[])
{
    new 
type[12], optional[64];
    if (
PlayerInfo[playerid][pAdmin] < 3)
        return 
SendClientMessage(playeridCOLOR_RED"You are not allowed to use this command.");
    if (
sscanf(params"s[12]S()[64]"typeoptional))
        return 
SendClientMessage(playeridCOLOR_GREY"USAGE: /event [create/destroy/open/close/start/stop/spawn/respawning/weapon]");
    if (!
strcmp(type"create"true))
    {
        
EventInfo[Created] = true;
        
EventInfo[SpawnHealth] = 100.0;
        
SendClientMessage(playeridCOLOR_YELLOW"[ADMIN]: {FFFFFF}You have created an event.");
        return 
1;
    }
    else if (!
strcmp(type"weapon"true))
    {
        if (!
EventInfo[Created])
            return 
SendClientMessage(playeridCOLOR_RED"There are no active events (type /event create to create one).");
        new 
slotweaponidammo;
        if (
sscanf(optional"ddd"slotweaponidammo))
            return 
SendClientMessage(playeridCOLOR_GREY"USAGE: /event weapon [slot] [weaponid] [ammo]");
        if (
slot || slot 12)
            return 
SendClientMessage(playeridCOLOR_RED"Invalid slot specified (valid are 0 to 12).");
        if (
weaponid || weaponid 46)
            return 
SendClientMessage(playeridCOLOR_RED"You have specified an invalid weapon ID.");
        if (
slot != GetWeaponSlot(weaponid))
            return 
SendClientMessageEx(playeridCOLOR_RED"This weapon can't be put in this slot (put in %d instead)."GetWeaponSlot(weaponid));
        if (
ammo 1)
            return 
SendClientMessage(playeridCOLOR_RED"The amount of ammo must be at least 1.");
        
EventInfo[Weapon][slot] = weaponid;
        
EventInfo[WeaponAmmo][slot] = ammo;
    }
    else 
SendClientMessage(playeridCOLOR_GREY"USAGE: /event [create/destroy/open/close/start/stop/spawn/respawning/weapon]");
    return 
1;

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)