|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quests::Q&A This is the quest support section |
|
|
|
08-04-2008, 04:56 AM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Using Variables in Quest Objects
For some reason, I can't seem to get this working. It seems like variables don't work in quest objects. I have tried many different combinations to get this working, but none seem to do what I want. Basically, I want the NPC to gate to one of the 8 possible locations when they are attacked.
This first code doesn't work at all, even though it seems to me like it should:
Code:
sub EVENT_ATTACK {
my $warp1 = "212.9, 2628.3, 67.2";
my $warp2 = "220.8, 2708.3, 67.1";
my $warp3 = "258.9, 2712.3, 67.1";
my $warp4 = "243.3, 2658.4, 67.1";
my $warp5 = "223.8, 2658.4, 67.1";
my $warp6 = "271.9, 2604.8, 67.1";
my $warp7 = "318.4, 2678.8, 67.1";
my $warp8 = "370.4, 2677.7, 76.1";
my $gate = quest::ChooseRandom($warp1,$warp2,$warp3,$warp4,$warp5,$warp6,$warp7,$warp8);
$npc->SendTo($gate);
}
This second version doesn't work right either, but at least it does something. Basically, it always teleports the NPC to the $warp8 location. I am guessing it is just executing all of the 8 locations and ends up on the last one. I don't know why it is executing these even though I am only trying to define them as a variable at that point. It definitely doesn't seem to want to use the random command properly to work for quest objects. I guess they don't mix well?
Code:
sub EVENT_ATTACK {
my $warp1 = $npc->SendTo(212.9, 2628.3, 67.2);
my $warp2 = $npc->SendTo(220.8, 2708.3, 67.1);
my $warp3 = $npc->SendTo(258.9, 2712.3, 67.1);
my $warp4 = $npc->SendTo(243.3, 2658.4, 67.1);
my $warp5 = $npc->SendTo(223.8, 2658.4, 67.1);
my $warp6 = $npc->SendTo(271.9, 2604.8, 67.1);
my $warp7 = $npc->SendTo(318.4, 2678.8, 67.1);
my $warp8 = $npc->SendTo(370.4, 2677.7, 76.1);
quest::ChooseRandom($warp1,$warp2,$warp3,$warp4,$warp5,$warp6,$warp7,$warp8);
}
I know the random part it working for locations, cause I have pulled out what it is selecting by adding this into the script:
Code:
quest::say("Trying to move to loc, $gate");
This isn't the full encounter I am planning to make, but until I can get this part working, I can't complete the rest of it.
Last edited by trevius; 08-04-2008 at 12:58 PM..
|
|
|
|
|
|
|
08-04-2008, 12:57 PM
|
Developer
|
|
Join Date: Mar 2007
Location: Ohio
Posts: 648
|
|
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.
|
|
|
|
08-04-2008, 02:25 PM
|
Developer
|
|
Join Date: Jul 2007
Location: my own little world
Posts: 751
|
|
try this
Code:
sub EVENT_ATTACK {
my @warp1 = (212.9, 2628.3, 67.2);
my @warp2 = (220.8, 2708.3, 67.1);
my @warp3 = (258.9, 2712.3, 67.1);
my @warp4 = (243.3, 2658.4, 67.1);
my @warp5 = (223.8, 2658.4, 67.1);
my @warp6 = (271.9, 2604.8, 67.1);
my @warp7 = (318.4, 2678.8, 67.1);
my @warp8 = (370.4, 2677.7, 76.1);
my $x, $y, $z;
($x, $y, $z)=quest::ChooseRandom(@warp1,@warp2,@warp3,@warp4,@warp5,@warp6,@warp7,@warp8);
$npc->SendTo($x, $y, $z);
}
|
08-04-2008, 04:36 PM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Thanks guys! I will give those a try and see how they work out. I appreciate the details on what is happening, AndMetal! I think it is time for me to go through some perl tutorials or something lol. If I had a better understanding of the basics, I probably wouldn't need so much help when trying to use it, lol.
I guess my main problem is that I try not to learn too much at once and I just started studying C Coding a bit. I think understanding C and Perl will be 2 things that will help me get a better understanding of what is going on for the emu and should let me be much more helpful around here.
|
08-05-2008, 11:01 PM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Finally got it working with AndMetals code. Thanks!
Code:
sub EVENT_ATTACK {
my $rand = quest::ChooseRandom(1, 2, 3, 4, 5, 6, 7, 8);
if ($rand == 1) {$npc->SendTo(212.9, 2628.3, 67.2)}
if ($rand == 2) {$npc->SendTo(220.8, 2708.3, 67.1)}
if ($rand == 3) {$npc->SendTo(258.9, 2712.3, 67.1)}
if ($rand == 4) {$npc->SendTo(243.3, 2658.4, 67.1)}
if ($rand == 5) {$npc->SendTo(223.8, 2658.4, 67.1)}
if ($rand == 6) {$npc->SendTo(271.9, 2604.8, 67.1)}
if ($rand == 7) {$npc->SendTo(318.4, 2678.8, 67.1)}
if ($rand == 8) {$npc->SendTo(370.4, 2677.7, 76.1)}
}
The other 2 suggestions in this thread didn't seem to work though. Maybe I was missing something.
|
08-06-2008, 01:37 PM
|
Developer
|
|
Join Date: Jul 2007
Location: my own little world
Posts: 751
|
|
I didn't fully test this for you, it looks like I messed up the "my" part of declaring the variables $x, $y and $z. Here's the fix (i think, still didn't test it).
@ is perl for array and each /loc is an array that gets loaded into x,y,z from
the chooserandom function
Code:
sub EVENT_ATTACK {
my @warp1 = (212.9, 2628.3, 67.2);
my @warp2 = (220.8, 2708.3, 67.1);
my @warp3 = (258.9, 2712.3, 67.1);
my @warp4 = (243.3, 2658.4, 67.1);
my @warp5 = (223.8, 2658.4, 67.1);
my @warp6 = (271.9, 2604.8, 67.1);
my @warp7 = (318.4, 2678.8, 67.1);
my @warp8 = (370.4, 2677.7, 76.1);
my($x, $y, $z)=quest::ChooseRandom(@warp1,@warp2,@warp3,@warp4,@warp5,@warp6,@warp7,@warp8);
$npc->SendTo($x, $y, $z);
}
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 03:46 AM.
|
|
|
|
|
|
|
|
|
|
|
|
|