Optinal multi params command using sscanf
#1

i need help please how to make an optional multi params command using sscanf like

* Kyro slaps 0 dont death match around a bit with a large trout.

will slap the player with reason dont death match

* Kyro slaps 0 around a bit with a large trout.

will slap the player with reason not specified

can any one help me please
Reply
#2

If you're using the sscanf plugin, use S (Capital).

If you're still using the old include, I would recommend that you switch to the plugin, if you can't, use z.
Reply
#3

yes iam using sscanf but look at this cmd ZCMD

Код:
CMD:slap(playerid, params[])
{
	    if(sscanf(params, "us[128]", pid, creason)) return SendClientMessage(playerid, Grey, "Usage:/slap <id> <reason>");
		else
		{
			GetPlayerPos(pid, X, Y, Z);
			SetPlayerPos(pid, X, Y, Z+6);
			new Float:Health;
			GetPlayerHealth(pid,Health);
			SetPlayerHealth(pid,Health-20);
			PlayerPlaySound(playerid,1190,0.0,0.0,0.0);
			PlayerPlaySound(pid,1190,0.0,0.0,0.0);
			GetPlayerName(playerid, pname, 24);
			GetPlayerName(pid, gname, 24);
			format(sc, sizeof(sc), "AdmCmd:%s(%d) Was slapped by admin %s reason: %s", gname, pid, pname, creason);
			SendClientMessageToAll(Red, sc);
		}
	return 1;
}
problem is that params has pid whick is the slapped player idk how to make the slapped player id cant be removed and the reason optional please help

YES IAM USING SSCANF

no other old shit plz
Reply
#4

I have given you sufficient information to help with your first question. For your second one, I have no idea what you are trying to say.
Reply
#5

slap command contains 2 params slapped player id and reason i wanna make reason optional but not slapped player id

Ex
* Kyro slaps around a bit with a large trout.
wrong return "usage bla bla"

* Kyro slaps 0 <dont blabla> around a bit with a large trout.
will slap him and send message with the reason

* Kyro slaps 0 around a bit with a large trout.

will do the same but without a reason

optional reason

i wanna make the reason param optional but not the slapped player id param

hope u understand
Reply
#6

I've already answered your question... Look at my first post. Just use S instead of s in your sscanf function.

To not send a message, make a check to see if your string is null, if it is, don't send anything.
Reply
#7

ok i made it like this

Код:
CMD:slap(playerid, params[])
{
	    if(sscanf(params, "uS[128]", pid, creason)) return SendClientMessage(playerid, Grey, "Usage:/slap <id> <reason>");
	    if(isnull(creason))
	    {
			GetPlayerPos(pid, X, Y, Z);
			SetPlayerPos(pid, X, Y, Z+6);
			new Float:Health;
			GetPlayerHealth(pid,Health);
			SetPlayerHealth(pid,Health-20);
			PlayerPlaySound(playerid,1190,0.0,0.0,0.0);
			PlayerPlaySound(pid,1190,0.0,0.0,0.0);
			GetPlayerName(playerid, pname, 24);
			GetPlayerName(pid, gname, 24);
			format(sc, sizeof(sc), "AdmCmd:%s(%d) Was slapped by admin %s reason: Not specified", gname, pid, pname);
			SendClientMessageToAll(Red, sc);
		}
		else
		{
			GetPlayerPos(pid, X, Y, Z);
			SetPlayerPos(pid, X, Y, Z+6);
			new Float:Health;
			GetPlayerHealth(pid,Health);
			SetPlayerHealth(pid,Health-20);
			PlayerPlaySound(playerid,1190,0.0,0.0,0.0);
			PlayerPlaySound(pid,1190,0.0,0.0,0.0);
			GetPlayerName(playerid, pname, 24);
			GetPlayerName(pid, gname, 24);
			format(sc, sizeof(sc), "AdmCmd:%s(%d) Was slapped by admin %s reason: %s", gname, pid, pname, creason);
			SendClientMessageToAll(Red, sc);
		}
	return 1;
}
but when i do /slap 0 <dontdo>

it do the slap cmd with reason dondo

but when i do /slap 0 after the cmd above

its the same

* Kyro slaps 0 around a bit with a large trout.

slap cmd with reason : <the same reason i wrote in /slap 0 <donto>

why?
Reply
#8

please any one help i really need to know how to make it works
Reply
#9

pawn Код:
CMD:slap( playerid, params[ ] )
{
    new ID,string[128],reason[66],Name[MAX_PLAYER_NAME],IdName[MAX_PLAYER_NAME],Float:x,Float:y,Float:z,Float:Health;
    if(sscanf(params, "uS(Not Specified)[65]", ID, reason)) return SendClientMessage(playerid, -1, "USAGE: /slap [PlayerID] [Reason]");
    else if(ID == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "[*] Enter a valid player ID/name!");
    GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(ID, IdName, sizeof(IdName));
    GetPlayerHealth(ID,Health);
    SetPlayerHealth(ID,Health-25);
    GetPlayerPos(ID,x,y,z);
    SetPlayerPos(ID,x,y,z+5);
    PlayerPlaySound(playerid,1190,0.0,0.0,0.0);
    PlayerPlaySound(ID,1190,0.0,0.0,0.0);
    format(string,sizeof(string),"You have been Slapped by Administrator %s | Reason: %s",IdName,reason);
    SendClientMessage(ID,-1,string);
    format(string,sizeof(string),"You have slapped %s | Reason: %s",IdName,reason);
    SendClientMessage(playerid,-1,string);
    return 1;
}
Reply
#10

omg clive i love u thanks so fcken much

it works thanks so much

james C thank u too

thanks guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)