User Tools

Site Tools


lua:scripting:examples:sharinginfo

Differences

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

Link to this comparison view

Next revision
Previous revision
lua:scripting:examples:sharinginfo [2014/12/24 05:28] – created vodurlua:scripting:examples:sharinginfo [2015/09/28 04:22] (current) vodur
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 '[[savetbl]]' and '[[savetbl|loadtbl]]'.+ 
 + 
 +**Note that as of today (9/27/2015), while this example is a valid example of savetbl/loadtbl, use of newly added 'shared' table will be more appropriate for many applications that required savetbl/loadtbl previously.** 
 + 
 +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 '[[:lua:savetbl|savetbl]]' and '[[:lua:savetbl|loadtbl]]'.
  
 Angels in the gauntlet at Angel's Heaven seem pretty indifferent to their fellow angels getting killed. Let's make it so they will all aggro the most recent person who has killed any of them. Angels in the gauntlet at Angel's Heaven seem pretty indifferent to their fellow angels getting killed. Let's make it so they will all aggro the most recent person who has killed any of them.
  
-A few things we need before we start: +A few things we need before we start: angel vnum ( 10709 ) 2 mprog vnums to use ( we'll use 10703 and 10704)
-angel vnum ( 10709 ) +
-2 mprog vnums to use ( we'll use 10703 and 10704)+
  
-Let's start off simple and just make a [[MprogDeath|death]] trigger and make sure it's working.+Let's start off simple and just make a [[:triggers:mprog:death|death]] trigger and make sure it's working.
  
 <code> <code>
Line 44: Line 46:
 </code> </code>
  
-Now for the secret sauce. +Now for the secret sauce. Note that 'savetbl' takes a table as the 2nd argument, so even if we only want to save just 1 thing we need to put it in a table, but it's no big deal. 
-Note that 'savetbl' takes a table as the 2nd argument, so even if we only want to save just 1 thing we need to put it in a table, but it's no big deal.+
 <code lua> <code lua>
 say("You killed me!") say("You killed me!")
Line 66: Line 68:
 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 "angelkill" saved in the Angel's heaven area directory that has a table with my name in it. Let's confirm. 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 "angelkill" saved in the Angel's heaven area directory that has a table with my name in it. Let's confirm.
  
-We'll set up our 2nd trigger and prog now. We'll have a [[MprogGreet|greet]] trigger that fires 100% of the time.+We'll set up our 2nd trigger and prog now. We'll have a [[:lua:scripting:examples:mproggreet|greet]] trigger that fires 100% of the time.
  
 <code> <code>
Line 93: Line 95:
 tprint(tbl) tprint(tbl)
 </code> </code>
- 
  
 <code> <code>
Line 102: Line 103:
 bless, to find a balm for woe, to tend the lone and featherless, is an bless, to find a balm for woe, to tend the lone and featherless, is an
 angel's work below" This text explains what angels are sent to do when angel's work below" This text explains what angels are sent to do when
-they visit the mortal realm.  +they visit the mortal realm.
  
 [Exits: north east] [Exits: north east]
Line 128: Line 129:
   return -- exit the script   return -- exit the script
 end end
- +
 say(ch.name..", you murderer!") say(ch.name..", you murderer!")
 kill(ch.name) kill(ch.name)
Line 134: Line 135:
  
 And an update to 10703 And an update to 10703
 +
 <code lua> <code lua>
 Vnum:       [10703] Vnum:       [10703]
Line 144: Line 146:
 tbl.killer=ch.name tbl.killer=ch.name
 savetbl("angelkill", tbl) -- save the table in a file called angelkill savetbl("angelkill", tbl) -- save the table in a file called angelkill
-  + 
--- Any angels in the room attack! +-- Any angels in the room attack!
 for _,char in pairs(mob.room.people) do for _,char in pairs(mob.room.people) do
   if char.vnum==mob.vnum then   if char.vnum==mob.vnum then
Line 155: Line 157:
  
 Final notes: savetbl and loadtbl will always save/load in area specific directory (angel's heaven dir in this case) according to HOME area, not current area. It's the same directory whether called from mob, object, or area so it means you can share info between any type of prog, but only in the same area. Final notes: savetbl and loadtbl will always save/load in area specific directory (angel's heaven dir in this case) according to HOME area, not current area. It's the same directory whether called from mob, object, or area so it means you can share info between any type of prog, but only in the same area.
 +
 +
lua/scripting/examples/sharinginfo.1419398884.txt.gz · Last modified: 2014/12/24 05:28 by vodur