Log in

View Full Version : Randomly Choose a quest::say()


Luccian
02-02-2012, 09:59 PM
Hello again. After getting a problem solved yesterday involving randomly choosing pauses between actions in a loop I decided to try using that same idea with phrases said upon hail.
This semi works, in the sense that when a player hails the NPC, they emote and say things, however it says all the options given.
I'm not sure how it should be scripted, but basically I'm looking to have a player be able to Hail this NPC, or group of NPCs sharing the same name, and have the NPC randomly choose a response based on what is put in the $randomphrase values rolled by the RandomRange plugin.

sub EVENT_SAY
{
if($text=~/Hail/)
{
quest::emote("appears to be one of Zimora's chosen elite. Light glistens off the shined plate armor.");
# Random choice of phrases to be said
my $randomphrase=plugin::RandomRange(1,3);
if($randomphrase=1)
{
quest::say(Hello);
}
if($randomphrase=2)
{
quest::say(Hi);
}
if($randomphrase=3)
{
quest::say(Heya);
}
}
}

I used easy basic responses til I can get it to work out correctly. Appreciate the help in advance.

lerxst2112
02-02-2012, 10:13 PM
if(x = y) means assign y to x and proceed if x is not 0.
if(x == y) means proceed if x is equal to y.

trevius
02-02-2012, 10:17 PM
Also, remember to always quote strings. You have it like this:

quest::say(Hello);

It should be like this:

quest::say("Hello");

Luccian
02-02-2012, 10:52 PM
So it should look something like this?

sub EVENT_SAY
{
if($text=~/Hail/)
{
quest::emote("appears to be one of Zimora's chosen elite. Light glistens off the shined plate armor.");
# Random choice of phrases to be said
my $randomphrase=plugin::RandomRange(1,3);
if($randomphrase==1)
{
quest::say("Hello");
}
if($randomphrase==2)
{
quest::say("Hi");
}
if($randomphrase==3)
{
quest::say("Heya");
}
}
}

I'll try and see if it works, just wanted to make sure I understood what you meant leerxst2112

Luccian
02-02-2012, 10:56 PM
Works as intended now! Thanks again for the help. Much appreciated =)
I may have questions about your formation_tools.pl sometime as well Trev. Had a pretty nifty idea, and will try to execute before asking to much

sorvani
02-03-2012, 01:16 AM
You should also think about using if and elsif statements so the server doesn't have to check each if statement even after it hit the right one and fired.

trevius
02-03-2012, 11:25 AM
Or, you can always use plugin::RandomSay() to make it really easy. Here is the plugin if you don't already have it. I keep it in a file named messages.pl, but not sure what it is on the plugin SVN offhand.


###Usage: plugin::RandomSay(chance(1-100), "message1","message2", etc..);
# Example: plugin::RandomSay(50, "I'll get you!", "Get over here!", "That's it!");
sub RandomSay {
my $chance = $_[0];

# First roll to see if a message will be sent or not depending on chance
my $RandomNum = plugin::RandomRange(1, 100);

# Choose the random message to send and send it
if ($RandomNum <= $chance)
{
$MessageCount = @_;
my $RandMessage = plugin::RandomRange(1, $MessageCount - 1);
quest::say($_[$RandMessage]);
}
}

Luccian
02-03-2012, 04:13 PM
Thanks for the additional support. I didn't know how to really properly use the elseif commands, thought I felt like it was the right way to go. So I tried to use the same type of script I used for the random animations I was using.

I like the random say plugin, I definitely will use that!

sorvani
02-03-2012, 08:18 PM
Thanks for the additional support. I didn't know how to really properly use the elseif commands, thought I felt like it was the right way to go. So I tried to use the same type of script I used for the random animations I was using.

I like the random say plugin, I definitely will use that!

The plugin is the way to go, but for your reference:

sub EVENT_SAY
{
if($text=~/Hail/)
{
quest::emote("appears to be one of Zimora's chosen elite. Light glistens off the shined plate armor.");
# Random choice of phrases to be said
my $randomphrase=plugin::RandomRange(1,3);
if($randomphrase==1) {
quest::say("Hello");
} elsif($randomphrase==2) {
quest::say("Hi");
} elsif($randomphrase==3) {
quest::say("Heya");
}
}
}

Luccian
02-04-2012, 12:43 PM
The plugin is the way to go, but for your reference:

sub EVENT_SAY
{
if($text=~/Hail/)
{
quest::emote("appears to be one of Zimora's chosen elite. Light glistens off the shined plate armor.");
# Random choice of phrases to be said
my $randomphrase=plugin::RandomRange(1,3);
if($randomphrase==1) {
quest::say("Hello");
} elsif($randomphrase==2) {
quest::say("Hi");
} elsif($randomphrase==3) {
quest::say("Heya");
}
}
}


Ah ok, yeah I figured it would look kinda like that, however the formatting wasn't clear to me. Thanks for clarifying =) I can use this kinda knowledge for future ventures as well. Appreciate it.