User Tools

Site Tools


lua:scripting:examples:mickeymouseears

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua:scripting:examples:mickeymouseears [2014/12/24 05:00] vodurlua:scripting:examples:mickeymouseears [2015/09/25 14:54] (current) vodur
Line 1: Line 1:
 ====== MickeyMouseEars ====== ====== MickeyMouseEars ======
  
-Let's make Mickey Mouse give us a quest point reward for giving his ears back. \\ +Let's make Mickey Mouse give us a quest point reward for giving his ears back.\\ 
-Before we get started, let's get a few things set up: \\ +Before we get started, let's get a few things set up:\\ 
-1. Turn wiznet on \\ +1. Turn wiznet on\\ 
-2. Turn on wiznet bug \\+2. Turn on wiznet bug\\
 This is important as any errors with our script will show up here. This is important as any errors with our script will show up here.
  
-A few things we need to know: \\ +A few things we need to know:\\ 
-1. Mickey's vnum: 11601 (find with 'vnum mickey') \\ +1. Mickey's vnum: 11601 (find with 'vnum mickey')\\ 
-2. Vnum for the ears: 11602 (find with 'vnum mickey') \\+2. Vnum for the ears: 11602 (find with 'vnum mickey')\\
 3. Mprog vnum we will use. 3. Mprog vnum we will use.
  
Line 16: Line 16:
 Create the mprog and set it to use lua: Create the mprog and set it to use lua:
  
-[code] +<code> 
-mpedit create 11601 \\+mpedit create 11601
 MobProgram Code Created. MobProgram Code Created.
  
-show \\ +show 
-Vnum: [11601] \\ +Vnum: [11601] 
-Lua: False \\+Lua: False
 Code: Code:
  
-lua \\+lua
 LUA set to TRUE LUA set to TRUE
  
-show \\ +show 
-Vnum: [11601] \\ +Vnum: [11601] 
-Lua: True \\+Lua: True
 Code: Code:
-[/code]+</code>
  
 We could write the code now, but first let's take a look at how we will attach it to the mob so we can understand better what will go into the code. We could write the code now, but first let's take a look at how we will attach it to the mob so we can understand better what will go into the code.
Line 38: Line 38:
 Use medit and addmp to set a trigger to run our prog: Use medit and addmp to set a trigger to run our prog:
  
 +<code>
 medit 11601 medit 11601
  
-addmp 11601 give 11602 \\+addmp 11601 give 11602
 Mprog Added. Mprog Added.
  
-show \\ +show 
-Name: [mickey mouse] \\ +Name: [mickey mouse] 
-Area: [ 3] Disney \\ +Area: [ 3] Disney 
-Act: [npc sentinel stay_area] \\ +Act: [npc sentinel stay_area] 
-Vnum: [11601] Sex: [male ] Race: [human] \\ +Vnum: [11601] Sex: [male ] Race: [human] 
-Level: [ 5] Align: [ 0] \\ +Level: [ 5] Align: [ 0] 
-Hitroll: [100%= 5] Damage: [100%= 7] Dam Type: [punch] \\ +Hitroll: [100%= 5] Damage: [100%= 7] Dam Type: [punch] 
-Hitpoints: [100%= 130] Mana: [100%= 110] Move: [100%= 110] \\ +Hitpoints: [100%= 130] Mana: [100%= 110] Move: [100%= 110] 
-Armor: [100%= 70] Saves: [100%= -2] \\ +Armor: [100%= 70] Saves: [100%= -2] 
-Affected by: [none] \\ +Affected by: [none] 
-Form: [edible sentient biped mammal] \\ +Form: [edible sentient biped mammal] 
-Parts: [head arms legs heart brains guts hands feet fingers ear eye tail] \\ +Parts: [head arms legs heart brains guts hands feet fingers ear eye tail] 
-Imm: [none] \\ +Imm: [none] 
-Res: [none] \\ +Res: [none] 
-Vuln: [bash] \\ +Vuln: [bash] 
-Off: [kick] \\ +Off: [kick] 
-Size: [medium] \\ +Size: [medium] 
-Start pos. [standing] \\ +Start pos. [standing] 
-Default pos [standing] \\ +Default pos [standing] 
-Wealth: [200%=22] \\ +Wealth: [200%=22] 
-Stance: [default] \\ +Stance: [default] 
-Short descr: Mickey Mouse \\ +Short descr: Mickey Mouse 
-Long descr: \\ +Long descr: 
-Mickey Mouse is here shaking everyone's hand. \\ +Mickey Mouse is here shaking everyone's hand. 
-Description: \\ +Description: 
-A tall friendly looking mouse. He tips his hat to you and smiles. You \\+A tall friendly looking mouse. He tips his hat to you and smiles. You
 try to repress the urge to pull his tail. try to repress the urge to pull his tail.
  
 MOBPrograms for [11601]: MOBPrograms for [11601]:
- 
-<code> 
 Number Vnum Trigger Phrase Number Vnum Trigger Phrase
  ------ ---- ------- ------  ------ ---- ------- ------
-</code> 
- 
 [ 0] 11601 GIVE 11602 [ 0] 11601 GIVE 11602
  
 done done
 +</code>
  
-We see we added a [[http://rooflez.com/wiki/index.php?n=Main.MprogGive|GIVE]] trigger with Phrase of 11602 which means it will run mprog vnum 11601 any time that item vnum 11602 is given to Mickey. \\+We see we added a [[:triggers:mprog:give|GIVE]] trigger with Phrase of 11602 which means it will run mprog vnum 11601 any time that item vnum 11602 is given to Mickey.\\
 Knowing that let's go back to our code and make him do what we want him to! Knowing that let's go back to our code and make him do what we want him to!
  
 +<code>
 mpedit 11601 mpedit 11601
  
-code \\+code
 -=======- Entering APPEND Mode -========- -=======- Entering APPEND Mode -========-
- 
-<code> 
 Type .h on a new line for help Type .h on a new line for help
  Terminate with a ~ or @ on a blank line.  Terminate with a ~ or @ on a blank line.
-</code> 
- 
 -=======================================- -=======================================-
- +> say("You just gave me what I was looking for")>
-> say("You just gave me what I was looking for"\\ +Fixing mob 11601.
-> @ \\ +
-Fixing mob 11601. \\+
 Fixed lua script for 11601. Fixed lua script for 11601.
  
-give ears mick \\ +give ears mick 
-You give Mickey Mouse ears to Mickey Mouse. \\+You give Mickey Mouse ears to Mickey Mouse.
 Mickey Mouse says 'You just gave me what I was looking for' Mickey Mouse says 'You just gave me what I was looking for'
 +</code>
  
 Great, it's working! Now let's get him to give a reward. Great, it's working! Now let's get him to give a reward.
  
-When the script runs, there are certain variables passed along to our script depending on the trigger and circumstances. Information is found at the [[http://rooflez.com/wiki/index.php?n=Main.MobProgs|Mob Progs]] page. In this case we see the player who gives the ears will be passed as a variable of type [[http://rooflez.com/wiki/index.php?n=Main.CHProperties|CH]] named ch. In the lua script we also have the mob represented as a [[http://rooflez.com/wiki/index.php?n=Main.CHProperties|CH]] named mob. This is important to know as it defines what the mob can do. We will need to use the [[http://rooflez.com/wiki/index.php?n=Main.CHProperties|CH]] method '[[http://rooflez.com/wiki/index.php?n=Main.ChReward|reward]]' to give the quest point reward.+When the script runs, there are certain variables passed along to our script depending on the trigger and circumstances. Information is found at the [[:triggers:mprog|Mob Progs]] page. In this case we see the player who gives the ears will be passed as a variable of type [[:lua:ch:members|CH]] named ch. In the lua script we also have the mob represented as a [[:lua:ch:members|CH]] named mob. This is important to know as it defines what the mob can do. We will need to use the [[:lua:ch:members|CH]] method '[[:lua:ch:reward|reward]]' to give the quest point reward.
  
-Please note that you can call any of the functions available to [[http://rooflez.com/wiki/index.php?n=Main.CHProperties|CH]] without a qualifier (like our say() above), it will automatically use the mob running the script to run that function. So our say() above is the equivalent of mob:say().+Please note that you can call any of the functions available to [[:lua:ch:members|CH]] without a qualifier (like our say() above), it will automatically use the mob running the script to run that function. So our say() above is the equivalent of mob:say().
  
 +<code>
 mpedit 11601 mpedit 11601
  
-code \\+code
 -=======- Entering APPEND Mode -========- -=======- Entering APPEND Mode -========-
- 
-<code> 
 Type .h on a new line for help Type .h on a new line for help
  Terminate with a ~ or @ on a blank line.  Terminate with a ~ or @ on a blank line.
-</code> 
- 
 -=======================================- -=======================================-
- +1. say("You just gave me what I was looking for")> .c 
-<code> +String cleared. > reward(ch.name.."qp 1") > say( "Thanks "..ch.name.."!!!") > @ 
-1. say("You just gave me what I was looking for") +Fixing mob 11601.
-</code> +
- +
-> .c \\ +
-String cleared. \\ +
-> \\ +
-The corpse of Mickey Mouse decays into dust. \\ +
-> reward(ch.name.."qp 1"\\ +
-> say( "Thanks "..ch.name.."!!!"\\ +
-> @ \\ +
-Fixing mob 11601. \\+
 Fixed lua script for 11601. Fixed lua script for 11601.
  
-give ear mick \\ +give ear mick 
-You give Mickey Mouse ears to Mickey Mouse. \\ +You give Mickey Mouse ears to Mickey Mouse. 
-[<nowiki>*</nowiki><nowiki>*</nowiki><nowiki>*</nowiki><nowiki>*</nowiki><nowiki>*</nowiki>] BUG: do_mpreward: Too few arguments from vnum 11601. \\+[*****] BUG: do_mpreward: Too few arguments from vnum 11601.
 Mickey Mouse exclaims 'Thanks Ranglor!!!' Mickey Mouse exclaims 'Thanks Ranglor!!!'
 +</code>
  
-Whoops! Did you see my mistake? \\+Whoops! Did you see my mistake?\\
 I missed a space between the name and "qp" in reward. This is why we have 'wiznet bug' on! We can use a different style to make it a little easier to see the format: I missed a space between the name and "qp" in reward. This is why we have 'wiznet bug' on! We can use a different style to make it a little easier to see the format:
  
-reward(ch.name.." qp 1" )\\+<code lua> 
 +reward(ch.name.." qp 1" )
 say( "Thanks "..ch.name.."!!!" ) say( "Thanks "..ch.name.."!!!" )
 +</code>
  
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=1|[$[Get Code]]]] +<code lua> 
- +reward( ("%s qp 1"):format(ch.name) )
-reward( ("%s qp 1"):format(ch.name) )\\+
 say( ("Thanks %s!!!"):format(ch.name) ) say( ("Thanks %s!!!"):format(ch.name) )
 +</code>
  
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=2|[$[Get Code]]]] +<code lua> 
- +reward( string.format( "%s qp 1",ch.name) )
-reward( string.format( "%s qp 1",ch.name) )\\+
 say( string.format( "Thanks %s!!!",ch.name) ) say( string.format( "Thanks %s!!!",ch.name) )
 +</code>
  
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=3|[$[Get Code]]]] +<code lua> 
- +reward( "%s qp 1",ch.name )
-reward( "%s qp 1",ch.name )\\+
 say( "Thanks %s!!!",ch.name ) say( "Thanks %s!!!",ch.name )
 +</code>
  
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=4|[$[Get Code]]]] +**Preferred**
- +<code lua> 
-Preferred: +reward(ch, "qp", 1 )
- +
-reward(ch, "qp", 1 )\\+
 say( "Thanks %s!!!",ch.name ) say( "Thanks %s!!!",ch.name )
- +</code>
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=5|[$[Get Code]]]]+
  
 Note the 5 equivalent syntaxes above. Note the 5 equivalent syntaxes above.
  
-You give Mickey Mouse ears to Mickey Mouse. \\ +<code> 
-You are rewarded 1 quest point! \\+You give Mickey Mouse ears to Mickey Mouse. 
 +You are rewarded 1 quest point!
 Mickey Mouse exclaims 'Thanks Ranglor!!!' Mickey Mouse exclaims 'Thanks Ranglor!!!'
 +</code>
  
 Ok good, but what if we don't want the same character to get the reward over and over and over? Let's try this: Ok good, but what if we don't want the same character to get the reward over and over and over? Let's try this:
  
-ifch.name==remembername then\\ +<code lua> 
-say( "Sorry %s, let somebody else try!",ch.name )\\ +if ch.name==remembername then 
-else\\ +    say( "Sorry %s, let somebody else try!",ch.name ) 
-reward(ch, "qp", 1)\\ +else 
-say( "Thanks %s!!!",ch.name)\\ +    reward(ch, "qp", 1) 
-remembername=ch.name\\+    say( "Thanks %s!!!",ch.name) 
 +    remembername=ch.name
 end end
 +</code>
  
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=6|[$[Get Code]]]] +<code> 
- +give ear mick 
-give ear mick \\ +You give Mickey Mouse ears to Mickey Mouse. 
-You give Mickey Mouse ears to Mickey Mouse. \\ +You are rewarded 1 quest point!
-You are rewarded 1 quest point! \\+
 Mickey Mouse exclaims 'Thanks Ranglor!!!' Mickey Mouse exclaims 'Thanks Ranglor!!!'
  
-give ear mick \\ +give ear mick 
-You give Mickey Mouse ears to Mickey Mouse. \\+You give Mickey Mouse ears to Mickey Mouse.
 Mickey Mouse exclaims 'Sorry Ranglor, let somebody else try!' Mickey Mouse exclaims 'Sorry Ranglor, let somebody else try!'
 +</code>
  
 Okay, now Mickey will reward the player only if he isn't the last person who was rewarded. Okay, now Mickey will reward the player only if he isn't the last person who was rewarded.
Line 204: Line 189:
 But we have another problem to solve. What happens when Mickey's inventory gets full? We have a couple of options. We probably don't want to drop them or the players could just keep picking them up and giving them back over and over. In this case we can choose between CH:junk() or OBJ:destroy() to get rid of the item. OBJ:destroy() is convenient for us because the object is passed into the script as an OBJ named obj1. But we have another problem to solve. What happens when Mickey's inventory gets full? We have a couple of options. We probably don't want to drop them or the players could just keep picking them up and giving them back over and over. In this case we can choose between CH:junk() or OBJ:destroy() to get rid of the item. OBJ:destroy() is convenient for us because the object is passed into the script as an OBJ named obj1.
  
-ifch.name==remembername then\\ +<code lua> 
-say( "Sorry %s, let somebody else try!",ch.name )\\ +if ch.name==remembername then 
-else\\ +    say( "Sorry %s, let somebody else try!",ch.name ) 
-reward(ch, "qp", 1) \\ +else 
-say( "Thanks %s!!!",ch.name)\\ +    reward(ch, "qp", 1) 
-remembername=ch.name\\ +    say( "Thanks %s!!!",ch.name) 
-end\\ +    remembername=ch.name 
-\\+end 
 obj1:destroy() obj1:destroy()
- +</code>
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=7|[$[Get Code]]]]+
  
 So we're being kind of mean because we are destroying the object whether or not we reward the player. Maybe we'll be nice and give it back if they don't get the reward: So we're being kind of mean because we are destroying the object whether or not we reward the player. Maybe we'll be nice and give it back if they don't get the reward:
  
-ifch.name==remembername then\\ +<code lua> 
-say( "Sorry %s, let somebody else try!",ch.name )\\ +if ch.name==remembername then 
-mdo("give '%s' %s" ,obj1.name,ch.name) \\ +    say( "Sorry %s, let somebody else try!",ch.name ) 
-mdo("drop %s",obj1.name) – Just in case the give didn't work somehow\\ +    mdo("give '%s' %s" ,obj1.name,ch.name) 
-else\\ +    mdo("drop %s",obj1.name) -- Just in case the give didn't work somehow 
-reward(ch, "qp", 1)\\ +else 
-say( "Thanks %s!!!",ch.name) \\ +    reward(ch, "qp", 1) 
-remembername=ch.name\\ +    say( "Thanks %s!!!",ch.name) 
-obj1:destroy()\\+    remembername=ch.name 
 +    obj1:destroy()
 end end
- +</code>
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=8|[$[Get Code]]]]+
  
 So we also try dropping it every time just in case the give doesn't work, but actually we can find out whether it worked or not based on its 'carriedby' property'! So we also try dropping it every time just in case the give doesn't work, but actually we can find out whether it worked or not based on its 'carriedby' property'!
  
-ifch.name==remembername then\\ +<code lua> 
-say( "Sorry %s, let somebody else try!",ch.name )\\ +if ch.name==remembername then 
-mdo( "give '%s' %s",obj1.name,ch.name )\\ +    say( "Sorry %s, let somebody else try!",ch.name ) 
-ifobj1.carriedby==mob then – It's still in mob's inventory! +    mdo( "give '%s' %s",obj1.name,ch.name ) 
- +    if obj1.carriedby==mob then -- It's still in mob's inventory! 
-<code> +        say("Hmmm, I couldn't give it back you...I'll just leave it here on the ground."
-say("Hmmm, I couldn't give it back you...I'll just leave it here on the ground.")\\ +        mdo("drop %s",obj1.name) 
-mdo("drop %s",obj1.name)\\+    end 
 +else 
 +    reward(ch, "qp", 1) 
 +    say( "Thanks %s!!!",ch.name) 
 +    remembername=ch.name 
 +    obj1:destroy() 
 +end
 </code> </code>
- 
-end\\ 
-else\\ 
-reward(ch, "qp", 1)\\ 
-say( "Thanks %s!!!",ch.name)\\ 
-remembername=ch.name\\ 
-obj1:destroy()\\ 
-end 
- 
-[[http://rooflez.com/wiki/index.php?n=Main.MickeyMouseEars?action=sourceblock&num=9|[$[Get Code]]]] 
  
 Note that for give, I ended up surrounding the obj1.name with single quotes. This is because the name is a list of keywords separated by spaces (as shown in oedit), so to be sent as a single argument they need to be in ''s. Note that for give, I ended up surrounding the obj1.name with single quotes. This is because the name is a list of keywords separated by spaces (as shown in oedit), so to be sent as a single argument they need to be in ''s.
  
lua/scripting/examples/mickeymouseears.1419397225.txt.gz · Last modified: 2014/12/24 05:00 by vodur