Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Position of strings (https://forums.graalonline.com/forums/showthread.php?t=55067)

ZeroTrack 08-25-2004 03:37 PM

Position of strings
 
Im just messing around wondering how would i get the postion of a string without tokenizeing the string... i've tried lindexof , indexof and triming the string and getting the var of each ... but none work, indexof was the closest thing to it but it gave the positon of the first letter in the entire string so say if i had
this.parts = one,two,three
indexof would give me 1,4,7
if it helps this is what i put when i trimed the string
NPC Code:

if(actionserverside)
sendtonc Debug:#p(0);
//#CLIENTSIDE
if(created){
setstring this.parts,skin,coat,sleeves,shoes,belt;
}
if(playerchats){
tokenize #c;
if(strcontains(#s(this.parts),#t(0))){
triggeraction 0,0,serverside,Player/Taylor,#e(indexof(#t(0),#s(this.parts)),strlen(#t( 0)),#s(this.parts))
,;
}
}


that gets me the string but i want the position of the string in the list
and this is with indexof
NPC Code:

if(actionserverside)
sendtonc Debug:#p(0);
//#CLIENTSIDE
if(created){
setstring this.parts,skin,coat,sleeves,shoes,belt;
}
if(playerchats){
tokenize #c;
if(strcontains(#s(this.parts),#t(0))){
triggeraction 0,0,serverside,Player/Taylor,#v(indexof(#t(0),#s(this.parts)))
,;
}
}


ZeroTrack 08-25-2004 11:08 PM

anyyone... aannyyyonneee? =(

calum 08-25-2004 11:13 PM

1. Stop double posting, it is something that i see you do frequently.
2. Have you tried using 'addstring' and using '#I'?

falco10291029 08-25-2004 11:13 PM

Explain a little further what u r trying to do...

ZeroTrack 08-25-2004 11:41 PM

Quote:

Originally Posted by calum
1. Stop double posting, it is something that i see you do frequently.

No i havent
Quote:

Originally Posted by calum
2. Have you tried using 'addstring' and using '#I'?

and yes i have

middo 08-26-2004 12:13 AM

#I is the way to go

I don't see why it wouldn't have worked.

ZeroTrack 08-26-2004 12:28 AM

Quote:

Originally Posted by middo
#I is the way to go

I don't see why it wouldn't have worked.

i've tried that but i need the interger not the string

Lance 08-26-2004 12:29 AM

lindexof(string,stringlist)

ZeroTrack 08-26-2004 12:53 AM

Quote:

Originally Posted by Lance
lindexof(string,stringlist)

tried that already see
Quote:

Originally Posted by ZeroTrack
i've tried lindexof , indexof and triming the string and getting the var of each ... but none work


falco10291029 08-26-2004 03:08 AM

wait how do you usae #I?

xManiamaNx 08-26-2004 03:46 AM

#I(string,token);
setstring this.foo,bar,asdf,fhqwhgads
#I(this.foo,2) = asdf

falco10291029 08-26-2004 04:49 AM

i got it thanks

osrs 08-26-2004 05:27 AM

NPC Code:

if(created){
setstring this.string,Welcome,to,graal,forums;
setstring this.search,forums;
}

if(playerenters){
pos = lindexof(#s(this.search),this.string);
if(pos>=0) message Word found at position: #v(pos);
else message Word not found;
}



I will explain it anyway:

NPC Code:

if(created){
setstring this.string,Welcome,to,graal,forums; // string list of course
setstring this.search,forums; // the word you're searching
}



That string (this.string) is divided into 4 pieces, you count the pieces since the number 0. (same method of triggeraction and other commands), so:
Welcome - piece 0
to - piece 1
graal - piece 2
forums - piece 3

NPC Code:

if(playerenters){
pos = lindexof(#s(this.search),this.string);
if(pos>=0) message Word found at position: #v(lindexof(#s(this.search),this.string));
else message Word not found;
}



I presume you know how lindexof work, so, create a variable (you don't really need it, but i like to) to hold the value of the lindexof(), just check if it is >= 0 and voalá, here is your example script.
Hope this help, took me - 5 minutes of sleep, good night. n_n'

Lance 08-26-2004 06:27 AM

Quote:

Originally Posted by ZeroTrack
tried that already see

Then you're doing something wrong...?

ZeroTrack 08-26-2004 05:11 PM

Quote:

Originally Posted by Lance
Then you're doing something wrong...?

no im not i did excatly this it was the first thing i tried
NPC Code:

if(actionserverside)
sendtonc Debug:#p(0);
//#CLIENTSIDE
if(created){
setstring this.parts,skin,coat,sleeves,shoes,belt;
}
if(playerchats){
tokenize #c;
if(strcontains(#s(this.parts),#t(0))){
triggeraction 0,0,serverside,Player/Taylor,#v(lindexof(#t(0),this.parts));
}
}


Lance 08-26-2004 05:43 PM

Quote:

Originally Posted by ZeroTrack
no im not i did excatly this it was the first thing i tried
NPC Code:

if(actionserverside)
sendtonc Debug:#p(0);
//#CLIENTSIDE
if(created){
setstring this.parts,skin,coat,sleeves,shoes,belt;
}
if(playerchats){
tokenize #c;
if(strcontains(#s(this.parts),#t(0))){
triggeraction 0,0,serverside,Player/Taylor,#v(lindexof(#t(0),this.parts));
}
}


It works perfectly, even though you should not be using strcontains...?

ZeroTrack 08-26-2004 06:58 PM

.. i reset the npcserver and it started working, and yes thats there for the taylor part
finshed script... no stealing please
NPC Code:

//#CLIENTSIDE
if(created)
setstring this.parts,skin,coat,sleeves,shoes,belt;

if(playerchats){
tokenize #c;
if(strcontains(#s(this.parts),#t(0))){
part=lindexof(#t(0),this.parts);
if(part=0)
setplayerprop #C0,#t(1);
if(part=1)
setplayerprop #C1,#t(1);
if(part=2)
setplayerprop #C2,#t(1);
if(part=3)
setplayerprop #C3,#t(1);
if(part=4)
setplayerprop #C4,#t(1);
}
}


osrs 08-26-2004 07:43 PM

NPC Code:

//#CLIENTSIDE

if(created){
setstring this.parts,skin,coat,sleeves,shoes,belt;
}

if(playerchats){
tokenize #c;
pos = lindexof(#t(0),this.parts);
if(pos>=0){
if(startswith(#t(0),#c)){
setplayerprop #c,[#I(this.parts,pos) was changed to color #t(1)];
if(pos == 0) setplayerprop #C0,#t(1);
if(pos == 1) setplayerprop #C1,#t(1);
if(pos == 2) setplayerprop #C2,#t(1);
if(pos == 3) setplayerprop #C3,#t(1);
if(pos == 4) setplayerprop #C4,#t(1);
}
}
}



Too simple, please try to understand the code and feel free to use it. :)

Crono 08-26-2004 07:53 PM

Quote:

Originally Posted by osrs
Too simple

You've got to be kidding O_O;

osrs 08-26-2004 07:59 PM

Quote:

Originally Posted by Gerami
You've got to be kidding O_O;

Things are simple when you want to learn & work hard to progress instead of look for help every time.


All times are GMT +2. The time now is 06:37 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.