Ok, I am goona bust this out supreme style...but I wanted to ask,, I have never used the callnpc command, so could someone tell me about it? Anyway, heres a supreme explanation of arrays. ;)
Arrays are basically values that contain other values, like a long string of numbers (unless unsing string arrays), that can be called and changed, it is one of the best ways I know of to keep organized. Also there are so many great values to arrays, you will end up using them in practiallcy every script. So what I will first define is the different ways to create your arrays. The first way is to actually use the setarray name,size; command.
NPC Code:
setarray this.rainx,100;
setarray this.rainy,100;
The second way of setting arrays is through curly brackets.
NPC Code:
this.rainx = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
this.rainy = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
The next thing I will discuss is getting and setting values of arrays. Ok, there are so many ways of actually setting the values, the first I will explain is the simple one.
NPC Code:
setarray this.rainx,100;
setarray this.rainy,100;
this.rainx[0] = 10;
this.rainx[1] = 15;
this.rainy[0] = 5;
this.rainy[1] = 10;
Something to always remember is that arrays start on the value 0 not 1, so the first value in the array is 0 and the last it the arraysize-1. The previous way of setting the array value is best for when setting only one or two values, the next way I will show you is a way for setting arrays when multiple values are needed
NPC Code:
this.rainx = {1,1,1,1,1,1,1,1,1,1};
This will set this.rainx with 10 values with 1 as each, this is a good way when having specific values that will be consistant thruout the script. The next thing I will explain is how to use a for loop to generate random values for an array using the arraylen() variable. If you call arraylen(this.rainx) on the previous example, it will return 10, because it measures how many values are in the array. So using this you could measure the size of an array with undefined values set with setarray; as in this example.
NPC Code:
setarray this.rainx,100;
for (i=0;i<arraylen(100);i++;)
this.rainx[i] = random(0,100);
The next thing I will explain is how to call array values, as in this example.
NPC Code:
setarray this.rainx,100;
for (i=0;i<arraylen(100);i++;) {
this.rainx[i] = random(0,100);
setplayerprop #c,#v(this.rainx[i]);
sleep .05;
}
So this correctly reads the value and sets the player's chat to the random value. The next thing I will exaplin is how to read values and act on them.
NPC Code:
setarray this.rainx,100;
for (i=0;i<arraylen(100);i++;)
this.rainx[i] = random(0,100);
if (this.rainx[5]>=3)
setplayerprop #c,this.rainx[5] is more than or equal to three, its exact value is #v(this.rainx[5]);
else
setplayerprop #c,this.rainx[5] is less than three, its exact value is #v(this.rainx[5]);
Another very little known fact, is that the value is set as it goes, so in this example, all values will be set correctly.
NPC Code:
this.rainx = {32,this.rainx[0]-10,this.rainx[0]-15};
This can be used very often when writing code that depends on other values. Also you can include conditions in arrays like so (if you don't know what a condition is, it can be an if statement or a block like this num = (a==0 ? 1 : 0) what this does is, if a equals 0 than num equals 1 otherwise it equals 0).
NPC Code:
this.rainx = {32,(this.rainx[0]>0 ? 1 : 0),this.rainx[0]-15};
I need to go now, so that is all I will explain for now, maybe later later. I hope that was useful.