View Single Post
  #3  
Old 03-17-2010, 12:14 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Edit: Appears I'm a couple minutes late..

For arrays inside arrays (multi-dimensional) you need to wrap { }'s around them like so:

PHP Code:
temp.array = {
  {
"innerarray""member"},
  {
"another""array"}
}; 
You can then use random, and the size of the array to pick a random array out of it.

PHP Code:
function onCreated() {
  
temp.examplearray = {
    {
"a""b""c"},
    {
"d""e""f"}
  };
  
temp.randomindex int(random(0temp.examplearray.size()));
  
temp.example temp.examplearray[temp.randomindex];

int(value) - Rounds the number (technically it converts it to an integer, but this is the result) to the number below it. I.e: int(3.8) = 3

random(float min, float max) - Picks a number between the minimum and maximum number, it will/should never equal the max value.

Therefore int(random(0, temp.array.size())) will return a valid index in the array.

To move NPCs you have to use warpto which accepts the same parameters as setlevel2.

warpto(str levelname, float x, float y);

When we put it altogether we get a nice little function like so:

PHP Code:
function warp() {
  
// Declare Locations Array
  
temp.locations = {
    {
"onlinestartlocal.nw"3030},
    {
"someotherlevel.nw"3030}
  };
  
// Select a location
  
temp.location temp.locations[int(random(0temp.locations.size()))];
  
// Warpto Location
  
warpto(temp.location[0], temp.location[1], temp.location[2]);
  
// Update (Forces NPC to save changes, probably not needed but whatever)
  
this.trigger("NPCUpdate""");

__________________
Quote:
Reply With Quote