Question about a command -
K9IsGodly - 02.01.2014
So I have a simple /setlevel command setup:
Код:
CMD:setlevel(playerid,params[])
{
SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
SendClientMessage(playerid, COLOR_RED, "Your level has been set!");
return 1;
}
How do I make it so it's more like /setlevel [playerid] [level] versus just going up by one level and having it done to yourself only?
Re: Question about a command -
GiamPy. - 02.01.2014
If you use sscanf, this is how it should be.
pawn Код:
CMD:setlevel(playerid,params[])
{
new userid, level;
if(sscanf(params, "ui", userid, level))
return SendClientMessage(playerid, -1, "/setlevel [playerid/partofname] [level]");
if(!IsPlayerConnected(userid))
return SendClientMessage(playerid, -1, "The user is offline.");
SetPlayerScore(userid, GetPlayerScore(userid)+level);
SendClientMessage(playerid, COLOR_RED, "The level has been set.");
return 1;
}
Re: Question about a command -
Hansrutger - 02.01.2014
https://sampforum.blast.hk/showthread.php?tid=120356
That should help your situation.
In a if-statement:
sscanf(params, ""Specifiers"", variable1, variable2))
sscanf will check anything that is after /cmd [here...] [and here] [and here] [etc...]
If nothing is written the if-statement will be true. Read about specifiers on the thread and you'll see what I mean, also look at the examples.
The "params" in the sscanf means the params you use in zcmd for instance:
CMD:yourCmd(playerid,
params[])
Re: Question about a command -
K9IsGodly - 02.01.2014
Yeah I do use sscanf. I have a question though, as I am quite new to scripting pawn, when you put "ui" what does that do? I've seen it several times but I don't understand what the "i" or "ui" is. Is "i" integer or something?
Re: Question about a command -
Hansrutger - 02.01.2014
Quote:
Originally Posted by K9IsGodly
Yeah I do use sscanf. I have a question though, as I am quite new to scripting pawn, when you put "ui" what does that do? I've seen it several times but I don't understand what the "i" or "ui" is. Is "i" integer or something?
|
Read about specifiers. u is the an ID. i is an integer. Get used to these as they are used elsewhere, like %i is integer as well. s (for sscanf) and %s (for for instance format) are strings.
Re: Question about a command -
GiamPy. - 02.01.2014
Quote:
Originally Posted by K9IsGodly
Yeah I do use sscanf. I have a question though, as I am quite new to scripting pawn, when you put "ui" what does that do? I've seen it several times but I don't understand what the "i" or "ui" is. Is "i" integer or something?
|
Specifier(s) | Name | Example values |
b | Binary | 01001, 0b1100 |
c | Character | a, o, * |
f | Float | 0.7, -99.5 |
g | IEEE Float | 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E |
h, x | Hex | 1A, 0x23 |
i, d | Integer | 1, 42, -10 |
l | Logical | true, false |
n | Number | 42, 0b010, 0xAC, 045 |
o | Octal | 045 12 |
q | Bot name/id | ShopBot, 27 |
r | Player name/id | ******, 42 |
u | User name/id (bots and players) | ******, 0 |
Re: Question about a command -
K9IsGodly - 02.01.2014
Quote:
Originally Posted by GiamPy.
If you use sscanf, this is how it should be.
pawn Код:
CMD:setlevel(playerid,params[]) { new userid, level; if(sscanf(params, "ui", userid, level) return SendClientMessage(playerid, -1, "/setlevel [playerid/partofname] [level]"); if(!IsPlayerConnected(userid)) return SendClientMessage(playerid, -1, "The user is offline."); SetPlayerScore(userid, GetPlayerScore(userid)+level); SendClientMessage(playerid, COLOR_RED, "The level has been set."); return 1; }
|
I used this code and tried to compile it, but I got this error:
Код:
C:\Users\Nolan\Desktop\Scripting Stuff\Sa-Mp Pawn\Pawn Scripting\pawno\Roleplayscript.pwn(376) : error 001: expected token: ")", but found "return"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Re: Question about a command -
GiamPy. - 02.01.2014
Yes, because by mistake I have missed out a ) in the code.
If you look at the post again, I have edited it with that thing fixed.
Re: Question about a command -
K9IsGodly - 02.01.2014
Quote:
Originally Posted by GiamPy.
Yes, because by mistake I have missed out a ) in the code.
If you look at the post again, I have edited it with that thing fixed.
|
Yeah it worked now. Thanks man!