lua:scripting:examples:sharinginfo
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| lua:scripting:examples:sharinginfo [2014/12/24 05:30] – vodur | lua:scripting:examples:sharinginfo [2026/10/15 23:41] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | We know how to make 1 mob remember a player by saving their name in a variable or table, but what if we wanted that information available to other mobs or even objects and area scripts? For this we can use ' | ||
| - | Angels in the gauntlet at Angel' | ||
| - | |||
| - | A few things we need before we start: | ||
| - | angel vnum ( 10709 ) | ||
| - | 2 mprog vnums to use ( we'll use 10703 and 10704) | ||
| - | |||
| - | Let's start off simple and just make a [[: | ||
| - | |||
| - | < | ||
| - | mpedit create 10703 | ||
| - | MobProgram Code Created. | ||
| - | |||
| - | medit 10709 | ||
| - | |||
| - | addmp 10703 death 100 | ||
| - | Mprog Added. | ||
| - | |||
| - | MOBPrograms for [10709]: | ||
| - | | ||
| - | | ||
| - | [ 0] 10703 DEATH 100 | ||
| - | </ | ||
| - | |||
| - | And just a simple prog. | ||
| - | |||
| - | <code lua> | ||
| - | Vnum: | ||
| - | Lua: True | ||
| - | Security: | ||
| - | Code: | ||
| - | say(" | ||
| - | |||
| - | </ | ||
| - | |||
| - | < | ||
| - | Your pierce does INCONCEIVABLE things to An angel! | ||
| - | An angel is DEAD!! | ||
| - | You have an evil thought. | ||
| - | An angel exclaims 'You killed me!' | ||
| - | You hear An angel' | ||
| - | You get 1701 silver coins and 114 gold coins from the corpse of An angel. | ||
| - | </ | ||
| - | |||
| - | Now for the secret sauce. | ||
| - | Note that ' | ||
| - | <code lua> | ||
| - | say(" | ||
| - | say(" | ||
| - | local tbl={} | ||
| - | tbl.killer=ch.name | ||
| - | savetbl(" | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | Your pierce does INCONCEIVABLE things to An angel! | ||
| - | An angel is DEAD!! | ||
| - | You have an evil thought. | ||
| - | An angel exclaims 'You killed me!' | ||
| - | An angel exclaims 'You will regret it soon!' | ||
| - | You hear An angel' | ||
| - | You get 1368 silver coins and 99 gold coins from the corpse of An angel. | ||
| - | </ | ||
| - | |||
| - | Ok, it LOOKS like it's working, but how do we know if the info got saved? If we did it right, there is a file called " | ||
| - | |||
| - | We'll set up our 2nd trigger and prog now. We'll have a [[MprogGreet|greet]] trigger that fires 100% of the time. | ||
| - | |||
| - | < | ||
| - | mpedit create 10704 | ||
| - | MobProgram Code Created. | ||
| - | |||
| - | medit 10709 | ||
| - | |||
| - | addmp 10704 greet 100 | ||
| - | Mprog Added. | ||
| - | |||
| - | MOBPrograms for [10709]: | ||
| - | | ||
| - | | ||
| - | [ 0] 10704 GREET 100 | ||
| - | [ 1] 10703 DEATH 100 | ||
| - | </ | ||
| - | |||
| - | <code lua> | ||
| - | local tbl=loadtbl(" | ||
| - | -- what if the file doesn' | ||
| - | if tbl==nil or tbl.killer==nil then | ||
| - | return -- exit the script | ||
| - | end | ||
| - | |||
| - | tprint(tbl) | ||
| - | </ | ||
| - | |||
| - | |||
| - | < | ||
| - | south | ||
| - | |||
| - | The south western corner [Room 10780 inside] | ||
| - | On the wall here there is a parchment. | ||
| - | bless, to find a balm for woe, to tend the lone and featherless, | ||
| - | angel' | ||
| - | they visit the mortal realm. | ||
| - | |||
| - | [Exits: north east] | ||
| - | An angel is here training in case of a war. | ||
| - | An angel is here training in case of a war. | ||
| - | An angel is here training in case of a war. | ||
| - | An angel says '" | ||
| - | ' | ||
| - | An angel says '" | ||
| - | ' | ||
| - | An angel says '" | ||
| - | ' | ||
| - | </ | ||
| - | |||
| - | Looks like we're good to go! Now to have them attack. | ||
| - | |||
| - | <code lua> | ||
| - | Vnum: | ||
| - | Lua: True | ||
| - | Security: | ||
| - | Code: | ||
| - | local tbl=loadtbl(" | ||
| - | -- what if the file doesn' | ||
| - | if tbl==nil or tbl.killer==nil then | ||
| - | return -- exit the script | ||
| - | end | ||
| - | |||
| - | say(ch.name..", | ||
| - | kill(ch.name) | ||
| - | </ | ||
| - | |||
| - | And an update to 10703 | ||
| - | <code lua> | ||
| - | Vnum: | ||
| - | Lua: True | ||
| - | Security: | ||
| - | Code: | ||
| - | say(" | ||
| - | say(" | ||
| - | local tbl={} | ||
| - | tbl.killer=ch.name | ||
| - | savetbl(" | ||
| - | |||
| - | -- Any angels in the room attack! | ||
| - | for _,char in pairs(mob.room.people) do | ||
| - | if char.vnum==mob.vnum then | ||
| - | char: | ||
| - | char: | ||
| - | end | ||
| - | end | ||
| - | </ | ||
| - | |||
| - | Final notes: savetbl and loadtbl will always save/load in area specific directory (angel' | ||
