Simple Auto-Healing

A full but basic selfrepair (self healing) script for NukeFire as a demonstration.

Again using NukeFire as an example, healing bots are another common type of automation. In this case, some character types can heal themselves. This example will look at selfrepair, a skill for the cyborg class. The lack of interaction with other characters or mud connections lets us focus on the key logic.

This bot needs to monitor four key pieces of information:

  1. whether the selfrepair skill been gained – from our previous ‘practice’ command triggers to gather data
  2. the bot’s maximum hitpoints level – from the previous ‘score’ command parsing
  3. the bot’s current hitpoints level – from the prompt parsing already implemented
  4. whether the bot is currently attempting to heal itself – set a flag as part of the new code for this example

As criteria for whether healing is necessary, we will look at two things:

  • whether current hitpoints are more than 50 points below max hitpoints
  • if the character has the ‘selfrepair’ skill
  • whether a healing attempt is currently underway

The following code handles failures by timing out. As an advantage, if the cause of the failure is temporary such as being busy or knocked out, another attempt will be made after the timer expires (5 seconds here).

This is the partial, new code required to run selfrepair at need. It will not function by itself; it needs the other pieces we built previously.

#ALIAS doselfrepair {#IF (%ismember("self repair",@skills)) {#IF ((@configmaxhit - @hp) > 50) {#IF (@selfrepairing == 0) {#VAR selfrepairing 1;#ALARM selfrepairalarm {+5} {#PRINT SELF REPAIR FAILED;endselfrepair};selfrepair}}}} "selfrepair"
#TRIGGER {^You repair yourself[.]} {endselfrepair} "selfrepair" "regex"#ALIAS endselfrepair {#UNTRIGGER selfrepairalarm;@VAR selfrepairing,0} "selfrepair"
#ALIAS endselfrepair {#VAR selfrepairing 0;#T- selfrepairalarm}

The complete code can be assembled manually or obtained as a CMUD Package.

An entire working example is:

//extract information from prompt and handle selfrepair in the pulse
#TRIGGER {^< ([-]{0,1}[0-9]+)H ([-]{0,1}[0-9]+)M ([-]{0,1}[0-9]+)V .*>} {#VAR hp %1;#VAR mana %2;#VAR move %3;dopulse} "" "regex|prompt"
#ALIAS dopulse {doselfrepair}

//configuration for skills
#ALIAS {getskills} {#ALARM {+5} {endgetskills};#VAR skillcheck 0;#T+ skills;practice}
#alias {endgetskills} {#IF (@skillcheck==0) {#ECHO "SKILL CHECK FAILED"} {#ECHO Skillcheck: @skillcheck};#T- tmpskill;#T- tmpblank;#T- skills}
#TRIGGER tmpskill {^([a-zA-Z]([a-zA-Z]+|([ ]([a-zA-Z])+))*)[ ].*} {#ADDITEM skills %1;#VAR skillcheck 1} "skills" "regex|disable"
#TRIGGER tmpblank {^$} {#IF (@skillcheck == 1) {#T- tmpskill;#T- tmpblank}} "skills" "disable"
#TRIGGER {^Skill Information\:} {#VAR skills "";#T+ tmpskill;#T+ tmpblank} "skills" "regex"
#T- skills

//get information from the score command
#ALIAS {configscore} {#T+ configscore;#VAR configscoreresult 0;#ALARM configscorealarm {+5} {endconfigscore};score}
#TRIGGER {^Name[:] (a-zA-Z)+} {#VAR configscoreresult 1;#VAR charname %1} "configscore" "regex"
#TRIGGER {^[[][| ]*\] - move[ ]+([0-9]+)[/]([0-9]+)} {#VAR configmaxmove %1;#VAR configscoreresult 1;endconfigscore} "configscore" "regex"
#TRIGGER {^[[][| ]*\] - hit[ ]+([0-9]+)[/]([0-9]+)} {#VAR configmaxhit %1} "configscore" "regex"
#TRIGGER {^[[][| ]*\] - mana[ ]+([0-9]+)[/]([0-9]+)} {#VAR configmaxmana %1} "configscore" "regex"
#TRIGGER {[ Credits[:][ ]+[$][ ]+([0-9]+) \]} {#VAR configcash %1} "configscore" "regex"
#ALIAS {endconfigscore} {#IF (@configscoreresult == 0) {#PRINT "CONFIG SCORE FAILED"};#T- configscorealarm;#T- configscore;#VAR configscoreresult 0} "configscore"
#T- configscore

//selfrepair
#ALIAS doselfrepair {#IF (%ismember("self repair",@skills)) {#IF ((@configmaxhit - @hp) > 50) {#IF (@selfrepairing == 0) {#VAR selfrepairing 1;#ALARM selfrepairalarm {+5} {#PRINT SELF REPAIR FAILED;endselfrepair};selfrepair}}}} "selfrepair"
#TRIGGER {^You repair yourself[.]} {endselfrepair} "selfrepair" "regex"#ALIAS endselfrepair {#UNTRIGGER selfrepairalarm;@VAR selfrepairing,0} "selfrepair"
#ALIAS endselfrepair {#VAR selfrepairing 0;#T- selfrepairalarm}

Discover more from OutGamer

Subscribe now to keep reading and get access to the full archive.

Continue reading