Post by Sakrateri on Jan 23, 2005 5:23:37 GMT -5
- If Statements -
Syntax:
if($variable1 [operator] $variable2){
quest::commands;
}
Operators:
$1 == $2 : If variable $1 is the same as variable $2, carry on.
$1 != $2 : If variable $1 is NOT the same as variable $2, carry on.
$1 > $2 : If variable $1 is greater than variable $2, carry on.
$1 < $2 : If variable $1 is less than variable $2, carry on.
$1 >= $2 : If variable $1 is greater than or equal to variable $2, carry on.
$1 <= $2 : If variable $1 is less than or equal to variable $2, carry on.
In this example, if the user is a smaller level than the mob the mob says "I'm a higher level than you!"
Code:
if($ulevel < $mlevel){
quest::say("I'm a higher level than you!");
}
$1 && $2 : If $variable1 and $variable2 are true, carry on.
$1 || $2 : If $variable1 or $variable2 are true, carry on.
In this example, if the user is a smaller level than the mob the mob and the mob is at least level 10, the mob says "I'm higher than you.". Note: You must put all calculations in brackets "(",")", otherwise they wil be calculated in the wrong order.
Code:
if(($ulevel < $mlevel) && ($mlevel >=10)){
quest::say("I'm higher than you!");
}
It is also easier if you break the quest up into lines, for easier reading. Here are a few useful examples of commonly used code:
Hail script:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Why hello there mister!");}
}
Multiple responses:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Hey, have you seen a [rock] around here?");}
if ($text=~ /rock/i){quest::say("Ya it was big and shiny");}
}
Item Turn-in:
Code:
sub EVENT_ITEM
{
if ($item1 == 1001){quest::say("Wow thanks for this.. cloth?!");}
}
NPC Shouting and Emoting:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i) { quest::me("Theres a sound of [wind] blowing as you come close to bob-the-npc");}
if ($text=~ /wind/i) { quest::shout("This guy is bugging me");}
}
NPC Death:
Code:
sub EVENT_DEATH
{
quest::say("I'll get you back $name!");
quest::shout("I've just died!");
}
Bone Chips:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Hail $name. We of Tunare are charged with protecting the Great Mother from the forces of Innoruk. Even now the evil minions of this foul deity are despoiling our great forest. Will you help us [protect the mother]?");}
if ($text=~ /perform a task/i){quest::say("Just outside the gates of Felwithe the forces of Innoruk gather in the guise of decaying skeletons. Bring me four sets of bone chips as proof of your vigilance. I assure you that your faith shall not go unrewarded.");}
}
sub EVENT_ITEM
{
if ($itemcount{13331} == 4){quest::say("Praise Tunare - I knew that you would be victorious. I reward you with this spell, and pray that it will help you in your fight against the unholy forces of Innoruk.");
quest::exp(125);
quest::faction(32,5);
quest::faction(57,-1);
quest::summonitem(15374);}
}
Priest of Discord:
Code:
sub EVENT_SAY {
if($text=~/Hail/i){quest::say("Greetings $name. Are you a child of Order? If you have come seeking the path of Discord I require only that you give me your [Tome of Order and Discord] and I shall show you the way. Only then will you be freed from Order's confining restraints.");}
if($text=~/tome of order and discord/i){quest::say("The Tome of Order and Discord was penned by the seventh member of the Tribunal and has become the key to a life of Discord in spite of the author's pitiful warnings. Do you not have one child of Order? Would you [like to read] it?");}
if($text=~/read it/i)
{
quest::say("Very well. Here you go. Simply return it to me to be released from the chains of Order.");
quest::summonitem(18700);
}
}
sub EVENT_ITEM
{
if($itemcount{18700} && $itemcount{18700} == 1)
{
quest::say("I see you wish to join us in Discord! Welcome! By turning your back on the protection of Order you are now open to many more opportunities for glory and power. Remember that you can now be harmed by others who have also heard the call of Discord.");
quest::exp(125);
quest::pvp("On");
}
}
Soulbinder:
Code:
sub EVENT_SAY
{
if($text=~/Hail/i){quest::say("Greetings $name. When a hero of our world is slain their soul returns to the place it was last bound and the body is reincarnated. As a member of the Order of Eternity it is my duty to [bind your soul] to this location if that is your wish.");}
if($text=~/bind my soul/i)
{
quest::say("Binding your soul. You will return here when you die.");
quest::castspell($userid,2049);
}
}
- Advanced -
Test script for testing $variables:
Code:
sub EVENT_SAY {
if ($text=~/name/i){quest::say("name = $name");}
if ($text=~/race/i){quest::say("race = $race");}
if ($text=~/class/i){quest::say("class = $class");}
if ($text=~/userid/i){quest::say("userid = $userid");}
if ($text=~/ulevel/i){quest::say("ulevel = $ulevel");}
if ($text=~/uguildid/i){quest::say("uguildid = $uguildid");}
if ($text=~/uguildrank/i){quest::say("uguildrank = $uguildrank");}
if ($text=~/mobid/i){quest::say("mobid = $mobid");}
if ($text=~/mname/i){quest::say("mname = $mname");}
if ($text=~/mlevel/i){quest::say("mlevel = $mlevel");}
if ($text=~/faction/i){quest::say("faction = $faction");}
if ($text=~/zonesn/i){quest::say("zonesn = $zonesn");}
if ($text=~/zoneln/i){quest::say("zoneln = $zoneln");}
if ($text=~/status/i){quest::say("status = $status");}
if ($text=~/emote/i){quest::emote("emotes before you.");}
if ($text=~/shout/i){quest::shout("Is this shouting?");}
if ($text=~/spawn1/i){quest::spawn(42,0,0,1,0,1);}
if ($text=~/echo/i){quest::echo("this is an echo echo echo echo echo");}
if ($text=~/summonitem1/i){quest::summonitem(17969);}
if ($text=~/summonitem2/i){quest::summonitem(13087, 2);}
if ($text=~/castspell/i){quest::castspell($userid, 278);}
if ($text=~/depop/i){quest::depop();}
if ($text=~/exp/i){quest::exp(100);}
if ($text=~/level/i){quest::level($ulevel + 1);}
if ($text=~/safemove/i){quest::safemove();}
if ($text=~/rain1/i){quest::rain(1);}
if ($text=~/snow1/i){quest::snow(1);}
if ($text=~/rain2/i){quest::rain(0);}
if ($text=~/snow2/i){quest::snow(0);}
if ($text=~/givecash/i){quest::givecash(0,0,0,50);}
if ($text=~/pvp1/i){quest::pvp("on");}
if ($text=~/pvp2/i){quest::pvp("off");}
if ($text=~/doanim/i){quest::doanim(3);}
if ($text=~/me/i){quest::me("The heavens applaud you.");}
if ($text=~/givefaction/i){quest::faction(1,1);}
if ($text=~/takefaction/i){quest::faction(101,-5);}
if ($text=~/setcumflag/i){quest::cumflag();}
if ($text=~/setflagnpc1/i){quest::flagnpc(1);}
if ($text=~/setflagnpc2/i){quest::flagnpc(2);}
if ($text=~/addskill/i){quest::addskill(1,5);}
if ($text=~/setguild/i){quest::setguild(1,1);}
if ($text=~/rebind/i){quest::rebind(9,1,0,3);}
if ($text=~/flagcheck/i){quest::flagcheck(50,2);quest::say("flag 50 = ");}
if ($text=~/write/i){quest::write();}
if ($text=~/settime/i){quest::settime(4,39);}
if ($text=~/setsky/i){quest::setsky(1);}
if ($text=~/settimer/i){quest::settimer(7,15);}
if ($text=~/stoptimer/i){quest::stoptimer(7);}
if ($text=~/settarget/i){quest::settarget(entity,$userid);}
if ($text=~/sfollow1/i){quest::sfollow();}
if ($text=~/follow2/i){quest::follow($userid);}
if ($text=~/movepc/i){quest::movepc(9,1,0,3);}
if ($text=~/gmmove/i){quest::gmmove(-1,0,3);}
if ($text=~/movegrp/i){quest::movegrp(9,0,1,3);}
if ($text=~/setallskill/i){quest::setallskill(55);}
if ($text=~/attack/i){quest::attack("$name");}
if ($text=~/save/i){quest::save();}
}
Money conversion (converts all coins into the lowest number of coins):
Code:
sub EVENT_SAY
{
if($text =~ /Hail/i){
quest::say("Greetings $name. Would you like me to [convert] some money?");}
if($text =~ /convert/i){
quest::say("Give me some loose change and I will change it into the highest coinage I can. I will always round down - I have to make a living somehow!");}
}
sub EVENT_ITEM
{
$myplatinum = (($copper/1000) + ($silver/100) + ($gold/10) + $platinum);
$mygold = (($copper/100) + ($silver/10) + $gold + (10*$platinum));
$mysilver = (($copper/10) + $silver + (10*$gold) + (100*$platinum));
$mycopper = ($copper + (10*$silver) + (100*$gold) + (1000*$platinum));
if($mycopper < 10){
quest::say("Sorry, but I need at least 10 copper to upgrade you into silver. Here, have your money back.");
quest::givecash($copper,0,0,0);}
if((($mycopper >= 10) && ($mycopper < 100)) || (($mysilver >= 1) && ($mysilver < 10))){
quest::say("You gave me coins worth a total value of $mysilver silver. Here you go:");
quest::givecash(0,$mysilver,0,0);}
if((($mycopper >= 100) && ($mycopper < 1000)) || (($mysilver >= 10) && ($mysilver < 100)) || (($mygold >= 1) && ($mygold < 10))){
quest::say("You gave me coins worth a total value of $mygold gold. Here you go:");
quest::givecash(0,0,$mygold,0);}
if(($mycopper >= 1000) || ($mysilver >= 100) || ($mygold >= 10) || ($myplatinum >= 1)){
quest::say("You gave me coins worth a total value of $myplatinum platinum. Here you go:");
quest::givecash(0,0,0,$myplatinum);}
}
Syntax:
if($variable1 [operator] $variable2){
quest::commands;
}
Operators:
$1 == $2 : If variable $1 is the same as variable $2, carry on.
$1 != $2 : If variable $1 is NOT the same as variable $2, carry on.
$1 > $2 : If variable $1 is greater than variable $2, carry on.
$1 < $2 : If variable $1 is less than variable $2, carry on.
$1 >= $2 : If variable $1 is greater than or equal to variable $2, carry on.
$1 <= $2 : If variable $1 is less than or equal to variable $2, carry on.
In this example, if the user is a smaller level than the mob the mob says "I'm a higher level than you!"
Code:
if($ulevel < $mlevel){
quest::say("I'm a higher level than you!");
}
$1 && $2 : If $variable1 and $variable2 are true, carry on.
$1 || $2 : If $variable1 or $variable2 are true, carry on.
In this example, if the user is a smaller level than the mob the mob and the mob is at least level 10, the mob says "I'm higher than you.". Note: You must put all calculations in brackets "(",")", otherwise they wil be calculated in the wrong order.
Code:
if(($ulevel < $mlevel) && ($mlevel >=10)){
quest::say("I'm higher than you!");
}
It is also easier if you break the quest up into lines, for easier reading. Here are a few useful examples of commonly used code:
Hail script:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Why hello there mister!");}
}
Multiple responses:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Hey, have you seen a [rock] around here?");}
if ($text=~ /rock/i){quest::say("Ya it was big and shiny");}
}
Item Turn-in:
Code:
sub EVENT_ITEM
{
if ($item1 == 1001){quest::say("Wow thanks for this.. cloth?!");}
}
NPC Shouting and Emoting:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i) { quest::me("Theres a sound of [wind] blowing as you come close to bob-the-npc");}
if ($text=~ /wind/i) { quest::shout("This guy is bugging me");}
}
NPC Death:
Code:
sub EVENT_DEATH
{
quest::say("I'll get you back $name!");
quest::shout("I've just died!");
}
Bone Chips:
Code:
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Hail $name. We of Tunare are charged with protecting the Great Mother from the forces of Innoruk. Even now the evil minions of this foul deity are despoiling our great forest. Will you help us [protect the mother]?");}
if ($text=~ /perform a task/i){quest::say("Just outside the gates of Felwithe the forces of Innoruk gather in the guise of decaying skeletons. Bring me four sets of bone chips as proof of your vigilance. I assure you that your faith shall not go unrewarded.");}
}
sub EVENT_ITEM
{
if ($itemcount{13331} == 4){quest::say("Praise Tunare - I knew that you would be victorious. I reward you with this spell, and pray that it will help you in your fight against the unholy forces of Innoruk.");
quest::exp(125);
quest::faction(32,5);
quest::faction(57,-1);
quest::summonitem(15374);}
}
Priest of Discord:
Code:
sub EVENT_SAY {
if($text=~/Hail/i){quest::say("Greetings $name. Are you a child of Order? If you have come seeking the path of Discord I require only that you give me your [Tome of Order and Discord] and I shall show you the way. Only then will you be freed from Order's confining restraints.");}
if($text=~/tome of order and discord/i){quest::say("The Tome of Order and Discord was penned by the seventh member of the Tribunal and has become the key to a life of Discord in spite of the author's pitiful warnings. Do you not have one child of Order? Would you [like to read] it?");}
if($text=~/read it/i)
{
quest::say("Very well. Here you go. Simply return it to me to be released from the chains of Order.");
quest::summonitem(18700);
}
}
sub EVENT_ITEM
{
if($itemcount{18700} && $itemcount{18700} == 1)
{
quest::say("I see you wish to join us in Discord! Welcome! By turning your back on the protection of Order you are now open to many more opportunities for glory and power. Remember that you can now be harmed by others who have also heard the call of Discord.");
quest::exp(125);
quest::pvp("On");
}
}
Soulbinder:
Code:
sub EVENT_SAY
{
if($text=~/Hail/i){quest::say("Greetings $name. When a hero of our world is slain their soul returns to the place it was last bound and the body is reincarnated. As a member of the Order of Eternity it is my duty to [bind your soul] to this location if that is your wish.");}
if($text=~/bind my soul/i)
{
quest::say("Binding your soul. You will return here when you die.");
quest::castspell($userid,2049);
}
}
- Advanced -
Test script for testing $variables:
Code:
sub EVENT_SAY {
if ($text=~/name/i){quest::say("name = $name");}
if ($text=~/race/i){quest::say("race = $race");}
if ($text=~/class/i){quest::say("class = $class");}
if ($text=~/userid/i){quest::say("userid = $userid");}
if ($text=~/ulevel/i){quest::say("ulevel = $ulevel");}
if ($text=~/uguildid/i){quest::say("uguildid = $uguildid");}
if ($text=~/uguildrank/i){quest::say("uguildrank = $uguildrank");}
if ($text=~/mobid/i){quest::say("mobid = $mobid");}
if ($text=~/mname/i){quest::say("mname = $mname");}
if ($text=~/mlevel/i){quest::say("mlevel = $mlevel");}
if ($text=~/faction/i){quest::say("faction = $faction");}
if ($text=~/zonesn/i){quest::say("zonesn = $zonesn");}
if ($text=~/zoneln/i){quest::say("zoneln = $zoneln");}
if ($text=~/status/i){quest::say("status = $status");}
if ($text=~/emote/i){quest::emote("emotes before you.");}
if ($text=~/shout/i){quest::shout("Is this shouting?");}
if ($text=~/spawn1/i){quest::spawn(42,0,0,1,0,1);}
if ($text=~/echo/i){quest::echo("this is an echo echo echo echo echo");}
if ($text=~/summonitem1/i){quest::summonitem(17969);}
if ($text=~/summonitem2/i){quest::summonitem(13087, 2);}
if ($text=~/castspell/i){quest::castspell($userid, 278);}
if ($text=~/depop/i){quest::depop();}
if ($text=~/exp/i){quest::exp(100);}
if ($text=~/level/i){quest::level($ulevel + 1);}
if ($text=~/safemove/i){quest::safemove();}
if ($text=~/rain1/i){quest::rain(1);}
if ($text=~/snow1/i){quest::snow(1);}
if ($text=~/rain2/i){quest::rain(0);}
if ($text=~/snow2/i){quest::snow(0);}
if ($text=~/givecash/i){quest::givecash(0,0,0,50);}
if ($text=~/pvp1/i){quest::pvp("on");}
if ($text=~/pvp2/i){quest::pvp("off");}
if ($text=~/doanim/i){quest::doanim(3);}
if ($text=~/me/i){quest::me("The heavens applaud you.");}
if ($text=~/givefaction/i){quest::faction(1,1);}
if ($text=~/takefaction/i){quest::faction(101,-5);}
if ($text=~/setcumflag/i){quest::cumflag();}
if ($text=~/setflagnpc1/i){quest::flagnpc(1);}
if ($text=~/setflagnpc2/i){quest::flagnpc(2);}
if ($text=~/addskill/i){quest::addskill(1,5);}
if ($text=~/setguild/i){quest::setguild(1,1);}
if ($text=~/rebind/i){quest::rebind(9,1,0,3);}
if ($text=~/flagcheck/i){quest::flagcheck(50,2);quest::say("flag 50 = ");}
if ($text=~/write/i){quest::write();}
if ($text=~/settime/i){quest::settime(4,39);}
if ($text=~/setsky/i){quest::setsky(1);}
if ($text=~/settimer/i){quest::settimer(7,15);}
if ($text=~/stoptimer/i){quest::stoptimer(7);}
if ($text=~/settarget/i){quest::settarget(entity,$userid);}
if ($text=~/sfollow1/i){quest::sfollow();}
if ($text=~/follow2/i){quest::follow($userid);}
if ($text=~/movepc/i){quest::movepc(9,1,0,3);}
if ($text=~/gmmove/i){quest::gmmove(-1,0,3);}
if ($text=~/movegrp/i){quest::movegrp(9,0,1,3);}
if ($text=~/setallskill/i){quest::setallskill(55);}
if ($text=~/attack/i){quest::attack("$name");}
if ($text=~/save/i){quest::save();}
}
Money conversion (converts all coins into the lowest number of coins):
Code:
sub EVENT_SAY
{
if($text =~ /Hail/i){
quest::say("Greetings $name. Would you like me to [convert] some money?");}
if($text =~ /convert/i){
quest::say("Give me some loose change and I will change it into the highest coinage I can. I will always round down - I have to make a living somehow!");}
}
sub EVENT_ITEM
{
$myplatinum = (($copper/1000) + ($silver/100) + ($gold/10) + $platinum);
$mygold = (($copper/100) + ($silver/10) + $gold + (10*$platinum));
$mysilver = (($copper/10) + $silver + (10*$gold) + (100*$platinum));
$mycopper = ($copper + (10*$silver) + (100*$gold) + (1000*$platinum));
if($mycopper < 10){
quest::say("Sorry, but I need at least 10 copper to upgrade you into silver. Here, have your money back.");
quest::givecash($copper,0,0,0);}
if((($mycopper >= 10) && ($mycopper < 100)) || (($mysilver >= 1) && ($mysilver < 10))){
quest::say("You gave me coins worth a total value of $mysilver silver. Here you go:");
quest::givecash(0,$mysilver,0,0);}
if((($mycopper >= 100) && ($mycopper < 1000)) || (($mysilver >= 10) && ($mysilver < 100)) || (($mygold >= 1) && ($mygold < 10))){
quest::say("You gave me coins worth a total value of $mygold gold. Here you go:");
quest::givecash(0,0,$mygold,0);}
if(($mycopper >= 1000) || ($mysilver >= 100) || ($mygold >= 10) || ($myplatinum >= 1)){
quest::say("You gave me coins worth a total value of $myplatinum platinum. Here you go:");
quest::givecash(0,0,0,$myplatinum);}
}