add menu for cubescript hooks

- add new hook "autoexec", executed right after autoexec.cfg
- properly report errors during hook execution
- new script to edit the contents of an alias in the console

DOCREF autoexec
This commit is contained in:
ac-stef
2017-05-16 13:11:32 +02:00
parent e256971725
commit 6f03d1819b
4 changed files with 27 additions and 0 deletions
+23
View File
@@ -516,6 +516,7 @@ menuitemslider [Font type: ] 0 2 [findlist $__fontlist (curfont)] 1 [Default Ser
menuitemslider [Mini-map background style: ] 0 2 "$showmapbackdrop" 1 ["Fully Transparent" Black White/Transparent] [ showmapbackdrop $arg1 ]
menuitemslider [Menu map file sort order: ] 0 (- (listlen (listoptions menufilesortorders)) 1) "$menufilesort_cgz" 1 (listoptions menufilesortorders) [menufilesort_cgz = $arg1]
menuitemslider [Menu demo file sort order: ] 0 (- (listlen (listoptions menufilesortorders)) 1) "$menufilesort_dmo" 1 (listoptions menufilesortorders) [menufilesort_dmo = $arg1]
menuitem [Edit hook script --> ] [ showmenu "Edit cubescript hook" ]
// Reduced game violence mode...
alias poniesmodeon 0
@@ -786,6 +787,28 @@ menuinit [
pop serverlist words
]
newmenu "Edit cubescript hook"
menuinit [
resetcurmenu
looplist [
autoexec "after autoexec.cfg"
afterinit "after saved.cfg but before autoexec.cfg"
mapstartalways "when a map was loaded"
onLastMin "when the last minute of a game has started"
start_intermission "when a game ended"
onNewMap "when a new (empty) map was created"
onPM "when you got a private message"
onConnect "after a player connected"
onDisconnect "after a player disconnected"
onCallVote "when a vote was called"
onVoteEnd "after voting ended"
onChangeVote "when a vote is changed"
] [ cmd desc ] [
menuitem (concatword "\fs\f2" $cmd ":\fr gets executed " $desc) (concat editalias $cmd) "" (if (checkalias $cmd) [ concatword "\fs\f4current: \fr" $$cmd ])
]
]
newmenu "Configure package server"
menuinit [
resetcurmenu
+1
View File
@@ -59,6 +59,7 @@ const gibsgore [
const fullscreentoggle [ fullscreen (! $fullscreen) ]
const editsvar [ inputcommand $$arg1 (concatword "push q (addpunct $cmdbuf) ; " $arg1 " (at $q 0) ; pop q") (concatword "edit " $arg1 :) ]
const editmapmsg [ editsvar mapmsg ]
const editalias [ if (checkalias $arg1) 0 [ alias $arg1 "" ] ; inputcommand $$arg1 (concatword "push q (addpunct $cmdbuf) ; " $arg1 " = (at $q 0) ; pop q") (concatword "edit " $arg1 :) ]
const return [ result $arg1 ]
const run [ push n (concatword "exec config/" $arg1 ".cfg ") ; loop i (- $numargs 1) [ n = (concat $n (getalias (concatword "arg" (+ $i 2)))) ] ; n ; pop n]
const closecurmenu [ closemenu (curmenu) ]
+2
View File
@@ -734,7 +734,9 @@ bool exechook(int context, const char *ident, const char *body,...) // execute
{
defvformatstring(arglist, body, body);
defformatstring(execbody)("%s%c%s", ident, *arglist ? ' ' : '\0', arglist);
setcontext("hook", execbody);
execute(execbody);
resetcontext();
return true;
}
return false;
+1
View File
@@ -1225,6 +1225,7 @@ int main(int argc, char **argv)
exechook(HOOK_SP_MP, "afterinit", "");
autostartscripts(""); // all remaining scripts
execfile("config/autoexec.cfg");
exechook(HOOK_SP_MP, "autoexec", "");
execute("addallfavcatmenus"); // exec here, to add all categories (including those defined in autoexec.cfg)
initing = NOT_INITING;
uniformtexres = !hirestextures;