Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 06-13-2007, 03:39 AM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default ChooseRandom issue:

I'm having problems getting this to work properly, and was hoping to catch a pointer from someone who would know. My intention is to create an aggro message chosen randomly from a list. I wanted to use the ChooseRandom feature and store all the possible phrases in variables, but I don't believe that you can store anything in a variable that isn't from the specific list found here.

The reason for all of this is to get the NPCs of the world saying the things they used to as you would aggro them. For example, each time a Guk froglok is aggro'd, he'll say 'Frrroooaaakkk!' along with another random phrase. ('I shall rid the land of another infamous villain.', 'Your foul deeds have earned my contempt.', etc.)

I know that this code is wrong, but it's the best that I could think of trying. Like I said, I believe that the problem is that those variables aren't in the list of defined ones, so I can't use them. Is there another way to go about this? I'm kind of embarrassed to show my crappy attempt at this, but I want to at least show that I've tried banging my head against the wall for awhile on it :(

Code:
sub EVENT_AGGRO {
  my $Phrase = quest::ChooseRandom($Phrase1,$Phrase2,$Phrase3,$Phrase4,$Phrase5,$Phrase6);
  $Phrase1 = 'Your faithless devotion to a false god leaves me no choice.'
  $Phrase2 = 'I shall rid the land of another infamous villain.'
  $Phrase3 = 'Your foul deeds have earned my contempt.'
  $Phrase4 = '${race}s like you are better left dead than alive.'
  $Phrase5 = 'It's ${class}s like you who have ruined your own lands, You'll not ruin mine!'
  $Phrase6 = 'Heathen! Unbeliever! Norrath must be cleansed!'
 quest::say('Frrroooaaakkk!');
 quest::say($Phrase);
}
Thanks for any help on this, guys. Once this is working, I can start knocking out a lot of the phrases I've pulled from this massive log file. Get ready to see a lot of your favorites back and working. ("an orc warrior says 'Orc stomp, Orc kill - Orc weapons your blood will spill.'" )

(Note: I know that in the code block above there's an inexplicable space in the middle of $Phrase4 on line 2, but it's correct when I type the post and I can't get rid of it for some reason. It's correct in my code as well, some odd sort of display error on the boards here.)
Reply With Quote
  #2  
Old 06-13-2007, 04:34 AM
sfisque
Hill Giant
 
Join Date: Oct 2006
Posts: 248
Default

assuming rand/srand dont work, you can do something like create "global variables" in the perl script of the
quest, something like:

Code:
$SEED = int( $npc->GetX() );
$NUMBER_OF_PHRASES = 7;
and then have a method like:

Code:
sub
generateRandom
{
    $SEED += int( $npc->GetX() );
    $SEED %= $NUMBER_OF_PHRASES;
    return $SEED;
}
and then you can do:

Code:
sub
EVENT_AGGRO
{
    quest::say( $PHRASE[ &generateRandom ] );
}
its not a perfect random number generator, but it should offer you a bootstrap until you can wire up a better random generator. you can try using srand/rand, but i do not know if they are exposed to the quest engine. you will have to redefine the phrases as an array for this (in either case) to work:

Code:
@PHRASE = 
(
    "phrase 1",
    "phrase 2", 
   # etc.
);
== sfisque

Last edited by sfisque; 06-13-2007 at 12:39 PM..
Reply With Quote
  #3  
Old 06-13-2007, 05:31 AM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default

Thank you for the idea. I'll see what I can do with it.
Reply With Quote
  #4  
Old 06-13-2007, 05:56 AM
sfisque
Hill Giant
 
Join Date: Oct 2006
Posts: 248
Default

NPNP

keep us posted on what you find (if srand/rand work or not) and stuff. i'm always eager to learn more about what the quest engine can handle.

== sfisque
Reply With Quote
  #5  
Old 06-13-2007, 01:57 PM
GeorgeS
Forum Guide
 
Join Date: Sep 2003
Location: California
Posts: 1,475
Default

In my quest editor there's an example where an npc walks around the zone randomly and returns to original spot. This is like a patrol, but is generated in a random manner. See the script example


GeorgeS

__________________
Your source for EQ database tools
Toolshop is open for business


http://www.georgestools.chrsschb.com//
Reply With Quote
  #6  
Old 06-14-2007, 03:52 AM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default

Thank you GeorgeS I wound up looking through most of the quest files included with that, and came across one (#2 that gave me an idea. I realized that I was perhaps putting too much thought into this.

I used a ChooseRandom with numbers 1-10, and just wrote ifs for each number. I stored the chosen value in the $a variable (since I wanted to test it with one that I knew would be recognized).

Well, I went a little further than that, and found that it will in fact let me use variables that I create myself (and thus aren't in the list here). I'm still new to writing in PERL, so I thought there were limitations from somewhere on what variables you could work with.

Anyway, here's what I wound up with, and it works pretty well. I'll be using this for every mob that I have aggro /say for, and it will have them give their standard aggro message along with a second one roughly 2/3 of the time. If they have a standard one that goes off each time (Frrroooaaakkk!), I'll just drop that at the top. Thank you so much for the help, both of you

Code:
sub EVENT_AGGRO{
 my $Phrase = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,0,0,0,0,0);
 quest::say('Frrroooaaakkk!');

if ($Phrase =~/1/) {
 quest::say("Your faithless devotion to a false god leaves me no choice.");
  }
if ($Phrase =~/2/) {
 quest::say("I shall rid the land of another infamous villain.");
  }
if ($Phrase =~/3/) {
 quest::say("Your foul deeds have earned my contempt.");
  }
if ($Phrase =~/4/) {
 quest::say("Your beliefs are an insult to us all!");
  }
if ($Phrase =~/5/) {
 quest::say("Your actions and history are a personal affront to all I stand for.");
  }
if ($Phrase =~/6/) {
 quest::say("${race}s like you are better left dead than alive.");
  }
if ($Phrase =~/7/) {
 quest::say("It's ${race}s like you who have ruined your own lands, You'll not ruin mine!");
  }
if ($Phrase =~/8/) {
 quest::say("It's time for you to take your blasphemy into the next realm.");
  }
if ($Phrase =~/9/) {
 quest::say("Your intolerable reputation insults all in this realm.");
  }
if ($Phrase =~/10/) {
 quest::say("${class}s like you are better left dead than alive.");
 }
}

#Submitted by: Jim Mills
(Note: Again, the board seems to be adding an extra space where it doesn't really belong inside of my code block. There are no spaces after the string of zeroes in the ChooseRandom when I enter this in, but they appear each time I preview my post. Quirky.)
Reply With Quote
  #7  
Old 06-14-2007, 10:13 PM
Budaworm
Fire Beetle
 
Join Date: Oct 2003
Posts: 20
Default

The way you had it written first works fine. You need to declare your variables first though. So if you write it like this:
Code:
sub EVENT_AGGRO {
my $Phrase1 = "Your faithless devotion to a false god leaves me no choice.";
my $Phrase2 = "I shall rid the land of another infamous villain.";
my $Phrase3 = "Your foul deeds have earned my contempt.";
my $Phrase4 = "${race}s like you are better left dead than alive.";
my $Phrase5 = "It's ${class}s like you who have ruined your own lands, You'll not ruin mine!";
my $Phrase6 = "Heathen! Unbeliever! Norrath must be cleansed!";
my $Phrase = quest::ChooseRandom($Phrase1, $Phrase2, $Phrase3, $Phrase4, $Phrase5, $Phrase6);
quest::say("Frrroooaaakkk!");
quest::say("$Phrase");
}
The mob will say the first message then say the randomly picked message. Looks much nicer and cleaner in your quest script.

Last edited by Budaworm; 06-15-2007 at 06:15 AM.. Reason: typos
Reply With Quote
  #8  
Old 06-15-2007, 12:55 AM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default

Haha, F. I didn't think about that =) No wonder all the /says were coming up as empty, it's because the variables were empty with the order it was executing. Doh =X

Okay, I think I'll go back to the way I was trying it originally, just because it's more compact. Thanks so much for all the help and ideas, all of you =)
Reply With Quote
  #9  
Old 06-15-2007, 04:58 AM
sfisque
Hill Giant
 
Join Date: Oct 2006
Posts: 248
Default

if you stuff them into a list, and just randomize the index, the code would be more modular and reusable across other mobs (you could even turn it into a plugin.pl type mod).

== sfisque
Reply With Quote
  #10  
Old 06-15-2007, 08:36 AM
EmanonCow
Sarnak
 
Join Date: Aug 2006
Posts: 35
Default

Quote:
Originally Posted by Budaworm
The way you had it written first works fine. You need to declare your variables first though. So if you write it like this:
Code:

The mob will say the first message then say the randomly picked message. Looks much nicer and cleaner in your quest script.
Cleaner solution:
Code:
sub EVENT_AGGRO {
	my @Phrases = (
		"Your faithless devotion to a false god leaves me no choice.",
		"I shall rid the land of another infamous villain.",
		"Your foul deeds have earned my contempt.",
		"${race}s like you are better left dead than alive.",
		"It's ${class}s like you who have ruined your own lands, You'll not ruin mine!",
		"Heathen! Unbeliever! Norrath must be cleansed!"
	);

	my $Phrase = quest::ChooseRandom(@Phrases);
	quest::say("Frrroooaaakkk!");
	quest::say("$Phrase");
}
I think that'll work, and you can add phrases to the list, and it automatically includes it in the random phrase pick.
Reply With Quote
  #11  
Old 06-15-2007, 11:22 PM
Budaworm
Fire Beetle
 
Join Date: Oct 2003
Posts: 20
Default

The method above looks even more compact but you gotta write it as
Code:
sub EVENT_AGGRO {
    my @Phrases = (
        "Your faithless devotion to a false god leaves me no choice.",
        "I shall rid the land of another infamous villain.",
        "Your foul deeds have earned my contempt.",
        "${race}s like you are better left dead than alive.",
        "It's ${class}s like you who have ruined your own lands, You'll not ruin mine!",
        "Heathen! Unbeliever! Norrath must be cleansed!"
    );
    quest::say("Frrroooaaakkk!");
    quest::say("$Phrases[int(rand($#Phrases+1))]");
}
to get it to work.
Reply With Quote
  #12  
Old 06-23-2007, 03:54 PM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default

Dammit. I had all of Guk working fine until I upgraded to the 1002 build, now I'm getting errors and no response from the frogs. Here's what I'm seeing in the error log:

Quote:
---------------------------------------------
[06.23. - 22:25:01] Starting Log: logs/eqemu_quest_zone_5488.log
[06.23. - 22:25:01] Tying perl output to eqemu logs
[06.23. - 22:25:01] Creating EQEmuIO=HASH(0x39d603c)
[06.23. - 22:25:01] Creating EQEmuIO=HASH(0x39efe60)
[06.23. - 22:25:01] Loading perlemb plugins.
[06.23. - 22:25:01] Loading perl commands...
[06.23. - 23:41:22] Useless use of a constant in void context at quests/poknowledge/#Yeril_Imsin.pl line 24.
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 8, near """Your"
[06.23. - 23:47:41] (Missing operator before Your?)
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 9, near "my $Phrase8 = "Your"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line
[06.23. - 23:47:41] (Do you need to predeclare my?)
[06.23. - 23:47:41] Unquoted string "stand" may clash with future reserved word at quests/gukbottom/a_ghoul_sentinel.pl line 9.
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 10, near "my $Phrase9 = "Your"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line 9)
[06.23. - 23:47:41] (Do you need to predeclare my?)
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 11, near "my $Phrase10 = "It's"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line 10)
[06.23. - 23:47:41] (Do you need to predeclare my?)
[06.23. - 23:47:41] Unquoted string "the" may clash with future reserved word at quests/gukbottom/a_ghoul_sentinel.pl line 11.
[06.23. - 23:47:41] Scalar found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 12, near "my $Phrase11 = "${race}"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line 11)
[06.23. - 23:47:41] (Do you need to predeclare my?)
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 12, near "s like you are better left dead than alive"
[06.23. - 23:47:41] (Do you need to predeclare s?)
[06.23. - 23:47:41] Unquoted string "ve" may clash with future reserved word at quests/gukbottom/a_ghoul_sentinel.pl line 12.
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 14, near "quest::say("Rrrrrrrrooooaaakkk"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line 12)
[06.23. - 23:47:41] Scalar found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 15, near "quest::say("$Phrase"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line 14)
[06.23. - 23:47:41] String found where operator expected at quests/gukbottom/a_ghoul_sentinel.pl line 15, at end of line
[06.23. - 23:47:41] (Missing semicolon on previous line?)
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_wan_ghoul_knight.pl line 8, near """Your"
[06.23. - 23:47:41] (Missing operator before Your?)
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_wan_ghoul_knight.pl line 9, near "my $Phrase8 = "Your"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line
[06.23. - 23:47:41] (Do you need to predeclare my?)
[06.23. - 23:47:41] Unquoted string "stand" may clash with future reserved word at quests/gukbottom/a_wan_ghoul_knight.pl line 9.
[06.23. - 23:47:41] Bareword found where operator expected at quests/gukbottom/a_wan_ghoul_knight.pl line 10, near "my $Phrase9 = "Your"
[06.23. - 23:47:41] (Might be a runaway multi-line "" string starting on line 9)
What'd we do wrong here?
Reply With Quote
  #13  
Old 06-23-2007, 06:03 PM
Bjerlk
Fire Beetle
 
Join Date: Apr 2007
Posts: 10
Default

Seems to be some differances in how you declare a parameter in te new version.
Check out how it has been changed in the changelog.

Maybe the string declaration (or what it now is) has ben changed to
$phrase8 := "yada yada";
Or similar. Check it out. There is the trouble it seems anyway since it errors on each of those code snipps...
Reply With Quote
  #14  
Old 06-24-2007, 07:55 AM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default

I checked the changelog, and there wasn't anything listed that would indicate these ever being changed. This is especially annoying, as I recently uploaded the whole batch for Upper and Lower Guk to PEQ's quest repository. Grrr. I think that when I have time (work is picking up; probably won't get the chance until next week at the earliest), I'll sit down and see if one of the other methods here will do the job without throwing me errors.

EmanonCow's code with Budaworm's correction looks like what I'll probably go with, but hopefully their version of things won't meet with the same errors that what I settled on did.
Reply With Quote
  #15  
Old 06-24-2007, 09:03 AM
Angelox
AX Classic Developer
 
Join Date: May 2006
Location: filler
Posts: 2,049
Default

Not part of the thread

Last edited by Angelox; 06-27-2007 at 07:26 AM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 07:01 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3