diff options
author | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-12-31 23:02:50 +0000 |
---|---|---|
committer | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-12-31 23:02:50 +0000 |
commit | 0f879d42f9f7681280525ed90d41d69cff08776c (patch) | |
tree | 2018e489fe68c3efd429d6636fc8b73cc0511a91 /src/map/script.c | |
parent | 23ed5af9a84477a11d3e946c97d39e7ed5725bfd (diff) | |
download | hercules-0f879d42f9f7681280525ed90d41d69cff08776c.tar.gz hercules-0f879d42f9f7681280525ed90d41d69cff08776c.tar.bz2 hercules-0f879d42f9f7681280525ed90d41d69cff08776c.tar.xz hercules-0f879d42f9f7681280525ed90d41d69cff08776c.zip |
Added 4 new all-handy script functions; special thanks to KeyWorld!
* getargcount()
-- to be used inside functions/callsub labels, returns quantity of arguments provided
* is_function(<function name>)
-- checks weather a "user" function exists, returning 1 if function is found and 0 otherwise.
* freeloop(<toggle>)
-- lets you to enable/disable (1 or 0) the loop infinity protection for that specific npc instance, allowing your script to loop as much as it may need.
* get_revision()
-- retrieves the current svn revision
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15340 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/map/script.c b/src/map/script.c index 1fdbc7c01..b03f0ede4 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3488,7 +3488,7 @@ void run_script_main(struct script_state *st) run_func(st); if(st->state==GOTO){ st->state = RUN; - if( gotocount>0 && (--gotocount)<=0 ){ + if( !st->freeloop && gotocount>0 && (--gotocount)<=0 ){ ShowError("run_script: infinity loop !\n"); script_reportsrc(st); st->state=END; @@ -3536,7 +3536,7 @@ void run_script_main(struct script_state *st) st->state=END; break; } - if( cmdcount>0 && (--cmdcount)<=0 ){ + if( !st->freeloop && cmdcount>0 && (--cmdcount)<=0 ){ ShowError("run_script: infinity loop !\n"); script_reportsrc(st); st->state=END; @@ -15965,6 +15965,64 @@ BUILDIN_FUNC(setmounting) { } return 0; } +/** + * Retrieves quantity of arguments provided to callfunc/callsub. + * getargcount() -> amount of arguments received in a function + **/ +BUILDIN_FUNC(getargcount) { + struct script_retinfo* ri; + + if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp - 1].type != C_RETINFO ) { + ShowError("script:getargcount: used out of function or callsub label!\n"); + st->state = END; + return 1; + } + ri = st->stack->stack_data[st->stack->defsp - 1].u.ri; + + script_pushint(st, ri->nargs); + + return 0; +} +/** + * is_function(<function name>) -> 1 if function exists, 0 otherwise + **/ +BUILDIN_FUNC(is_function) { + const char* str = script_getstr(st,2); + + if( ((struct script_code*)strdb_get(userfunc_db, str)) != NULL ) + script_pushint(st,1); + else + script_pushint(st,0); + + return 0; +} +/** + * get_revision() -> retrieves the current svn revision (if available) + **/ +BUILDIN_FUNC(get_revision) { + const char * revision; + + if ( (revision = get_svn_revision()) != 0 ) + script_pushstrcopy(st,revision); + else + script_pushconststr(st,"Unknown"); + + return 0; +} +/** + * freeloop(<toggle>) -> toggles this script instance's looping-check ability + **/ +BUILDIN_FUNC(freeloop) { + + if( script_getnum(st,2) ) + st->freeloop = 1; + else + st->freeloop = 0; + + script_pushint(st, st->freeloop); + + return 0; +} // declarations that were supposed to be exported from npc_chat.c #ifdef PCRE_SUPPORT BUILDIN_FUNC(defpattern); @@ -16386,6 +16444,13 @@ struct script_function buildin_func[] = { BUILDIN_DEF(setdragon,"?"),//[Ind] BUILDIN_DEF(ismounting,""),//[Ind] BUILDIN_DEF(setmounting,""),//[Ind] + /** + * rAthena and beyond! + **/ + BUILDIN_DEF(getargcount,""), + BUILDIN_DEF(is_function,"s"), + BUILDIN_DEF(get_revision,""), + BUILDIN_DEF(freeloop,"i"), //Quest Log System [Inkfish] BUILDIN_DEF(setquest, "i"), BUILDIN_DEF(erasequest, "i"), |