PDA

View Full Version : /w


InSain
23/02/2018, 05:42 AM
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;
}

BulletRaja
23/02/2018, 05:58 AM
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.

RogueDrifter
23/02/2018, 05:59 AM
CMD:w(playerid, params[])
{
new weapid, ammo;
if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GRAY, "You are not authorized to use that command!");
if (sscanf(params, "di", weapid, ammo)) return SendClientMessage(playerid, COLOR_GRAY, "Usage: /w [weapon id] [ammo]");
if (weapid < 0 || weapid > 46) return SendClientMessage(playerid, COLOR_GRAY, "Invalid weapon ID!");
else
{
GivePlayerWeapon(playerid, weapid, ammo);
}
return 1;
}
1- Don't just send code, explain it.
2- That code will never work.

BulletRaja
23/02/2018, 07:13 AM
1- Don't just send code, explain it.
2- That code will never work.

ok edited

rfr
23/02/2018, 07:58 AM
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

RogueDrifter
23/02/2018, 08:00 AM
that code that bulletraja sent works fine for me, what you on about
The thread:
I'm trying to make it so that the player id is optional

What he posted:

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?

rfr
23/02/2018, 08:02 AM
1- Don't just send code, explain it.
2- That code will never work.

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

https://cdn.discordapp.com/attachments/385115162060914698/416519626797875200/unknown.png

RogueDrifter
23/02/2018, 08:05 AM
why don't you run the code and see for yourself

https://cdn.discordapp.com/attachments/385115162060914698/416519626797875200/unknown.png
Why don't you review what i posted?

the op said: I'm trying to make it so that the player id is optional
bulletraja posted a function that gives weapons to the command issuer alone.

rfr
23/02/2018, 08:07 AM
Why don't you review what i posted?

the op said: I'm trying to make it so that the player id is optional
bulletraja posted a function that gives weapons to the command issuer alone.

2- That code will never work.

it's not what the op wanted but his code works

RogueDrifter
23/02/2018, 08:08 AM
2- That code will never work.

it's not what the op wanted but his code works
That's not how you fix something lol, you don't change it to another cmd that functions in a different way.
It will never work for the purpose wanted by the thread.

Kane
23/02/2018, 08:10 AM
CMD:w( playerid, params[] ) {
new weapid, ammo,
userid;

if( !IsPlayerAdmin( playerid ) )
return SendClientMessage(playerid, COLOR_GRAY, "You are not authorized to use that command!");

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

if( weapid < 0 || weapid > 46 )
return SendClientMessage(playerid, COLOR_GRAY, "Invalid weapon ID!");

if( ammo <= 0 )
return SendClientMessage(playerid, COLOR_GRAY, "Invalid ammo!");

if( userid == INVALID_PLAYER_ID ) {
userid = playerid;
} else {
if( !IsPlayerConnected( userid ) )
return SendClientMessage( playerid, COLOR_GRAY, "Player isn't connected." );
}
GivePlayerWeapon( userid, weapid, ammo );
SendClientMessage( playerid, COLOR_GRAY, "Gun spawned!" );
return 1;
}

Read up on sscanf specifiers. A capital U means optional.
http://forum.sa-mp.com/showthread.php?t=570927

Stev
23/02/2018, 08:16 AM
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 :)

kingmk
23/02/2018, 11:34 AM
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;
}

InSain
23/02/2018, 06:55 PM
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;
}



Thank you, this helps. The only problem with the code is that it doesn't spit out the usage. I'll try and figure that out myself.