PDA

View Full Version : In game menu


Disorder
02-11-2013, 04:38 AM
I'm attempting to create an in game menu. The idea is not original to me (I saw Akkadius do it, and I think it is great).

Anyway, I've searched and can't find anyone that's posted code for it. I've attempted to do it myself. However, It is not working for me. Here is my code:

sub EVENT_SAY
{
my $menuHelp = quest::saylink("Server Information");
my $menuScribeSpells = quest::saylink("Scribe your spells");
my $menuUnscribeSpells = quest::saylink("Unscribe your spells");

if ($text=~/menu/i)
{
plugin::Whisper("What would you like to do? Would you like [$menuHelp]?");
plugin::Whisper("Wold you like to [$menuScribeSpells]?");
plugin::Whisper("Would you like to [$menuUnscribeSpells]?");
}

if($text="Server Information")
{
Blah blah Lots of crap here..
my $Yel = plugin::PWColor("Yellow");
my $Blu = plugin::PWColor("Light Blue");
my $Red = plugin::PWColor("Red");
my $grn = plugin::PWColor("Forest Green");
quest::popup("Welcome",
"$Yel $TextToCenter <br>
$Yel $TextToCenter2 </c> <br>
$Yel $TextToCenter3 </c> <br>
$Yel $TextToCenter4 </c> <br>
$Yel $TextToCenter5 </c> <br>
$Yel $TextToCenter6 </c> <br>
$Yel $TextToCenter7 </7> <br>
$Yel $TextToCenter8 </7> <br>
$Yel $TextToCenter9 </7> <br> <br>
$Indent $globalload <br>
$Indent $spellfile
");
}
}

It isn't finished, but I prefer to check my work as I go to find errors. I get no response when I say menu or Menu, etc. I put it in global_players.pl and also tried it in a zone player.pl.

I put the script on a NPC and it functioned correctly when I said menu. Maybe sub EVENT_SAY is not the correct event to use. Any suggestions? Thanks.

Disorder
02-11-2013, 06:15 AM
Ok, I think I've figured it out.

pluggin::whisper must be just for npc's

I used $client->Message(315, ---------- and it worked. :)

liquest
02-11-2013, 06:58 AM
So its just edited to this here?

sub EVENT_SAY
{
my $menuHelp = quest::saylink("Server Information");
my $menuScribeSpells = quest::saylink("Scribe your spells");
my $menuUnscribeSpells = quest::saylink("Unscribe your spells");

if ($text=~/menu/i)
{
$client->Message(315, ("What would you like to do? Would you like [$menuHelp]?");
$client->Message(315, ("Wold you like to [$menuScribeSpells]?");
$client->Message(315, ("Would you like to [$menuUnscribeSpells]?");
}

if($text="Server Information")
{
Blah blah Lots of crap here..
my $Yel = plugin::PWColor("Yellow");
my $Blu = plugin::PWColor("Light Blue");
my $Red = plugin::PWColor("Red");
my $grn = plugin::PWColor("Forest Green");
quest::popup("Welcome",
"$Yel $TextToCenter <br>
$Yel $TextToCenter2 </c> <br>
$Yel $TextToCenter3 </c> <br>
$Yel $TextToCenter4 </c> <br>
$Yel $TextToCenter5 </c> <br>
$Yel $TextToCenter6 </c> <br>
$Yel $TextToCenter7 </7> <br>
$Yel $TextToCenter8 </7> <br>
$Yel $TextToCenter9 </7> <br> <br>
$Indent $globalload <br>
$Indent $spellfile
");
}
}

Disorder
02-11-2013, 07:19 AM
I changed to this but I am having troubles with unscribespells and untraindiscs.

sub EVENT_SAY
{
$menuHelp = quest::saylink("Server Information");
$menuScribeSpells = quest::saylink("Scribe your spells");
$menuUnscribeSpells = quest::saylink("Unscribe your spells");
$menuUnscribeDiscs = quest::saylink("Unscribe your disciplines");
$menuTrainDiscs = quest::saylink("Learn your disciplines");

if ($text=~/menu/i)
{
$client->Message(315, "What would you like to do? Would you like [$menuHelp]?");
$client->Message(315, "Wold you like to [$menuScribeSpells]?");
$client->Message(315, "Would you like to [$menuUnscribeSpells]?");
$client->Message(315, "Would you like to [$menuTrainDiscs]?");
$client->Message(315, "Would you like to [$menuUnscribeDiscs]?");
}

elsif($text=~/Server Information/i)
{
Taken out for length
my $Yel = plugin::PWColor("Yellow");
my $Blu = plugin::PWColor("Light Blue");
my $Red = plugin::PWColor("Red");
my $grn = plugin::PWColor("Forest Green");
quest::popup("Welcome",
"$Yel $TextToCenter <br>
$Yel $TextToCenter2 </c> <br>
$Yel $TextToCenter3 </c> <br>
$Yel $TextToCenter4 </c> <br>
$Yel $TextToCenter5 </c> <br>
$Yel $TextToCenter6 </c> <br>
$Yel $TextToCenter7 </7> <br>
$Yel $TextToCenter8 </7> <br>
$Yel $TextToCenter9 </7> <br> <br>
$Indent $globalload <br>
$Indent $spellfile
");
}

elsif ($text=~/Scribe your spells/i)
{
quest::scribespells($ulevel);
}

elsif ($text=~/Unscribe your spells/i)
{
quest::unscribespells();

}

elsif ($text=~/Learn your disciplines/i)
{
quest::traindiscs($ulevel);

}

elsif ($text=~/Unscribe your disciplines/i)
{
quest::untraindiscs();

}

}


}

The untrain and unscribe refuse to work. Not sure what I am doing wrong.

lerxst2112
02-11-2013, 07:48 AM
The untrain and unscribe refuse to work. Not sure what I am doing wrong.

What client are you using? Did you zone or relog after you did it?

trevius
02-11-2013, 09:26 AM
Gonna guess that when you try to use unscribe spells, it scribes them again. This might be because "/Unscribe your spells/i" also contains "/Scribe your spells/i" when it searches for $text that contains the phrase and doesn't match case because you set "i" at the end. And because you are using elsif instead of just if, it matches the first one then stops. You might want to add a "^" at the beginning to make sure the line starts with what you want it to start with and not match both. Though, that doesn't explain why your disc one isn't working. Also, there isn't really a reason to use a bunch of elsifs like that, regulate ifs should be good enough as long as you set your matching correctly.

c0ncrete
02-11-2013, 01:35 PM
i'm going to have to disagree with your assertion about if/elsif, simply because it's good practice. getting into the habit of using only if statements without using other means of flow control will cause unexpected issues and will make things more difficult to troubleshoot. explicit is always better than implicit in these situations, and not allowing the script to continue looking for a match when you have the only one you need in a subroutine is a good thing.

Disorder
02-11-2013, 04:36 PM
As far as the elsif/if statements, I'm learning everything from the forums, so I've been emulating what I see. I can't exactly say I know the benefits of one vs the other. Either way, Thanks for the information. I'll go look into it more now that I have time.

To clarify /text you want/ would accept randomtextText you wantRandomtext as long as it finds what it is looking for? and ^text you want/ would take only text you wantrandomtext? If that makes sense..

Disorder
02-11-2013, 04:57 PM
This was the fix:

sub EVENT_SAY
{
$menuHelp = quest::saylink("Server Information");
$menuScribeSpells = quest::saylink("Scribe your spells");
$menuUnscribeSpells = quest::saylink("Unscribe your spells");
$menuUnscribeDiscs = quest::saylink("Unscribe your disciplines");
$menuTrainDiscs = quest::saylink("Learn your disciplines");

if ($text=~/menu/i)
{
$client->Message(315, "What would you like to do? Would you like [$menuHelp]?");
$client->Message(315, "Wold you like to [$menuScribeSpells]?");
$client->Message(315, "Would you like to [$menuUnscribeSpells]?");
$client->Message(315, "Would you like to [$menuTrainDiscs]?");
$client->Message(315, "Would you like to [$menuUnscribeDiscs]?");
}

elsif($text=~/Server Information/i)
{
Removed for length
my $Yel = plugin::PWColor("Yellow");
my $Blu = plugin::PWColor("Light Blue");
my $Red = plugin::PWColor("Red");
my $grn = plugin::PWColor("Forest Green");
quest::popup("Welcome",
"$Yel $TextToCenter <br>
$Yel $TextToCenter2 </c> <br>
$Yel $TextToCenter3 </c> <br>
$Yel $TextToCenter4 </c> <br>
$Yel $TextToCenter5 </c> <br>
$Yel $TextToCenter6 </c> <br>
$Yel $TextToCenter7 </7> <br>
$Yel $TextToCenter8 </7> <br>
$Yel $TextToCenter9 </7> <br> <br>
$Indent $globalload <br>
$Indent $spellfile
");
}

elsif ($text=~/Scribe your spells/)
{
quest::scribespells($ulevel);
}

elsif ($text=~/Unscribe your spells/)
{
quest::unscribespells();

}

elsif ($text=~/Learn your disciplines/i)
{
quest::traindiscs($ulevel);

}

elsif ($text=~/Unscribe your disciplines/i)
{
quest::untraindiscs();

}

}

c0ncrete
02-11-2013, 06:49 PM
regular expressions take a while to learn to use, but you can achieve a great deal of control in your statements when you have a firm grasp of them.

http://perldoc.perl.org/perlre.html
http://www.regular-expressions.info/