Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Teaching: for() (https://forums.graalonline.com/forums/showthread.php?t=47776)

Mal1core 09-07-2003 08:57 PM

Teaching: for()
 
for those of you who are new like me and dont know how the for command it used, its like saying:


i=0//the index is equil to zero
while(i<64)//this is like adding to the if(), saying the index must be less then 64.
and then the last section is adding or subtracting forom the index.
so all together it looks like:

for(i=0; i<64; i+=2;){
in here u may put commands. i will also give one example of how this may be used.

if(created){toweapons test;
}
if(weaponfired){
for(explosionx=playerx; explosionx<64 explosionx+=1.5;)
putexplosion 1,explosionx,playery+1;
}
}

this script is a little messed up but does show a little how to use for.

note: props to jagen for teaching me what for's are, and also if someone can show me how to put in a scripting section to make this easier to read it would be greatly apreciated.

Python523 09-07-2003 09:44 PM

Re: Teaching: for()
 
Quote:

Originally posted by Mal1core
for those of you who are new like me and dont know how the for command it used, its like saying:


if (i=0)//if the index is equil to zero it will perform the command
while(i<#)//this is like adding to the if(), saying the index must be less then 64.
and then the last section is adding or subtracting forom the index.
so all together it looks like:

for(i=0; i<64; i+=2;){
in here u may put commands. i will also give one example of how this may be used.

if(created){toweapons test;
}
if(weaponfired){
for(explosionx=playerx; explosionx<64 explosionx+=1.5;)
putexplosion 1,explosionx,playery+1;
}
}

this script is a little messed up but does show a little how to use for.

note: props to jagen for teaching me what for's are, and also if someone can show me how to put in a scriting section to make this easier to read it would be greatly apreciated.

you misunderstood me x_X its
i=0;
while(i<#) i++;
not if(i=0)

Mal1core 09-07-2003 09:59 PM

oh yeah, i messed up, lol.

CheeToS2 09-08-2003 02:48 AM

>.>

format:
for (initialization-operation;test;increment-operation){
commands;
}
(don't kill me if I got the words wrong, they still make sense >:O)

initialization-operation = what happens right before the loop begins for the first time.

test = what the loop will check and make sure is true before going onto the next loop.

increment-operation = what happens after one loop completes

EXAMPLE:
for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}

OUTPUT:
I CAN COUNT: 0!
I CAN COUNT: 1!
I CAN COUNT: 2!
I CAN COUNT: 3!
I CAN COUNT: 4!
I CAN COUNT: 5!
I CAN COUNT: 6!
I CAN COUNT: 7!
I CAN COUNT: 8!
I CAN COUNT: 9!

WHAT IT MEANS:
for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}
i=0 makes it set the variable "i" to 0 before beginning the loop.

for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}
i<10 checks whether or not the variable "i" is less than 10 before beginning the loop

for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}
i++ makes the variable "i" increase by 1 after a loop completes.


ORDER OF OPERATIONS:
i is set to 0
checks whether or not i is less than 10
if i is less than 10, sets players' chat text to "I CAN COUNT: <value of i>!
increases i by 1
checks whether or not i is less than 10
if i is less than 10, sets players' chat text to "I CAN COUNT: <value of i>!
...and so on



Some people may be confused why it never outputs "I CAN COUNT: 10!".. thats because the test checks if its less than 10, meaning it will not actually include 10. If you wanted to include 10, you could make the test "i<11" or "i<=10"

Riot-Starter 09-08-2003 02:52 AM

Quote:

Originally posted by CheeToS2
* setplayerprop #c,I CAN COUNT: #v(i)!;

Double check syntax if not using the test button in the editer ;)

Mal1core 09-08-2003 02:55 AM

this should get stickied along with detailed explainations of other comands when they pop up.... and cheetos, im not exactly sure some people know like, initializing opertation and such, most do but i wouldnt be surprised if they didnt, anyway, there u have it folks, 2 nice and detailed explainations of for loops :D

// NPC made by Malicore (Hybrid)
if (created) {toweapons BOOMY;
}
if (playertouchsme) {
}
if(weaponfired && dir=3
){
for(explosionx=playerx+5; explosionx<playerx+15; explosionx+=1.5;){
sleep .1;
putexplosion 1,explosionx,playery+1;
}
}
if(weaponfired && dir=1){
for(explosionx2=playerx-5; explosionx2>playerx-15; explosionx2-=1.5;){
sleep .1;
putexplosion 1,explosionx2,playery+1;
}
}
if(weaponfired && dir=0){
for(explosiony=playery-5; explosiony>playery-15; explosiony-=1.5;){
sleep .1;
putexplosion 1,playerx+1,explosiony;
}
}
if(weaponfired && dir=2){
for(explosiony2=playery+5; explosiony2<playery+15; explosiony2+=1.5;){
sleep .1;
putexplosion 1,playerx+1,explosiony2;
}
}

i am now working on controlling the fire :D

Dach 09-08-2003 03:20 AM

Quote:

Originally posted by Mal1core
lookie ^
icky-icky doo-doo

Mal1core 09-08-2003 03:42 AM

:confused: huh?

Riot-Starter 09-08-2003 04:10 AM

Quote:

Originally posted by Mal1core
:confused: huh?
Hes saying the code uses bad format and inefficient coding.

CheeToS2 09-08-2003 04:19 AM

woops, haha, I was in a rush while typing that so I could finish my homework *fix* (they all have the same error cause I copy/pasted ;o)

Tseng 09-08-2003 04:21 AM

Quote:

Originally posted by Mal1core
[snip]toweapons BOOMY;[/snip]
Use toweapons in a script online, and die.

Mal1core 09-08-2003 05:23 AM

Quote:

Originally posted by Tseng


Use toweapons in a script online, and die.

i have no experiance serverside, what would i replace it with?

CheeToS2 09-08-2003 05:26 AM

Quote:

Originally posted by Mal1core


i have no experiance serverside, what would i replace it with?

In NC (the 4 green buttons on the bottom-right of RC, above the chat box), click the second button (the big red W), that will open the Database weapons list. Click add, set the weapon's icon, put the script in there, take out any playertouchsme & toweapons stuff, and put //#CLIENTSIDE at the top, click send.
to get the weapon, use addweapon WeaponName; in a script

-Ramirez- 09-08-2003 05:44 AM

Quote:

Originally posted by Tseng


Use toweapons in a script online, and die.

I guess I should go die then. *points at Classic*

CheeToS2 09-08-2003 01:12 PM

Quote:

Originally posted by -Ramirez-

I guess I should go die then. *points at Classic*

except classic :p

Tseng 09-08-2003 03:40 PM

Quote:

Originally posted by -Ramirez-

I guess I should go die then. *points at Classic*

Yes, you should. :p

-Ramirez- 09-08-2003 07:20 PM

Quote:

Originally posted by Tseng


Yes, you should. :p

:(

Tseng 09-08-2003 07:30 PM

Quote:

Originally posted by -Ramirez-

:(

Make your new weapons for NPC-Server. :(

-Ramirez- 09-08-2003 08:46 PM

Quote:

Originally posted by Tseng


Make your new weapons for NPC-Server. :(

I haven't added any new permanent weapons, just messing around with the clientside-only scripting when I was first hired.


All times are GMT +2. The time now is 09:48 AM.

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