SA-MP Forums Archive
strfind inputtext - 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: strfind inputtext (/showthread.php?tid=647674)



strfind inputtext - maksicnm - 08.01.2018

Code:
Код HTML:
if(dialogid == DIALOG_ADUTY)
	{
		if(!response) return 1;
		if(response)
		{
			if(strfind(inputtext) == PI[playerid][pKod]) //Warning here
			{
				new string[128];
				SetPlayerArmour(playerid, 100.0);
				g_SetPlayerHealth(playerid, 100.0);
				SetPlayerColor(playerid,AZUTA);
				format(string, sizeof(string), ""CRVENA"AG-AC | "BELA"Admin "HZELENA"%s "BELA"je na duznosti! (Admin Level %d)", GetName(playerid), PI[playerid][pAdmin]);
				AdminGameMaster(-1, string);
				AdminDuty[playerid] = 1;
			}
			else
			{
				SCM(playerid, -1, ""CRVENA"AG-AC | "BELA"Pogresili ste kod, kikovani ste!");
				freeze[playerid] = SetTimerEx("KonektKick", 500, 0, "d", playerid);
			}
		}
	}
Problem:
Код HTML:
warning 202: number of arguments does not match definition
And when i go IG, i input code but dialog does nothing


Re: strfind inputtext - MEW273 - 08.01.2018

That is not how you use strfind, see below example:
https://sampwiki.blast.hk/wiki/Strfind
Код:
if(strfind("Are you in here?", "you", true) != -1) //returns 4, because the start of 'you' (y) is at index 4 in the string
{
    SendClientMessageToAll(0xFFFFFFFF, "I found you!");
}
If I am reading your code correctly it should be this:
Код:
if(strfind(inputtext, PI[playerid][pKod], false) != -1)



Re: strfind inputtext - Misiur - 08.01.2018

If compiler shows you warnings (yes, not errors, warnings), don't ignore them because in most cases this usually means broken code.

https://sampwiki.blast.hk/wiki/Strfind

pawn Код:
if(strfind(inputtext, PI[playerid][pKod]) != -1)



Re: strfind inputtext - maksicnm - 08.01.2018

Quote:
Originally Posted by Misiur
Посмотреть сообщение
If compiler shows you warnings (yes, not errors, warnings), don't ignore them because in most cases this usually means broken code.

https://sampwiki.blast.hk/wiki/Strfind

pawn Код:
if(strfind(inputtext, PI[playerid][pKod]) != -1)
I need this to be same as pKod, not different, because when i enter admin code, it kicks me and say its wrong...
Actually, any code i enter it says wrong code...


Re: strfind inputtext - MEW273 - 08.01.2018

The code we both provided above will check if pKod and inputtext are the same, or technically if pKod string exists within inputtext.

Replace your code:
Код:
if(strfind(inputtext) == PI[playerid][pKod]) //Warning here
With this code:
Код:
if(strfind(inputtext, PI[playerid][pKod]) != -1)



Re: strfind inputtext - Misiur - 08.01.2018

Oh, however you should use strcmp for this, not strfind (then "12345" won't work if the code is "1234")


Re: strfind inputtext - maksicnm - 08.01.2018

Код HTML:
if(dialogid == DIALOG_ADUTY)
	{
		if(!response) return 1;
		if(response)
		{
			if(strcmp(inputtext, PI[playerid][pKod]) != -1)
			{
				new string[128];
				SetPlayerArmour(playerid, 100.0);
				g_SetPlayerHealth(playerid, 100.0);
				SetPlayerColor(playerid,AZUTA);
				format(string, sizeof(string), ""CRVENA"AG-AC | "BELA"Admin "HZELENA"%s "BELA"je na duznosti! (Admin Level %d)", GetName(playerid), PI[playerid][pAdmin]);
				AdminGameMaster(-1, string);
				AdminDuty[playerid] = 1;
			}
			else
			{
				SCM(playerid, -1, ""CRVENA"AG-AC | "BELA"Pogresili ste kod, kikovani ste!");
				freeze[playerid] = SetTimerEx("KonektKick", 500, 0, "d", playerid);
			}
		}
	}
I make it like this, but it still says that admin code is wrong and kicks me out, code is 942 ( every player have one in .ini )


Re: strfind inputtext - MEW273 - 08.01.2018

Try debugging the code to make sure that inputtext and pKod are actually being set correctly:
Код:
printf("inputtext is %s", inputtext);
printf("pKod is %s", PI[playerid][pKod]); 
if(strcmp(inputtext, PI[playerid][pKod]) != -1)
			{
Try this code and when you enter the code in game then check the server log to see what values are printed.

Could there be an issue with how you're loading pKod?


Re: strfind inputtext - Misiur - 08.01.2018

Strcmp is a little different, you have to check if the return IS 0. So
pawn Код:
if(strcmp(inputtext, PI[playerid][pKod]) == 0)
Or
pawn Код:
if(!strcmp(inputtext, PI[playerid][pKod]))



Re: strfind inputtext - maksicnm - 08.01.2018

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Strcmp is a little different, you have to check if the return IS 0. So
pawn Код:
if(strcmp(inputtext, PI[playerid][pKod]) == 0)
Or
pawn Код:
if(!strcmp(inputtext, PI[playerid][pKod]))
Tryied with if(!strcmp(inputtext, PI[playerid][pKod]))
And result is still same ( NO )