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 [[:triggers:mprog:speech|speech]] trigger that will fire every time. We will use vnum 10289.
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
-- 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! '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.
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"
'
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 [[:triggers:mprog:social|social]] trigger for the 'poke' social.
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
-- 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] )
And remove the tprint line from 10289
-- 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 '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'