User Tools

Site Tools


lua:scripting:examples:trackingplayers

Differences

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

Link to this comparison view

Next revision
Previous revision
lua:scripting:examples:trackingplayers [2014/12/24 05:23]
vodur created
— (current)
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 [[MprogSpeech|speech]] trigger that will fire every time. 
-We will use vnum 10289. 
- 
-<​code>​ 
-medit 10224 
- 
-addmp 10289 speech * 
- 
-MOBPrograms for [10224]: 
- ​Number Vnum Trigger Phrase 
- ​------ ---- ------- ------ 
-[    0] 10289  SPEECH * 
-[    1] 10288  RANDOM 15 
-[    2] 10287     ACT gets a map of bastion 
-</​code>​ 
- 
-<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 
-</​code>​ 
-Yes, it's as easy as that! '​tracker'​ will be a table of keys and values where the key will be a player name (a string)and the value will be '​trigger'​ which in this case will be what they said (another string). We will use '​tprint'​ to see what the table looks like. 
-<​code>​ 
-You say '​hi'​ 
-Nog says '"​Ranglor"​="​hi"​ 
-' 
- 
-The Odoth says '​erbzaaat'​ 
-Nog says '"​Ranglor"​="​hi"​ 
-"​Odoth"​="​erbzaaat"​ 
-' 
- 
-say shabadoo 
-You say '​shabadoo'​ 
-Nog says '"​Ranglor"​="​shabadoo"​ 
-"​Odoth"​="​erbzaaat"​ 
-' 
-</​code>​ 
-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 '​poke'​ social. 
- 
-<​code>​ 
-medit 10224 
-addmp 10290 social poke 
- 
-MOBPrograms for [10224]: 
- ​Number Vnum Trigger Phrase 
- ​------ ---- ------- ------ 
-[    0] 10290  SOCIAL poke 
-[    1] 10289  SPEECH * 
-[    2] 10288  RANDOM 15 
-[    3] 10287     ACT gets a map of bastion 
-</​code>​ 
- 
- 
-<code lua> 
--- vnum 10290 
--- what if tracker doesn'​t exist yet? Need to account for that 
-tracker=tracker or {} 
- 
--- what if the player didn't say anything yet? 
-if tracker[ch.name]==nil then 
-  say( ch.name.."​ you haven'​t said anything yet!") 
-  return -- end the script 
-end 
- 
-say( "%s, the last thing you said to me was: %s", ch.name, tracker[ch.name] ) 
-</​code>​ 
- 
-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 
-</​code>​ 
- 
-<​code>​ 
-purge 
-Ok. 
-redit reset 
-Room reset. 
- 
-say hi 
-You say '​hi'​ 
- 
-poke nog 
-Nog says '​Ranglor,​ the last thing you said to me was: hi' 
- 
-The Odoth says '​heheheheHE'​ 
- 
-poke nog 
-Nog says '​Ranglor,​ the last thing you said to me was: hi' 
- 
-say werkz 
-You say '​werkz'​ 
- 
-poke nog 
-Nog says '​Ranglor,​ the last thing you said to me was: werkz' 
- 
-Nog says '​Odoth,​ the last thing you said to me was: heheheheHE'​ 
- 
-</​code>​ 
  
lua/scripting/examples/trackingplayers.1419398612.txt.gz ยท Last modified: 2014/12/24 05:23 by vodur