Find string in array - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Find string in array (
/showthread.php?tid=152629)
Find string in array -
clavador - 05.06.2010
Hi!
I'm trying to make a chat with a bot and I don't know how to find a string inside an array, for example:
Quote:
new Chat[4][128] =
{
"hi",
"how are you?",
"hello",
"ajsdknjsd"
};
if(strfind(text, SEARCH_ARRAY_OF_ANSWERS) != -1) <- I want to check the "Chat" array for the possible answers a player can make. I dont wanna be full of "if" or "elses"
|
Anyone got a clue?
Re: Find string in array -
clavador - 05.06.2010
Any one has a clue?
My FS depends on this :P
There's has to be a way of doing this!
Re: Find string in array -
DJDhan - 05.06.2010
Code:
new Chat[4][128] =
{
"hi",
"how are you?",
"hello",
"ajsdknjsd"
};
Code:
new i,j;
for(i=0;i<4,i++)
{
for(j=0;j<128,j++)
{
if(!strcmp(cmdtext,Chat[i][j],false) return SendClientMessage(playerid,0xffffffaa,"You are answer wasn't understood by me Sir.");
//then your script here
}
}
I am not sure coz I learned C++ and maybe it might work. Try something like that.
Re: Find string in array -
Calgon - 05.06.2010
Could use
strlib (by Westie), there's a specific function for this.
Re: Find string in array -
RyDeR` - 05.06.2010
pawn Code:
new
Array[][] =
{
"Hi",
"How are you?",
"Hello",
"ajsdknjsd"
}
;
pawn Code:
new
x
;
for(;;)
{
//printf("%s", Array[x]);
if(strfind(Array[x], "Hi") != -1)
{
// The rest of you code
}
if(x > sizeof(Array)) break;
x++;
}
Re: Find string in array -
clavador - 05.06.2010
Quote:
Originally Posted by Calgon
Could use strlib (by Westie), there's a specific function for this.
|
That worked great!
Thanks everybody!