PDA

View Full Version : ChooseRandom issue:


So_1337
06-13-2007, 03:39 AM
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 (http://www.eqemulator.net/wiki/wikka.php?wakka=QuestTutorial#variables).

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 :(

sub EVENT_AGGRO {
my $Phrase = quest::ChooseRandom($Phrase1,$Phrase2,$Phrase3,$Ph rase4,$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.)

sfisque
06-13-2007, 04:34 AM
assuming rand/srand dont work, you can do something like create "global variables" in the perl script of the
quest, something like:


$SEED = int( $npc->GetX() );
$NUMBER_OF_PHRASES = 7;


and then have a method like:


sub
generateRandom
{
$SEED += int( $npc->GetX() );
$SEED %= $NUMBER_OF_PHRASES;
return $SEED;
}


and then you can do:


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:


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


== sfisque

So_1337
06-13-2007, 05:31 AM
Thank you for the idea. I'll see what I can do with it.

sfisque
06-13-2007, 05:56 AM
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

GeorgeS
06-13-2007, 01:57 PM
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

So_1337
06-14-2007, 03:52 AM
Thank you GeorgeS :) I wound up looking through most of the quest files included with that, and came across one (#28) 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 (http://www.eqemulator.net/wiki/wikka.php?wakka=QuestTutorial#variables)). 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 :)

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.)

Budaworm
06-14-2007, 10:13 PM
The way you had it written first works fine. You need to declare your variables first though. So if you write it like this: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.

So_1337
06-15-2007, 12:55 AM
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 =)

sfisque
06-15-2007, 04:58 AM
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

EmanonCow
06-15-2007, 08:36 AM
The way you had it written first works fine. You need to declare your variables first though. So if you write it like this:

The mob will say the first message then say the randomly picked message. Looks much nicer and cleaner in your quest script.

Cleaner solution:

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.

Budaworm
06-15-2007, 11:22 PM
The method above looks even more compact but you gotta write it as 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.

So_1337
06-23-2007, 03:54 PM
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:

---------------------------------------------
[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 8)
[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 8)
[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?

Bjerlk
06-23-2007, 06:03 PM
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...

So_1337
06-24-2007, 07:55 AM
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.

Angelox
06-24-2007, 09:03 AM
Not part of the thread

fathernitwit
06-26-2007, 05:22 PM
The method above looks even more compact but you gotta write it as
quest::say("$Phrases[int(rand($#Phrases+1))]");
} to get it to work.

Just to prevent confusion, this is exactly what ChooseRandom was written to avoid... its just too ugly, and shouldent be nescesary.

Also, nothing changed about quests recently that I am aware of... maybe you upgraded perl versions?

So_1337
06-26-2007, 11:26 PM
Hrm. Nope. Only moved from 992 to 1002.

I'm out of town and pretty busy until at least after the 4th, so I haven't had a chance to delve into this any further. My main goal is just to go back to a method that works so that I can at least edit all the files that I dropped into the PEQ quest submission area. I was running trains of screaming frogloks before, so I know it worked at that point.

So_1337
01-15-2008, 05:59 AM
I never did post back here, and figured I'd bump this in case anyone has any input to offer or issues they notice with it. The only issue that I'm concerned with is that it's quite a big block of text to be jamming every file with that I intend to do, but it's the best way I know of to get things working.

The final version that I've been working with looks like this below:

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 = "${class}s like you are better left dead than alive.";
my $Phrase5 = "It's ${races}s like you who have ruined your own lands, You'll not ruin mine!";
my $Phrase6 = "Heathen! Unbeliever! Norrath must be cleansed!";
my $Phrase7 = "Your beliefs are an insult to us all!";
my $Phrase8 = "Your actions and history are a personal affront to all I stand for.";
my $Phrase9 = "Your intolerable reputation insults all in this realm.";
my $Phrase10 = "It's time for you to take your blasphemy into the next realm.";
my $Phrase11 = "${race}s like you are better left dead than alive.";
my $Phrase = quest::ChooseRandom($Phrase1,$Phrase2,$Phrase3,$Ph rase4,$Phrase5,$Phrase6,$Phrase7,$Phrase8,$Phrase9 ,$Phrase10,$Phrase11);
quest::say("Areeeeewwwww");
my $Chance = quest::ChooseRandom(1,2,3,4);
if ($Chance == '1') {
quest::say("$Phrase");
}
}

#Submitted by: Jim Mills

On aggro, a random phrase (from the 11 included) is chosen. The mob will say their default aggro /say, and 25% of the time will say one of the 11 random phrases. I know it wasn't every time on Live, and I put the chance at about what I figured it should be. If it were occurring every time, though it might bring back some nostalgia, I think it'd get a bit annoying :P

I have a whole list of old world says to go through. Just a sample:
Butcherblock:
Guard Haldin says 'For the glory of Kaladim, have at thee!!'
Guard Haldin says 'For the glory of Kaladim!! You are no more.'

Greater Faydark:
Guard Highmoon says 'Time to die.'

Feerott:
a spectre says 'Areeeeewwwww'
a spectre says 'I really hate $classes like you.'
a spectre says '$classes like you always bring out the worst in me.'

Oggok:
Bouncer Wrok says 'Bouncer smash you!!
Bouncer Wrok says 'Ha!! Bouncers best. I am victorioo.. Victer.. I win!!

Guk:
a froglok shin knight says 'Frrroooaaakkk!'
a shin ghoul warrior says 'Rrrrrrrrooooaaakkk!'

Qeynos Guards:
Guard Weleth says 'Halt! Halt in the name of Antonius Bayle!'
Guard Gehnus says 'It's Shadowknights like you that insult all of Norrath.'
Guard Gehnus says 'Shadowknights like you always bring out the worst in me.'
Guard Hezlan says 'I really hate Shadowknights like you.'
Corporal Lancot says 'Halt! You are an enemy of the people of Qeynos! Stop in the name of Antonius Bayle and prepare for punishment!'

Qeynos Hills:
a gnoll pup says 'Half Elves like you are better left dead than alive.'
a gnoll pup says 'It's Half Elves like you who have ruined your own lands, You'll not ruin mine!'
a gnoll pup says 'Half Elves have no place in our realm!'
a gnoll pup says 'Filthy Half Elves like you must die!'
a gnoll pup says 'YAP! YAP! YAP! In the way of my father, I claim your blood for the glory of Blackburrow!! WOOOOOOOF!!'

Fippy Darkpaw shouts 'BBBBBAAAARRRKKKK!!!!! You humans will pay for ruining our homeland!! GRRRRRRRR!!!! Family Darkpaw of the Sabretooth Clan will slay you all!! BARK!

Oasis:
a dry bones skeleton says 'Areeeeewwwww
a dry bones skeleton says 'It's Wizards like you that insult all of Norrath.'
a dry bones skeleton says 'Enchanters like you are an affront to my senses.'
a dry bones skeleton says 'I really hate Rogues like you.'
a Dervish Thug's corpse0 says 'My comrades will avenge my death'

Solusek B:
greater kobold says 'Grrrrr. Bark. Bark. Grrrrr.'
greater kobold says 'Your foul deeds have earned my contempt.'
greater kobold shaman says 'Grrrrr. Bark. Bark. Grrrrr.'
greater kobold shaman says 'Filthy Scumsuckers like you must die!'
lava guardian says 'I'll teach you to interfere with me $name'
lava guardian's corpse0 says 'My comrades will avenge my death'
Solusek kobold says 'Grrrrr. Bark. Bark. Grrrrr.'
a fire goblin scout says 'Die by lava - Die by flame - Fire Peak goblins kill and maim.'

Qeynos:
Nixx Darkpaw shouts 'BBBBBAAAARRRKKKK!!!!! You humans will pay for ruining our homeland!! GRRRRRRRR!!!! Family Darkpaw of the Sabretooth Clan will slay you all!! BARK!'

Lashun Novashine shouts 'Cease this endless conflict and seek salvation in the Temple of Life! The glory of Rodcet Nife awaits you!'

Sentinel Aegeo says 'Ogres have no place in our realm!'
Sentinel Aegeo says 'Prepare to die, infidel!!

Freeport:
Guard Jacsen says 'Let your death be a warning to all who dare oppose the Freeport Militia!
Sergeant J`Narus says 'Die, like the fool you are!

Nektulos:
Corporal D`Abth says 'Die, like the fool you are!'
Sergeant C`Orm says 'Prepare to meet the skilled fury of a Neriak Dragoon.'
Guard D`Bious says 'Your guild must be destroyed!'
Sergeant C`Orm says 'Hardly a worthy adversary. A member of the Indigo Brotherhood deserves a much better opponent.'

Plane of Sky:
Sirran the Lunatic says 'These are the keys! Use them well! Hold them in your hand and touch them to the runed platforms! Guide you they will! Hah! The last to go, must tell me so, or be in for a [hassle]. If there is a hassle I will go!!
Sirran the Lunatic says 'Ehem! What? Oh, hello there! Sirran be my name. Yes? So, come to the Plane of Sky, have you? Killed all my fairies! Hah! So! Do you wish to know how to traverse this plane? Or should I just go away? I know much about this plane. You would do well to listen!

Mistmoore:
a will pillager says 'Do not underestimate the might of Mistmoore!'
a shadowy sage says 'Do not underestimate the might of Mistmoore!'
a hemo enologist says 'Do not underestimate the might of Mistmoore!

a cyclops says 'Little man, little man, filled with red - I'll crunch your bones when you are dead.'
Poacher Willa says 'It's time for you to take your blasphemy into the next realm'
Poacher Willa says 'Time to die.'

orc centurion says 'Aaarrghh!! The Deathfist shall hunt you down. My death will not go unnoticed.'
Tabitha's corpse0 says 'My comrades will avenge my death'
Lorud's corpse0 says 'My comrades will avenge my death'
Tralinda's corpse0 says 'My comrades will avenge my death'
Tralinda says 'Dark Elves have no place in our realm!'
Tralinda says 'Time to die Dempi'

an orc warrior says 'Orc stomp, Orc kill - Orc weapons your blood will spill.'
orc pawn says 'You shall have all the Crushbone Orc Legions on your tail for my death.
a lizard man warrior says 'Hssssssssssss.'
Just trying to liven up Norrath and make our critters a little more talkative :)

Dibalamin
04-10-2009, 11:40 AM
/casts rez really dead thread

Care to share the full list if you still have it 1337?

So_1337
04-10-2009, 11:50 AM
I've had my EQ server down for about six months, and had a WoW server up in its place. All my EQ stuff is safe and sound, but stashed away on the server to where I can't really get at it for now =P (The main problem being that I chopped up all the log files I had into 10 meg chunks, so they're cumbersome to sort through, especially on a remote connection.)

I'll post back once I pull them again and can dig through them. I didn't even get to finish the ones I had posted here, truth be told. Still something on my list of things I'd like to code.

Dibalamin
04-10-2009, 12:44 PM
That would be awesome! Thanks!

Use jujuedit! Opened one of my 1.5 gig log files in about 2 seconds. Sadly, it was my freakin bank mules/bazaar mules log file ><. Need 3 years of Emarr auction data?!