User Tools

Site Tools


user:karl:cauldron:cf_funcs_heal_sh

Bash functions for Healing

This function library contains bash shell functions related to improve the Health of a player.
Though it had been tested with the busybox ash shell, some functions might only work correctly in bash ( or the other way around ).

The functions use code from

These client side scripting files are suggested to be installed inside the user's “HOME/.crossfire/s/” folder,
with a shortcut link cf → to the .crossfire directory,
to do have not much typing to do in the client's commandline.

Functions are usually named _function(){ ;} , functions named _ _function and _ _ _function are usually alternatives to the _function.

The main function currently is _check_hp, which calls _ _check_hp, which is not an alternative function for _check_hp here in the code.

The function _heal applies a parameter to increase hit points, falls back to the HEAL_ITEM variable.
The HEAL_ITEM variable can be set to something like HEAL_ITEM=“rod of heal” in calling scripts.

75 lines of code without much explanations…

#!/bin/ash
 
[ "$HAVE_FUNCS_HEAL" ] && return 0
 
# depends :
[ "$HAVE_FUNCS_COMMON"   ] || . cf_funcs_common.sh
[ "$HAVE_FUNCS_REQUESTS" ] || . cf_funcs_requests.sh
[ "$HAVE_FUNCS_ITEMS" ]    || . cf_funcs_items.sh
 
__check_hp(){
_debug "__check_hp:$*"
_log   "__check_hp:$*"
 
while :; do
 unset HP MAXHP
 _request_stat_hp
 case $HP in '') :;; *) break 1;; esac
 sleep 0.1
done
 
  if test $MAXHP -le 20; then return 0
elif test $HP -le 100; then
     test $HP -gt $(( ( MAXHP / 10 ) * 9 ))
else test $HP -gt $(( ( MAXHP / 100 ) * 90 ))
fi
}
 
_heal(){
_debug "_heal:$*"
_log   "_heal:$*"
 
local lITEM=${*:-"$HEAL_ITEM"}
 
case $lITEM in
*rod*|*staff*|*wand*|*horn*|*scroll*)
 if _check_have_item_in_inventory $lITEM; then
      unset NROF_ITEM
 else unset NROF_ITEM
      return 1
 fi
 ;;
*) :;;
esac
 
case $lITEM in
*rod*|*staff*|*wand*|*horn*)
 _is 1 1 apply -u $lITEM
 _is 1 1 apply -a $lITEM
 _is 1 1 fire 0
 _is 1 1 fire_stop
 ;;
*scroll*) _is 1 1 apply $lITEM;;
'') :;;
*) _is 1 1 invoke $lITEM;;
esac
 
}
 
_check_hp(){
_debug "_check_hp:$*"
_log   "_check_hp:$*"
 
while :;
do
 __check_hp && return 0
 _heal
 _sleep
done
 
}
 
HAVE_FUNCS_HEAL=1
###END###
user/karl/cauldron/cf_funcs_heal_sh.txt · Last modified: 2018/04/06 05:00 by karl