Adapting health bar plugin to Geas MUD

Posted by Chaotzin on Mon 30 Oct 2017 08:25 PM — 3 posts, 17,147 views.

#0
Hi all

I'm very new to scripting but have started playing Geas MUD and would like to adapt a few simple plugins to working over there.

As a start, I'm trying to modify Nick's 'improved health bar plugin' (as seen here: https://www.gammon.com.au/forum/bbshowpost.php?id=9270&page=1).

Geas MUD uses a text/description based prompt as opposed to a numerical one. The prompt always reports on physical, mental and fatigue status, but also reports on stamina when that value is not 100%.

The physical/mental/fatigue output looks like this:


You are slightly hurt, in full vigour and extremely alert.


And with stamina:


You are somewhat hurt, slightly degraded, extremely alert and breathing slightly faster.


I've modified the trigger in Nick's plugin to identify this prompt and to name the variables physical, mental, fatigue and stamina. When a stamina message doesn't show, the trigger picks up the punctuation instead for that variable - I plan to use this to give stamina a 100% value. The full trigger looks like this:


<triggers>
  <trigger
   enabled="y"
   match="^You are (?<physical>(at deaths door|barely alive|terribly hurt|in a very bad shape|in a bad shape|not in a good shape|not feeling very well|hurt|somewhat hurt|slightly hurt|feeling very well))\, (?<mental>(in a vegetable state|exhausted|worn down|indisposed|in a bad shape|not in a good shape|not feeling very well|degraded|somewhat degraded|slightly degraded|in full vigour))(\,| and) (?<fatigue>(extremely exhausted|very exhausted|exhausted|somewhat exhausted|slightly exhausted|extremely tired|very tired|tired|somewhat tired|slightly tired|extremely weary|very weary|weary|somewhat weary|slightly weary|slightly alert|somewhat alert|alert|very alert|extremely alert))( and )?(?<stamina>(completely out of breath|having trouble breathing|panting heavily|panting|breathing heavily|short of breath|slightly short of breath|breathing slightly faster|\.))\.?$"
   regexp="y"
   script="do_prompt"
   sequence="100"
   name="prompt"
  >
  </trigger>
</triggers>


I've tested this just by printing the wildcards and it all seems to work OK up to here. But I've run into a problem trying to assign numerical values to these descriptions.

This is my attempt at a table with numerical values that I've assigned to the various physical messages:


physical = { 
	"at deaths door" = 10,
	"barely alive" = 19, 
	"terribly hurt" = 28, 
	"in a very bad shape" = 37, 
	"in a bad shape" = 46, 
	"not in a good shape" = 55, 
	"not feeling very well" = 64, 
	"hurt" = 73, 
	"somewhat hurt" = 82, 
	"slightly hurt" = 91, 
	"feeling very well" = 100 
	}


And the subsequent action to use these values in the do_prompt function:


function do_prompt (name, line, wildcards)

  local physical = physical [wildcards.physical]


I haven't used tables before so I expect I've got that part wrong. Appreciate any advice.

Thanks!
USA Global Moderator #1
Try

physical = { 
	["at deaths door"] = 10,
	["barely alive"] = 19, 
	["terribly hurt"] = 28, 
	["in a very bad shape"] = 37, 
	["in a bad shape"] = 46, 
	["not in a good shape"] = 55, 
	["not feeling very well"] = 64, 
	["hurt"] = 73, 
	["somewhat hurt"] = 82, 
	["slightly hurt"] = 91, 
	["feeling very well"] = 100 
	}


https://stackoverflow.com/questions/4514636/lua-implicit-table-creation-with-string-keys-why-the-extra-brackets
Amended on Mon 30 Oct 2017 10:46 PM by Fiendish
#2
Thanks Fiendish. All works perfectly now :)