Universal Functions
A large collection of global functions, some may not be useful, some may.
Functions:
abs(),
add(),
after(),
and(),
before(),
capstr(),
controls(),
convsecs(),
delete(),
e(),
edit(),
escape(),
extract(),
fdiv(),
filter(),
flags(),
get(),
gt(),
hasflag(),
haspower(),
hastype(),
inc(),
iter(),
lattr(),
lcon(),
lcstr(),
lnum(),
loc(),
locate(),
lsearch(),
match(),
member(),
mid(),
mul(),
name(),
not(),
num(),
or(),
orflags(),
owner(),
pmatch(),
r(),
rest(),
rjust(),
rloc(),
round(),
s(),
secure(),
set(),
setq(),
space(),
squish(),
strlen(),
strmatch(),
sub(),
switch(),
t(),
tel(),
time(),
trunc(),
type(),
u(),
ucstr(),
ulocal(),
v(),
zone().
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for Universal Functions
@create Universal Functions
@link Universal Functions=#2
@set Universal Functions=!NO_COMMAND
@set Universal Functions=OPAQUE
@set Universal Functions=INHERIT
@set Universal Functions=WIZARD
@set Universal Functions=SAFE
@STARTUP Universal Functions=@dolist [lattr(me/FUN_*)]=@function [after(##,FUN_)]=me,##
&FUN_ALERT Universal Functions=[get([zone([loc(%#)])]/alert)]
&FUN_ATPLACE Universal Functions=[switch(or(controls(%#,%0),match(rloc(%L,100),rloc(%0,100))),1,extract(get(%0/PLACENUMS), %1, 1, |),PERMISSION DENIED)]
&FUN_CLASS Universal Functions=[switch(%0,me,[get(%#/class)],[get(*%0/class)])]
&FUN_DATE Universal Functions=[extract(time(),2,2)], [extract(time(),5,1)]
&FUN_DIVISION Universal Functions=[switch(%0, me, [name([get(%#/org)])], [name([get(*%0/org)])])]
&FUN_DTIME Universal Functions=[extract(time(),1,3)] [sub([mid(extract(time(),4,1),0,2)],4)][mid(extract(time(),4,1),2,6)] [extract(time(),5,1)]
&FUN_ECONS Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/econs))]
&FUN_EMPIRE Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/empire))]
&FUN_HASDEVFLAG Universal Functions=[switch(locate(%#,%0,*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS OBJECT,t(member(ucstr(get(#$/devflags)),ucstr(%1))))]
&FUN_IF Universal Functions=[switch(t(v(0)),1,v(1))]
&FUN_IFELSE Universal Functions=[switch(t(%0),1,%1,%2)]
&FUN_IFTHEN Universal Functions=[switch([t(%0)],1,%1)]
&FUN_INTEGER Universal Functions=[before(abs(%0),.)]
&FUN_INZONE Universal Functions=[switch(%0,here,[lsearch(all,zone,[zone(loc(%#))])],[lsearch(all,zone,%0)])]
&FUN_INDENT Universal Functions=[ulocal(u_indent,%0,%1,%2,%3)]
&FUN_INLIST Universal Functions=[switch([member([v(0)],[v(1)])],0,0,1)]
&FUN_ISBUILDER Universal Functions=[haspower([num(*%0)],builder)]
&FUN_ISCONN Universal Functions=hasflag(secure(pmatch(%0)),CONNECTED)
&FUN_ISCONPLAYER Universal Functions=[and(and(hastype(%0,Player),orflags(%0,c)),not(hasflag(%0,Dark)))]
&FUN_ISDARK Universal Functions=hasflag(secure(%0),DARK)
&FUN_ISIC Universal Functions=[switch([get(*%0/playstatus)],IC,1,0)]
&FUN_ISINZONE Universal Functions=[strmatch([switch(%1,,zone(loc(%#)),%1)],[zone(loc(%0))])]
&FUN_ISPLAYER Universal Functions=[switch(type(%0),Player,1,0)]
&FUN_LCPLAYER Universal Functions=[squish(iter(lcon(locate(%#,%0,*)),ifthen(u(isconplayer,##),##)))]
&FUN_LCPLAYERS Universal Functions=[setq(0,locate(%#,%0,PRT*))][switch(%q0,#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,switch(u(can_lcplayer,%#,%q0),0,#-1 PERMISSION DENIED,squish(u(int_lcplayers,%q0))))]
&FUN_NUKE Universal Functions=[switch(locate(%@,%0,*),#-1,#-1 INVALID OBJECT,#-2,#-2 AMBIGUOUS OBJECT,switch(or(controls(%@,#$),hasflag(#$,Destroy_Ok)),0,#-1 PERMISSION DENIED,[set(v(Garbage_Can),Nuke_List:[get(v(Garbage_Can)/Nuke_List)] #$)][tel(#$,v(Garbage_Can))]))]
&FUN_ORG Universal Functions=[switch(%0, me, [get(%#/org)], [get(*%0/org)])]
&FUN_PEMPIRE Universal Functions=[squish(iter(lsearch(all,type,player),switch(get(##/empire),%0,##)))]
&FUN_PINZONE Universal Functions=[squish([iter([squish([iter(inzone([switch(%0,here,zone(loc(%#)),%0)]),[lcon(##)])])],[switch(type(##),PLAYER,##)])])]
&FUN_PLACEINFO Universal Functions=[switch(or(controls(%#,%0),match(rloc(%L,100),rloc(%0,100))),1,extract(get(%0/PLACE%1),match(NAME MAXPLACES CURPLACES FIXED FULL EMPTY JOIN OJOIN DEPART ODEPART PREFIX,%2),1,|),PERMISSION DENIED)]
&FUN_PLACES Universal Functions=switch(0,gt(get(%0/placesmax),0),,rest(lnum(inc(get(%0/placesmax)))))
&FUN_PLAYSTATUS Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/playstatus))]
&FUN_POSITION Universal Functions=[switch(%0,me,[get(%#/title)],[get(*%0/title)])]
&FUN_POWERS Universal Functions=[switch(locate(%#,%0,*),#-1,#-1,[setq(0,#$)][filter(haspower_filter,v(powers_list))])]
&FUN_RACE Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/race))]
&FUN_RANK Universal Functions=[switch(%0, me, [get(%#/rank)], [get(*%0/rank)])]
&FUN_STARDATE Universal Functions=[switch([extract([time(),2,1)])],Jan,[set(me,month:0)],Feb,[set(me,month:31)],Mar,[set(me,month:59)],Apr,[set(me,month:90)],May,[set(me,month:120)],Jun,[set(me,month:151)],Jul,[set(me,month:181)],Aug,[set(me,month:212)],Sep,[set(me,month:243)],Oct,[set(me,month:273)],Nov,[set(me,month:304)],Dec,[set(me,month:334)])][trunc([mul(1000,[add(97,[fdiv([add([get(me/month)],[extract(time(),3,1)])],365)])])])].[mid([round([fdiv([mid([time()],11,2)],24)],1)],2,1)]%b%b[extract(time(),4,1)]
&FUN_SART Universal Functions=[switch([member([mid([name(*%0)],[sub([strlen([name(*%0)])],1)],1)],s)],0,[name(*%0)]'s,1,[name(*%0)]')]
&FUN_SECS2SD Universal Functions=[mid(convsecs(%0),23,1)][mid(fdiv(%0,31556999),3,3)][mid(round(add(fdiv(mid(convsecs(%0),11,2),24),fdiv(mid(convsecs(%0),14,2),1440)),3),1,4)][space(1)][extract(convsecs(%0),4,1)]
&FUN_SEX Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/sex))]
&FUN_TIMECONV Universal Functions=[Edit(s({[Rjust(match(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,Delete(Delete([time()],0,4),3,17)),2)]/[Delete(Delete([time()],0,8),2,14)]/[Delete([time()],0,22)]}),Space(1),0)] [Delete(Delete([time()],0,11),5,8)]
&FUN_TITLE Universal Functions=[switch(%0, me, [get(%#/title)], [get(*%0/title)])]
&FUN_TRUE Universal Functions=[switch(%0,0,0,1)]
&FUN_USERDBREF Universal Functions=ifelse(match(me,secure(%0)),%#,pmatch(secure(%0)))
&FUN_VIEWS Universal Functions=iter(lattr(%0/VIEW_*),[u(CAPITALIZE,edit(after(##,VIEW_), ~,%B))]%B%B)
&FUN_WHICHPLACE Universal Functions=[switch(or(controls(%#,%0),match(rloc(%L,100),rloc(%0,100))),1,match(get(%0/PLACENUMS), *%1%b*, |),PERMISSION DENIED)]
&FUN_WIZ Universal Functions=[switch(hasflag(%0,WIZARD),1,1,0)]
&FUN_WIZARDGET Universal Functions=[switch(hasflag(owner(%@),WIZARD),0,#-1 PERMISSION DENIED,get([locate(%@,%0,*)]/%1))]
&FUN_WIZARDFLAGS Universal Functions=[switch(hasflag(owner(%@),WIZARD),0,#-1 PERMISSION DENIED,flags(locate(%@,%0,*)))]
&FUN_WIZARDS Universal Functions=[squish([iter([lsearch(all,flag,PW)],[switch([hasflag(##,wizard)],1,{[switch([name(##)],*-BC,,##)]})])])]
&FUN_XTIME Universal Functions=[extract(time(),1,3)] [sub([mid([extract(time(),4,1)],0,2)],4)][mid([extract(time(),4,1)],2,8)] [extract(time(),5,1)]
&POWERS_LIST Universal Functions=announce boot builder cemit chat_privs functions guest halt hide idle login long_fingers no_pay no_quota pemit_all poll player_create queue quota search see_all see_queue tport_anything tport_anywhere unkillable
&HASPOWER_FILTER Universal Functions=[haspower(r(0),%0)]
&ICTIME Universal Functions=[extract(time(),1,3)] [sub([mid(extract(time(),4,1),0,2)],4)][mid(extract(time(),4,1),2,6)] [add(153,[extract(time(),5,1)])]
&ESC_COMMA Universal Functions=[edit({%0},{,},{XXX-COMMA})]
&ESC_PAREN Universal Functions=[set(me,tmp_esc_paren:[edit(%0,{\(},{\\\(})])][edit(v(tmp_esc_paren),{\)},{\\\)})]
&U_INDENT Universal Functions=[setq(0, 0)][iter(u(esc_paren,u(esc_comma,escape(edit(%2,%r,%bXXX-NEWLINE%b)))),[switch(##,XXX-NEWLINE,%r[space(%0)][setq(0,0)],[switch(gt(r(0),0),1,%b)][setq(0,add(r(0),add(strlen(##),1)))][switch(gt(r(0),%1),1,%r[space(%0)][edit({##},XXX-COMMA,{,})][setq(0,strlen(##))],[edit({##},XXX-COMMA,{,})])])],,)]
&TMP_ESC_PAREN Universal Functions=\\[32m\[0m
&CAPITALIZE Universal Functions=iter(lcstr(%0),capstr(##))
@link Universal Functions=#2
@set Universal Functions=!NO_COMMAND
@set Universal Functions=OPAQUE
@set Universal Functions=INHERIT
@set Universal Functions=WIZARD
@set Universal Functions=SAFE
@STARTUP Universal Functions=@dolist [lattr(me/FUN_*)]=@function [after(##,FUN_)]=me,##
&FUN_ALERT Universal Functions=[get([zone([loc(%#)])]/alert)]
&FUN_ATPLACE Universal Functions=[switch(or(controls(%#,%0),match(rloc(%L,100),rloc(%0,100))),1,extract(get(%0/PLACENUMS), %1, 1, |),PERMISSION DENIED)]
&FUN_CLASS Universal Functions=[switch(%0,me,[get(%#/class)],[get(*%0/class)])]
&FUN_DATE Universal Functions=[extract(time(),2,2)], [extract(time(),5,1)]
&FUN_DIVISION Universal Functions=[switch(%0, me, [name([get(%#/org)])], [name([get(*%0/org)])])]
&FUN_DTIME Universal Functions=[extract(time(),1,3)] [sub([mid(extract(time(),4,1),0,2)],4)][mid(extract(time(),4,1),2,6)] [extract(time(),5,1)]
&FUN_ECONS Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/econs))]
&FUN_EMPIRE Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/empire))]
&FUN_HASDEVFLAG Universal Functions=[switch(locate(%#,%0,*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS OBJECT,t(member(ucstr(get(#$/devflags)),ucstr(%1))))]
&FUN_IF Universal Functions=[switch(t(v(0)),1,v(1))]
&FUN_IFELSE Universal Functions=[switch(t(%0),1,%1,%2)]
&FUN_IFTHEN Universal Functions=[switch([t(%0)],1,%1)]
&FUN_INTEGER Universal Functions=[before(abs(%0),.)]
&FUN_INZONE Universal Functions=[switch(%0,here,[lsearch(all,zone,[zone(loc(%#))])],[lsearch(all,zone,%0)])]
&FUN_INDENT Universal Functions=[ulocal(u_indent,%0,%1,%2,%3)]
&FUN_INLIST Universal Functions=[switch([member([v(0)],[v(1)])],0,0,1)]
&FUN_ISBUILDER Universal Functions=[haspower([num(*%0)],builder)]
&FUN_ISCONN Universal Functions=hasflag(secure(pmatch(%0)),CONNECTED)
&FUN_ISCONPLAYER Universal Functions=[and(and(hastype(%0,Player),orflags(%0,c)),not(hasflag(%0,Dark)))]
&FUN_ISDARK Universal Functions=hasflag(secure(%0),DARK)
&FUN_ISIC Universal Functions=[switch([get(*%0/playstatus)],IC,1,0)]
&FUN_ISINZONE Universal Functions=[strmatch([switch(%1,,zone(loc(%#)),%1)],[zone(loc(%0))])]
&FUN_ISPLAYER Universal Functions=[switch(type(%0),Player,1,0)]
&FUN_LCPLAYER Universal Functions=[squish(iter(lcon(locate(%#,%0,*)),ifthen(u(isconplayer,##),##)))]
&FUN_LCPLAYERS Universal Functions=[setq(0,locate(%#,%0,PRT*))][switch(%q0,#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,switch(u(can_lcplayer,%#,%q0),0,#-1 PERMISSION DENIED,squish(u(int_lcplayers,%q0))))]
&FUN_NUKE Universal Functions=[switch(locate(%@,%0,*),#-1,#-1 INVALID OBJECT,#-2,#-2 AMBIGUOUS OBJECT,switch(or(controls(%@,#$),hasflag(#$,Destroy_Ok)),0,#-1 PERMISSION DENIED,[set(v(Garbage_Can),Nuke_List:[get(v(Garbage_Can)/Nuke_List)] #$)][tel(#$,v(Garbage_Can))]))]
&FUN_ORG Universal Functions=[switch(%0, me, [get(%#/org)], [get(*%0/org)])]
&FUN_PEMPIRE Universal Functions=[squish(iter(lsearch(all,type,player),switch(get(##/empire),%0,##)))]
&FUN_PINZONE Universal Functions=[squish([iter([squish([iter(inzone([switch(%0,here,zone(loc(%#)),%0)]),[lcon(##)])])],[switch(type(##),PLAYER,##)])])]
&FUN_PLACEINFO Universal Functions=[switch(or(controls(%#,%0),match(rloc(%L,100),rloc(%0,100))),1,extract(get(%0/PLACE%1),match(NAME MAXPLACES CURPLACES FIXED FULL EMPTY JOIN OJOIN DEPART ODEPART PREFIX,%2),1,|),PERMISSION DENIED)]
&FUN_PLACES Universal Functions=switch(0,gt(get(%0/placesmax),0),,rest(lnum(inc(get(%0/placesmax)))))
&FUN_PLAYSTATUS Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/playstatus))]
&FUN_POSITION Universal Functions=[switch(%0,me,[get(%#/title)],[get(*%0/title)])]
&FUN_POWERS Universal Functions=[switch(locate(%#,%0,*),#-1,#-1,[setq(0,#$)][filter(haspower_filter,v(powers_list))])]
&FUN_RACE Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/race))]
&FUN_RANK Universal Functions=[switch(%0, me, [get(%#/rank)], [get(*%0/rank)])]
&FUN_STARDATE Universal Functions=[switch([extract([time(),2,1)])],Jan,[set(me,month:0)],Feb,[set(me,month:31)],Mar,[set(me,month:59)],Apr,[set(me,month:90)],May,[set(me,month:120)],Jun,[set(me,month:151)],Jul,[set(me,month:181)],Aug,[set(me,month:212)],Sep,[set(me,month:243)],Oct,[set(me,month:273)],Nov,[set(me,month:304)],Dec,[set(me,month:334)])][trunc([mul(1000,[add(97,[fdiv([add([get(me/month)],[extract(time(),3,1)])],365)])])])].[mid([round([fdiv([mid([time()],11,2)],24)],1)],2,1)]%b%b[extract(time(),4,1)]
&FUN_SART Universal Functions=[switch([member([mid([name(*%0)],[sub([strlen([name(*%0)])],1)],1)],s)],0,[name(*%0)]'s,1,[name(*%0)]')]
&FUN_SECS2SD Universal Functions=[mid(convsecs(%0),23,1)][mid(fdiv(%0,31556999),3,3)][mid(round(add(fdiv(mid(convsecs(%0),11,2),24),fdiv(mid(convsecs(%0),14,2),1440)),3),1,4)][space(1)][extract(convsecs(%0),4,1)]
&FUN_SEX Universal Functions=[switch(locate(%#,%0,PT*),#-1,#-1 NO SUCH OBJECT VISIBLE,#-2,#-1 AMBIGUOUS MATCH,get(#$/sex))]
&FUN_TIMECONV Universal Functions=[Edit(s({[Rjust(match(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,Delete(Delete([time()],0,4),3,17)),2)]/[Delete(Delete([time()],0,8),2,14)]/[Delete([time()],0,22)]}),Space(1),0)] [Delete(Delete([time()],0,11),5,8)]
&FUN_TITLE Universal Functions=[switch(%0, me, [get(%#/title)], [get(*%0/title)])]
&FUN_TRUE Universal Functions=[switch(%0,0,0,1)]
&FUN_USERDBREF Universal Functions=ifelse(match(me,secure(%0)),%#,pmatch(secure(%0)))
&FUN_VIEWS Universal Functions=iter(lattr(%0/VIEW_*),[u(CAPITALIZE,edit(after(##,VIEW_), ~,%B))]%B%B)
&FUN_WHICHPLACE Universal Functions=[switch(or(controls(%#,%0),match(rloc(%L,100),rloc(%0,100))),1,match(get(%0/PLACENUMS), *%1%b*, |),PERMISSION DENIED)]
&FUN_WIZ Universal Functions=[switch(hasflag(%0,WIZARD),1,1,0)]
&FUN_WIZARDGET Universal Functions=[switch(hasflag(owner(%@),WIZARD),0,#-1 PERMISSION DENIED,get([locate(%@,%0,*)]/%1))]
&FUN_WIZARDFLAGS Universal Functions=[switch(hasflag(owner(%@),WIZARD),0,#-1 PERMISSION DENIED,flags(locate(%@,%0,*)))]
&FUN_WIZARDS Universal Functions=[squish([iter([lsearch(all,flag,PW)],[switch([hasflag(##,wizard)],1,{[switch([name(##)],*-BC,,##)]})])])]
&FUN_XTIME Universal Functions=[extract(time(),1,3)] [sub([mid([extract(time(),4,1)],0,2)],4)][mid([extract(time(),4,1)],2,8)] [extract(time(),5,1)]
&POWERS_LIST Universal Functions=announce boot builder cemit chat_privs functions guest halt hide idle login long_fingers no_pay no_quota pemit_all poll player_create queue quota search see_all see_queue tport_anything tport_anywhere unkillable
&HASPOWER_FILTER Universal Functions=[haspower(r(0),%0)]
&ICTIME Universal Functions=[extract(time(),1,3)] [sub([mid(extract(time(),4,1),0,2)],4)][mid(extract(time(),4,1),2,6)] [add(153,[extract(time(),5,1)])]
&ESC_COMMA Universal Functions=[edit({%0},{,},{XXX-COMMA})]
&ESC_PAREN Universal Functions=[set(me,tmp_esc_paren:[edit(%0,{\(},{\\\(})])][edit(v(tmp_esc_paren),{\)},{\\\)})]
&U_INDENT Universal Functions=[setq(0, 0)][iter(u(esc_paren,u(esc_comma,escape(edit(%2,%r,%bXXX-NEWLINE%b)))),[switch(##,XXX-NEWLINE,%r[space(%0)][setq(0,0)],[switch(gt(r(0),0),1,%b)][setq(0,add(r(0),add(strlen(##),1)))][switch(gt(r(0),%1),1,%r[space(%0)][edit({##},XXX-COMMA,{,})][setq(0,strlen(##))],[edit({##},XXX-COMMA,{,})])])],,)]
&TMP_ESC_PAREN Universal Functions=\\[32m\[0m
&CAPITALIZE Universal Functions=iter(lcstr(%0),capstr(##))