client_side_scripting:scripts:bash:cf_melt_icecube
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
client_side_scripting:scripts:bash:cf_melt_icecube [2018/02/16 15:54] – created karl | client_side_scripting:scripts:bash:cf_melt_icecube [2025/07/14 17:54] (current) – Update web forum to use URL https://forum.cross-fire.org leaf | ||
---|---|---|---|
Line 2: | Line 2: | ||
- | What a nasty situation : You used some icestorm spell to eliminate some monsters, | + | What for a nasty situation : You used some icestorm spell to eliminate some monsters, |
but now almost all items on the ground are boxed inside an one-time ice cube container. | but now almost all items on the ground are boxed inside an one-time ice cube container. | ||
Line 21: | Line 21: | ||
* _say_count() | * _say_count() | ||
+ | ==== Code == | ||
<code bash> | <code bash> | ||
#!/bin/bash | #!/bin/bash | ||
- | MARK_ITEM=' | + | VERSION=0.0 |
- | ITEM='flint and steel' | + | VERSION=1.0 # posted on https:// |
+ | VERSION=2.0 # 2018-01-10 code overhaul now using functions, posted on wiki.cross-fire.org | ||
+ | VERSION=2.1 # 2018-02-17 more code overhauling | ||
+ | Version=2.2 # 2018-04-16 code overhaul | ||
- | DEBUG=1 | + | MARK_ITEM=' |
- | MSGLEVEL=7 | + | ITEM=' |
+ | |||
+ | DEBUG='' | ||
+ | MSGLEVEL=6 #7 # 0 - 7 | ||
+ | LOGGING='' | ||
MY_SELF=`realpath " | MY_SELF=`realpath " | ||
MY_BASE=${MY_SELF## | MY_BASE=${MY_SELF## | ||
+ | MY_DIR=${MY_SELF%/ | ||
- | test -f "${MY_SELF%/ | + | test -f "$MY_DIR"/ |
_set_global_variables " | _set_global_variables " | ||
+ | |||
+ | cd " | ||
# *** Override any VARIABLES in cf_functions.sh *** # | # *** Override any VARIABLES in cf_functions.sh *** # | ||
- | test -f "${MY_SELF%/ | + | test -f "$MY_DIR"/" |
- | # *** Here begins program *** # | + | unset DIRB DIRF |
- | _say_start_msg " | + | |
- | # *** Check for parameters *** # | + | # functions: |
- | while [ " | + | _say_help(){ |
- | do | + | _draw 2 " |
- | PARAM_1=" | + | _draw 2 " |
- | + | _draw 4 " | |
- | # *** implementing ' | + | _draw 2 " |
- | case " | + | _draw 2 " |
- | + | _draw 2 "For example: ' | |
- | _draw 5 " | + | _draw 2 "will issue mark icecube and apply flint and steel" |
- | _draw 5 " | + | _draw 2 " until 5 icecubes have been melt." |
- | _draw 2 " | + | |
- | _draw 5 " | + | |
- | _draw 5 " | + | |
- | _draw 5 "For example: ' | + | |
- | _draw 5 "will issue 5 times mark icecube and apply flint and steel." | + | |
exit 0 | exit 0 | ||
- | ;; | + | } |
- | -d) DEBUG=$((DEBUG+1));; | + | |
- | -V) _say_version;; | + | |
- | *) | + | |
- | # *** testing parameters for validity *** # | + | |
- | PARAM_1test=" | + | |
- | test " | + | |
- | _draw 3 "Only :digit: numbers as first option allowed." | + | |
- | exit 1 #exit if other input than letters | + | |
- | | + | |
- | NUMBER=$PARAM_1 | ||
- | ;; | ||
- | esac | ||
- | |||
- | shift | ||
- | sleep 0.1 | ||
- | done | ||
- | |||
- | # functions: | ||
_mark_item(){ | _mark_item(){ | ||
+ | # returns not 0, if message says | ||
+ | # no match | ||
_debug " | _debug " | ||
+ | _log " | ||
+ | |||
local lITEM=${*: | local lITEM=${*: | ||
+ | |||
lITEM=${lITEM: | lITEM=${lITEM: | ||
lITEM=${lITEM: | lITEM=${lITEM: | ||
+ | |||
test " | test " | ||
Line 90: | Line 83: | ||
_is 1 1 mark " | _is 1 1 mark " | ||
- | | + | |
- | unset REPLY | + | unset REPLY |
read -t $TMOUT | read -t $TMOUT | ||
- | _log " | + | |
- | | + | _debug " |
case $REPLY in | case $REPLY in | ||
- | *Could*not*find*an*object*that*matches*) lRV=1;break 1;; | + | |
- | | + | *scripttell*break*) break ${REPLY## |
- | | + | *scripttell*exit*) |
- | | + | *'YOU HAVE DIED.' |
- | '' | + | '' |
esac | esac | ||
- | #unset REPLY | + | sleep 0.1 |
- | sleep 0.1s | + | |
done | done | ||
Line 110: | Line 102: | ||
_apply_item(){ | _apply_item(){ | ||
+ | # returns 0 on success, | ||
+ | # -gt 0 otherwise | ||
+ | |||
_debug " | _debug " | ||
+ | _log " | ||
+ | |||
local lITEM=${*: | local lITEM=${*: | ||
+ | |||
lITEM=${lITEM: | lITEM=${lITEM: | ||
+ | |||
test " | test " | ||
local lRV=0 | local lRV=0 | ||
+ | |||
_is 1 1 apply " | _is 1 1 apply " | ||
- | | + | |
- | unset REPLY | + | unset REPLY |
read -t $TMOUT | read -t $TMOUT | ||
- | _log " | + | |
- | | + | _debug " |
case $REPLY in | case $REPLY in | ||
- | *used*up*flint*and*steel*) lRV=5; break 1;; | + | |
- | | + | *fail*used*up*flint*and*steel*) lRV=5; break 1;; |
- | *You*need*to*mark*a*lightable*object.*) NO_FAIL=1; | + | *fail*) |
- | '' | + | *Could*not*find*any*match*to*the*flint*and*steel*) lRV=6; break 1;; |
- | | + | *You*need*to*mark*a*lightable*object.*) lRV=7; break 1;; |
- | *You*light*the*icecube*with*the*flint*and*steel.*) lRV=0; SUCC=$((SUCC+1)); break 1;; | + | |
- | | + | |
- | | + | *scripttell*exit*) |
- | | + | *'YOU HAVE DIED.' |
- | *) :;; | + | |
+ | '' | ||
+ | | ||
esac | esac | ||
- | #unset REPLY | + | sleep 0.1 |
- | sleep 0.1s | + | |
done | done | ||
Line 143: | Line 144: | ||
_say_count(){ | _say_count(){ | ||
- | case $SUCC in [0-9]*) _draw 7 "You had smolten | + | case $SUCC in [0-9]*) _draw 7 "You had melt $SUCC icecube(s).";; |
- | case $FAIL in [0-9]*) _draw 4 "You tried $FAIL time(s) | + | case $FAIL in [0-9]*) _draw 4 "You tried $FAIL time(s) |
} | } | ||
+ | |||
+ | # *** Here begins program *** # | ||
+ | |||
+ | # *** Check for parameters *** # | ||
+ | |||
+ | while [ " | ||
+ | do | ||
+ | PARAM_1=" | ||
+ | |||
+ | # *** implementing ' | ||
+ | case " | ||
+ | -h|*" | ||
+ | -d) DEBUG=$((DEBUG+1));; | ||
+ | -L) LOGGING=$((LOGGING+1));; | ||
+ | -V) _say_version;; | ||
+ | *) # *** testing parameters for validity *** # | ||
+ | | ||
+ | test " | ||
+ | #exit if other input than letters | ||
+ | NUMBER=$PARAM_1 | ||
+ | ;; | ||
+ | esac | ||
+ | |||
+ | shift | ||
+ | sleep 0.1 | ||
+ | done | ||
+ | |||
+ | # Prerequsites: | ||
+ | # prevent multiple scripts running, | ||
+ | # set sleep values according to player speed | ||
+ | _say_start_msg " | ||
# *** Getting Player' | # *** Getting Player' | ||
Line 152: | Line 184: | ||
test " | test " | ||
- | # *** Actual script to pray multiple times *** # | + | test " |
- | # MAIN | + | _debug " |
SUCC=0 | SUCC=0 | ||
FAIL=0 | FAIL=0 | ||
- | test " | + | # *** Actual script to pray multiple times *** # |
- | _debug " | + | # MAIN |
- | _watch | + | _watch |
unset one | unset one | ||
Line 171: | Line 203: | ||
_sleep | _sleep | ||
- | NO_FAIL= | + | while :; |
- | until [ " | + | |
do | do | ||
Line 182: | Line 213: | ||
3) :;; # | 3) :;; # | ||
4) :;; # | 4) :;; # | ||
- | 5) break 2;; #used up | + | |
+ | _warn "Your flint and steel is used up."; | ||
+ | | ||
6) break 2;; #no item | 6) break 2;; #no item | ||
7) break 1;; #not marked | 7) break 1;; #not marked | ||
Line 189: | Line 222: | ||
esac | esac | ||
- | | + | #_say_count |
| | ||
- | | + | done |
- | #test " | ||
case $NUMBER in $one) break 1;; esac | case $NUMBER in $one) break 1;; esac | ||
+ | _say_count | ||
done #main while loop | done #main while loop | ||
Line 208: | Line 241: | ||
The usual disclaimer : | The usual disclaimer : | ||
If [parts of] the script do[es] not work for you, you are welcome to post a bug report on | If [parts of] the script do[es] not work for you, you are welcome to post a bug report on | ||
- | the metalforge forum in [[http://forum.metalforge.net/ | + | the metalforge forum in [[https://forum.cross-fire.org/phpBB3/ |
client_side_scripting/scripts/bash/cf_melt_icecube.1518818070.txt.gz · Last modified: (external edit)