#1

I'm trying to make it so that the player id is optional and that it defaults to yourself with sscanf. When I run the command without the player id, it doesn't give me the "Usage" output, indicating that sscanf recognizes that it's optional, but it doesn't give me the playerid.

Код:
CMD:w(playerid, params[])
{
	new weapid, recieverid, ammo;
	recieverid = playerid;
	if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GRAY, "You are not authorized to use that command!");
	if (sscanf(params, "diU", weapid, ammo, recieverid)) return SendClientMessage(playerid, COLOR_GRAY, "Usage: /w [weapon id] [ammo] [player id]");
	if (weapid < 0 || weapid > 46) return SendClientMessage(playerid, COLOR_GRAY, "Invalid weapon ID!");
	else
		{
		GivePlayerWeapon(recieverid, weapid, ammo);
		}
	return 1;
}
Reply
#2

EDIT: removed
2: you cant give weapon without playerid to anyone
3: by removing playerid only who press /w [weap id] [ammo] will get the gun.
Reply
#3

Quote:
Originally Posted by BulletRaja
Посмотреть сообщение
PHP код:
CMD:w(playeridparams[])
{
    new 
weapidammo;
    if (!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_GRAY"You are not authorized to use that command!");
    if (
sscanf(params"di"weapidammo)) return SendClientMessage(playeridCOLOR_GRAY"Usage: /w [weapon id] [ammo]");
    if (
weapid || weapid 46) return SendClientMessage(playeridCOLOR_GRAY"Invalid weapon ID!");
    else
        {
        
GivePlayerWeapon(playeridweapidammo);
        }
    return 
1;

1- Don't just send code, explain it.
2- That code will never work.
Reply
#4

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
1- Don't just send code, explain it.
2- That code will never work.
ok edited
Reply
#5

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
1- Don't just send code, explain it.
2- That code will never work.
that code that bulletraja sent works fine for me, what you on about
Reply
#6

Quote:
Originally Posted by rfr
Посмотреть сообщение
that code that bulletraja sent works fine for me, what you on about
The thread:
Quote:
Originally Posted by InSain
I'm trying to make it so that the player id is optional
What he posted:
Quote:

if (sscanf(params, "di", weapid, ammo)) return SendClientMessage(playerid, COLOR_GRAY, "Usage: /w [weapon id] [ammo]");

How's that going to give weapons to other players?
Reply
#7

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
1- Don't just send code, explain it.
2- That code will never work.
Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
The thread:


What he posted:


How's that going to give weapons to other players?
why don't you run the code and see for yourself

Reply
#8

PHP код:
CMD:wplayeridparams[] ) {
    new 
weapidammo
        
userid;
    if( !
IsPlayerAdminplayerid ) )
        return 
SendClientMessage(playeridCOLOR_GRAY"You are not authorized to use that command!"); 
    if( 
sscanfparams"iiU(65535)"weapidammouserid ) ) 
        return 
SendClientMessageplayeridCOLOR_GRAY"Usage: /w [weapon id] [ammo] [optional playerid]" );
    if( 
weapid || weapid 46 )
        return 
SendClientMessage(playeridCOLOR_GRAY"Invalid weapon ID!"); 
    if( 
ammo <= )
        return 
SendClientMessage(playeridCOLOR_GRAY"Invalid ammo!"); 
    if( 
userid == INVALID_PLAYER_ID ) {
        
userid playerid;
    } else {
        if( !
IsPlayerConnecteduserid ) )
            return 
SendClientMessageplayeridCOLOR_GRAY"Player isn't connected." );
    }
    
GivePlayerWeaponuseridweapidammo );
    
SendClientMessageplayeridCOLOR_GRAY"Gun spawned!" );
    return 
1;

Read up on sscanf specifiers. A capital U means optional.
https://sampforum.blast.hk/showthread.php?tid=570927
Reply
#9

Staying on topic of this thread, you had the right idea with the code itself, just didn't set it up correctly.

Using sscanf you can set a default value if the param is not used.

EDIT: Use @Arthur Kane, he beat me too it
Reply
#10

I hope i helped u, i didn't test the code.

Код:
CMD:w(playerid, params[])
{
	new weapid, recieverid, ammo;
	if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GRAY, "You are not authorized to use that command!");
        if(sscanf(params, "diu", weapid, ammo, recieverid))
        {
               if (weapid < 0 || weapid > 46) return SendClientMessage(playerid, COLOR_GRAY, "Invalid weapon ID!");
               GivePlayerWeapon(playerid, weapid, ammo);
        }
        else if(!sscanf(params, "diu", weapid, ammo, recieverid))
        {
               if(IsPlayerConnected(recieverid))
               {
                          if(weapid < 0 || weapid > 46) return SendClientMessage(playerid, COLOR_GRAY, "Invalid weapon ID!");
                          GivePlayerWeapon(recieverid, weapid, ammo);
               }
        }
        else return SendClientMessage(playerid, COLOR_WHITE,"Usage: /w [WeapID] [Ammo] [PlayerID(Optional)]");
        return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)