====== Bash functions for Skills ====== This function library contains bash shell functions related to [[:skills]] . \\ 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 - [[cf_funcs_common_sh]] 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 **.**[[:client: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 only function currently in it is **_check_skill_available** , \\ to probe, if a player possesses a given skill or not. \\ Syntax : ''_check_skill_available '' \\ Example : _check_skill_available punching \\ Returns : **0** if read ''*'Readied skill: '"$lSKILL"*'' drawn inside the info messages window of the client, \\ greater than zero otherwise. A little bit tricky is, when the skill is already made the foreground attack, \\ readying that skill again, does not draw anything in the info pane to be read, \\ to confirm that the skill is available and allowed to the player. \\ One way would be to use one of the [[:skills:Basic Skills]] , but the [[:classes:barbarians]] do not \\ possess all basic skills because of missing [[:skills:literacy]] . \\ Therefore the variables SKILL_NOT_PUNCHING and SKILL_NOT_THROWING can be set to an other skill. \\ The code falls back to SKILL_NOT_PUNCHING=throwing and SKILL_NOT_THROWING=punching if these are not set in calling scripts. ===== The Code == 60 lines of code without much explanations... #!/bin/ash [ "$HAVE_FUNCS_SKILLS" ] && return 0 # depends : [ "$HAVE_FUNCS_COMMON" ] || . cf_funcs_common.sh _check_skill_available(){ _debug "_check_skill_available:$*" _log "_check_skill_available:$*" local lSKILL=${1:-"$SKILL"} test "$lSKILL" || return 254 local lRV= _empty_message_stream _watch $DRAWINFO case "$lSKILL" in punch*) _is 1 1 ready_skill ${SKILL_NOT_PUNCHING:-throwing};; throw*) _is 1 1 ready_skill ${SKILL_NOT_THROWING:-punching};; *) _is 1 1 ready_skill ${2:-punching};; # force response, because when not changing esac # range attack, no message is printed _is 1 1 ready_skill "$lSKILL" while :; do unset REPLY read -t $TMOUT _log "_check_skill_available:$REPLY" _debug "$REPLY" case $REPLY in '') break 1;; *'Readied skill: '"$lSKILL"*) lRV=0; break 1;; # if (!(aflags & AP_NOPRINT)) # server/apply.c: new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", # server/apply.c- op->skill? op->skill:op->name); *'Unable to find skill '*) lRV=1; break 1;; # new_draw_info_format(NDI_UNIQUE, 0, op, # server/skill_util.c: "Unable to find skill %s", string); # server/skill_util.c- return 0; *scripttell*break*) break ${REPLY##*?break};; *scripttell*exit*) _exit 1 $REPLY;; *'YOU HAVE DIED.'*) _just_exit;; *) :;; esac sleep 0.01 done _unwatch $DRAWINFO _empty_message_stream return ${lRV:-3} } ###END### HAVE_FUNCS_SKILLS=1