lua:scripting:examples:mickeymouseears
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lua:scripting:examples:mickeymouseears [2014/12/24 05:05] – vodur | lua: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' | + | 1. 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 17: | Line 17: | ||
< | < | ||
- | 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: |
</ | </ | ||
Line 60: | Line 60: | ||
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] | ||
Line 68: | Line 68: | ||
Long descr: | Long descr: | ||
Mickey Mouse is here shaking everyone' | Mickey Mouse is here shaking everyone' | ||
- | 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. | ||
Line 80: | Line 80: | ||
</ | </ | ||
- | We see we added a [[http:// | + | We see we added a [[:triggers: |
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! | ||
+ | < | ||
mpedit 11601 | mpedit 11601 | ||
- | code \\ | + | code |
-=======- Entering APPEND Mode -========- | -=======- Entering APPEND Mode -========- | ||
- | |||
- | < | ||
Type .h on a new line for help | Type .h on a new line for help | ||
| | ||
- | </ | ||
- | |||
-=======================================- | -=======================================- | ||
- | + | > say(" | |
- | > say(" | + | 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' | ||
+ | </ | ||
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:// | + | 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: |
- | Please note that you can call any of the functions available to [[http:// | + | Please note that you can call any of the functions available to [[:lua: |
+ | < | ||
mpedit 11601 | mpedit 11601 | ||
- | code \\ | + | code |
-=======- Entering APPEND Mode -========- | -=======- Entering APPEND Mode -========- | ||
- | |||
- | < | ||
Type .h on a new line for help | Type .h on a new line for help | ||
| | ||
- | </ | ||
- | |||
-=======================================- | -=======================================- | ||
- | + | 1. say(" | |
- | < | + | String cleared. > reward(ch.name.." |
- | 1. say(" | + | Fixing mob 11601. |
- | </ | + | |
- | + | ||
- | > .c \\ | + | |
- | String cleared. | + | |
- | > \\ | + | |
- | The corpse of Mickey Mouse decays into dust. \\ | + | |
- | > reward(ch.name.." | + | |
- | > say( " | + | |
- | > @ \\ | + | |
- | 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. |
- | [< | + | [*****] BUG: do_mpreward: |
Mickey Mouse exclaims ' | Mickey Mouse exclaims ' | ||
+ | </ | ||
- | Whoops! Did you see my mistake? \\ | + | Whoops! Did you see my mistake?\\ |
I missed a space between the name and " | I missed a space between the name and " | ||
- | reward(ch.name.." | + | <code lua> |
+ | reward(ch.name.." | ||
say( " | say( " | ||
+ | </ | ||
- | [[http:// | + | <code lua> |
- | + | reward( ("%s qp 1" | |
- | reward( ("%s qp 1" | + | |
say( (" | say( (" | ||
+ | </ | ||
- | [[http:// | + | <code lua> |
- | + | reward( string.format( "%s qp 1", | |
- | reward( string.format( "%s qp 1", | + | |
say( string.format( " | say( string.format( " | ||
+ | </ | ||
- | [[http:// | + | <code lua> |
- | + | reward( "%s qp 1", | |
- | reward( "%s qp 1", | + | |
say( " | say( " | ||
+ | </ | ||
- | [[http:// | + | **Preferred**: |
- | + | <code lua> | |
- | Preferred: | + | reward(ch, " |
- | + | ||
- | reward(ch, " | + | |
say( " | say( " | ||
- | + | </code> | |
- | [[http:// | + | |
Note the 5 equivalent syntaxes above. | Note the 5 equivalent syntaxes above. | ||
- | You give Mickey Mouse ears to Mickey Mouse. | + | < |
- | You are rewarded 1 quest point! | + | You give Mickey Mouse ears to Mickey Mouse. |
+ | You are rewarded 1 quest point! | ||
Mickey Mouse exclaims ' | Mickey Mouse exclaims ' | ||
+ | </ | ||
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!", | + | if ch.name==remembername then |
- | else\\ | + | say( "Sorry %s, let somebody else try!", |
- | reward(ch, " | + | else |
- | say( " | + | reward(ch, " |
- | remembername=ch.name\\ | + | say( " |
+ | remembername=ch.name | ||
end | end | ||
+ | </ | ||
- | [[http:// | + | < |
- | + | 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 ' | Mickey Mouse exclaims ' | ||
- | 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!' | ||
+ | </ | ||
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 202: | Line 189: | ||
But we have another problem to solve. What happens when Mickey' | But we have another problem to solve. What happens when Mickey' | ||
- | ifch.name==remembername then\\ | + | <code lua> |
- | say( "Sorry %s, let somebody else try!", | + | if ch.name==remembername then |
- | else\\ | + | say( "Sorry %s, let somebody else try!", |
- | reward(ch, " | + | else |
- | say( " | + | reward(ch, " |
- | remembername=ch.name\\ | + | say( " |
- | end\\ | + | remembername=ch.name |
- | \\ | + | end |
obj1: | obj1: | ||
- | + | </code> | |
- | [[http:// | + | |
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!", | + | if ch.name==remembername then |
- | mdo(" | + | say( "Sorry %s, let somebody else try!", |
- | mdo(" | + | mdo(" |
- | else\\ | + | mdo(" |
- | reward(ch, " | + | else |
- | say( " | + | reward(ch, " |
- | remembername=ch.name\\ | + | say( " |
- | obj1: | + | remembername=ch.name |
+ | obj1: | ||
end | end | ||
- | + | </code> | |
- | [[http:// | + | |
So we also try dropping it every time just in case the give doesn' | So we also try dropping it every time just in case the give doesn' | ||
- | ifch.name==remembername then\\ | + | <code lua> |
- | say( "Sorry %s, let somebody else try!", | + | if ch.name==remembername then |
- | mdo( "give ' | + | say( "Sorry %s, let somebody else try!", |
- | ifobj1.carriedby==mob then – It's still in mob's inventory! | + | mdo( "give ' |
- | + | if obj1.carriedby==mob then -- It's still in mob's inventory! | |
- | < | + | say(" |
- | say(" | + | mdo(" |
- | mdo(" | + | end |
+ | else | ||
+ | reward(ch, " | ||
+ | say( " | ||
+ | remembername=ch.name | ||
+ | obj1: | ||
+ | end | ||
</ | </ | ||
- | |||
- | end\\ | ||
- | else\\ | ||
- | reward(ch, " | ||
- | say( " | ||
- | remembername=ch.name\\ | ||
- | obj1: | ||
- | end | ||
- | |||
- | [[http:// | ||
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 '' | 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 '' | ||
lua/scripting/examples/mickeymouseears.1419397510.txt.gz · Last modified: 2014/12/24 05:05 by vodur