Multiple parameter help (sscanf) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multiple parameter help (sscanf) (
/showthread.php?tid=381741)
Multiple parameter help (sscanf) -
2KY - 30.09.2012
pawn Код:
CMD:wear( playerid, params[] )
{
/*
Slot 0 - Hats, caps.
*/
if( strcmp( params, "policecap", false ) == 0 )
{
if( plStats [ playerid ] [ HasAPoliceCap ] == 1 )
{
SetPlayerAttachedObject( playerid, 0, 18636, 2 );
EditAttachedObject( playerid, 0 );
}
else return ShowPlayerErrorMessage( playerid, "You don't have a \"Police Cap\"!" );
}
if( strcmp( params, "beret", false ) == 0 )
{
new
colour [ 32 ];
strdel( params, 0, 5 );
if( sscanf( params, "s[32]", colour ) )
return SendClientMessage( playerid, Colour_RankOrange, "HELP: "#Int_White"/wear beret [ colour (red, black, blue, army) ]" );
if( strcmp( colour, "red", false ) == 0 )
{
SetPlayerAttachedObject( playerid, 0, 18922, 2 );
EditAttachedObject( playerid, 0 );
}
else return ShowPlayerErrorMessage( playerid, "Invalid colour!" );
}
return true;
}
I had this working a while ago, problem is, now it's not lol. The problem is located in the 'beret' part of this, and I'm assuming has something to do with my strdel. Any ideas?
Re: Multiple parameter help (sscanf) -
mamorunl - 30.09.2012
pawn Код:
CMD:wear( playerid, params[] )
{
/*
Slot 0 - Hats, caps.
*/
new colour[32], object[40];
if(!sscanf(params, "s[40]S[32], object, colour)) {
if(!strcmp(object, "policecap")) {
if( plStats [ playerid ] [ HasAPoliceCap ] == 1 )
{
SetPlayerAttachedObject( playerid, 0, 18636, 2 );
EditAttachedObject( playerid, 0 );
}
else return ShowPlayerErrorMessage( playerid, "You don't have a \"Police Cap\"!" );
} elseif(!strcmp(object, "beret")) {
if(strlen(colour) == 0) return SendClientMessage( playerid, Colour_RankOrange, "HELP: "#Int_White"/wear beret [ colour (red, black, blue, army) ]" );
if(!strcmp(colour, "red")) {
SetPlayerAttachedObject( playerid, 0, 18922, 2 );
EditAttachedObject( playerid, 0 );
}
else return ShowPlayerErrorMessage( playerid, "Invalid colour!" );
}
}
return true;
}
This reduces your code a huge bit. Explanation:
s[40]S[32] - a capital s is an optional string. It can be taken in at your beret colour.
Then we check the object (which we took from the first param) and enter the code. Then checking the length of colour. if it is 0, then no colour is given and thus we throw the error, else,, you continue with your own code. For the rest, I didn't come across anything else that looked a little dodgey