lua:scripting:examples:trackingplayers
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| lua:scripting:examples:trackingplayers [2014/12/24 05:25] – vodur | lua:scripting:examples:trackingplayers [2026/10/16 17:02] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Let's make a Nog the Librarian be able track the last thing that any given player has said. | ||
| - | |||
| - | Nog already has a couple of mprogs, but we add 1 more, a [[: | ||
| - | We will use vnum 10289. | ||
| - | |||
| - | < | ||
| - | medit 10224 | ||
| - | |||
| - | addmp 10289 speech * | ||
| - | |||
| - | MOBPrograms for [10224]: | ||
| - | | ||
| - | | ||
| - | [ 0] 10289 SPEECH * | ||
| - | [ 1] 10288 RANDOM 15 | ||
| - | [ 2] 10287 ACT gets a map of bastion | ||
| - | </ | ||
| - | |||
| - | <code lua> | ||
| - | -- vnum 10289 | ||
| - | -- First time the prog runs we need to initialize the tracker variable | ||
| - | tracker=tracker or {} -- same as "if tracker==nil then tracker={} end" | ||
| - | tracker[ch.name]=trigger | ||
| - | tprint(tracker) -- just for debug, will remove this later | ||
| - | </ | ||
| - | Yes, it's as easy as that! ' | ||
| - | < | ||
| - | You say ' | ||
| - | Nog says '" | ||
| - | ' | ||
| - | |||
| - | The Odoth says ' | ||
| - | Nog says '" | ||
| - | " | ||
| - | ' | ||
| - | |||
| - | say shabadoo | ||
| - | You say ' | ||
| - | Nog says '" | ||
| - | " | ||
| - | ' | ||
| - | </ | ||
| - | Maybe it's a little ugly but it confirms that things are working like we want them to. | ||
| - | |||
| - | |||
| - | So only one thing is missing now; we need a real way for Nog to tell us what we said (not tprint)! We'll need another trigger and another prog for this. Let's use 10290 on a [[MprogSocial|social]] trigger for the ' | ||
| - | |||
| - | < | ||
| - | medit 10224 | ||
| - | addmp 10290 social poke | ||
| - | |||
| - | MOBPrograms for [10224]: | ||
| - | | ||
| - | | ||
| - | [ 0] 10290 SOCIAL poke | ||
| - | [ 1] 10289 SPEECH * | ||
| - | [ 2] 10288 RANDOM 15 | ||
| - | [ 3] 10287 ACT gets a map of bastion | ||
| - | </ | ||
| - | |||
| - | |||
| - | <code lua> | ||
| - | -- vnum 10290 | ||
| - | -- what if tracker doesn' | ||
| - | tracker=tracker or {} | ||
| - | |||
| - | -- what if the player didn't say anything yet? | ||
| - | if tracker[ch.name]==nil then | ||
| - | say( ch.name.." | ||
| - | return -- end the script | ||
| - | end | ||
| - | |||
| - | say( "%s, the last thing you said to me was: %s", ch.name, tracker[ch.name] ) | ||
| - | </ | ||
| - | |||
| - | And remove the tprint line from 10289 | ||
| - | <code lua> | ||
| - | -- vnum 10289 | ||
| - | -- First time the prog runs we need to initialize the tracker variable | ||
| - | tracker=tracker or {} -- same as "if tracker==nil then tracker={} end" | ||
| - | tracker[ch.name]=trigger | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | purge | ||
| - | Ok. | ||
| - | redit reset | ||
| - | Room reset. | ||
| - | |||
| - | say hi | ||
| - | You say ' | ||
| - | |||
| - | poke nog | ||
| - | Nog says ' | ||
| - | |||
| - | The Odoth says ' | ||
| - | |||
| - | poke nog | ||
| - | Nog says ' | ||
| - | |||
| - | say werkz | ||
| - | You say ' | ||
| - | |||
| - | poke nog | ||
| - | Nog says ' | ||
| - | |||
| - | Nog says ' | ||
| - | |||
| - | </ | ||
