SA-MP Forums Archive
Doubt with Command. - 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: Doubt with Command. (/showthread.php?tid=640139)



Doubt with Command. - Shaheen - 28.08.2017

Hai,
So i am making a puzzle roberry and ended up in a doubt.

so here it goes.
Код:
CMD:crack(playerid, params[])
{
new num1,num2,num3;
if(sscanf(params,"iii", num1,num2,num3)) 
{
    SendClientMessage(playerid,Color_Red,"Incorrect Usage");
}
return 1;
}
so here when i type /crack 1 2 3 - These spaces i have to remove. so it should look like /crack 123

and second doubt.
if i just type this letters by pressing "t" is there any way i can get or assign this variable to num1,num2 and num3 ??

thnx in advance


Re: Doubt with Command. - Misiur - 28.08.2017

You can't, there must be some kind of separator. I'd suggest you use sscanf to get a string[3], then just
pawn Код:
new num1 = yourstring[0];
if (!('0' <= num1 <= '9')) return SCM(playerid, -1, "Invalid param 1");
num1 = num1 - 48;
new num2 = yourstring[1];
// And so on



Re: Doubt with Command. - Shaheen - 28.08.2017

Okay so for eg: if a player enter checkpoint and if he open chat box and typed 123. so is there anyway to get 1=num1 , 2=num2 , 3=num3 ??
I hope u understood !


Re: Doubt with Command. - 10MIN - 28.08.2017

Yup. Also I have seen this on a server. Declare 2 arrays:
Код:
new bool:g_crack[MAX_PLAYERS]; //Used 'g' just to make sure there are no conflicts
new code[MAX_PLAYERS][3];
//Somewhere in CMD:crack

bool:g_crack(playerid) = true;
//Somewhere on OnPlayerText:

if(g_crack[playerid])
{
   code[playerid][0] = strval(text[0]);
   code[playerid][1] = strval(text[1]);
   code[playerid][2] = strval(text[2]);
}
Or some parts of this crap can be writen as:
Код:
new code[MAX_PLAYERS];

//OnPlayerText:

if(g_crack[playerid] && strlen(text) == 3)  code[MAX_PLAYERS] = strval(text);
This should work.
E: Didn't seen misiur's answer


Re: Doubt with Command. - Misiur - 28.08.2017

The code I wrote _is_ already getting you num1 num2 num3 (add length check for a good measure). But 10MiN code might be clearer for you.


Re: Doubt with Command. - Shaheen - 28.08.2017

and whatabout without using commands. if i want to use it while onplayerentercheckpoint.

Edit Reped to Both..


Re: Doubt with Command. - Shaheen - 28.08.2017

anyway to use this in a checkpoint instead of a command ??


Re: Doubt with Command. - Misiur - 28.08.2017

? From what you've said you want checkpoint -> dialog - then just either method we showed you on inputtext