View Single Post
  #2  
Old 08-04-2008, 12:57 PM
AndMetal
Developer
 
Join Date: Mar 2007
Location: Ohio
Posts: 648
Default

As I understand it, this has to do with the data types that are being passed. $warp1 through $warp8 is a string, where SendTo is looking for 3 separate numbers. Essentially, you would need to use arrays or hashes. You could use nested data structures to create nested arrays, but because you kinda have to hack it to work (it's not as direct as PHP), it's real difficult. I was messing with it for a half hour and couldn't quite get it to do what I wanted it to do.

I think an easier way to do it would be to choose a random # first, in this case between 1 & 8, to see which location to warp to. This can be done one of 2 different ways:
Code:
my $rand = quest::ChooseRandom(1, 2, 3, 4, 5, 6, 7, 8);

my $rand = int(rand(8));
I honestly don't know if there is a real difference (read: weighting of the result depending on what was successful last time) between the two, so you should be fine with either.

Then run through IF statements for each one:
Code:
if ($rand == 1) {$npc->SendTo(212.9, 2628.3, 67.2)}
elsif ($rand == 2) {$npc->SendTo(220.8, 2708.3, 67.1)}
elsif ($rand == 3) {$npc->SendTo(258.9, 2712.3, 67.1)}
elsif ($rand == 4) {$npc->SendTo(243.3, 2658.4, 67.1)}
elsif ($rand == 5) {$npc->SendTo(223.8, 2658.4, 67.1)}
elsif ($rand == 6) {$npc->SendTo(271.9, 2604.8, 67.1)}
elsif ($rand == 7) {$npc->SendTo(318.4, 2678.8, 67.1)}
elsif ($rand == 8) {$npc->SendTo(370.4, 2677.7, 76.1)}
You can also do this using switch/case, which is normally much faster:
Code:
use Switch;

switch ($rand) {
	case 1 {$npc->SentTo(212.9, 2628.3, 67.2)}
	case 2 {$npc->SendTo(220.8, 2708.3, 67.1)}
	case 3 {$npc->SendTo(258.9, 2712.3, 67.1)}
	case 4 {$npc->SendTo(243.3, 2658.4, 67.1)}
	case 5 {$npc->SendTo(223.8, 2658.4, 67.1)}
	case 6 {$npc->SendTo(271.9, 2604.8, 67.1)}
	case 7 {$npc->SendTo(318.4, 2678.8, 67.1)}
	case 8 {$npc->SendTo(370.4, 2677.7, 76.1)}
};
This is probably better overall, especially since we're not working with extremely large data sets.

Anyway, hope this helps.
__________________
GM-Impossible of 'A work in progress'
A non-legit PEQ DB server
How to create your own non-legit server

My Contributions to the Wiki
Reply With Quote