Graal Forums

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

khortez 08-08-2010 11:04 AM

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.

Skyld 08-08-2010 01:33 PM

Quote:

Originally Posted by khortez (Post 1592094)
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.

DrakilorP2P 08-08-2010 01:48 PM

Quote:

Originally Posted by khortez (Post 1592094)
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 (Post 1592094)
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().

cbk1994 08-08-2010 03:29 PM

This might help with the for loop.


Quote:

Originally Posted by cbk1994 (Post 1493584)
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];




khortez 08-09-2010 01:31 AM

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?

Jiroxys7 08-09-2010 10:43 AM

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?

Loriel 08-09-2010 01:38 PM

that kind of depends on the array

adam 08-09-2010 06:48 PM

Or if you even want to loop through an array. It always depends on what you want to do.

Switch 08-09-2010 07:37 PM

Quote:

Originally Posted by khortez (Post 1592275)
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 (Post 1592355)
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...

khortez 08-10-2010 08:34 AM

Quote:

Originally Posted by Switch (Post 1592420)
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?

Switch 08-11-2010 08:26 PM

Quote:

Originally Posted by khortez (Post 1592541)
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.

khortez 08-11-2010 09:25 PM

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.

Deas_Voice 08-11-2010 10:44 PM

Quote:

Originally Posted by Switch (Post 1592860)
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.


All times are GMT +2. The time now is 01:58 AM.

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