Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-12-2001, 05:30 AM
ShockwaveISTHEBEST ShockwaveISTHEBEST is offline
Registered User
Join Date: Nov 2001
Location: never never land
Posts: 208
ShockwaveISTHEBEST is on a distinguished road
Send a message via AIM to ShockwaveISTHEBEST Send a message via Yahoo to ShockwaveISTHEBEST
Looping

How do you make something loop. For instance.

if (playerenters) {
hide;
sleep 2;
show;
sleep 2;
}

How would i loop it?
Thanks. =]
__________________
[img]http://rick.*******ers.net/ss/users/jerrytyrrell64/Shockwave%20Sig%2003.jpg[/img]
Reply With Quote
  #2  
Old 12-12-2001, 05:33 AM
AlexH AlexH is offline
Have A Drink On Me
AlexH's Avatar
Join Date: Jun 2001
Location: Somewhere In Time
Posts: 7,442
AlexH is on a distinguished road
Send a message via AIM to AlexH Send a message via MSN to AlexH
use timeout
__________________
QUICK LOOK BUSY JESUS IS COMING!
Reply With Quote
  #3  
Old 12-12-2001, 05:38 AM
ShockwaveISTHEBEST ShockwaveISTHEBEST is offline
Registered User
Join Date: Nov 2001
Location: never never land
Posts: 208
ShockwaveISTHEBEST is on a distinguished road
Send a message via AIM to ShockwaveISTHEBEST Send a message via Yahoo to ShockwaveISTHEBEST
yes but could you help me out. I'm trying that, but i can't get it to work.
__________________
[img]http://rick.*******ers.net/ss/users/jerrytyrrell64/Shockwave%20Sig%2003.jpg[/img]
Reply With Quote
  #4  
Old 12-12-2001, 05:47 AM
btedji btedji is offline
bryan986
btedji's Avatar
Join Date: Apr 2001
Location: Force 10
Posts: 1,153
btedji is on a distinguished road
Send a message via ICQ to btedji Send a message via AIM to btedji Send a message via Yahoo to btedji
Re: Looping

Quote:
Originally posted by ShockwaveISTHEBEST
How do you make something loop. For instance.

if (playerenters) {
hide;
sleep 2;
show;
sleep 2;
}

How would i loop it?
Thanks. =]
NPC Code:

if (playerenters||timeout) {
hide;
sleep 2;
show;
sleep 2;
timeout=.05;
}



I will have timeouts in my script guide soon
Reply With Quote
  #5  
Old 12-12-2001, 05:51 AM
ShockwaveISTHEBEST ShockwaveISTHEBEST is offline
Registered User
Join Date: Nov 2001
Location: never never land
Posts: 208
ShockwaveISTHEBEST is on a distinguished road
Send a message via AIM to ShockwaveISTHEBEST Send a message via Yahoo to ShockwaveISTHEBEST
thanks
__________________
[img]http://rick.*******ers.net/ss/users/jerrytyrrell64/Shockwave%20Sig%2003.jpg[/img]
Reply With Quote
  #6  
Old 12-12-2001, 06:39 AM
T-Squad T-Squad is offline
Banned
T-Squad's Avatar
Join Date: Mar 2001
Location: United States of America
Posts: 1,733
T-Squad is on a distinguished road
Have you ever heard of timeout you complete *****. There is also while, which to loop that you could try sleep or break, but the falg you are using while with must be true for it to loop...
Reply With Quote
  #7  
Old 12-12-2001, 06:45 AM
AlexH AlexH is offline
Have A Drink On Me
AlexH's Avatar
Join Date: Jun 2001
Location: Somewhere In Time
Posts: 7,442
AlexH is on a distinguished road
Send a message via AIM to AlexH Send a message via MSN to AlexH
timeout is easy
but while wouldnt work the way he done it
while (playerenters) just doesnt work
__________________
QUICK LOOK BUSY JESUS IS COMING!
Reply With Quote
  #8  
Old 12-12-2001, 06:20 PM
cell424 cell424 is offline
Registered User
Join Date: Mar 2001
Location: USA/PA
Posts: 184
cell424 is on a distinguished road
Send a message via AIM to cell424
Red face

Very True. while isnt the best thing to use when using a script. You would have to set a flag and then use while (flagname) {script here; } and when you dont want it to loop any more unset the flagname.
__________________
Trunks
Reply With Quote
  #9  
Old 12-13-2001, 01:15 AM
Kumada Kumada is offline
Ded
Kumada's Avatar
Join Date: Nov 2001
Location: Usa
Posts: 1,088
Kumada is on a distinguished road
Re: Looping

Quote:
Originally posted by ShockwaveISTHEBEST
How do you make something loop. For instance.

if (playerenters) {
hide;
sleep 2;
show;
sleep 2;
}

How would i loop it?
Thanks. =]
BAHAHAHHAHHHHA
//#CLIENTSIDE
if (playerenters){
timeout=.05;
}

//#CLIENTSIDE
while (timeout){
hide;
sleep2;
show;
sleep .10;
}
__________________
Aim: Mmm Kumada

Reply With Quote
  #10  
Old 12-13-2001, 07:55 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Re: Re: Looping

Quote:
Originally posted by Kumada

BAHAHAHHAHHHHA
//#CLIENTSIDE
if (playerenters){
timeout=.05;
}

//#CLIENTSIDE
while (timeout){
hide;
sleep2;
show;
sleep .10;
}
The second //#CLIENTSIDE is unneccesary
Reply With Quote
  #11  
Old 12-13-2001, 08:25 PM
btedji btedji is offline
bryan986
btedji's Avatar
Join Date: Apr 2001
Location: Force 10
Posts: 1,153
btedji is on a distinguished road
Send a message via ICQ to btedji Send a message via AIM to btedji Send a message via Yahoo to btedji
timeout isnt a constant flag is set to true once only the moment it gets to 0 so a while loop with timeout wouldnt work
Reply With Quote
  #12  
Old 12-14-2001, 12:08 AM
Xaviar Xaviar is offline
Registered User
Join Date: Aug 2001
Location: Fairyland
Posts: 463
Xaviar is on a distinguished road
Send a message via ICQ to Xaviar Send a message via AIM to Xaviar
if (playerenters) timeout = .05;

if (timeout) {
if (visible) hide;
else
show;
timeout = 2;
}
__________________
One by one, the penguins steal my sanity.

*cookie for Xaviar* --Originally posted by Tyhm

--Xaviar

A m e r i c a
Reply With Quote
  #13  
Old 12-16-2001, 12:42 AM
mikepg mikepg is offline
Registered User
Join Date: Nov 2001
Location: VA, USA
Posts: 501
mikepg is on a distinguished road
Send a message via AIM to mikepg Send a message via Yahoo to mikepg
hmm

if possible, you want to stay away from sleep variables, because that stops everything in the NPC until the sleep is over. Try using something like this.sleep like this:

if (playerenters) {timeout = .1; show;
this.sleep=20;
this.on=1;
}

if (timeout) {
if (this.sleep>0) {this.sleep-=1;
}
if (this.sleep<=0) {this.sleep=20;
if (this.on=1) {this.on=0; hide;
}
if (this.on=0) {this.on=1; show;
}
}
timeout = .1;
}

That will make it so other flags can be unset/set while the sleep counter is going. If all you want to do in the npc is hide and show for some reason, use one of the previous scripts, other wise, if you have a lot of sleeping required, use this.vars so things are timed correctly.
also, since timeout is equal to 1/10th of a second, this.sleep=20 would wait 2 seconds, and then change. if the timeout was equal to .05 you might want to use 40 for this.sleep.

That about wraps it up.
__________________
~War Lord Mpg2
Bravo Online's Asst. Staff Manager

"Sittin by the tree, sippin eggnog, waitin on christmas gifts"
Reply With Quote
  #14  
Old 12-16-2001, 12:52 AM
Sennema Sennema is offline
Registered User
Join Date: Nov 2001
Location: Ontario, Canada
Posts: 132
Sennema is on a distinguished road
Send a message via ICQ to Sennema Send a message via AIM to Sennema
you could use:
NPC Code:

if (playerenters||timeout) {
hide;
sleep 2;
show;
timeout=2;
}



or, you could go for the less convenient option...

NPC Code:

if(strequals(#L,levelname)){
set onlevel;
}
while(onlevel){
hide;
sleep 2;
show;
sleep 2;
}



But the second is pointless. Use the first.
__________________
~Draemus Windblade


Just over 90% of all messages have no point or meaning.

"In order to preserve ourselves we seek out and eliminate anything that may do use harm. In doing so, we destroy things that, though possibly hazzardous, may be important to survival. So you see, in trying to save ourselves, we ultimately bring about our own destruction"


Luminar
Reply With Quote
  #15  
Old 12-16-2001, 01:40 AM
kyle0654 kyle0654 is offline
-. .`
kyle0654's Avatar
Join Date: Mar 2001
Posts: 1,000
kyle0654 will become famous soon enough
oye...why must idiots insult people who can't script as well as them and haven't done anything to deserve harsh words?

anyway...


timeout loops
NPC Code:

if (playerenters||timeout) {
hide;
sleep 2;
show;
sleep 2;
timeout = .05;
}



Timeout will make the timeout counter count down to 0 if you set it to anything above 0, and when it gets to 0, it will trigger a flag called timeout on the npc. If you place a timeout at the end of an if (timeout) statement, then it will loop.


while loops
NPC Code:

if (playerenters) {
while (1==1) {
hide;
sleep 2;
show;
sleep 2;
}
}



While is just like if, except when it finds a } it will go back to the while () and check the statement again. If the conditions in the brackets are still true, it will do the loop again. Otherwise, it will jump back to the } and continue with the script.

Above, I have while (1==1), which will create an infinite loop.


for loops
NPC Code:

if (playerenters) {
for (i = 0; i>=0; i++) {
hide;
sleep 2;
show;
sleep 2;
}
}



For is very useful, and most loops you encounter (that aren't timeout loops) will use for. If you have read the commands.rtf, you should notice that the syntax for for is something like:

for (initial; condition; increment) {

Now, the loop above could be written like this, and work the same way:
NPC Code:

if (playerenters) {
i = 0;
while (i>=0) {
hide;
sleep 2;
show;
sleep 2;
i++;
}
}


And, if you look at the debugger while playing (F6), you'll notice that your for loops are changed into while loops when they're processed by the scripting engine. The reason you use for though is because it's much easier to write, and is harder to mess up with.

The best advantage with for loops is that you can use the variable that is looping in your scripting. So, you could loop through an entire array and add all the numbers like this:
NPC Code:

if (playerenters) {
sum = 0;
myarray = {0,13,16,64,34};

for (i = 0; i < arraylen(myarray); i++) {
sum += myarray[i];
}

message #v(sum);
}


Now, I'll assume you don't know arrays since you're asking about loops, but just remember that loops can be very useful with arrays when you get to them.
Reply With Quote
  #16  
Old 12-16-2001, 03:35 AM
Xaviar Xaviar is offline
Registered User
Join Date: Aug 2001
Location: Fairyland
Posts: 463
Xaviar is on a distinguished road
Send a message via ICQ to Xaviar Send a message via AIM to Xaviar
Quote:
Originally posted by Xaviar
if (playerenters) timeout = .05;

if (timeout) {
if (visible) hide;
else
show;
timeout = 2;
}
__________________
One by one, the penguins steal my sanity.

*cookie for Xaviar* --Originally posted by Tyhm

--Xaviar

A m e r i c a
Reply With Quote
  #17  
Old 12-19-2001, 04:34 AM
ShockwaveISTHEBEST ShockwaveISTHEBEST is offline
Registered User
Join Date: Nov 2001
Location: never never land
Posts: 208
ShockwaveISTHEBEST is on a distinguished road
Send a message via AIM to ShockwaveISTHEBEST Send a message via Yahoo to ShockwaveISTHEBEST
Damn Kyle your good.
__________________
[img]http://rick.*******ers.net/ss/users/jerrytyrrell64/Shockwave%20Sig%2003.jpg[/img]
Reply With Quote
  #18  
Old 12-19-2001, 11:54 AM
Saga2001 Saga2001 is offline
Wishing he had 3 feet
Join Date: Aug 2001
Location: Basement
Posts: 1,565
Saga2001 is on a distinguished road
Send a message via ICQ to Saga2001 Send a message via AIM to Saga2001 Send a message via Yahoo to Saga2001
ummmm...

actually when it hits 0 it becomes true until a timeout is set again meaning this:
NPC Code:

if (playerenters) timeout=.05;
while (timeout) {
actions...
sleep .05;
}


would work...
__________________

!Wan ( 11:27:55 AM):
can i c ur scripts please?
Zorg (RC): If I hear NPC Server call Ne0, Past Austin or Brent sexy one more time im disconnecting it
Reply With Quote
  #19  
Old 12-20-2001, 11:52 PM
ShockwaveISTHEBEST ShockwaveISTHEBEST is offline
Registered User
Join Date: Nov 2001
Location: never never land
Posts: 208
ShockwaveISTHEBEST is on a distinguished road
Send a message via AIM to ShockwaveISTHEBEST Send a message via Yahoo to ShockwaveISTHEBEST
Oh I see thanks
__________________
[img]http://rick.*******ers.net/ss/users/jerrytyrrell64/Shockwave%20Sig%2003.jpg[/img]
Reply With Quote
  #20  
Old 12-21-2001, 11:44 AM
Warcaptain Warcaptain is offline
Banned
Warcaptain's Avatar
Join Date: Jun 2001
Location: Virginia, USA
Posts: 2,086
Warcaptain is on a distinguished road
Send a message via ICQ to Warcaptain Send a message via AIM to Warcaptain Send a message via Yahoo to Warcaptain
Quote:
Originally posted by cell424
Very True. while isnt the best thing to use when using a script. You would have to set a flag and then use while (flagname) {script here; } and when you dont want it to loop any more unset the flagname.
not really....
flag just means an event to call it.
NPC Code:

i=0;
while (i<10){
commands;
i++;
}



is same as
[code]
while (i=0;i<10;i++{
commands;
}
[/codes]

its just a lengthier version
same as

NPC Code:

if (i<10){
this.var=this.var+1;
}else this.var=0+1;


same as
NPC Code:

this.var=this.var%10+1;

Reply With Quote
  #21  
Old 12-21-2001, 12:48 PM
kyle0654 kyle0654 is offline
-. .`
kyle0654's Avatar
Join Date: Mar 2001
Posts: 1,000
kyle0654 will become famous soon enough
Not every flag triggers an NPC...in fact, many don't. If you callnpc it will though.
Reply With Quote
  #22  
Old 12-21-2001, 05:38 PM
nyghtGT nyghtGT is offline
Banned
nyghtGT's Avatar
Join Date: Jun 2001
Posts: 3,993
nyghtGT is on a distinguished road
Send a message via AIM to nyghtGT
ohh and if he did not know:
NPC Code:

NPC Code:

i=1;
while (i>=0) {
i++;
}

is the same as (does the same thing as):

for (i=0;i>=0;i++) {}




Reply With Quote
  #23  
Old 12-21-2001, 08:22 PM
btedji btedji is offline
bryan986
btedji's Avatar
Join Date: Apr 2001
Location: Force 10
Posts: 1,153
btedji is on a distinguished road
Send a message via ICQ to btedji Send a message via AIM to btedji Send a message via Yahoo to btedji
Quote:
Originally posted by nyghtGT
ohh and if he did not know:
NPC Code:

NPC Code:

i=1;
while (i>=0) {
i++;
}

is the same as (does the same thing as):

for (i=0;i>=0;i++) {}




Your not setting i to the same thing both times.
Reply With Quote
  #24  
Old 12-22-2001, 01:34 AM
ShockwaveISTHEBEST ShockwaveISTHEBEST is offline
Registered User
Join Date: Nov 2001
Location: never never land
Posts: 208
ShockwaveISTHEBEST is on a distinguished road
Send a message via AIM to ShockwaveISTHEBEST Send a message via Yahoo to ShockwaveISTHEBEST
How the hell did you guys learn to script I suck and then your all here putting leet scripts all over forums. I feel so inferior
__________________
[img]http://rick.*******ers.net/ss/users/jerrytyrrell64/Shockwave%20Sig%2003.jpg[/img]
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:56 AM.


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