diff options
author | mekolat <mekolat@users.noreply.github.com> | 2016-06-20 23:23:50 -0400 |
---|---|---|
committer | mekolat <mekolat@users.noreply.github.com> | 2016-06-22 14:49:42 -0400 |
commit | 4215b2baf47faf8eec14060e3da655d98ffe1636 (patch) | |
tree | fbb98b89fc9fe333e97394e5a21e0c6c905496b0 | |
parent | d7765ee21045c3be2dd48edb329125fa7251de0f (diff) | |
download | serverdata-4215b2baf47faf8eec14060e3da655d98ffe1636.tar.gz serverdata-4215b2baf47faf8eec14060e3da655d98ffe1636.tar.bz2 serverdata-4215b2baf47faf8eec14060e3da655d98ffe1636.tar.xz serverdata-4215b2baf47faf8eec14060e3da655d98ffe1636.zip |
add `@music` atcommand
-rw-r--r-- | npc/commands/music.txt | 46 | ||||
-rw-r--r-- | npc/functions/string.txt | 66 | ||||
-rw-r--r-- | npc/scripts.conf | 4 |
3 files changed, 116 insertions, 0 deletions
diff --git a/npc/commands/music.txt b/npc/commands/music.txt new file mode 100644 index 00000000..3f001919 --- /dev/null +++ b/npc/commands/music.txt @@ -0,0 +1,46 @@ +// @music atcommand +// changes the music for all players on the map +// +// group lv: 2 +// group char lv: 99 +// log: True +// +// usage: +// @music <short name> +// +// example: +// @music fun + +- script @music 32767,{ + end; + +OnCall: + // TODO: tmw-like argv splitter + getmapxy .@map$, .@void, .@void, UNITTYPE_PC; // get map + + .@key$ = .@atcmd_parameters$[0]; + .@m$ = htget(.hash, .@key$, "Not found"); + + if (.@m$ == "Not found") + { + .@m$ = implode(.@atcmd_parameters$[0], " "); + } + + changemusic .@map$, .@m$ + ".ogg"; + end; + +OnInit: + if (.hash) + { + htdelete(.hash); // delete it on Live-Reload (@reloadscripts) + } + + bindatcmd "music", "@music::OnCall", 2, 99, 1; + + .hash = htnew; // create hashtable + htput(.hash, "forest", "bartk - in the forest of the birches"); + htput(.hash, "adventure", "bartk - the adventure begins"); + htput(.hash, "fun", "eric matyas - ghoulish fun"); + htput(.hash, "surreal", "eric matyas - surreal place"); + htput(.hash, "ocean", "ezili - ocean sounds"); +} diff --git a/npc/functions/string.txt b/npc/functions/string.txt new file mode 100644 index 00000000..ef910961 --- /dev/null +++ b/npc/functions/string.txt @@ -0,0 +1,66 @@ +// safe string manipulation functions +// ** does not require PCRE + + +// startswith( "string", "search" ) +// +// returns true if "string" begins with "search" +function script startswith { + return substr(getarg(0), 0, getstrlen(getarg(1)) - 1) == getarg(1); +} + +// endswith( "string", "search" ) +// +// returns true if "string" ends with "search" +function script endswith { + .@t = getstrlen(getarg(0)); // total length + .@n = getstrlen(getarg(1)); // substring length + return substr(getarg(0), .@t - .@n, .@t - 1) == getarg(1); +} + +// capitalize( "string" ) +// +// returns "string" with its first letter capitalized +function script capitalize { + .@original$ = charat(getarg(0), 0); + return setchar(getarg(0), strtoupper(.@original$), 0); +} + +// titlecase( "string" [, "delimiter" [, camel]] ) +// +// returns "string" with the first letter of each word capitalized +// if camel is true, the string is joined in a camelCase fashion +function script titlecase { + .@delimiter$ = getarg(1, " "); + .@c = getarg(2, 0); + explode(.@words$, getarg(0), .@delimiter$); + + for (.@i = (.@c ? 1 : 0); .@i < 255; ++.@i) + { + if (.@words$[.@i] == "") + { + break; + } + + .@original$ = charat(.@words$[.@i], 0); + .@words$[.@i] = setchar(.@words$[.@i], strtoupper(.@original$), 0); + } + + return implode(.@words$, (.@c ? "" : .@delimiter$)); +} + +// zfill( "string" [, width [, "padding"]] ) +// +// returns "string" padded to the left with "padding" up to width +function script zfill { + .@str$ = getarg(0); + .@width = getarg(1, 8); + .@padding$ = getarg(2, "0"); + + for (.@s = getstrlen(.@str$); .@s < .@width; ++.@s) + { + .@str$ = .@padding$ + .@str$; + } + + return .@str$; +} diff --git a/npc/scripts.conf b/npc/scripts.conf index 9ee2d688..85d55303 100644 --- a/npc/scripts.conf +++ b/npc/scripts.conf @@ -30,6 +30,10 @@ npc: npc/functions/villagertalk.txt npc: npc/functions/npcmovegraph.txt npc: npc/functions/fishing.txt npc: npc/functions/mouboofunc.txt +npc: npc/functions/string.txt + +// custom atcommands +npc: npc/commands/music.txt // Maps specific scripts import: npc/_import.txt |