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 08-08-2010, 11:04 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Scripting questions

I've looked around, and I don't see anyone else asking these questions so I'll ask them here. Please try to answer my questions in the simplest form that you can. There will be multiple questions. And a attempt to make things easier, I'll post 1/2 of the script & function here, and ask questions below it.



In trying to make my questions clear and less missunderstood, I bolded the questions... So I hope there won't be no missunderstandings.



PHP Code:
function onTimeout(){ 

temp.= (player.vecx(player.dir) * 1.5) + this.origins(player.dir[0]);
temp.= (player.vecy(player.dir) * 4) + this.origins(player.dir[1]);

temp.angle = (pi 2) * (player.dir );

for(
temp.0this.bullets i ++)
shoot(xyzangle random((- this.spray), this.spray));


As some of you probably have obviously noticed already, theres quite a bit missing in the script. Note I have only left the portion of the script that I'm unsure of. And some pieces that possibly might help you answer my questions better.



Questions:

First off can someone explain "for"? I thought I had a good grip on what it means but I'm not sure anymore.



Note: this.bullets is how many shots fired/taken away from the gun.







Just to save trouble for posting later.. I'll ask about these too.

Whats the diffrence between player.x and vecx?




And most likely a dumb question but,

is random a event?

Not sure of its purpose but believe it to regulate the spread.



Last two questions...

And in temp.x , does(player.dir[1]) mean the first direction?



In (temp.angle = (pi / 2) * (player.dir + 1);

Also does player.dir + 1 mean the first direction?


If not what do they mean?


thanks to whoever reads this and tries to help me for your time.
Reply With Quote
  #2  
Old 08-08-2010, 01:33 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by khortez View Post
First off can someone explain "for"? I thought I had a good grip on what it means but I'm not sure anymore.
PHP Code:
for (ABC)
{
  
D;

In this sequence, A is run once. Then as long as the condition B is true, C and D will run continuously. For example:
PHP Code:
for (temp.0temp.3temp.++)
{
  echo(
temp.i);

… is a simple counter. It starts by setting temp.i = 0, and then as long as temp.i < 3, then it will run temp.i ++ (adding 1 onto temp.i) and then echoing the result.
Quote:
Whats the diffrence between player.x and vecx?
player.x is a variable containing the player's X position on the level. vecx() is a function which determines horizontal vectors.
Quote:
is random a event?
No, random(min, max) is a function which returns a random value which is somewhere between the given minimum and maximum values.
__________________
Skyld
Reply With Quote
  #3  
Old 08-08-2010, 01:48 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by khortez View Post
And in temp.x , does(player.dir[1]) mean the first direction?
No, it's erroneous and means nothing.

These are the directions in numbers:
0: Up
1: Left
2: Down
3: Right


Quote:
Originally Posted by khortez View Post
In (temp.angle = (pi / 2) * (player.dir + 1);

Also does player.dir + 1 mean the first direction?
No, it's the player's current direction plus one. The entire line is used to convert the player's current direction into an angle value so it can be used with shoot().
Reply With Quote
  #4  
Old 08-08-2010, 03:29 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
This might help with the for loop.


Quote:
Originally Posted by cbk1994 View Post
Let's say you have something like
PHP Code:
for (temp.010++) {
  echo(
i);
  
sleep(1);

It's going to output this in RC, with a one second delay between each number.

Quote:
0
1
2
3
4
5
6
7
8
9
What it does is loop through something a certain number of times.

PHP Code:
function countTo(numberdelay) {
  for (
temp.0number++) {
    echo(
i);
    
sleep(delay);
  }

would let you count to any number.

PHP Code:
temp.0;

for (
temp.05++) {
  
+= int(random(15));
  
sleep(0.5);

Here's what this would be doing in English.

Quote:
SET v TO 0
START FOR LOOP
SET n TO 0
SET v to 2
SLEEP .5 SECONDS
SET n TO 1
SET v to 3
SLEEP .5 SECONDS
SET n to 2
SET v to 6
SLEEP .5 SECONDS

[and all the way to 4]
Here's the basic structure.

PHP Code:
for (variable startvariable (inequalitymax/minvariable change) {
  
// code to be executed

so

PHP Code:
for (temp.30--) {
  echo(
x);

would say that x starts at 3. It would then execute the code in the middle by outputting '3'. Then, x is decreased to 2. It checks if 2 is more than 0, which it is, so it keeps going and executes the code. x now equals 1, which is more than 0, so it goes again. x now equals 0, which is not more than 0, so it breaks out of the for loop.


Another, different type of for loop is like a foreach loop in other languages. It's done like this:

PHP Code:
for (variable : array) {
  echo(
variable);

Arrays are defined like this

PHP Code:
temp.array = {"one""two""three""hello""world"}; 
which means you can also do

PHP Code:
for (variable : {"one""two""three""hello""world"}) {
  echo(
variable);

however, you need to specify a variable

PHP Code:
for (temp.number : array) {
  echo(
number);

would output

Quote:
one
two
three
hello
world
Be sure not to get the two types of for loops mixed up. The for each loop does the same thing as

PHP Code:
temp.array = {"one""two""three""hello""world"};

for (
temp.0< array.size(); ++) {
  
temp.variable = array[i];

__________________
Reply With Quote
  #5  
Old 08-09-2010, 01:31 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Alright thanks guys I think I understand it all now, gonna keep playing with scripts to get the best handle I can get on them. But thanks again.


Edit: messed up on something, it wasn't
PHP Code:
(player.direction[1]) 




it was:

PHP Code:
temp.= (player.vecx(player.dir) * 1.5) + this.origins[player.dir][0];

temp.= (player.vecx(player.dir) * 2) + this.origins[player.dir][1]; 

been doing quite a bit of editing to this script, trying to understand its functions and what not etc. And this wasn't copied/pasted. so yeah sorry about that. If someone could, could they re-explain those lines?

Last edited by khortez; 08-09-2010 at 05:24 AM..
Reply With Quote
  #6  
Old 08-09-2010, 10:43 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
so
PHP Code:
for (temp.010++) { 
  echo(
i); 

and
PHP Code:
for (temp.number : array) { 
  echo(
number); 

pretty much do the same thing and are just personal preference?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #7  
Old 08-09-2010, 01:38 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
that kind of depends on the array
Reply With Quote
  #8  
Old 08-09-2010, 06:48 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Or if you even want to loop through an array. It always depends on what you want to do.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #9  
Old 08-09-2010, 07:37 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by khortez View Post
Edit: messed up on something, it wasn't
PHP Code:
(player.direction[1]) 
it was:
PHP Code:
temp.= (player.vecx(player.dir) * 1.5) + this.origins[player.dir][0];

temp.= (player.vecx(player.dir) * 2) + this.origins[player.dir][1]; 
been doing quite a bit of editing to this script, trying to understand its functions and what not etc. And this wasn't copied/pasted. so yeah sorry about that. If someone could, could they re-explain those lines?
In that case, this.origins is a multi-dimensional array, sort of like matrices.

Arrays store multiple variables.
PHP Code:
temp.array = {"Hello""World""!"};
echo(array[
0SPC array[1] @ array[2]); 
The first line defines the array, containing the strings "Hello", "World", and "!".
The second line outputs "Hello World!" on RC. To get a specific variable from an array, you need [#], where the number inside braces ([]) relates to the position in the array starting at the lowest integer 0, so "Hello" is 0, "World" is 1, and "!" is 2.

Now for multi-dimensional arrays.
PHP Code:
temp.array = {{"Hello""World""!"}, {"Nice""day""we're""having""!"}};
echo(array[
0][0SPC array[0][1] @ array[0][1]);
echo(array[
1][0SPC array[1][1SPC array[1][2SPC array[1][3] @ array[1][4]); 
The first line defines the array, with as the first variable and another array as the second.
The second line outputs "Hello World!" on RC. It gets the first array's variables with array[0][#].
The third line outputs "Nice day we're having!" on RC. It gets the second array's variables with array[1][#].

Also, please stop with all the enters.



Quote:
Originally Posted by Jiroxys7 View Post
so
PHP Code:
for (temp.010++) { 
  echo(
i); 

and
PHP Code:
for (temp.number : array) { 
  echo(
number); 

pretty much do the same thing and are just personal preference?
For Loops
PHP Code:
for (ABC) {
  
D

Use A as a number to do D (or just to do D the amount of times between A with a C increase/decrease and B)

For-Each Loops
PHP Code:
for (B) {
  
C

Use A as each of the variables in B (array) in order to do C.

For-each loops are simplified from this.
PHP Code:
for (temp.i=0temp.i<array.size(); temp.i++) {
  
temp.= array[i];
  
//do things with v



Too much explaining...
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #10  
Old 08-10-2010, 08:34 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Quote:
Originally Posted by Switch View Post
In that case, this.origins is a multi-dimensional array, sort of like matrices.

Arrays store multiple variables.
PHP Code:
temp.array = {"Hello""World""!"};
echo(array[
0SPC array[1] @ array[2]); 
The first line defines the array, containing the strings "Hello", "World", and "!".
The second line outputs "Hello World!" on RC. To get a specific variable from an array, you need [#], where the number inside braces ([]) relates to the position in the array starting at the lowest integer 0, so "Hello" is 0, "World" is 1, and "!" is 2.

Now for multi-dimensional arrays.
PHP Code:
temp.array = {{"Hello""World""!"}, {"Nice""day""we're""having""!"}};
echo(array[
0][0SPC array[0][1] @ array[0][1]);
echo(array[
1][0SPC array[1][1SPC array[1][2SPC array[1][3] @ array[1][4]); 
The first line defines the array, with as the first variable and another array as the second.
The second line outputs "Hello World!" on RC. It gets the first array's variables with array[0][#].
The third line outputs "Nice day we're having!" on RC. It gets the second array's variables with array[1][#].

Also, please stop with all the enters.





For Loops
PHP Code:
for (ABC) {
  
D

Use A as a number to do D (or just to do D the amount of times between A with a C increase/decrease and B)

For-Each Loops
PHP Code:
for (B) {
  
C

Use A as each of the variables in B (array) in order to do C.

For-each loops are simplified from this.
PHP Code:
for (temp.i=0temp.i<array.size(); temp.i++) {
  
temp.= array[i];
  
//do things with v



Too much explaining...


Nothing wrong with that, helps people that don't know how to use 'for' and the uses of it understand it better. Also saves possible future questions. Thanks guys, all this helped a lot. Now I got one last thing fustrating me,

Now for me this is pretty pathetic on my part if I really did this wrong. Such a simple script. But not working for me.

I was trying to test my knowledge on arrays by making a list, and then having a specific variable be output in F2 in-game. That failed, so I went even simpler. Just to see if I was doing something wrong

This is what I did....

PHP Code:
//#CLIENTSIDE
function onPlayerChats(){
if(
player.chat == "/test")

echo(
"test");

I tried sendRPGMessage(); too like someone suggested, but that was a no-go.

I Also tried this server-side, and it worked, once? Out of the 5x i tried calling on it.

What did I mess up on?
Reply With Quote
  #11  
Old 08-11-2010, 08:26 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by khortez View Post
Nothing wrong with that, helps people that don't know how to use 'for' and the uses of it understand it better. Also saves possible future questions. Thanks guys, all this helped a lot. Now I got one last thing fustrating me,

Now for me this is pretty pathetic on my part if I really did this wrong. Such a simple script. But not working for me.

I was trying to test my knowledge on arrays by making a list, and then having a specific variable be output in F2 in-game. That failed, so I went even simpler. Just to see if I was doing something wrong

This is what I did....

PHP Code:
//#CLIENTSIDE
function onPlayerChats(){
if(
player.chat == "/test")

echo(
"test");

I tried sendRPGMessage(); too like someone suggested, but that was a no-go.

I Also tried this server-side, and it worked, once? Out of the 5x i tried calling on it.

What did I mess up on?
Is that exactly what it is in your script? I don't see a problem with it.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #12  
Old 08-11-2010, 09:25 PM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Yeah but it's alright now I think, had to delete most of my weapons for whatever script I created to work but, it seems to be working for now.
Reply With Quote
  #13  
Old 08-11-2010, 10:44 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Switch View Post
Is that exactly what it is in your script? I don't see a problem with it.
10 bucks he forgot to add it to himself.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
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:14 AM.


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