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 11-03-2001, 05:41 AM
Vinvect Vinvect is offline
Registered User
Join Date: Aug 2001
Location: U.S.A,California,Milpitas,In A House,In Room,On A Seat,On a Computer
Posts: 157
Vinvect is on a distinguished road
Send a message via ICQ to Vinvect Send a message via Yahoo to Vinvect
Help Explaining for()

can someone explain what for()
is for and ow i use it? plz tell meh
__________________
==========================
I Script Really Good
&
Looking For A NAT Job
==========================
Quote:
That's like a big lugee!
-Evolution The Movie
Quote:
Ha Ha Ha Give It Up!
-Cyrus From Bomberman
I'm not a Bomy anymore.
I'm a MUTATED BROCLI MONSTER!
(or SIGN MONSTER)
If you make me angry,
I'LL EAT YOU WHOLE!
ME, MUTATED BROCLI MONSTER MASTER
(or SIGN MONSTER)
WILL EAT YOU ALL UP!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Quest Valley Owner
Looking For Staff
Pm Me
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
O.o Still Have My Braen Damaegd o.O


Thanks To Esiah, He Made This For Me!
Thanks Esiah!
Reply With Quote
  #2  
Old 11-03-2001, 05:53 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
A for loop is a counter driven loop, the syntax is for(var and starting value; condition to loop while true; increment) { commands to be executed }

So for instance,
NPC Code:

for (i = 0; i < 10; i++) {
playerx+=.5;
sleep .05;
}


will move the player 5 spaces to the right (.5 spaces, 10 times)

But don't use it like that, the best time to use it (In my opinion) is with arrays:
Say I've got a 5 element array, and I want to set each element to whereever it is in the array, + 1, so that the array will be {1, 2, 3, 4, 5} (the first element's index in an array is 0, remember) I would do this:

NPC Code:

for (i = 0; i < 5; i++) {
myarray[i] = i + 1;
}


Get it?
__________________
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
  #3  
Old 11-03-2001, 06:40 AM
Vinvect Vinvect is offline
Registered User
Join Date: Aug 2001
Location: U.S.A,California,Milpitas,In A House,In Room,On A Seat,On a Computer
Posts: 157
Vinvect is on a distinguished road
Send a message via ICQ to Vinvect Send a message via Yahoo to Vinvect
i dont get it still
__________________
==========================
I Script Really Good
&
Looking For A NAT Job
==========================
Quote:
That's like a big lugee!
-Evolution The Movie
Quote:
Ha Ha Ha Give It Up!
-Cyrus From Bomberman
I'm not a Bomy anymore.
I'm a MUTATED BROCLI MONSTER!
(or SIGN MONSTER)
If you make me angry,
I'LL EAT YOU WHOLE!
ME, MUTATED BROCLI MONSTER MASTER
(or SIGN MONSTER)
WILL EAT YOU ALL UP!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Quest Valley Owner
Looking For Staff
Pm Me
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
O.o Still Have My Braen Damaegd o.O


Thanks To Esiah, He Made This For Me!
Thanks Esiah!
Reply With Quote
  #4  
Old 11-03-2001, 08:13 AM
SSRobgeta SSRobgeta is offline
Ebil Cloud = l337 *kupo*
SSRobgeta's Avatar
Join Date: Aug 2001
Location: Monroeville, PA
Posts: 1,084
SSRobgeta is on a distinguished road
Send a message via AIM to SSRobgeta
A Quote:
One who dies... Well... Dies
__________________
Rob Getashu
Anyone can show you the way, but the real adventure is finding it yourself..
Reply With Quote
  #5  
Old 11-03-2001, 09:39 AM
TDO2000 TDO2000 is offline
Registered User
TDO2000's Avatar
Join Date: Jul 2001
Location: Germany
Posts: 655
TDO2000 is on a distinguished road
okkkk time for a TDO explanation ;D

sooo a for-loop is a possibility to do different things like:
getting every array, move npcs or just count something

an example

for(this.i=0;this.i < 5;this.i++){
playerx++;
}

this small code would move the player 5 fields to the right

explanation:
ok
for(this.i=0 ....
this is a starting value of a variable at the first time this.i will be 0

...;this.i < 5;...
and as long this.i is smaller the 5

...;this.i++){
this.i will get one added

so what it really does:
at the first time this.i is set to 0
it's smaller then 5
1 is added to this.i
the code in { } is executed with this.i=1
then back to the beginning
this.i is 1 so it's smaller then 5
so: this.i++ 1 is added to this.i and its 2
the code is executed with this.i = 2
and as long this.i is smaller then 5 the this.i gets 1 and the code is executed (so the playerx gets 5 times bigger)

so for arrays (don't want to explan arrays)
see this array: this.array={2,1,5,6};

if u had an array and wanted to check every element in it for a value (lets say if an element is 5) u can use a for loop

this.array={2,1,5,6};
this.lengt = arraylen(this.array); //this will get the elemts in the array

//now our checking for-loop
for(this.i=0;this.i < this.lenght;this.i++){
if(this.array[this.i]==5){
message Arraypos #v(this.i) is 5;
}
}

so the loop will start at the first array-pos (it's 0) and loop untill it got the full count of elements

It will start with 0
if(this.array[0]==5) //at the first time this.i would be 0
and check the first element of the array (here it's 2)
if this elemt is 5
==5
it would say: "Arraypos 0 is 5"
but because it's not 5 it will ignore this and add 1 to this.i
then the 2nd elemt of the array is checked etc.

Hope that's understandable
__________________
No Webhost at the moment
Reply With Quote
  #6  
Old 11-03-2001, 09:49 AM
Vinvect Vinvect is offline
Registered User
Join Date: Aug 2001
Location: U.S.A,California,Milpitas,In A House,In Room,On A Seat,On a Computer
Posts: 157
Vinvect is on a distinguished road
Send a message via ICQ to Vinvect Send a message via Yahoo to Vinvect
i understand the "for" part but not the "array" part
=/
__________________
==========================
I Script Really Good
&
Looking For A NAT Job
==========================
Quote:
That's like a big lugee!
-Evolution The Movie
Quote:
Ha Ha Ha Give It Up!
-Cyrus From Bomberman
I'm not a Bomy anymore.
I'm a MUTATED BROCLI MONSTER!
(or SIGN MONSTER)
If you make me angry,
I'LL EAT YOU WHOLE!
ME, MUTATED BROCLI MONSTER MASTER
(or SIGN MONSTER)
WILL EAT YOU ALL UP!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Quest Valley Owner
Looking For Staff
Pm Me
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
O.o Still Have My Braen Damaegd o.O


Thanks To Esiah, He Made This For Me!
Thanks Esiah!
Reply With Quote
  #7  
Old 11-03-2001, 09:51 AM
Slaktmaster Slaktmaster is offline
man with the mastahplan
Slaktmaster's Avatar
Join Date: Apr 2001
Location: Half-way over the river styx
Posts: 4,422
Slaktmaster is an unknown quantity at this point
Send a message via ICQ to Slaktmaster Send a message via AIM to Slaktmaster
Re: Help Explaining for()

Quote:
Originally posted by Vinvect
==========================
I Script Really Good
&
Looking For A NAT Job
==========================
Reply With Quote
  #8  
Old 11-03-2001, 09:58 AM
TDO2000 TDO2000 is offline
Registered User
TDO2000's Avatar
Join Date: Jul 2001
Location: Germany
Posts: 655
TDO2000 is on a distinguished road
Quote:
Originally posted by Vinvect
i understand the "for" part but not the "array" part
=/
I didn't want to explain the arrays just the for (I said it in the last post)
__________________
No Webhost at the moment
Reply With Quote
  #9  
Old 11-03-2001, 07:27 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
NPC Code:
if (playerenters) {
for (command1; flag; command2) {
Stuff;
}
}


If you run that in a script, command1 will be run, then while flag is true, stuff and command2 will be run. It would be the same as
NPC Code:
if (playerenters( {
command1;
while (flag) {
Stuff;
command2;
}
}


An example for moving a NPC:
NPC Code:
if (whatever) {
setcharani walk,;
for (this.destx = x+5; x<this.destx; x+= 0.5) {
sleep 0.05;
}
setcharani idle,;
}


Or killing all the policemen:
NPC Code:
if (weaponfired) {
for (i=0; i<playerscount; i++) {
if (strequals(#g(i),Police)) hitplayer i,40,x,y;
}
}

Reply With Quote
  #10  
Old 11-03-2001, 10:32 PM
Vinvect Vinvect is offline
Registered User
Join Date: Aug 2001
Location: U.S.A,California,Milpitas,In A House,In Room,On A Seat,On a Computer
Posts: 157
Vinvect is on a distinguished road
Send a message via ICQ to Vinvect Send a message via Yahoo to Vinvect
Re: Re: Help Explaining for()

Quote:
Originally posted by Slaktmaster
?
__________________
==========================
I Script Really Good
&
Looking For A NAT Job
==========================
Quote:
That's like a big lugee!
-Evolution The Movie
Quote:
Ha Ha Ha Give It Up!
-Cyrus From Bomberman
I'm not a Bomy anymore.
I'm a MUTATED BROCLI MONSTER!
(or SIGN MONSTER)
If you make me angry,
I'LL EAT YOU WHOLE!
ME, MUTATED BROCLI MONSTER MASTER
(or SIGN MONSTER)
WILL EAT YOU ALL UP!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Quest Valley Owner
Looking For Staff
Pm Me
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
O.o Still Have My Braen Damaegd o.O


Thanks To Esiah, He Made This For Me!
Thanks Esiah!
Reply With Quote
  #11  
Old 11-03-2001, 11:16 PM
LiquidIce00 LiquidIce00 is offline
RadioActive Monkeeh
LiquidIce00's Avatar
Join Date: Apr 2001
Location: dirty south
Posts: 2,112
LiquidIce00 is on a distinguished road
Send a message via ICQ to LiquidIce00 Send a message via AIM to LiquidIce00 Send a message via Yahoo to LiquidIce00
Quote:
Originally posted by Xaviar
But don't use it like that, the best time to use it (In my opinion) is with arrays:
[/code]
Actually i think its better using that for then doing

playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;

=)
and better then doing

while (this.i<10) {
this.i++;
playerx+=.5;
sleep .05;
}
__________________
LiquidIce *Owner* (UnholyNation)
-UN Website
http://www.unholynation.com
-UN Forum
http://forums.unholynation.com
-
-the thinker
-

-
onwall2 for nonp2p (i suck at onwall)
Reply With Quote
  #12  
Old 11-04-2001, 01:50 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 LiquidIce00


Actually i think its better using that for then doing

playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;
playerx+=.5;
sleep .05;

=)
and better then doing

while (this.i<10) {
this.i++;
playerx+=.5;
sleep .05;
}
Aye, but sleep isn't exactly the greatest command in the world, if you follow my meaning.
__________________
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 11-04-2001, 02:02 AM
Poogle Poogle is offline
Registered User
Poogle's Avatar
Join Date: Jun 2001
Posts: 2,471
Poogle is on a distinguished road
Sleep is one of them. Also set FLAG; while (flag) {//loop crap here}
Reply With Quote
  #14  
Old 11-04-2001, 02:04 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 Poogle
Sleep is one of them. Also set FLAG; while (flag) {//loop crap here}
*shrugs* I've seen worse...

if (playerenters) setlevel #L;
__________________
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
  #15  
Old 11-04-2001, 03:51 AM
TDO2000 TDO2000 is offline
Registered User
TDO2000's Avatar
Join Date: Jul 2001
Location: Germany
Posts: 655
TDO2000 is on a distinguished road
thats great:
if(playerenters){
while(true){
toweapons crap;
sleep .01;
}
}
__________________
No Webhost at the moment
Reply With Quote
  #16  
Old 11-04-2001, 04:22 AM
grim_squeaker_x grim_squeaker_x is offline
Retired Oldbie
grim_squeaker_x's Avatar
Join Date: Mar 2001
Posts: 3,084
grim_squeaker_x will become famous soon enough
Quote:
Originally posted by TDO2000
thats great:
if(playerenters){
while(true){
toweapons crap;
sleep .01;
}
}
Nah, you should name it /crap that has far funner effects on someone's weapon list.
__________________

Reply With Quote
  #17  
Old 11-04-2001, 04:29 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
NPC Code:
if (playerenters) {
while (true) {
while (true) toweapons #v(random(0,10));
sleep 0.05;
}
}

This would be cool if you could use message codes in weapon names
Reply With Quote
  #18  
Old 11-04-2001, 05:30 AM
TDO2000 TDO2000 is offline
Registered User
TDO2000's Avatar
Join Date: Jul 2001
Location: Germany
Posts: 655
TDO2000 is on a distinguished road
and that's why u can't use messagecodes in weaponnames
__________________
No Webhost at the moment
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 08:52 AM.


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