![]() |
Using Random() {Major Help needed}
Hey guys,
I'm trying to put together a script that will make an NPC warp from one location to a list of ~100 locations on a server. The locations will be pre-determined. That means that I will have a list of the level, x, and y position that the NPC will warp to. I just need to know how to make the NPC randomly select between these locations, and how it will warp there, etc. It will randomly choose from the specified list of levels every 5 minutes. I have very little scripting knowledge. I'm just trying to pull this together last-minute (needs to be done by tonight, ew). Any help would be tremendously helpful. So far, I've started scripting the NPC in a class script (I assumed this would be better than a level NPC). This is all I have so far: NPC Code: Almost certain none of the above is correct. Can anyone help me <3? |
I suggest putting it in a DBNPC since you're in a hurry. Doing so might be kinda ugly but eliminates a range of possible errors.
You can define the array of locations like this: PHP Code:
PHP Code:
I think warpto() is what you use for NPCs. PHP Code:
|
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:
PHP Code:
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:
|
HTML Code:
function warp() { |
Quote:
|
Oh, such as...?
|
Quote:
Your array of: PHP Code:
PHP Code:
PHP Code:
PHP Code:
The issue with this is all the implicit casting between arrays and strings, and it is essentially an abuse of the internal handling of data in GS2. In the midst of all this complexity, there is a lot of room for error and inefficiency. |
Quote:
PHP Code:
Quote:
|
Yes, when using an array with one element, it is totally broken. Seems to work with more than one well enough. And I didn't have any trouble with multi-dimensional arrays. But I would avoid it just on the single element array issue.
|
Hey guys, thanks for the help. Got it working :).
|
Quote:
|
Quote:
|
| All times are GMT +2. The time now is 11:00 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.