
09-26-2001, 02:40 AM
|
|
RadioActive Monkeeh
|
 |
Join Date: Apr 2001
Location: dirty south
Posts: 2,112
|
|
#e uses..
|
Im bored.. so I am going to teach some ppl how to do some neat things using #e..
I learned #e+indexof when I was doing vb (indexof is InStr .. and they also have InStrRev)
Also another thing which can be used with it, is indexof()
#e is used for doing string parsing .. like tokenize and so on..
it allows you to get part of a str .. for example:
setstring hellostring,hello how are you?;
setplayerprop #c,#e(0,3,#s(hellostring));
That would return "hello"
now you might say.. thats useless .. well its not!
for example ..
the bomy script when you say
command one -> command two
you can get the first part and second part easily with #e!
how?
using indexof and strlen it can be easily done
if (playerchats) {
this.indexof=indexof(->,#c);
if (this.indexof>=1) {
setstring command1,#T(#e(0,strlen(#c)-this.indexof,#c));
setstring command2,#T(#e(this.indexof+2,strlen(#c)-this.indexof,#c));
}
}
now to explain ..
I first got the indexof to a variable because i want to make the #e's shorter and also check to see if the player said
something->something
*indexof will return the location of the partstr specified in that string*
then I check to see if this.indexof is >= 1 .. why? because if the partstr does not appear in the string (if they said something that doesnt contain ->) it will return -1.. and I did >=1 because we want to ignore indexof if it is 0 (because that means they said ->something .. and not something->something)
after that we find the first part (before ->) using #e and strlen and the indexof..
command1 of course begins in the beggining so our startindex for #e in command1 will be 0.
the length of the string will be the length of what the player said minus indexof.
for example if the player said "kaka->kaka"
indexof -> will be 4 and strlen of #c will be 10
I did #T() which is trim .. it removes any spaced from the end/beggining of a string. it is useful there because the player could have said "whatever -> whatever"
and we wouldnt want our string to be "whatever " we want it without the space.
the second command is a bit more confusing .. since the startindex is not the beggining of a string, but after the ->
so the only change will be the startindex which will be this.indexof+2
why +2 ? well because the strlen of -> is 2. and if we just did this.indexof then it would return "->whatever" as the 2nd part.. and we dont want that!
so add +2 to eliminate the ->
there you go=)
now just use your imagination ..
here is a little code of something cool that can be done with #e (on UN the chat scroller is using #e.. but a little more complicated.. this is a simple scroller)
[code]
if (playerchats) {
while (strlen(#c)>0) {
sleep .2;
setplayerprop #c,#e(0,strlen(#c)-1,#c);
}
}
[code] |
Last edited by LiquidIce00; 09-26-2001 at 03:13 AM..
|
|
|