diff options
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 9076 |
1 files changed, 4425 insertions, 4651 deletions
diff --git a/src/map/script.c b/src/map/script.c index 4099820f1..41f8e7472 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams //#define DEBUG_DISP //#define DEBUG_DISASM @@ -49,6 +50,7 @@ #include "script.h" #include "quest.h" #include "elemental.h" +#include "../config/core.h" #include <stdio.h> #include <stdlib.h> @@ -61,110 +63,6 @@ #include <setjmp.h> #include <errno.h> -#ifdef BETA_THREAD_TEST - #include "../common/atomic.h" - #include "../common/spinlock.h" - #include "../common/thread.h" - #include "../common/mutex.h" -#endif - - -/////////////////////////////////////////////////////////////////////////////// -//## TODO possible enhancements: [FlavioJS] -// - 'callfunc' supporting labels in the current npc "::LabelName" -// - 'callfunc' supporting labels in other npcs "NpcName::LabelName" -// - 'function FuncName;' function declarations reverting to global functions -// if local label isn't found -// - join callfunc and callsub's functionality -// - remove dynamic allocation in add_word() -// - remove GETVALUE / SETVALUE -// - clean up the set_reg / set_val / setd_sub mess -// - detect invalid label references at parse-time - -// -// struct script_state* st; -// - -/// Returns the script_data at the target index -#define script_getdata(st,i) ( &((st)->stack->stack_data[(st)->start + (i)]) ) -/// Returns if the stack contains data at the target index -#define script_hasdata(st,i) ( (st)->end > (st)->start + (i) ) -/// Returns the index of the last data in the stack -#define script_lastdata(st) ( (st)->end - (st)->start - 1 ) -/// Pushes an int into the stack -#define script_pushint(st,val) push_val((st)->stack, C_INT, (val)) -/// Pushes a string into the stack (script engine frees it automatically) -#define script_pushstr(st,val) push_str((st)->stack, C_STR, (val)) -/// Pushes a copy of a string into the stack -#define script_pushstrcopy(st,val) push_str((st)->stack, C_STR, aStrdup(val)) -/// Pushes a constant string into the stack (must never change or be freed) -#define script_pushconststr(st,val) push_str((st)->stack, C_CONSTSTR, (val)) -/// Pushes a nil into the stack -#define script_pushnil(st) push_val((st)->stack, C_NOP, 0) -/// Pushes a copy of the data in the target index -#define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i)) - -#define script_isstring(st,i) data_isstring(script_getdata(st,i)) -#define script_isint(st,i) data_isint(script_getdata(st,i)) - -#define script_getnum(st,val) conv_num(st, script_getdata(st,val)) -#define script_getstr(st,val) conv_str(st, script_getdata(st,val)) -#define script_getref(st,val) ( script_getdata(st,val)->ref ) - -// Note: "top" functions/defines use indexes relative to the top of the stack -// -1 is the index of the data at the top - -/// Returns the script_data at the target index relative to the top of the stack -#define script_getdatatop(st,i) ( &((st)->stack->stack_data[(st)->stack->sp + (i)]) ) -/// Pushes a copy of the data in the target index relative to the top of the stack -#define script_pushcopytop(st,i) push_copy((st)->stack, (st)->stack->sp + (i)) -/// Removes the range of values [start,end[ relative to the top of the stack -#define script_removetop(st,start,end) ( pop_stack((st), ((st)->stack->sp + (start)), (st)->stack->sp + (end)) ) - -// -// struct script_data* data; -// - -/// Returns if the script data is a string -#define data_isstring(data) ( (data)->type == C_STR || (data)->type == C_CONSTSTR ) -/// Returns if the script data is an int -#define data_isint(data) ( (data)->type == C_INT ) -/// Returns if the script data is a reference -#define data_isreference(data) ( (data)->type == C_NAME ) -/// Returns if the script data is a label -#define data_islabel(data) ( (data)->type == C_POS ) -/// Returns if the script data is an internal script function label -#define data_isfunclabel(data) ( (data)->type == C_USERFUNC_POS ) - -/// Returns if this is a reference to a constant -#define reference_toconstant(data) ( str_data[reference_getid(data)].type == C_INT ) -/// Returns if this a reference to a param -#define reference_toparam(data) ( str_data[reference_getid(data)].type == C_PARAM ) -/// Returns if this a reference to a variable -//##TODO confirm it's C_NAME [FlavioJS] -#define reference_tovariable(data) ( str_data[reference_getid(data)].type == C_NAME ) -/// Returns the unique id of the reference (id and index) -#define reference_getuid(data) ( (data)->u.num ) -/// Returns the id of the reference -#define reference_getid(data) ( (int32)(reference_getuid(data) & 0x00ffffff) ) -/// Returns the array index of the reference -#define reference_getindex(data) ( (int32)(((uint32)(reference_getuid(data) & 0xff000000)) >> 24) ) -/// Returns the name of the reference -#define reference_getname(data) ( str_buf + str_data[reference_getid(data)].str ) -/// Returns the linked list of uid-value pairs of the reference (can be NULL) -#define reference_getref(data) ( (data)->ref ) -/// Returns the value of the constant -#define reference_getconstant(data) ( str_data[reference_getid(data)].val ) -/// Returns the type of param -#define reference_getparamtype(data) ( str_data[reference_getid(data)].val ) - -/// Composes the uid of a reference from the id and the index -#define reference_uid(id,idx) ( (int32)((((uint32)(id)) & 0x00ffffff) | (((uint32)(idx)) << 24)) ) - -#define not_server_variable(prefix) ( (prefix) != '$' && (prefix) != '.' && (prefix) != '\'') -#define not_array_variable(prefix) ( (prefix) != '$' && (prefix) != '@' && (prefix) != '.' && (prefix) != '\'' ) -#define is_string_variable(name) ( (name)[strlen(name) - 1] == '$' ) - #define FETCH(n, t) \ if( script_hasdata(st,n) ) \ (t)=script_getnum(st,n); @@ -198,7 +96,7 @@ static struct str_data_struct { int str; int backpatch; int label; - int (*func)(struct script_state *st); + bool (*func)(struct script_state *st); int val; int next; } *str_data = NULL; @@ -303,40 +201,8 @@ int potion_target=0; c_op get_com(unsigned char *script,int *pos); int get_num(unsigned char *script,int *pos); -typedef struct script_function { - int (*func)(struct script_state *st); - const char *name; - const char *arg; -} script_function; - -extern script_function buildin_func[]; - static struct linkdb_node* sleep_db;// int oid -> struct script_state* -#ifdef BETA_THREAD_TEST -/** - * MySQL Query Slave - **/ -static SPIN_LOCK queryThreadLock; -static rAthread queryThread = NULL; -static ramutex queryThreadMutex = NULL; -static racond queryThreadCond = NULL; -static volatile int32 queryThreadTerminate = 0; - -struct queryThreadEntry { - bool ok; - bool type; /* main db or log db? */ - struct script_state *st; -}; - -/* Ladies and Gentleman the Manager! */ -struct { - struct queryThreadEntry **entry;/* array of structs */ - int count; - int timer;/* used to receive processed entries */ -} queryThreadData; -#endif - /*========================================== * (Only those needed) local declaration prototype *------------------------------------------*/ @@ -364,13 +230,8 @@ enum { MF_FOG, MF_SAKURA, MF_LEAVES, - /** - * No longer available, keeping here just in case it's back someday. [Ind] - **/ - //MF_RAIN, //20 - // 21 free - MF_NOGO = 22, - MF_CLOUDS, + /* 21 - 22 free */ + MF_CLOUDS = 23, MF_CLOUDS2, MF_FIREWORKS, MF_GVG_CASTLE, @@ -383,7 +244,7 @@ enum { MF_NORETURN, MF_NOWARPTO, MF_NIGHTMAREDROP, - MF_RESTRICTED, + MF_ZONE, MF_NOCOMMAND, MF_NODROP, MF_JEXP, @@ -506,20 +367,19 @@ static void script_reportsrc(struct script_state *st) if( bl == NULL ) return; - switch( bl->type ) - { - case BL_NPC: - if( bl->m >= 0 ) - ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y); - else - ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name); - break; - default: - if( bl->m >= 0 ) - ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(bl), map[bl->m].name, bl->x, bl->y); - else - ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl)); - break; + switch( bl->type ) { + case BL_NPC: + if( bl->m >= 0 ) + ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y); + else + ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name); + break; + default: + if( bl->m >= 0 ) + ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(bl), map[bl->m].name, bl->x, bl->y); + else + ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl)); + break; } } @@ -528,54 +388,43 @@ static void script_reportdata(struct script_data* data) { if( data == NULL ) return; - switch( data->type ) - { - case C_NOP:// no value - ShowDebug("Data: nothing (nil)\n"); - break; - case C_INT:// number - ShowDebug("Data: number value=%d\n", data->u.num); - break; - case C_STR: - case C_CONSTSTR:// string - if( data->u.str ) - { - ShowDebug("Data: string value=\"%s\"\n", data->u.str); - } - else - { - ShowDebug("Data: string value=NULL\n"); - } - break; - case C_NAME:// reference - if( reference_tovariable(data) ) - {// variable - const char* name = reference_getname(data); - if( not_array_variable(*name) ) - ShowDebug("Data: variable name='%s'\n", name); - else - ShowDebug("Data: variable name='%s' index=%d\n", name, reference_getindex(data)); - } - else if( reference_toconstant(data) ) - {// constant - ShowDebug("Data: constant name='%s' value=%d\n", reference_getname(data), reference_getconstant(data)); - } - else if( reference_toparam(data) ) - {// param - ShowDebug("Data: param name='%s' type=%d\n", reference_getname(data), reference_getparamtype(data)); - } - else - {// ??? - ShowDebug("Data: reference name='%s' type=%s\n", reference_getname(data), script_op2name(data->type)); - ShowDebug("Please report this!!! - str_data.type=%s\n", script_op2name(str_data[reference_getid(data)].type)); - } - break; - case C_POS:// label - ShowDebug("Data: label pos=%d\n", data->u.num); - break; - default: - ShowDebug("Data: %s\n", script_op2name(data->type)); - break; + switch( data->type ) { + case C_NOP:// no value + ShowDebug("Data: nothing (nil)\n"); + break; + case C_INT:// number + ShowDebug("Data: number value=%d\n", data->u.num); + break; + case C_STR: + case C_CONSTSTR:// string + if( data->u.str ) { + ShowDebug("Data: string value=\"%s\"\n", data->u.str); + } else { + ShowDebug("Data: string value=NULL\n"); + } + break; + case C_NAME:// reference + if( reference_tovariable(data) ) {// variable + const char* name = reference_getname(data); + if( not_array_variable(*name) ) + ShowDebug("Data: variable name='%s'\n", name); + else + ShowDebug("Data: variable name='%s' index=%d\n", name, reference_getindex(data)); + } else if( reference_toconstant(data) ) {// constant + ShowDebug("Data: constant name='%s' value=%d\n", reference_getname(data), reference_getconstant(data)); + } else if( reference_toparam(data) ) {// param + ShowDebug("Data: param name='%s' type=%d\n", reference_getname(data), reference_getparamtype(data)); + } else {// ??? + ShowDebug("Data: reference name='%s' type=%s\n", reference_getname(data), script_op2name(data->type)); + ShowDebug("Please report this!!! - str_data.type=%s\n", script_op2name(str_data[reference_getid(data)].type)); + } + break; + case C_POS:// label + ShowDebug("Data: label pos=%d\n", data->u.num); + break; + default: + ShowDebug("Data: %s\n", script_op2name(data->type)); + break; } } @@ -807,33 +656,33 @@ static void add_scriptl(int l) int backpatch = str_data[l].backpatch; switch(str_data[l].type){ - case C_POS: - case C_USERFUNC_POS: - add_scriptc(C_POS); - add_scriptb(str_data[l].label); - add_scriptb(str_data[l].label>>8); - add_scriptb(str_data[l].label>>16); - break; - case C_NOP: - case C_USERFUNC: - // Embedded data backpatch there is a possibility of label - add_scriptc(C_NAME); - str_data[l].backpatch = script_pos; - add_scriptb(backpatch); - add_scriptb(backpatch>>8); - add_scriptb(backpatch>>16); - break; - case C_INT: - add_scripti(abs(str_data[l].val)); - if( str_data[l].val < 0 ) //Notice that this is negative, from jA (Rayce) - add_scriptc(C_NEG); - break; - default: // assume C_NAME - add_scriptc(C_NAME); - add_scriptb(l); - add_scriptb(l>>8); - add_scriptb(l>>16); - break; + case C_POS: + case C_USERFUNC_POS: + add_scriptc(C_POS); + add_scriptb(str_data[l].label); + add_scriptb(str_data[l].label>>8); + add_scriptb(str_data[l].label>>16); + break; + case C_NOP: + case C_USERFUNC: + // Embedded data backpatch there is a possibility of label + add_scriptc(C_NAME); + str_data[l].backpatch = script_pos; + add_scriptb(backpatch); + add_scriptb(backpatch>>8); + add_scriptb(backpatch>>16); + break; + case C_INT: + add_scripti(abs(str_data[l].val)); + if( str_data[l].val < 0 ) //Notice that this is negative, from jA (Rayce) + add_scriptc(C_NEG); + break; + default: // assume C_NAME + add_scriptc(C_NAME); + add_scriptb(l); + add_scriptb(l>>8); + add_scriptb(l>>16); + break; } } @@ -961,8 +810,8 @@ int add_word(const char* p) static const char* parse_callfunc(const char* p, int require_paren, int is_custom) { - const char* p2; - const char* arg=NULL; + const char *p2; + char *arg = NULL; int func; func = add_word(p); @@ -970,13 +819,13 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) // buildin function add_scriptl(func); add_scriptc(C_ARG); - arg = buildin_func[str_data[func].val].arg; + arg = script->buildin[str_data[func].val]; } else if( str_data[func].type == C_USERFUNC || str_data[func].type == C_USERFUNC_POS ){ // script defined function add_scriptl(buildin_callsub_ref); add_scriptc(C_ARG); add_scriptl(func); - arg = buildin_func[str_data[buildin_callsub_ref].val].arg; + arg = script->buildin[str_data[buildin_callsub_ref].val]; if( *arg == 0 ) disp_error_message("parse_callfunc: callsub has no arguments, please review it's definition",p); if( *arg != '*' ) @@ -994,7 +843,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) add_scriptc(C_STR); while( *name ) add_scriptb(*name ++); add_scriptb(0); - arg = buildin_func[str_data[buildin_callfunc_ref].val].arg; + arg = script->buildin[str_data[buildin_callfunc_ref].val]; if( *arg != '*' ) ++ arg; } #endif @@ -1016,8 +865,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) {// <func name> syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN; */ - } else - {// <func name> <arg list> + } else {// <func name> <arg list> if( require_paren ){ if( *p != '(' ) disp_error_message("need '('",p); @@ -1043,7 +891,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) } --syntax.curly_count; } - if( *arg && *arg != '?' && *arg != '*' ) + if( arg && *arg && *arg != '?' && *arg != '*' ) disp_error_message2("parse_callfunc: not enough arguments, expected ','", p, script_config.warn_func_mismatch_paramnum); if( syntax.curly[syntax.curly_count].type != TYPE_ARGLIST ) disp_error_message("parse_callfunc: DEBUG last curly is not an argument list",p); @@ -1247,18 +1095,16 @@ const char* parse_simpleexpr(const char *p) add_scriptc(C_STR); p++; while( *p && *p != '"' ){ - if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) - { + if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) { char buf[8]; - size_t len = skip_escaped_c(p) - p; - size_t n = sv_unescape_c(buf, p, len); + size_t len = sv->skip_escaped_c(p) - p; + size_t n = sv->unescape_c(buf, p, len); if( n != 1 ) ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf); p += len; add_scriptb(*buf); continue; - } - else if( *p == '\n' ) + } else if( *p == '\n' ) disp_error_message("parse_simpleexpr: unexpected newline @ string",p); add_scriptb(*p++); } @@ -1609,9 +1455,9 @@ const char* parse_syntax(const char* p) set_label(l,script_pos,p); } // check duplication of case label [Rayce] - if(linkdb_search(&syntax.curly[pos].case_label, (void*)__64BPRTSIZE(v)) != NULL) + if(linkdb_search(&syntax.curly[pos].case_label, (void*)__64BPTRSIZE(v)) != NULL) disp_error_message("parse_syntax: dup 'case'",p); - linkdb_insert(&syntax.curly[pos].case_label, (void*)__64BPRTSIZE(v), (void*)1); + linkdb_insert(&syntax.curly[pos].case_label, (void*)__64BPTRSIZE(v), (void*)1); sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index); syntax.curly[syntax.curly_count++].type = TYPE_NULL; @@ -2121,45 +1967,6 @@ const char* parse_syntax_close_sub(const char* p,int* flag) } } -/*========================================== - * Added built-in functions - *------------------------------------------*/ -static void add_buildin_func(void) -{ - int i,n; - const char* p; - for( i = 0; buildin_func[i].func; i++ ) - { - // arg must follow the pattern: (v|s|i|r|l)*\?*\*? - // 'v' - value (either string or int or reference) - // 's' - string - // 'i' - int - // 'r' - reference (of a variable) - // 'l' - label - // '?' - one optional parameter - // '*' - unknown number of optional parameters - p = buildin_func[i].arg; - while( *p == 'v' || *p == 's' || *p == 'i' || *p == 'r' || *p == 'l' ) ++p; - while( *p == '?' ) ++p; - if( *p == '*' ) ++p; - if( *p != 0){ - ShowWarning("add_buildin_func: ignoring function \"%s\" with invalid arg \"%s\".\n", buildin_func[i].name, buildin_func[i].arg); - } else if( *skip_word(buildin_func[i].name) != 0 ){ - ShowWarning("add_buildin_func: ignoring function with invalid name \"%s\" (must be a word).\n", buildin_func[i].name); - } else { - n = add_str(buildin_func[i].name); - str_data[n].type = C_FUNC; - str_data[n].val = i; - str_data[n].func = buildin_func[i].func; - - if (!strcmp(buildin_func[i].name, "set")) buildin_set_ref = n; - else if (!strcmp(buildin_func[i].name, "callsub")) buildin_callsub_ref = n; - else if (!strcmp(buildin_func[i].name, "callfunc")) buildin_callfunc_ref = n; - else if( !strcmp(buildin_func[i].name, "getelementofarray") ) buildin_getelementofarray_ref = n; - } - } -} - /// Retrieves the value of a constant. bool script_get_constant(const char* name, int* value) { @@ -2231,16 +2038,16 @@ static const char* script_print_line(StringBuf* buf, const char* p, const char* int i; if( p == NULL || !p[0] ) return NULL; if( line < 0 ) - StringBuf_Printf(buf, "*% 5d : ", -line); + StrBuf->Printf(buf, "*% 5d : ", -line); else - StringBuf_Printf(buf, " % 5d : ", line); + StrBuf->Printf(buf, " % 5d : ", line); for(i=0;p[i] && p[i] != '\n';i++){ if(p + i != mark) - StringBuf_Printf(buf, "%c", p[i]); + StrBuf->Printf(buf, "%c", p[i]); else - StringBuf_Printf(buf, "\'%c\'", p[i]); + StrBuf->Printf(buf, "\'%c\'", p[i]); } - StringBuf_AppendStr(buf, "\n"); + StrBuf->AppendStr(buf, "\n"); return p+i+(p[i] == '\n' ? 1 : 0); } @@ -2265,10 +2072,10 @@ void script_error(const char* src, const char* file, int start_line, const char* p=lineend+1; } - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "\a\n"); - StringBuf_Printf(&buf, "script error on %s line %d\n", file, line); - StringBuf_Printf(&buf, " %s\n", error_msg); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "\a\n"); + StrBuf->Printf(&buf, "script error on %s line %d\n", file, line); + StrBuf->Printf(&buf, " %s\n", error_msg); for(j = 0; j < 5; j++ ) { script_print_line(&buf, linestart[j], NULL, line + j - 5); } @@ -2276,8 +2083,8 @@ void script_error(const char* src, const char* file, int start_line, const char* for(j = 0; j < 5; j++) { p = script_print_line(&buf, p, NULL, line + j + 1 ); } - ShowError("%s", StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + ShowError("%s", StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); } /*========================================== @@ -2288,7 +2095,6 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o const char *p,*tmpp; int i; struct script_code* code = NULL; - static int first=1; char end; bool unresolved_names = false; @@ -2296,11 +2102,6 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o return NULL;// empty script memset(&syntax,0,sizeof(syntax)); - if(first){ - add_buildin_func(); - read_constdb(); - first=0; - } script_buf=(unsigned char *)aMalloc(SCRIPT_BLOCK_SIZE*sizeof(unsigned char)); script_pos=0; @@ -2649,7 +2450,7 @@ void* get_val2(struct script_state* st, int uid, struct DBMap** ref) push_val2(st->stack, C_NAME, uid, ref); data = script_getdatatop(st, -1); get_val(st, data); - return (data->type == C_INT ? (void*)__64BPRTSIZE(data->u.num) : (void*)__64BPRTSIZE(data->u.str)); + return (data->type == C_INT ? (void*)__64BPTRSIZE(data->u.num) : (void*)__64BPTRSIZE(data->u.str)); } /*========================================== @@ -2694,7 +2495,7 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam } else {// integer variable - int val = (int)__64BPRTSIZE(value); + int val = (int)__64BPTRSIZE(value); if(str_data[num&0x00ffffff].type == C_PARAM) { if( pc_setparam(sd, str_data[num&0x00ffffff].val, val) == 0 ) @@ -2788,8 +2589,7 @@ const char* conv_str(struct script_state* st, struct script_data* data) } /// Converts the data to an int -int conv_num(struct script_state* st, struct script_data* data) -{ +int conv_num(struct script_state* st, struct script_data* data) { char* p; long num; @@ -3016,6 +2816,7 @@ struct script_state* script_alloc_state(struct script_code* script, int pos, int st->rid = rid; st->oid = oid; st->sleep.timer = INVALID_TIMER; + st->npc_item_flag = battle_config.item_enabled_npc; return st; } @@ -3248,11 +3049,11 @@ void op_2(struct script_state *st, int op) case C_ADD: if( data_isint(left) && data_isstring(right) ) {// convert int-string to string-string - conv_str(st, left); + script->conv_str(st, left); } else if( data_isstring(left) && data_isint(right) ) {// convert string-int to string-string - conv_str(st, right); + script->conv_str(st, right); } break; } @@ -3339,26 +3140,20 @@ static void script_check_buildin_argtype(struct script_state* st, int func) { char type; int idx, invalid = 0; - script_function* sf = &buildin_func[str_data[func].val]; + char* sf = script->buildin[str_data[func].val]; - for( idx = 2; script_hasdata(st, idx); idx++ ) - { + for( idx = 2; script_hasdata(st, idx); idx++ ) { struct script_data* data = script_getdata(st, idx); - type = sf->arg[idx-2]; - - if( type == '?' || type == '*' ) - {// optional argument or unknown number of optional parameters ( no types are after this ) + type = sf[idx-2]; + + if( type == '?' || type == '*' ) {// optional argument or unknown number of optional parameters ( no types are after this ) break; - } - else if( type == 0 ) - {// more arguments than necessary ( should not happen, as it is checked before ) + } else if( type == 0 ) {// more arguments than necessary ( should not happen, as it is checked before ) ShowWarning("Found more arguments than necessary. unexpected arg type %s\n",script_op2name(data->type)); invalid++; break; - } - else - { + } else { const char* name = NULL; if( data_isreference(data) ) @@ -3366,8 +3161,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func) name = reference_getname(data); } - switch( type ) - { + switch( type ) { case 'v': if( !data_isstring(data) && !data_isint(data) && !data_isreference(data) ) {// variant @@ -3412,8 +3206,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func) } } - if(invalid) - { + if(invalid) { ShowDebug("Function: %s\n", get_str(func)); script_reportsrc(st); } @@ -3460,7 +3253,7 @@ int run_func(struct script_state *st) } if(str_data[func].func){ - if (str_data[func].func(st)) //Report error + if (!(str_data[func].func(st))) //Report error script_reportsrc(st); } else { ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", get_str(func), func, script_op2name(str_data[func].type)); @@ -3527,7 +3320,7 @@ void script_stop_sleeptimers(int id) struct script_state* st; for(;;) { - st = (struct script_state*)linkdb_erase(&sleep_db,(void*)__64BPRTSIZE(id)); + st = (struct script_state*)linkdb_erase(&sleep_db,(void*)__64BPTRSIZE(id)); if( st == NULL ) break; // no more sleep timers script_free_state(st); @@ -3569,7 +3362,7 @@ int run_script_timer(int tid, unsigned int tick, int id, intptr_t data) st->state = END; } while( node && st->sleep.timer != INVALID_TIMER ) { - if( (int)__64BPRTSIZE(node->key) == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) { + if( (int)__64BPTRSIZE(node->key) == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) { script_erase_sleepdb(node); st->sleep.timer = INVALID_TIMER; break; @@ -3590,30 +3383,26 @@ static void script_detach_state(struct script_state* st, bool dequeue_event) { struct map_session_data* sd; - if(st->rid && (sd = map_id2sd(st->rid))!=NULL) - { + if(st->rid && (sd = map_id2sd(st->rid))!=NULL) { sd->st = st->bk_st; sd->npc_id = st->bk_npcid; - /** - * For the Secure NPC Timeout option (check config/Secure.h) [RR] - **/ - #if SECURE_NPCTIMEOUT - /** - * We're done with this NPC session, so we cancel the timer (if existent) and move on - **/ - if( sd->npc_idle_timer != INVALID_TIMER ) { - delete_timer(sd->npc_idle_timer,npc_rr_secure_timeout_timer); - sd->npc_idle_timer = INVALID_TIMER; - } - #endif - if(st->bk_st) - { + if(st->bk_st) { //Remove tag for removal. st->bk_st = NULL; st->bk_npcid = 0; - } - else if(dequeue_event) - { + } else if(dequeue_event) { + /** + * For the Secure NPC Timeout option (check config/Secure.h) [RR] + **/ +#ifdef SECURE_NPCTIMEOUT + /** + * We're done with this NPC session, so we cancel the timer (if existent) and move on + **/ + if( sd->npc_idle_timer != INVALID_TIMER ) { + delete_timer(sd->npc_idle_timer,npc_rr_secure_timeout_timer); + sd->npc_idle_timer = INVALID_TIMER; + } +#endif npc_event_dequeue(sd); } } @@ -3647,10 +3436,11 @@ static void script_attach_state(struct script_state* st) } sd->st = st; sd->npc_id = st->oid; + sd->npc_item_flag = st->npc_item_flag; // load default. /** * For the Secure NPC Timeout option (check config/Secure.h) [RR] **/ -#if SECURE_NPCTIMEOUT +#ifdef SECURE_NPCTIMEOUT if( sd->npc_idle_timer == INVALID_TIMER ) sd->npc_idle_timer = add_timer(gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0); sd->npc_idle_tick = gettick(); @@ -3778,7 +3568,7 @@ void run_script_main(struct script_state *st) st->sleep.charid = sd?sd->status.char_id:0; st->sleep.timer = add_timer(gettick()+st->sleep.tick, run_script_timer, st->sleep.charid, (intptr_t)st); - linkdb_insert(&sleep_db, (void*)__64BPRTSIZE(st->oid), st); + linkdb_insert(&sleep_db, (void*)__64BPTRSIZE(st->oid), st); } else if(st->state != END && st->rid){ //Resume later (st is already attached to player). @@ -3798,7 +3588,7 @@ void run_script_main(struct script_state *st) if ((sd = map_id2sd(st->rid))!=NULL) { //Restore previous stack and save char. if(sd->state.using_fake_npc){ - clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd); + clif->clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd); sd->state.using_fake_npc = 0; } //Restore previous script if any. @@ -3868,7 +3658,7 @@ int script_config_read(char *cfgName) */ static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap) { - struct script_code *code = db_data2ptr(data); + struct script_code *code = DB->data2ptr(data); if (code) script_free_code(code); return 0; @@ -3922,7 +3712,7 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void { for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ ) { - pc_setreg(sd, reference_uid(key, idx), (int)__64BPRTSIZE(value)); + pc_setreg(sd, reference_uid(key, idx), (int)__64BPTRSIZE(value)); } } } @@ -3954,7 +3744,7 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 } else { - pc_setreg(sd, reference_uid(key, idx), (int)__64BPRTSIZE(value)); + pc_setreg(sd, reference_uid(key, idx), (int)__64BPTRSIZE(value)); } if( refcache ) @@ -3962,179 +3752,10 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 refcache[0] = key; } } -#ifdef BETA_THREAD_TEST -int buildin_query_sql_sub(struct script_state* st, Sql* handle); - -/* used to receive items the queryThread has already processed */ -int queryThread_timer(int tid, unsigned int tick, int id, intptr_t data) { - int i, cursor = 0; - bool allOk = true; - - EnterSpinLock(&queryThreadLock); - - for( i = 0; i < queryThreadData.count; i++ ) { - struct queryThreadEntry *entry = queryThreadData.entry[i]; - - if( !entry->ok ) { - allOk = false; - continue; - } - - run_script_main(entry->st); - - entry->st = NULL;/* empty entries */ - aFree(entry); - queryThreadData.entry[i] = NULL; - } - - - if( allOk ) { - /* cancel the repeating timer -- it'll re-create itself when necessary, dont need to remain looping */ - delete_timer(queryThreadData.timer, queryThread_timer); - queryThreadData.timer = INVALID_TIMER; - } - - /* now lets clear the mess. */ - for( i = 0; i < queryThreadData.count; i++ ) { - struct queryThreadEntry *entry = queryThreadData.entry[i]; - if( entry == NULL ) - continue;/* entry on hold */ - - /* move */ - memmove(&queryThreadData.entry[cursor], &queryThreadData.entry[i], sizeof(struct queryThreadEntry*)); - - cursor++; - } - - queryThreadData.count = cursor; - - LeaveSpinLock(&queryThreadLock); - - return 0; -} - -void queryThread_add(struct script_state *st, bool type) { - int idx = 0; - struct queryThreadEntry* entry = NULL; - - EnterSpinLock(&queryThreadLock); - - if( queryThreadData.count++ != 0 ) - RECREATE(queryThreadData.entry, struct queryThreadEntry* , queryThreadData.count); - - idx = queryThreadData.count-1; - - CREATE(queryThreadData.entry[idx],struct queryThreadEntry,1); - - entry = queryThreadData.entry[idx]; - - entry->st = st; - entry->ok = false; - entry->type = type; - if( queryThreadData.timer == INVALID_TIMER ) { /* start the receiver timer */ - queryThreadData.timer = add_timer_interval(gettick() + 100, queryThread_timer, 0, 0, 100); - } - - LeaveSpinLock(&queryThreadLock); - - /* unlock the queryThread */ - racond_signal(queryThreadCond); -} -/* adds a new log to the queue */ -void queryThread_log(char * entry, int length) { - int idx = logThreadData.count; - - EnterSpinLock(&queryThreadLock); - - if( logThreadData.count++ != 0 ) - RECREATE(logThreadData.entry, char* , logThreadData.count); - - CREATE(logThreadData.entry[idx], char, length + 1 ); - safestrncpy(logThreadData.entry[idx], entry, length + 1 ); - - LeaveSpinLock(&queryThreadLock); - - /* unlock the queryThread */ - racond_signal(queryThreadCond); -} - -/* queryThread_main */ -static void *queryThread_main(void *x) { - Sql *queryThread_handle = Sql_Malloc(); - int i; - - if ( SQL_ERROR == Sql_Connect(queryThread_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ) - exit(EXIT_FAILURE); - - if( strlen(default_codepage) > 0 ) - if ( SQL_ERROR == Sql_SetEncoding(queryThread_handle, default_codepage) ) - Sql_ShowDebug(queryThread_handle); - - if( log_config.sql_logs ) { - logmysql_handle = Sql_Malloc(); - - if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ) - exit(EXIT_FAILURE); - - if( strlen(default_codepage) > 0 ) - if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) ) - Sql_ShowDebug(logmysql_handle); - } - - while( 1 ) { - - if(queryThreadTerminate > 0) - break; - - EnterSpinLock(&queryThreadLock); - - /* mess with queryThreadData within the lock */ - for( i = 0; i < queryThreadData.count; i++ ) { - struct queryThreadEntry *entry = queryThreadData.entry[i]; - - if( entry->ok ) - continue; - else if ( !entry->st || !entry->st->stack ) { - entry->ok = true;/* dispose */ - continue; - } - - buildin_query_sql_sub(entry->st, entry->type ? logmysql_handle : queryThread_handle); - - entry->ok = true;/* we're done with this */ - } - - /* also check for any logs in need to be sent */ - if( log_config.sql_logs ) { - for( i = 0; i < logThreadData.count; i++ ) { - if( SQL_ERROR == Sql_Query(logmysql_handle, logThreadData.entry[i]) ) - Sql_ShowDebug(logmysql_handle); - aFree(logThreadData.entry[i]); - } - logThreadData.count = 0; - } - - LeaveSpinLock(&queryThreadLock); - - ramutex_lock( queryThreadMutex ); - racond_wait( queryThreadCond, queryThreadMutex, -1 ); - ramutex_unlock( queryThreadMutex ); - - } - - Sql_Free(queryThread_handle); - - if( log_config.sql_logs ) { - Sql_Free(logmysql_handle); - } - - return NULL; -} -#endif /*========================================== * Destructor *------------------------------------------*/ -int do_final_script() { +void do_final_script(void) { int i; #ifdef DEBUG_HASH if (battle_config.etc_log) @@ -4211,107 +3832,49 @@ int do_final_script() { if (str_buf) aFree(str_buf); - for( i = 0; i < atcmd_binding_count; i++ ) { - aFree(atcmd_binding[i]); + for( i = 0; i < atcommand->binding_count; i++ ) { + aFree(atcommand->binding[i]); } - if( atcmd_binding_count != 0 ) - aFree(atcmd_binding); -#ifdef BETA_THREAD_TEST - /* QueryThread */ - InterlockedIncrement(&queryThreadTerminate); - racond_signal(queryThreadCond); - rathread_wait(queryThread, NULL); - - // Destroy cond var and mutex. - racond_destroy( queryThreadCond ); - ramutex_destroy( queryThreadMutex ); - - /* Clear missing vars */ - for( i = 0; i < queryThreadData.count; i++ ) { - aFree(queryThreadData.entry[i]); - } - - aFree(queryThreadData.entry); - - for( i = 0; i < logThreadData.count; i++ ) { - aFree(logThreadData.entry[i]); + if( atcommand->binding_count != 0 ) + aFree(atcommand->binding); + + for( i = 0; i < script->buildin_count; i++) { + if( script->buildin[i] ) { + aFree(script->buildin[i]); + script->buildin[i] = NULL; + } } + + aFree(script->buildin); - aFree(logThreadData.entry); -#endif - - return 0; } /*========================================== * Initialization *------------------------------------------*/ -int do_init_script() { - userfunc_db=strdb_alloc(DB_OPT_DUP_KEY,0); - scriptlabel_db=strdb_alloc(DB_OPT_DUP_KEY,50); +void do_init_script(void) { + userfunc_db = strdb_alloc(DB_OPT_DUP_KEY,0); + scriptlabel_db = strdb_alloc(DB_OPT_DUP_KEY,50); autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0); - + script->parse_builtin(); + read_constdb(); mapreg_init(); -#ifdef BETA_THREAD_TEST - CREATE(queryThreadData.entry, struct queryThreadEntry*, 1); - queryThreadData.count = 0; - CREATE(logThreadData.entry, char *, 1); - logThreadData.count = 0; - /* QueryThread Start */ - - InitializeSpinLock(&queryThreadLock); - - queryThreadData.timer = INVALID_TIMER; - queryThreadTerminate = 0; - queryThreadMutex = ramutex_create(); - queryThreadCond = racond_create(); - - queryThread = rathread_create(queryThread_main, NULL); - - if(queryThread == NULL){ - ShowFatalError("do_init_script: cannot spawn Query Thread.\n"); - exit(EXIT_FAILURE); - } - - add_timer_func_list(queryThread_timer, "queryThread_timer"); -#endif - return 0; } int script_reload() { int i; -#ifdef BETA_THREAD_TEST - /* we're reloading so any queries undergoing should be...exterminated. */ - EnterSpinLock(&queryThreadLock); - - for( i = 0; i < queryThreadData.count; i++ ) { - aFree(queryThreadData.entry[i]); - } - queryThreadData.count = 0; - - if( queryThreadData.timer != INVALID_TIMER ) { - delete_timer(queryThreadData.timer, queryThread_timer); - queryThreadData.timer = INVALID_TIMER; - } - - LeaveSpinLock(&queryThreadLock); -#endif - - userfunc_db->clear(userfunc_db, db_script_free_code_sub); db_clear(scriptlabel_db); - // @commands (script based) - // Clear bindings - for( i = 0; i < atcmd_binding_count; i++ ) { - aFree(atcmd_binding[i]); + for( i = 0; i < atcommand->binding_count; i++ ) { + aFree(atcommand->binding[i]); } - if( atcmd_binding_count != 0 ) - aFree(atcmd_binding); + if( atcommand->binding_count != 0 ) + aFree(atcommand->binding); - atcmd_binding_count = 0; + atcommand->binding_count = 0; if(sleep_db) { struct linkdb_node *n = (struct linkdb_node *)sleep_db; @@ -4332,7 +3895,6 @@ int script_reload() { #define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args } #define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args } -#define BUILDIN_FUNC(x) int buildin_ ## x (struct script_state* st) ///////////////////////////////////////////////////////////////////// // NPC interaction @@ -4342,79 +3904,81 @@ int script_reload() { /// If a dialog doesn't exist yet, one is created. /// /// mes "<message>"; -BUILDIN_FUNC(mes) +BUILDIN(mes) { TBL_PC* sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if( !script_hasdata(st, 3) ) {// only a single line detected in the script - clif_scriptmes(sd, st->oid, script_getstr(st, 2)); + clif->scriptmes(sd, st->oid, script_getstr(st, 2)); } else {// parse multiple lines as they exist int i; - + for( i = 2; script_hasdata(st, i); i++ ) { // send the message to the client - clif_scriptmes(sd, st->oid, script_getstr(st, i)); + clif->scriptmes(sd, st->oid, script_getstr(st, i)); } } - - return 0; + + return true; } /// Displays the button 'next' in the npc dialog. /// The dialog text is cleared and the script continues when the button is pressed. /// /// next; -BUILDIN_FUNC(next) +BUILDIN(next) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; +#ifdef SECURE_NPCTIMEOUT + sd->npc_idle_type = NPCT_WAIT; +#endif st->state = STOP; - clif_scriptnext(sd, st->oid); - return 0; + clif->scriptnext(sd, st->oid); + return true; } /// Ends the script and displays the button 'close' on the npc dialog. /// The dialog is closed when the button is pressed. /// /// close; -BUILDIN_FUNC(close) +BUILDIN(close) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - - st->state = END; - clif_scriptclose(sd, st->oid); - return 0; + return true; + + st->state = CLOSE; + clif->scriptclose(sd, st->oid); + return true; } /// Displays the button 'close' on the npc dialog. /// The dialog is closed and the script continues when the button is pressed. /// /// close2; -BUILDIN_FUNC(close2) +BUILDIN(close2) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + st->state = STOP; - clif_scriptclose(sd, st->oid); - return 0; + clif->scriptclose(sd, st->oid); + return true; } /// Counts the number of valid and total number of options in 'str' @@ -4424,11 +3988,11 @@ static int menu_countoptions(const char* str, int max_count, int* total) { int count = 0; int bogus_total; - + if( total == NULL ) total = &bogus_total; ++(*total); - + // initial empty options while( *str == ':' ) { @@ -4469,74 +4033,78 @@ static int menu_countoptions(const char* str, int max_count, int* total) /// NOTE: the client closes the npc dialog when cancel is pressed /// /// menu "<option_text>",<target_label>{,"<option_text>",<target_label>,...}; -BUILDIN_FUNC(menu) +BUILDIN(menu) { int i; const char* text; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + +#ifdef SECURE_NPCTIMEOUT + sd->npc_idle_type = NPCT_MENU; +#endif + // TODO detect multiple scripts waiting for input at the same time, and what to do when that happens if( sd->state.menu_or_input == 0 ) { struct StringBuf buf; struct script_data* data; - + if( script_lastdata(st) % 2 == 0 ) {// argument count is not even (1st argument is at index 2) ShowError("script:menu: illegal number of arguments (%d).\n", (script_lastdata(st) - 1)); st->state = END; - return 1; + return false; } - - StringBuf_Init(&buf); + + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i < script_lastdata(st); i += 2 ) { // menu options text = script_getstr(st, i); - + // target label data = script_getdata(st, i+1); if( !data_islabel(data) ) {// not a label - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); ShowError("script:menu: argument #%d (from 1) is not a label or label not found.\n", i); script_reportdata(data); st->state = END; - return 1; + return false; } - + // append option(s) if( text[0] == '\0' ) continue;// empty string, ignore if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } st->state = RERUNLINE; sd->state.menu_or_input = 1; - + /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); - clif_scriptmenu(sd, st->oid, menu); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); + clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - - StringBuf_Destroy(&buf); - + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + + StrBuf->Destroy(&buf); + if( sd->npc_menu >= 0xff ) {// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow ShowWarning("buildin_menu: Too many options specified (current=%d, max=254).\n", sd->npc_menu); @@ -4551,15 +4119,15 @@ BUILDIN_FUNC(menu) else {// goto target label int menu = 0; - + sd->state.menu_or_input = 0; if( sd->npc_menu <= 0 ) { ShowDebug("script:menu: unexpected selection (%d)\n", sd->npc_menu); st->state = END; - return 1; + return false; } - + // get target label for( i = 2; i < script_lastdata(st); i += 2 ) { @@ -4572,20 +4140,20 @@ BUILDIN_FUNC(menu) {// Invalid selection ShowDebug("script:menu: selection is out of range (%d pairs are missing?) - please report this\n", sd->npc_menu); st->state = END; - return 1; + return false; } if( !data_islabel(script_getdata(st, i + 1)) ) {// TODO remove this temporary crash-prevention code (fallback for multiple scripts requesting user input) ShowError("script:menu: unexpected data in label argument\n"); script_reportdata(script_getdata(st, i + 1)); st->state = END; - return 1; + return false; } pc_setreg(sd, add_str("@menu"), menu); st->pos = script_getnum(st, i + 1); st->state = GOTO; } - return 0; + return true; } /// Displays a menu with options and returns the selected option. @@ -4594,49 +4162,53 @@ BUILDIN_FUNC(menu) /// select(<option_text>{,<option_text>,...}) -> <selected_option> /// /// @see menu -BUILDIN_FUNC(select) +BUILDIN(select) { int i; const char* text; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + +#ifdef SECURE_NPCTIMEOUT + sd->npc_idle_type = NPCT_MENU; +#endif + if( sd->state.menu_or_input == 0 ) { struct StringBuf buf; - - StringBuf_Init(&buf); + + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); - + if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } - + st->state = RERUNLINE; sd->state.menu_or_input = 1; - + /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); - clif_scriptmenu(sd, st->oid, menu); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); + clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); - + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); + if( sd->npc_menu >= 0xff ) { ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu); script_reportsrc(st); @@ -4646,7 +4218,7 @@ BUILDIN_FUNC(select) st->state = END; } else {// return selected option int menu = 0; - + sd->state.menu_or_input = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); @@ -4658,7 +4230,7 @@ BUILDIN_FUNC(select) script_pushint(st, menu); st->state = RUN; } - return 0; + return true; } /// Displays a menu with options and returns the selected option. @@ -4669,49 +4241,53 @@ BUILDIN_FUNC(select) /// prompt(<option_text>{,<option_text>,...}) -> <selected_option> /// /// @see menu -BUILDIN_FUNC(prompt) +BUILDIN(prompt) { int i; const char *text; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + +#ifdef SECURE_NPCTIMEOUT + sd->npc_idle_type = NPCT_MENU; +#endif + if( sd->state.menu_or_input == 0 ) { struct StringBuf buf; - - StringBuf_Init(&buf); + + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } - + st->state = RERUNLINE; sd->state.menu_or_input = 1; - + /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); - clif_scriptmenu(sd, st->oid, menu); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); + clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); - + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); + if( sd->npc_menu >= 0xff ) { ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu); @@ -4728,7 +4304,7 @@ BUILDIN_FUNC(prompt) else {// return selected option int menu = 0; - + sd->state.menu_or_input = 0; for( i = 2; i <= script_lastdata(st); ++i ) { @@ -4741,7 +4317,7 @@ BUILDIN_FUNC(prompt) script_pushint(st, menu); st->state = RUN; } - return 0; + return true; } ///////////////////////////////////////////////////////////////////// @@ -4751,40 +4327,40 @@ BUILDIN_FUNC(prompt) /// Jumps to the target script label. /// /// goto <label>; -BUILDIN_FUNC(goto) +BUILDIN(goto) { if( !data_islabel(script_getdata(st,2)) ) { ShowError("script:goto: not a label\n"); script_reportdata(script_getdata(st,2)); st->state = END; - return 1; + return false; } - + st->pos = script_getnum(st,2); st->state = GOTO; - return 0; + return true; } /*========================================== * user-defined function call *------------------------------------------*/ -BUILDIN_FUNC(callfunc) +BUILDIN(callfunc) { int i, j; struct script_retinfo* ri; struct script_code* scr; const char* str = script_getstr(st,2); DBMap **ref = NULL; - + scr = (struct script_code*)strdb_get(userfunc_db, str); if( !scr ) { ShowError("script:callfunc: function not found! [%s]\n", str); st->state = END; - return 1; + return false; } - + for( i = st->start+3, j = 0; i < st->end; i++, j++ ) { struct script_data* data = push_copy(st->stack,i); @@ -4792,15 +4368,13 @@ BUILDIN_FUNC(callfunc) { const char* name = reference_getname(data); if( name[0] == '.' ) { - if ( !ref ) { - ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1); - ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars); - } + ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1); + ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars); data->ref = ref; } } } - + CREATE(ri, struct script_retinfo, 1); ri->script = st->script;// script code ri->var_function = st->stack->var_function;// scope variables @@ -4808,33 +4382,33 @@ BUILDIN_FUNC(callfunc) ri->nargs = j;// argument count ri->defsp = st->stack->defsp;// default stack pointer push_retinfo(st->stack, ri, ref); - + st->pos = 0; st->script = scr; st->stack->defsp = st->stack->sp; st->state = GOTO; st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA); - - return 0; + + return true; } /*========================================== * subroutine call *------------------------------------------*/ -BUILDIN_FUNC(callsub) +BUILDIN(callsub) { int i,j; struct script_retinfo* ri; int pos = script_getnum(st,2); DBMap **ref = NULL; - + if( !data_islabel(script_getdata(st,2)) && !data_isfunclabel(script_getdata(st,2)) ) { ShowError("script:callsub: argument is not a label\n"); script_reportdata(script_getdata(st,2)); st->state = END; - return 1; + return false; } - + for( i = st->start+3, j = 0; i < st->end; i++, j++ ) { struct script_data* data = push_copy(st->stack,i); @@ -4850,7 +4424,7 @@ BUILDIN_FUNC(callsub) } } } - + CREATE(ri, struct script_retinfo, 1); ri->script = st->script;// script code ri->var_function = st->stack->var_function;// scope variables @@ -4858,34 +4432,34 @@ BUILDIN_FUNC(callsub) ri->nargs = j;// argument count ri->defsp = st->stack->defsp;// default stack pointer push_retinfo(st->stack, ri, ref); - + st->pos = pos; st->stack->defsp = st->stack->sp; st->state = GOTO; st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA); - - return 0; + + return true; } /// Retrieves an argument provided to callfunc/callsub. /// If the argument doesn't exist /// /// getarg(<index>{,<default_value>}) -> <value> -BUILDIN_FUNC(getarg) +BUILDIN(getarg) { struct script_retinfo* ri; int idx; - + if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp - 1].type != C_RETINFO ) { ShowError("script:getarg: no callfunc or callsub!\n"); st->state = END; - return 1; + return false; } ri = st->stack->stack_data[st->stack->defsp - 1].u.ri; - + idx = script_getnum(st,2); - + if( idx >= 0 && idx < ri->nargs ) push_copy(st->stack, st->stack->defsp - 1 - ri->nargs + idx); else if( script_hasdata(st,3) ) @@ -4894,10 +4468,10 @@ BUILDIN_FUNC(getarg) { ShowError("script:getarg: index (idx=%d) out of range (nargs=%d) and no default value found\n", idx, ri->nargs); st->state = END; - return 1; + return false; } - - return 0; + + return true; } /// Returns from the current function, optionaly returning a value from the functions. @@ -4905,7 +4479,7 @@ BUILDIN_FUNC(getarg) /// /// return; /// return <value>; -BUILDIN_FUNC(return) +BUILDIN(return) { if( script_hasdata(st,2) ) {// return value @@ -4931,7 +4505,7 @@ BUILDIN_FUNC(return) script_pushnil(st); } st->state = RETFUNC; - return 0; + return true; } /// Returns a random number from 0 to <range>-1. @@ -4939,12 +4513,12 @@ BUILDIN_FUNC(return) /// If <min> is greater than <max>, their numbers are switched. /// rand(<range>) -> <int> /// rand(<min>,<max>) -> <int> -BUILDIN_FUNC(rand) +BUILDIN(rand) { int range; int min; int max; - + if( script_hasdata(st,3) ) {// min,max min = script_getnum(st,2); @@ -4962,41 +4536,41 @@ BUILDIN_FUNC(rand) script_pushint(st, min); else script_pushint(st, rnd()%range + min); - - return 0; + + return true; } /*========================================== * Warp sd to str,x,y or Random or SavePoint/Save *------------------------------------------*/ -BUILDIN_FUNC(warp) +BUILDIN(warp) { int ret; int x,y; const char* str; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + str = script_getstr(st,2); x = script_getnum(st,3); y = script_getnum(st,4); - + if(strcmp(str,"Random")==0) ret = pc_randomwarp(sd,CLR_TELEPORT); else if(strcmp(str,"SavePoint")==0 || strcmp(str,"Save")==0) ret = pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); else ret = pc_setpos(sd,mapindex_name2id(str),x,y,CLR_OUTSIGHT); - + if( ret ) { ShowError("buildin_warp: moving player '%s' to \"%s\",%d,%d failed.\n", sd->status.name, str, x, y); script_reportsrc(st); } - - return 0; + + return true; } /*========================================== * Warp a specified area @@ -5005,42 +4579,42 @@ static int buildin_areawarp_sub(struct block_list *bl,va_list ap) { int x2,y2,x3,y3; unsigned int index; - + index = va_arg(ap,unsigned int); x2 = va_arg(ap,int); y2 = va_arg(ap,int); x3 = va_arg(ap,int); y3 = va_arg(ap,int); - + if(index == 0) pc_randomwarp((TBL_PC *)bl,CLR_TELEPORT); else if(x3 && y3) { int max, tx, ty, j = 0; - + // choose a suitable max number of attempts if( (max = (y3-y2+1)*(x3-x2+1)*3) > 1000 ) max = 1000; - + // find a suitable map cell do { tx = rnd()%(x3-x2+1)+x2; ty = rnd()%(y3-y2+1)+y2; j++; } while( map_getcell(index,tx,ty,CELL_CHKNOPASS) && j < max ); - + pc_setpos((TBL_PC *)bl,index,tx,ty,CLR_OUTSIGHT); } else pc_setpos((TBL_PC *)bl,index,x2,y2,CLR_OUTSIGHT); return 0; } -BUILDIN_FUNC(areawarp) +BUILDIN(areawarp) { int16 m, x0,y0,x1,y1, x2,y2,x3=0,y3=0; unsigned int index; const char *str; const char *mapname; - + mapname = script_getstr(st,2); x0 = script_getnum(st,3); y0 = script_getnum(st,4); @@ -5049,7 +4623,7 @@ BUILDIN_FUNC(areawarp) str = script_getstr(st,7); x2 = script_getnum(st,8); y2 = script_getnum(st,9); - + if( script_hasdata(st,10) && script_hasdata(st,11) ) { // Warp area to area if( (x3 = script_getnum(st,10)) < 0 || (y3 = script_getnum(st,11)) < 0 ){ x3 = 0; @@ -5060,17 +4634,17 @@ BUILDIN_FUNC(areawarp) if( y3 < y2 ) swap(y3,y2); } } - + if( (m = map_mapname2mapid(mapname)) < 0 ) - return 0; - + return true; + if( strcmp(str,"Random") == 0 ) index = 0; else if( !(index=mapindex_name2id(str)) ) - return 0; - + return true; + map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3); - return 0; + return true; } /*========================================== @@ -5084,12 +4658,12 @@ static int buildin_areapercentheal_sub(struct block_list *bl,va_list ap) pc_percentheal((TBL_PC *)bl,hp,sp); return 0; } -BUILDIN_FUNC(areapercentheal) +BUILDIN(areapercentheal) { int hp,sp,m; const char *mapname; int x0,y0,x1,y1; - + mapname=script_getstr(st,2); x0=script_getnum(st,3); y0=script_getnum(st,4); @@ -5097,12 +4671,12 @@ BUILDIN_FUNC(areapercentheal) y1=script_getnum(st,6); hp=script_getnum(st,7); sp=script_getnum(st,8); - + if( (m=map_mapname2mapid(mapname))< 0) - return 0; - + return true; + map_foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp); - return 0; + return true; } /*========================================== @@ -5111,37 +4685,37 @@ BUILDIN_FUNC(areapercentheal) * another player npc-session. * Using: warpchar "mapname",x,y,Char_ID; *------------------------------------------*/ -BUILDIN_FUNC(warpchar) +BUILDIN(warpchar) { int x,y,a; const char *str; TBL_PC *sd; - + str=script_getstr(st,2); x=script_getnum(st,3); y=script_getnum(st,4); a=script_getnum(st,5); - + sd = map_charid2sd(a); if( sd == NULL ) - return 0; - + return true; + if(strcmp(str, "Random") == 0) pc_randomwarp(sd, CLR_TELEPORT); else - if(strcmp(str, "SavePoint") == 0) - pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT); - else - pc_setpos(sd, mapindex_name2id(str), x, y, CLR_TELEPORT); - - return 0; + if(strcmp(str, "SavePoint") == 0) + pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT); + else + pc_setpos(sd, mapindex_name2id(str), x, y, CLR_TELEPORT); + + return true; } /*========================================== * Warpparty - [Fredzilla] [Paradox924X] * Syntax: warpparty "to_mapname",x,y,Party_ID,{"from_mapname"}; * If 'from_mapname' is specified, only the party members on that map will be warped *------------------------------------------*/ -BUILDIN_FUNC(warpparty) +BUILDIN(warpparty) { TBL_PC *sd = NULL; TBL_PC *pl_sd; @@ -5149,7 +4723,7 @@ BUILDIN_FUNC(warpparty) int type; int mapindex; int i; - + const char* str = script_getstr(st,2); int x = script_getnum(st,3); int y = script_getnum(st,4); @@ -5157,235 +4731,235 @@ BUILDIN_FUNC(warpparty) const char* str2 = NULL; if ( script_hasdata(st,6) ) str2 = script_getstr(st,6); - + p = party_search(p_id); if(!p) - return 0; - + return true; + type = ( strcmp(str,"Random")==0 ) ? 0 - : ( strcmp(str,"SavePointAll")==0 ) ? 1 - : ( strcmp(str,"SavePoint")==0 ) ? 2 - : ( strcmp(str,"Leader")==0 ) ? 3 - : 4; - + : ( strcmp(str,"SavePointAll")==0 ) ? 1 + : ( strcmp(str,"SavePoint")==0 ) ? 2 + : ( strcmp(str,"Leader")==0 ) ? 3 + : 4; + switch (type) { - case 3: - for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++); - if (i == MAX_PARTY || !p->data[i].sd) //Leader not found / not online - return 0; - pl_sd = p->data[i].sd; - mapindex = pl_sd->mapindex; - x = pl_sd->bl.x; - y = pl_sd->bl.y; - break; - case 4: - mapindex = mapindex_name2id(str); - break; - case 2: - //"SavePoint" uses save point of the currently attached player - if (( sd = script_rid2sd(st) ) == NULL ) - return 0; - default: - mapindex = 0; - break; + case 3: + for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++); + if (i == MAX_PARTY || !p->data[i].sd) //Leader not found / not online + return true; + pl_sd = p->data[i].sd; + mapindex = pl_sd->mapindex; + x = pl_sd->bl.x; + y = pl_sd->bl.y; + break; + case 4: + mapindex = mapindex_name2id(str); + break; + case 2: + //"SavePoint" uses save point of the currently attached player + if (( sd = script_rid2sd(st) ) == NULL ) + return true; + default: + mapindex = 0; + break; } - + for (i = 0; i < MAX_PARTY; i++) { if( !(pl_sd = p->data[i].sd) || pl_sd->status.party_id != p_id ) continue; - + if( str2 && strcmp(str2, map[pl_sd->bl.m].name) != 0 ) continue; - + if( pc_isdead(pl_sd) ) continue; - + switch( type ) { - case 0: // Random - if(!map[pl_sd->bl.m].flag.nowarp) - pc_randomwarp(pl_sd,CLR_TELEPORT); - break; - case 1: // SavePointAll - if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); - break; - case 2: // SavePoint - if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); - break; - case 3: // Leader - case 4: // m,x,y - if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp) - pc_setpos(pl_sd,mapindex,x,y,CLR_TELEPORT); - break; + case 0: // Random + if(!map[pl_sd->bl.m].flag.nowarp) + pc_randomwarp(pl_sd,CLR_TELEPORT); + break; + case 1: // SavePointAll + if(!map[pl_sd->bl.m].flag.noreturn) + pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); + break; + case 2: // SavePoint + if(!map[pl_sd->bl.m].flag.noreturn) + pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); + break; + case 3: // Leader + case 4: // m,x,y + if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp) + pc_setpos(pl_sd,mapindex,x,y,CLR_TELEPORT); + break; } } - - return 0; + + return true; } /*========================================== * Warpguild - [Fredzilla] * Syntax: warpguild "mapname",x,y,Guild_ID; *------------------------------------------*/ -BUILDIN_FUNC(warpguild) +BUILDIN(warpguild) { TBL_PC *sd = NULL; TBL_PC *pl_sd; struct guild* g; struct s_mapiterator* iter; int type; - + const char* str = script_getstr(st,2); int x = script_getnum(st,3); int y = script_getnum(st,4); int gid = script_getnum(st,5); - - g = guild_search(gid); + + g = guild->search(gid); if( g == NULL ) - return 0; - + return true; + type = ( strcmp(str,"Random")==0 ) ? 0 - : ( strcmp(str,"SavePointAll")==0 ) ? 1 - : ( strcmp(str,"SavePoint")==0 ) ? 2 - : 3; - + : ( strcmp(str,"SavePointAll")==0 ) ? 1 + : ( strcmp(str,"SavePoint")==0 ) ? 2 + : 3; + if( type == 2 && ( sd = script_rid2sd(st) ) == NULL ) {// "SavePoint" uses save point of the currently attached player - return 0; + return true; } - + iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->status.guild_id != gid ) continue; - + switch( type ) { - case 0: // Random - if(!map[pl_sd->bl.m].flag.nowarp) - pc_randomwarp(pl_sd,CLR_TELEPORT); - break; - case 1: // SavePointAll - if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); - break; - case 2: // SavePoint - if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); - break; - case 3: // m,x,y - if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp) - pc_setpos(pl_sd,mapindex_name2id(str),x,y,CLR_TELEPORT); - break; + case 0: // Random + if(!map[pl_sd->bl.m].flag.nowarp) + pc_randomwarp(pl_sd,CLR_TELEPORT); + break; + case 1: // SavePointAll + if(!map[pl_sd->bl.m].flag.noreturn) + pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); + break; + case 2: // SavePoint + if(!map[pl_sd->bl.m].flag.noreturn) + pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); + break; + case 3: // m,x,y + if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp) + pc_setpos(pl_sd,mapindex_name2id(str),x,y,CLR_TELEPORT); + break; } } - mapit_free(iter); - - return 0; + mapit->free(iter); + + return true; } /*========================================== * Force Heal a player (hp and sp) *------------------------------------------*/ -BUILDIN_FUNC(heal) +BUILDIN(heal) { TBL_PC *sd; int hp,sp; - + sd = script_rid2sd(st); - if (!sd) return 0; - + if (!sd) return true; + hp=script_getnum(st,2); sp=script_getnum(st,3); status_heal(&sd->bl, hp, sp, 1); - return 0; + return true; } /*========================================== * Heal a player by item (get vit bonus etc) *------------------------------------------*/ -BUILDIN_FUNC(itemheal) +BUILDIN(itemheal) { TBL_PC *sd; int hp,sp; - + hp=script_getnum(st,2); sp=script_getnum(st,3); - + if(potion_flag==1) { potion_hp = hp; potion_sp = sp; - return 0; + return true; } - + sd = script_rid2sd(st); - if (!sd) return 0; + if (!sd) return true; pc_itemheal(sd,sd->itemid,hp,sp); - return 0; + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(percentheal) +BUILDIN(percentheal) { int hp,sp; TBL_PC* sd; - + hp=script_getnum(st,2); sp=script_getnum(st,3); - + if(potion_flag==1) { potion_per_hp = hp; potion_per_sp = sp; - return 0; + return true; } - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; + return true; #ifdef RENEWAL if( sd->sc.data[SC_EXTREMITYFIST2] ) sp = 0; #endif pc_percentheal(sd,hp,sp); - return 0; + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(jobchange) +BUILDIN(jobchange) { int job, upper=-1; - + job=script_getnum(st,2); if( script_hasdata(st,3) ) upper=script_getnum(st,3); - + if (pcdb_checkid(job)) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pc_jobchange(sd, job, upper); } - - return 0; + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(jobname) +BUILDIN(jobname) { int class_=script_getnum(st,2); script_pushconststr(st, (char*)job_name(class_)); - return 0; + return true; } /// Get input from the player. @@ -5395,7 +4969,7 @@ BUILDIN_FUNC(jobname) /// shorter than 'min' and 0 otherwise. /// /// input(<var>{,<min>{,<max>}}) -> <int> -BUILDIN_FUNC(input) +BUILDIN(input) { TBL_PC* sd; struct script_data* data; @@ -5403,31 +4977,35 @@ BUILDIN_FUNC(input) const char* name; int min; int max; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + data = script_getdata(st,2); if( !data_isreference(data) ){ ShowError("script:input: not a variable\n"); script_reportdata(data); st->state = END; - return 1; + return false; } uid = reference_getuid(data); name = reference_getname(data); min = (script_hasdata(st,3) ? script_getnum(st,3) : script_config.input_min_value); max = (script_hasdata(st,4) ? script_getnum(st,4) : script_config.input_max_value); - + +#ifdef SECURE_NPCTIMEOUT + sd->npc_idle_type = NPCT_WAIT; +#endif + if( !sd->state.menu_or_input ) { // first invocation, display npc input box sd->state.menu_or_input = 1; st->state = RERUNLINE; if( is_string_variable(name) ) - clif_scriptinputstr(sd,st->oid); + clif->scriptinputstr(sd,st->oid); else - clif_scriptinput(sd,st->oid); + clif->scriptinput(sd,st->oid); } else { // take received text/value and store it in the designated variable @@ -5441,22 +5019,22 @@ BUILDIN_FUNC(input) else { int amount = sd->npc_amount; - set_reg(st, sd, uid, name, (void*)__64BPRTSIZE(cap_value(amount,min,max)), script_getref(st,2)); + set_reg(st, sd, uid, name, (void*)__64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2)); script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0)); } st->state = RUN; } - return 0; + return true; } // declare the copyarray method here for future reference -BUILDIN_FUNC(copyarray); +BUILDIN(copyarray); /// Sets the value of a variable. /// The value is converted to the type of the variable. /// /// set(<variable>,<value>) -> <variable> -BUILDIN_FUNC(set) +BUILDIN(set) { TBL_PC* sd = NULL; struct script_data* data; @@ -5464,7 +5042,7 @@ BUILDIN_FUNC(set) int num; const char* name; char prefix; - + data = script_getdata(st,2); //datavalue = script_getdata(st,3); if( !data_isreference(data) ) @@ -5472,60 +5050,60 @@ BUILDIN_FUNC(set) ShowError("script:set: not a variable\n"); script_reportdata(script_getdata(st,2)); st->state = END; - return 1; + return false; } - + num = reference_getuid(data); name = reference_getname(data); prefix = *name; - + if( not_server_variable(prefix) ) { sd = script_rid2sd(st); if( sd == NULL ) { ShowError("script:set: no player attached for player variable '%s'\n", name); - return 0; + return true; } } - + #if 0 if( data_isreference(datavalue) ) {// the value being referenced is a variable const char* namevalue = reference_getname(datavalue); - + if( !not_array_variable(*namevalue) ) {// array variable being copied into another array variable if( sd == NULL && not_server_variable(*namevalue) && !(sd = script_rid2sd(st)) ) {// player must be attached in order to copy a player variable ShowError("script:set: no player attached for player variable '%s'\n", namevalue); - return 0; + return true; } - + if( is_string_variable(namevalue) != is_string_variable(name) ) {// non-matching array value types ShowWarning("script:set: two array variables do not match in type.\n"); - return 0; + return true; } - + // push the maximum number of array values to the stack push_val(st->stack, C_INT, SCRIPT_MAX_ARRAYSIZE); - + // call the copy array method directly return buildin_copyarray(st); } } #endif - + if( is_string_variable(name) ) set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2)); else - set_reg(st,sd,num,name,(void*)__64BPRTSIZE(script_getnum(st,3)),script_getref(st,2)); - + set_reg(st,sd,num,name,(void*)__64BPTRSIZE(script_getnum(st,3)),script_getref(st,2)); + // return a copy of the variable reference script_pushcopy(st,2); - - return 0; + + return true; } ///////////////////////////////////////////////////////////////////// @@ -5536,7 +5114,7 @@ BUILDIN_FUNC(set) static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct DBMap** ref) { int32 ret = idx; - + if( isstring ) { for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx ) @@ -5551,7 +5129,7 @@ static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isst { for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx ) { - int32 num = (int32)__64BPRTSIZE(get_val2(st, reference_uid(id, idx), ref)); + int32 num = (int32)__64BPTRSIZE(get_val2(st, reference_uid(id, idx), ref)); if( num ) ret = idx + 1; script_removetop(st, -1, 0); @@ -5564,7 +5142,7 @@ static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isst /// ex: setarray arr[1],1,2,3; /// /// setarray <array variable>,<value1>{,<value2>...}; -BUILDIN_FUNC(setarray) +BUILDIN(setarray) { struct script_data* data; const char* name; @@ -5573,16 +5151,16 @@ BUILDIN_FUNC(setarray) int32 id; int32 i; TBL_PC* sd = NULL; - + data = script_getdata(st, 2); if( !data_isreference(data) ) { ShowError("script:setarray: not a variable\n"); script_reportdata(data); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); start = reference_getindex(data); name = reference_getname(data); @@ -5591,20 +5169,20 @@ BUILDIN_FUNC(setarray) ShowError("script:setarray: illegal scope\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + end = start + script_lastdata(st) - 2; if( end > SCRIPT_MAX_ARRAYSIZE ) end = SCRIPT_MAX_ARRAYSIZE; - + if( is_string_variable(name) ) {// string array for( i = 3; start < end; ++start, ++i ) @@ -5613,16 +5191,16 @@ BUILDIN_FUNC(setarray) else {// int array for( i = 3; start < end; ++start, ++i ) - set_reg(st, sd, reference_uid(id, start), name, (void*)__64BPRTSIZE(script_getnum(st,i)), reference_getref(data)); + set_reg(st, sd, reference_uid(id, start), name, (void*)__64BPTRSIZE(script_getnum(st,i)), reference_getref(data)); } - return 0; + return true; } /// Sets count values of an array, from the starting index. /// ex: cleararray arr[0],0,1; /// /// cleararray <array variable>,<value>,<count>; -BUILDIN_FUNC(cleararray) +BUILDIN(cleararray) { struct script_data* data; const char* name; @@ -5631,16 +5209,16 @@ BUILDIN_FUNC(cleararray) int32 id; void* v; TBL_PC* sd = NULL; - + data = script_getdata(st, 2); if( !data_isreference(data) ) { ShowError("script:cleararray: not a variable\n"); script_reportdata(data); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); start = reference_getindex(data); name = reference_getname(data); @@ -5649,35 +5227,35 @@ BUILDIN_FUNC(cleararray) ShowError("script:cleararray: illegal scope\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + if( is_string_variable(name) ) v = (void*)script_getstr(st, 3); else - v = (void*)__64BPRTSIZE(script_getnum(st, 3)); - + v = (void*)__64BPTRSIZE(script_getnum(st, 3)); + end = start + script_getnum(st, 4); if( end > SCRIPT_MAX_ARRAYSIZE ) end = SCRIPT_MAX_ARRAYSIZE; - + for( ; start < end; ++start ) set_reg(st, sd, reference_uid(id, start), name, v, script_getref(st,2)); - return 0; + return true; } /// Copies data from one array to another. /// ex: copyarray arr[0],arr[2],2; /// /// copyarray <destination array variable>,<source array variable>,<count>; -BUILDIN_FUNC(copyarray) +BUILDIN(copyarray) { struct script_data* data1; struct script_data* data2; @@ -5691,7 +5269,7 @@ BUILDIN_FUNC(copyarray) int32 i; int32 count; TBL_PC* sd = NULL; - + data1 = script_getdata(st, 2); data2 = script_getdata(st, 3); if( !data_isreference(data1) || !data_isreference(data2) ) @@ -5700,9 +5278,9 @@ BUILDIN_FUNC(copyarray) script_reportdata(data1); script_reportdata(data2); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id1 = reference_getid(data1); id2 = reference_getid(data2); idx1 = reference_getindex(data1); @@ -5715,31 +5293,31 @@ BUILDIN_FUNC(copyarray) script_reportdata(data1); script_reportdata(data2); st->state = END; - return 1;// not supported + return false;// not supported } - + if( is_string_variable(name1) != is_string_variable(name2) ) { ShowError("script:copyarray: type mismatch\n"); script_reportdata(data1); script_reportdata(data2); st->state = END; - return 1;// data type mismatch + return false;// data type mismatch } - + if( not_server_variable(*name1) || not_server_variable(*name2) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + count = script_getnum(st, 4); if( count > SCRIPT_MAX_ARRAYSIZE - idx1 ) count = SCRIPT_MAX_ARRAYSIZE - idx1; if( count <= 0 || (id1 == id2 && idx1 == idx2) ) - return 0;// nothing to copy - + return true;// nothing to copy + if( id1 == id2 && idx1 > idx2 ) {// destination might be overlapping the source - copy in reverse order for( i = count - 1; i >= 0; --i ) @@ -5763,7 +5341,7 @@ BUILDIN_FUNC(copyarray) set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1)); } } - return 0; + return true; } /// Returns the size of the array. @@ -5771,11 +5349,11 @@ BUILDIN_FUNC(copyarray) /// ex: getarraysize(arr[3]) /// /// getarraysize(<array variable>) -> <int> -BUILDIN_FUNC(getarraysize) +BUILDIN(getarraysize) { struct script_data* data; const char* name; - + data = script_getdata(st, 2); if( !data_isreference(data) ) { @@ -5783,9 +5361,9 @@ BUILDIN_FUNC(getarraysize) script_reportdata(data); script_pushnil(st); st->state = END; - return 1;// not a variable + return false;// not a variable } - + name = reference_getname(data); if( not_array_variable(*name) ) { @@ -5793,11 +5371,11 @@ BUILDIN_FUNC(getarraysize) script_reportdata(data); script_pushnil(st); st->state = END; - return 1;// not supported + return false;// not supported } - + script_pushint(st, getarraysize(st, reference_getid(data), reference_getindex(data), is_string_variable(name), reference_getref(data))); - return 0; + return true; } /// Deletes count or all the elements in an array, from the starting index. @@ -5805,7 +5383,7 @@ BUILDIN_FUNC(getarraysize) /// /// deletearray <array variable>; /// deletearray <array variable>,<count>; -BUILDIN_FUNC(deletearray) +BUILDIN(deletearray) { struct script_data* data; const char* name; @@ -5813,16 +5391,16 @@ BUILDIN_FUNC(deletearray) int end; int id; TBL_PC *sd = NULL; - + data = script_getdata(st, 2); if( !data_isreference(data) ) { ShowError("script:deletearray: not a variable\n"); script_reportdata(data); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); start = reference_getindex(data); name = reference_getname(data); @@ -5831,29 +5409,29 @@ BUILDIN_FUNC(deletearray) ShowError("script:deletearray: illegal scope\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + end = SCRIPT_MAX_ARRAYSIZE; - + if( start >= end ) - return 0;// nothing to free - + return true;// nothing to free + if( script_hasdata(st,3) ) { int count = script_getnum(st, 3); if( count > end - start ) count = end - start; if( count <= 0 ) - return 0;// nothing to free - + return true;// nothing to free + // move rest of the elements backward for( ; start + count < end; ++start ) { @@ -5862,7 +5440,7 @@ BUILDIN_FUNC(deletearray) script_removetop(st, -1, 0); } } - + // clear the rest of the array if( is_string_variable(name) ) { @@ -5874,20 +5452,20 @@ BUILDIN_FUNC(deletearray) for( ; start < end; ++start ) set_reg(st, sd, reference_uid(id, start), name, (void*)0, reference_getref(data)); } - return 0; + return true; } /// Returns a reference to the target index of the array variable. /// Equivalent to var[index]. /// /// getelementofarray(<array variable>,<index>) -> <variable reference> -BUILDIN_FUNC(getelementofarray) +BUILDIN(getelementofarray) { struct script_data* data; const char* name; int32 id; int i; - + data = script_getdata(st, 2); if( !data_isreference(data) ) { @@ -5895,9 +5473,9 @@ BUILDIN_FUNC(getelementofarray) script_reportdata(data); script_pushnil(st); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); name = reference_getname(data); if( not_array_variable(*name) ) @@ -5906,9 +5484,9 @@ BUILDIN_FUNC(getelementofarray) script_reportdata(data); script_pushnil(st); st->state = END; - return 1;// not supported + return false;// not supported } - + i = script_getnum(st, 3); if( i < 0 || i >= SCRIPT_MAX_ARRAYSIZE ) { @@ -5916,11 +5494,11 @@ BUILDIN_FUNC(getelementofarray) script_reportdata(data); script_pushnil(st); st->state = END; - return 1;// out of range + return false;// out of range } - + push_val2(st->stack, C_NAME, reference_uid(id, i), reference_getref(data)); - return 0; + return true; } ///////////////////////////////////////////////////////////////////// @@ -5930,160 +5508,160 @@ BUILDIN_FUNC(getelementofarray) /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(setlook) +BUILDIN(setlook) { int type,val; TBL_PC* sd; - + type=script_getnum(st,2); val=script_getnum(st,3); - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pc_changelook(sd,type,val); - - return 0; + + return true; } -BUILDIN_FUNC(changelook) +BUILDIN(changelook) { // As setlook but only client side int type,val; TBL_PC* sd; - + type=script_getnum(st,2); val=script_getnum(st,3); - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - - clif_changelook(&sd->bl,type,val); - - return 0; + return true; + + clif->changelook(&sd->bl,type,val); + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(cutin) +BUILDIN(cutin) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - - clif_cutin(sd,script_getstr(st,2),script_getnum(st,3)); - return 0; + return true; + + clif->cutin(sd,script_getstr(st,2),script_getnum(st,3)); + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(viewpoint) +BUILDIN(viewpoint) { int type,x,y,id,color; TBL_PC* sd; - + type=script_getnum(st,2); x=script_getnum(st,3); y=script_getnum(st,4); id=script_getnum(st,5); color=script_getnum(st,6); - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - - clif_viewpoint(sd,st->oid,type,x,y,id,color); - - return 0; + return true; + + clif->viewpoint(sd,st->oid,type,x,y,id,color); + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(countitem) +BUILDIN(countitem) { int nameid, i; int count = 0; struct item_data* id = NULL; struct script_data* data; - + TBL_PC* sd = script_rid2sd(st); if (!sd) { script_pushint(st,0); - return 0; + return true; } - + data = script_getdata(st,2); get_val(st, data); // convert into value in case of a variable - + if( data_isstring(data) ) {// item name - id = itemdb_searchname(conv_str(st, data)); + id = itemdb_searchname(script->conv_str(st, data)); } else {// item id - id = itemdb_exists(conv_num(st, data)); + id = itemdb_exists(script->conv_num(st, data)); } - + if( id == NULL ) { ShowError("buildin_countitem: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was script_pushint(st,0); - return 1; + return false; } - + nameid = id->nameid; - + for(i = 0; i < MAX_INVENTORY; i++) if(sd->status.inventory[i].nameid == nameid) count += sd->status.inventory[i].amount; - + script_pushint(st,count); - return 0; + return true; } /*========================================== * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus] * returns number of items that meet the conditions *------------------------------------------*/ -BUILDIN_FUNC(countitem2) +BUILDIN(countitem2) { int nameid, iden, ref, attr, c1, c2, c3, c4; int count = 0; int i; struct item_data* id = NULL; struct script_data* data; - + TBL_PC* sd = script_rid2sd(st); if (!sd) { script_pushint(st,0); - return 0; + return true; } - + data = script_getdata(st,2); get_val(st, data); // convert into value in case of a variable - + if( data_isstring(data) ) {// item name - id = itemdb_searchname(conv_str(st, data)); + id = itemdb_searchname(script->conv_str(st, data)); } else {// item id - id = itemdb_exists(conv_num(st, data)); + id = itemdb_exists(script->conv_num(st, data)); } - + if( id == NULL ) { ShowError("buildin_countitem2: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was script_pushint(st,0); - return 1; + return false; } - + nameid = id->nameid; iden = script_getnum(st,3); ref = script_getnum(st,4); @@ -6092,7 +5670,7 @@ BUILDIN_FUNC(countitem2) c2 = (short)script_getnum(st,7); c3 = (short)script_getnum(st,8); c4 = (short)script_getnum(st,9); - + for(i = 0; i < MAX_INVENTORY; i++) if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] != NULL && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].nameid == nameid && @@ -6100,11 +5678,11 @@ BUILDIN_FUNC(countitem2) sd->status.inventory[i].attribute == attr && sd->status.inventory[i].card[0] == c1 && sd->status.inventory[i].card[1] == c2 && sd->status.inventory[i].card[2] == c3 && sd->status.inventory[i].card[3] == c4 - ) + ) count += sd->status.inventory[i].amount; - + script_pushint(st,count); - return 0; + return true; } /*========================================== @@ -6114,54 +5692,54 @@ BUILDIN_FUNC(countitem2) * 0 : fail * 1 : success (npc side only) *------------------------------------------*/ -BUILDIN_FUNC(checkweight) +BUILDIN(checkweight) { int nameid, amount, slots, amount2=0; unsigned int weight=0, i, nbargs; struct item_data* id = NULL; struct map_session_data* sd; struct script_data* data; - + if( ( sd = script_rid2sd(st) ) == NULL ){ - return 0; + return true; } nbargs = script_lastdata(st)+1; if(nbargs%2){ ShowError("buildin_checkweight: Invalid nb of args should be a multiple of 2.\n"); script_pushint(st,0); - return 1; + return false; } slots = pc_inventoryblank(sd); //nb of empty slot - + for(i=2; i<nbargs; i=i+2){ data = script_getdata(st,i); get_val(st, data); // convert into value in case of a variable if( data_isstring(data) ){// item name - id = itemdb_searchname(conv_str(st, data)); + id = itemdb_searchname(script->conv_str(st, data)); } else {// item id - id = itemdb_exists(conv_num(st, data)); + id = itemdb_exists(script->conv_num(st, data)); } if( id == NULL ) { ShowError("buildin_checkweight: Invalid item '%s'.\n", script_getstr(st,i)); // returns string, regardless of what it was script_pushint(st,0); - return 1; + return false; } nameid = id->nameid; - + amount = script_getnum(st,i+1); if( amount < 1 ) { ShowError("buildin_checkweight: Invalid amount '%d'.\n", amount); script_pushint(st,0); - return 1; + return false; } - + weight += itemdb_weight(nameid)*amount; //total weight for all chk if( weight + sd->weight > sd->max_weight ) {// too heavy script_pushint(st,0); - return 0; + return true; } - + switch( pc_checkadditem(sd, nameid, amount) ) { case ADDITEM_EXIST: @@ -6172,105 +5750,105 @@ BUILDIN_FUNC(checkweight) amount2++; if( slots < amount2 ) { script_pushint(st,0); - return 0; + return true; } } else {// non-stackable amount2 += amount; if( slots < amount2){ script_pushint(st,0); - return 0; + return true; } } break; case ADDITEM_OVERAMOUNT: script_pushint(st,0); - return 0; + return true; } } script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(checkweight2) +BUILDIN(checkweight2) { - //variable sub checkweight - int32 nameid=-1, amount=-1; - int i=0, amount2=0, slots=0, weight=0; + //variable sub checkweight + int32 nameid=-1, amount=-1; + int i=0, amount2=0, slots=0, weight=0; short fail=0; - - //variable for array parsing - struct script_data* data_it; - struct script_data* data_nb; - const char* name_it; - const char* name_nb; - int32 id_it, id_nb; - int32 idx_it, idx_nb; - int nb_it, nb_nb; //array size - - TBL_PC *sd = script_rid2sd(st); - nullpo_retr(1,sd); - - data_it = script_getdata(st, 2); - data_nb = script_getdata(st, 3); - - if( !data_isreference(data_it) || !data_isreference(data_nb)) - { - ShowError("script:checkweight2: parameter not a variable\n"); - script_pushint(st,0); - return 1;// not a variable - } - id_it = reference_getid(data_it); - id_nb = reference_getid(data_nb); - idx_it = reference_getindex(data_it); - idx_nb = reference_getindex(data_nb); - name_it = reference_getname(data_it); - name_nb = reference_getname(data_nb); - - if( not_array_variable(*name_it) || not_array_variable(*name_nb)) - { - ShowError("script:checkweight2: illegal scope\n"); - script_pushint(st,0); - return 1;// not supported - } - if(is_string_variable(name_it) || is_string_variable(name_nb)){ - ShowError("script:checkweight2: illegal type, need int\n"); - script_pushint(st,0); - return 1;// not supported - } - nb_it = getarraysize(st, id_it, idx_it, 0, reference_getref(data_it)); - nb_nb = getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb)); - if(nb_it != nb_nb){ - ShowError("Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb); + + //variable for array parsing + struct script_data* data_it; + struct script_data* data_nb; + const char* name_it; + const char* name_nb; + int32 id_it, id_nb; + int32 idx_it, idx_nb; + int nb_it, nb_nb; //array size + + TBL_PC *sd = script_rid2sd(st); + nullpo_retr(1,sd); + + data_it = script_getdata(st, 2); + data_nb = script_getdata(st, 3); + + if( !data_isreference(data_it) || !data_isreference(data_nb)) + { + ShowError("script:checkweight2: parameter not a variable\n"); + script_pushint(st,0); + return false;// not a variable + } + id_it = reference_getid(data_it); + id_nb = reference_getid(data_nb); + idx_it = reference_getindex(data_it); + idx_nb = reference_getindex(data_nb); + name_it = reference_getname(data_it); + name_nb = reference_getname(data_nb); + + if( not_array_variable(*name_it) || not_array_variable(*name_nb)) + { + ShowError("script:checkweight2: illegal scope\n"); + script_pushint(st,0); + return false;// not supported + } + if(is_string_variable(name_it) || is_string_variable(name_nb)){ + ShowError("script:checkweight2: illegal type, need int\n"); + script_pushint(st,0); + return false;// not supported + } + nb_it = getarraysize(st, id_it, idx_it, 0, reference_getref(data_it)); + nb_nb = getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb)); + if(nb_it != nb_nb){ + ShowError("Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb); fail = 1; - } - - slots = pc_inventoryblank(sd); - for(i=0; i<nb_it; i++){ - nameid = (int32)__64BPRTSIZE(get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it))); + } + + slots = pc_inventoryblank(sd); + for(i=0; i<nb_it; i++){ + nameid = (int32)__64BPTRSIZE(get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it))); script_removetop(st, -1, 0); - amount = (int32)__64BPRTSIZE(get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb))); + amount = (int32)__64BPTRSIZE(get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb))); script_removetop(st, -1, 0); if(fail) continue; //cpntonie to depop rest - - if(itemdb_exists(nameid) == NULL ){ - ShowError("buildin_checkweight2: Invalid item '%d'.\n", nameid); - fail=1; - continue; - } - if(amount < 0 ){ - ShowError("buildin_checkweight2: Invalid amount '%d'.\n", amount); - fail = 1; - continue; - } + + if(itemdb_exists(nameid) == NULL ){ + ShowError("buildin_checkweight2: Invalid item '%d'.\n", nameid); + fail=1; + continue; + } + if(amount < 0 ){ + ShowError("buildin_checkweight2: Invalid amount '%d'.\n", amount); + fail = 1; + continue; + } weight += itemdb_weight(nameid)*amount; if( weight + sd->weight > sd->max_weight ){ - fail = 1; - continue; + fail = 1; + continue; } switch( pc_checkadditem(sd, nameid, amount) ) { case ADDITEM_EXIST: - // item is already in inventory, but there is still space for the requested amount + // item is already in inventory, but there is still space for the requested amount break; case ADDITEM_NEW: if( itemdb_isstackable(nameid) ){// stackable @@ -6289,75 +5867,74 @@ BUILDIN_FUNC(checkweight2) fail = 1; } //end switch } //end loop DO NOT break it prematurly we need to depop all stack - - fail?script_pushint(st,0):script_pushint(st,1); - return 0; + + fail?script_pushint(st,0):script_pushint(st,1); + return true; } /*========================================== * getitem <item id>,<amount>{,<account ID>}; * getitem "<item name>",<amount>{,<account ID>}; *------------------------------------------*/ -BUILDIN_FUNC(getitem) +BUILDIN(getitem) { int nameid,amount,get_count,i,flag = 0; struct item it; TBL_PC *sd; struct script_data *data; - + struct item_data *item_data; + data=script_getdata(st,2); get_val(st,data); if( data_isstring(data) ) {// "<item name>" - const char *name=conv_str(st,data); - struct item_data *item_data = itemdb_searchname(name); - if( item_data == NULL ){ + const char *name=script->conv_str(st,data); + if( (item_data = itemdb_searchname(name)) == NULL ){ ShowError("buildin_getitem: Nonexistant item %s requested.\n", name); - return 1; //No item created. + return false; //No item created. } nameid=item_data->nameid; - } else if( data_isint(data) ) - {// <item id> - nameid=conv_num(st,data); + } else if( data_isint(data) ) {// <item id> + nameid=script->conv_num(st,data); //Violet Box, Blue Box, etc - random item pick if( nameid < 0 ) { nameid = -nameid; flag = 1; } - if( nameid <= 0 || !itemdb_exists(nameid) ){ + if( nameid <= 0 || !(item_data = itemdb_exists(nameid)) ){ ShowError("buildin_getitem: Nonexistant item %d requested.\n", nameid); - return 1; //No item created. + return false; //No item created. } } else { ShowError("buildin_getitem: invalid data type for argument #1 (%d).", data->type); - return 1; + return false; } - + // <amount> if( (amount=script_getnum(st,3)) <= 0) - return 0; //return if amount <=0, skip the useles iteration - + return true; //return if amount <=0, skip the useles iteration + memset(&it,0,sizeof(it)); it.nameid=nameid; if(!flag) it.identify=1; else - it.identify=itemdb_isidentified(nameid); - + it.identify=itemdb_isidentified2(item_data); + if( script_hasdata(st,4) ) sd=map_id2sd(script_getnum(st,4)); // <Account ID> else sd=script_rid2sd(st); // Attached player - + if( sd == NULL ) // no target - return 0; - + return true; + //Check if it's stackable. if (!itemdb_isstackable(nameid)) get_count = 1; else get_count = amount; - + for (i = 0; i < amount; i += get_count) { // if not pet egg @@ -6365,20 +5942,20 @@ BUILDIN_FUNC(getitem) { if ((flag = pc_additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) { - clif_additem(sd, 0, 0, flag); + clif->additem(sd, 0, 0, flag); if( pc_candrop(sd,&it) ) map_addflooritem(&it,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } - - return 0; + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(getitem2) +BUILDIN(getitem2) { int nameid,amount,get_count,i,flag = 0; int iden,ref,attr,c1,c2,c3,c4; @@ -6386,27 +5963,27 @@ BUILDIN_FUNC(getitem2) struct item item_tmp; TBL_PC *sd; struct script_data *data; - + if( script_hasdata(st,11) ) sd=map_id2sd(script_getnum(st,11)); // <Account ID> else sd=script_rid2sd(st); // Attached player - + if( sd == NULL ) // no target - return 0; - + return true; + data=script_getdata(st,2); get_val(st,data); if( data_isstring(data) ){ - const char *name=conv_str(st,data); + const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); if( item_data ) nameid=item_data->nameid; else nameid=UNKNOWN_ITEM_ID; }else - nameid=conv_num(st,data); - + nameid=script->conv_num(st,data); + amount=script_getnum(st,3); iden=script_getnum(st,4); ref=script_getnum(st,5); @@ -6415,12 +5992,12 @@ BUILDIN_FUNC(getitem2) c2=(short)script_getnum(st,8); c3=(short)script_getnum(st,9); c4=(short)script_getnum(st,10); - + if(nameid<0) { // Invalide nameid nameid = -nameid; flag = 1; } - + if(nameid > 0) { memset(&item_tmp,0,sizeof(item_tmp)); item_data=itemdb_exists(nameid); @@ -6437,7 +6014,7 @@ BUILDIN_FUNC(getitem2) iden = 1; ref = attr = 0; } - + item_tmp.nameid=nameid; if(!flag) item_tmp.identify=iden; @@ -6449,13 +6026,13 @@ BUILDIN_FUNC(getitem2) item_tmp.card[1]=(short)c2; item_tmp.card[2]=(short)c3; item_tmp.card[3]=(short)c4; - + //Check if it's stackable. if (!itemdb_isstackable(nameid)) get_count = 1; else get_count = amount; - + for (i = 0; i < amount; i += get_count) { // if not pet egg @@ -6463,74 +6040,74 @@ BUILDIN_FUNC(getitem2) { if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { - clif_additem(sd, 0, 0, flag); + clif->additem(sd, 0, 0, flag); if( pc_candrop(sd,&item_tmp) ) map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } } - - return 0; + + return true; } /*========================================== * rentitem <item id>,<seconds> * rentitem "<item name>",<seconds> *------------------------------------------*/ -BUILDIN_FUNC(rentitem) +BUILDIN(rentitem) { struct map_session_data *sd; struct script_data *data; struct item it; int seconds; int nameid = 0, flag; - + data = script_getdata(st,2); get_val(st,data); - + if( (sd = script_rid2sd(st)) == NULL ) - return 0; - + return true; + if( data_isstring(data) ) { - const char *name = conv_str(st,data); + const char *name = script->conv_str(st,data); struct item_data *itd = itemdb_searchname(name); if( itd == NULL ) { ShowError("buildin_rentitem: Nonexistant item %s requested.\n", name); - return 1; + return false; } nameid = itd->nameid; } else if( data_isint(data) ) { - nameid = conv_num(st,data); + nameid = script->conv_num(st,data); if( nameid <= 0 || !itemdb_exists(nameid) ) { ShowError("buildin_rentitem: Nonexistant item %d requested.\n", nameid); - return 1; + return false; } } else { ShowError("buildin_rentitem: invalid data type for argument #1 (%d).\n", data->type); - return 1; + return false; } - + seconds = script_getnum(st,3); memset(&it, 0, sizeof(it)); it.nameid = nameid; it.identify = 1; it.expire_time = (unsigned int)(time(NULL) + seconds); - + if( (flag = pc_additem(sd, &it, 1, LOG_TYPE_SCRIPT)) ) { - clif_additem(sd, 0, 0, flag); - return 1; + clif->additem(sd, 0, 0, flag); + return false; } - - return 0; + + return true; } /*========================================== @@ -6539,53 +6116,53 @@ BUILDIN_FUNC(rentitem) * Returned Qty is always 1, only works on equip-able * equipment *------------------------------------------*/ -BUILDIN_FUNC(getnameditem) +BUILDIN(getnameditem) { int nameid; struct item item_tmp; TBL_PC *sd, *tsd; struct script_data *data; - + sd = script_rid2sd(st); if (sd == NULL) { //Player not attached! script_pushint(st,0); - return 0; + return true; } - + data=script_getdata(st,2); get_val(st,data); if( data_isstring(data) ){ - const char *name=conv_str(st,data); + const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); if( item_data == NULL) { //Failed script_pushint(st,0); - return 0; + return true; } nameid = item_data->nameid; }else - nameid = conv_num(st,data); - + nameid = script->conv_num(st,data); + if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/) { //Even though named stackable items "could" be risky, they are required for certain quests. script_pushint(st,0); - return 0; + return true; } - + data=script_getdata(st,3); get_val(st,data); if( data_isstring(data) ) //Char Name - tsd=map_nick2sd(conv_str(st,data)); + tsd=map_nick2sd(script->conv_str(st,data)); else //Char Id was given - tsd=map_charid2sd(conv_num(st,data)); - + tsd=map_charid2sd(script->conv_num(st,data)); + if( tsd == NULL ) { //Failed script_pushint(st,0); - return 0; + return true; } - + memset(&item_tmp,0,sizeof(item_tmp)); item_tmp.nameid=nameid; item_tmp.amount=1; @@ -6595,80 +6172,77 @@ BUILDIN_FUNC(getnameditem) item_tmp.card[3]=tsd->status.char_id >> 16; if(pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT)) { script_pushint(st,0); - return 0; //Failed to add item, we will not drop if they don't fit + return true; //Failed to add item, we will not drop if they don't fit } - + script_pushint(st,1); - return 0; + return true; } /*========================================== * gets a random item ID from an item group [Skotlex] * groupranditem group_num *------------------------------------------*/ -BUILDIN_FUNC(grouprandomitem) +BUILDIN(grouprandomitem) { int group; - + group = script_getnum(st,2); script_pushint(st,itemdb_searchrandomid(group)); - return 0; + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(makeitem) +BUILDIN(makeitem) { int nameid,amount,flag = 0; int x,y,m; const char *mapname; struct item item_tmp; struct script_data *data; + struct item_data *item_data; data=script_getdata(st,2); get_val(st,data); if( data_isstring(data) ){ - const char *name=conv_str(st,data); - struct item_data *item_data = itemdb_searchname(name); - if( item_data ) + const char *name=script->conv_str(st,data); + if( (item_data = itemdb_searchname(name)) ) nameid=item_data->nameid; else nameid=UNKNOWN_ITEM_ID; - }else - nameid=conv_num(st,data); - + } else { + nameid=script->conv_num(st,data); + if( nameid <= 0 || !(item_data = itemdb_exists(nameid)) ){ + ShowError("makeitem: Nonexistant item %d requested.\n", nameid); + return false; //No item created. + } + } amount=script_getnum(st,3); mapname =script_getstr(st,4); x =script_getnum(st,5); y =script_getnum(st,6); - + if(strcmp(mapname,"this")==0) { TBL_PC *sd; sd = script_rid2sd(st); - if (!sd) return 0; //Failed... + if (!sd) return true; //Failed... m=sd->bl.m; } else m=map_mapname2mapid(mapname); - - if(nameid<0) { - nameid = -nameid; - flag = 1; - } - - if(nameid > 0) { - memset(&item_tmp,0,sizeof(item_tmp)); - item_tmp.nameid=nameid; - if(!flag) - item_tmp.identify=1; - else - item_tmp.identify=itemdb_isidentified(nameid); - - map_addflooritem(&item_tmp,amount,m,x,y,0,0,0,0); - } - - return 0; + + memset(&item_tmp,0,sizeof(item_tmp)); + item_tmp.nameid=nameid; + if(!flag) + item_tmp.identify=1; + else + item_tmp.identify=itemdb_isidentified2(item_data); + + map_addflooritem(&item_tmp,amount,m,x,y,0,0,0,0); + + return true; } @@ -6679,9 +6253,9 @@ static void buildin_delitem_delete(struct map_session_data* sd, int idx, int* am { int delamount; struct item* inv = &sd->status.inventory[idx]; - + delamount = ( amount[0] < inv->amount ) ? amount[0] : inv->amount; - + if( delete_items ) { if( sd->inventory_data[idx]->type == IT_PETEGG && inv->card[0] == CARD0_PET ) @@ -6690,7 +6264,7 @@ static void buildin_delitem_delete(struct map_session_data* sd, int idx, int* am } pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_SCRIPT); } - + amount[0]-= delamount; } @@ -6705,10 +6279,10 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool delete_items = false; int i, amount, important; struct item* inv; - + // prefer always non-equipped items it->equip = 0; - + // when searching for nameid only, prefer additionally if( !exact_match ) { @@ -6717,28 +6291,28 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, // card-less items memset(it->card, 0, sizeof(it->card)); } - + for(;;) { amount = it->amount; important = 0; - + // 1st pass -- less important items / exact match for( i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++ ) { inv = &sd->status.inventory[i]; - + if( !inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid ) {// wrong/invalid item continue; } - + if( inv->equip != it->equip || inv->refine != it->refine ) {// not matching attributes important++; continue; } - + if( exact_match ) { if( inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card)) ) @@ -6761,11 +6335,11 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, continue; } } - + // count / delete item buildin_delitem_delete(sd, i, &amount, delete_items); } - + // 2nd pass -- any matching item if( amount == 0 || important == 0 ) {// either everything was already consumed or no items were skipped @@ -6774,17 +6348,17 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, else for( i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++ ) { inv = &sd->status.inventory[i]; - + if( !inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid ) {// wrong/invalid item continue; } - + if( sd->inventory_data[i]->type == IT_PETEGG && inv->card[0] == CARD0_PET && CheckForCharServer() ) {// pet which cannot be deleted continue; } - + if( exact_match ) { if( inv->refine != it->refine || inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card)) ) @@ -6792,11 +6366,11 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, continue; } } - + // count / delete item buildin_delitem_delete(sd, i, &amount, delete_items); } - + if( amount ) {// not enough items return false; @@ -6818,12 +6392,12 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, /// /// delitem <item id>,<amount>{,<account id>} /// delitem "<item name>",<amount>{,<account id>} -BUILDIN_FUNC(delitem) +BUILDIN(delitem) { TBL_PC *sd; struct item it; struct script_data *data; - + if( script_hasdata(st,4) ) { int account_id = script_getnum(st,4); @@ -6832,67 +6406,67 @@ BUILDIN_FUNC(delitem) { ShowError("script:delitem: player not found (AID=%d).\n", account_id); st->state = END; - return 1; + return false; } } else { sd = script_rid2sd(st);// attached player if( sd == NULL ) - return 0; + return true; } - + data = script_getdata(st,2); get_val(st,data); if( data_isstring(data) ) { - const char* item_name = conv_str(st,data); + const char* item_name = script->conv_str(st,data); struct item_data* id = itemdb_searchname(item_name); if( id == NULL ) { ShowError("script:delitem: unknown item \"%s\".\n", item_name); st->state = END; - return 1; + return false; } it.nameid = id->nameid;// "<item name>" } else { - it.nameid = conv_num(st,data);// <item id> + it.nameid = script->conv_num(st,data);// <item id> if( !itemdb_exists( it.nameid ) ) { ShowError("script:delitem: unknown item \"%d\".\n", it.nameid); st->state = END; - return 1; + return false; } } - + it.amount=script_getnum(st,3); - + if( it.amount <= 0 ) - return 0;// nothing to do - + return true;// nothing to do + if( buildin_delitem_search(sd, &it, false) ) {// success - return 0; + return true; } - + ShowError("script:delitem: failed to delete %d items (AID=%d item_id=%d).\n", it.amount, sd->status.account_id, it.nameid); st->state = END; - clif_scriptclose(sd, st->oid); - return 1; + clif->scriptclose(sd, st->oid); + return false; } /// Deletes items from the target/attached player. /// /// delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>} /// delitem2 "<Item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>} -BUILDIN_FUNC(delitem2) +BUILDIN(delitem2) { TBL_PC *sd; struct item it; struct script_data *data; - + if( script_hasdata(st,11) ) { int account_id = script_getnum(st,11); @@ -6901,41 +6475,41 @@ BUILDIN_FUNC(delitem2) { ShowError("script:delitem2: player not found (AID=%d).\n", account_id); st->state = END; - return 1; + return false; } } else { sd = script_rid2sd(st);// attached player if( sd == NULL ) - return 0; + return true; } - + data = script_getdata(st,2); get_val(st,data); if( data_isstring(data) ) { - const char* item_name = conv_str(st,data); + const char* item_name = script->conv_str(st,data); struct item_data* id = itemdb_searchname(item_name); if( id == NULL ) { ShowError("script:delitem2: unknown item \"%s\".\n", item_name); st->state = END; - return 1; + return false; } it.nameid = id->nameid;// "<item name>" } else { - it.nameid = conv_num(st,data);// <item id> + it.nameid = script->conv_num(st,data);// <item id> if( !itemdb_exists( it.nameid ) ) { ShowError("script:delitem: unknown item \"%d\".\n", it.nameid); st->state = END; - return 1; + return false; } } - + it.amount=script_getnum(st,3); it.identify=script_getnum(st,4); it.refine=script_getnum(st,5); @@ -6944,65 +6518,65 @@ BUILDIN_FUNC(delitem2) it.card[1]=(short)script_getnum(st,8); it.card[2]=(short)script_getnum(st,9); it.card[3]=(short)script_getnum(st,10); - + if( it.amount <= 0 ) - return 0;// nothing to do - + return true;// nothing to do + if( buildin_delitem_search(sd, &it, true) ) {// success - return 0; + return true; } - + ShowError("script:delitem2: failed to delete %d items (AID=%d item_id=%d).\n", it.amount, sd->status.account_id, it.nameid); st->state = END; - clif_scriptclose(sd, st->oid); - return 1; + clif->scriptclose(sd, st->oid); + return false; } /*========================================== * Enables/Disables use of items while in an NPC [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(enableitemuse) +BUILDIN(enableitemuse) { TBL_PC *sd; sd=script_rid2sd(st); if (sd) - sd->npc_item_flag = st->oid; - return 0; + st->npc_item_flag = sd->npc_item_flag = 1; + return true; } -BUILDIN_FUNC(disableitemuse) +BUILDIN(disableitemuse) { TBL_PC *sd; sd=script_rid2sd(st); if (sd) - sd->npc_item_flag = 0; - return 0; + st->npc_item_flag = sd->npc_item_flag = 0; + return true; } /*========================================== * return the basic stats of sd * chk pc_readparam for available type *------------------------------------------*/ -BUILDIN_FUNC(readparam) +BUILDIN(readparam) { int type; TBL_PC *sd; - + type=script_getnum(st,2); if( script_hasdata(st,3) ) sd=map_nick2sd(script_getstr(st,3)); else sd=script_rid2sd(st); - + if(sd==NULL){ script_pushint(st,-1); - return 0; + return true; } - + script_pushint(st,pc_readparam(sd,type)); - - return 0; + + return true; } /*========================================== @@ -7014,54 +6588,54 @@ BUILDIN_FUNC(readparam) * 3 : account_id * 4 : bg_id *------------------------------------------*/ -BUILDIN_FUNC(getcharid) +BUILDIN(getcharid) { int num; TBL_PC *sd; - + num = script_getnum(st,2); if( script_hasdata(st,3) ) sd=map_nick2sd(script_getstr(st,3)); else sd=script_rid2sd(st); - + if(sd==NULL){ script_pushint(st,0); //return 0, according docs - return 0; + return true; } - + switch( num ) { - case 0: script_pushint(st,sd->status.char_id); break; - case 1: script_pushint(st,sd->status.party_id); break; - case 2: script_pushint(st,sd->status.guild_id); break; - case 3: script_pushint(st,sd->status.account_id); break; - case 4: script_pushint(st,sd->bg_id); break; - default: - ShowError("buildin_getcharid: invalid parameter (%d).\n", num); - script_pushint(st,0); - break; + case 0: script_pushint(st,sd->status.char_id); break; + case 1: script_pushint(st,sd->status.party_id); break; + case 2: script_pushint(st,sd->status.guild_id); break; + case 3: script_pushint(st,sd->status.account_id); break; + case 4: script_pushint(st,sd->bg_id); break; + default: + ShowError("buildin_getcharid: invalid parameter (%d).\n", num); + script_pushint(st,0); + break; } - - return 0; + + return true; } /*========================================== * returns the GID of an NPC *------------------------------------------*/ -BUILDIN_FUNC(getnpcid) +BUILDIN(getnpcid) { int num = script_getnum(st,2); struct npc_data* nd = NULL; - + if( script_hasdata(st,3) ) {// unique npc name if( ( nd = npc_name2id(script_getstr(st,3)) ) == NULL ) { ShowError("buildin_getnpcid: No such NPC '%s'.\n", script_getstr(st,3)); script_pushint(st,0); - return 1; + return false; } } - + switch (num) { case 0: script_pushint(st,nd ? nd->bl.id : st->oid); @@ -7069,23 +6643,23 @@ BUILDIN_FUNC(getnpcid) default: ShowError("buildin_getnpcid: invalid parameter (%d).\n", num); script_pushint(st,0); - return 1; + return false; } - - return 0; + + return true; } /*========================================== * Return the name of the party_id * null if not found *------------------------------------------*/ -BUILDIN_FUNC(getpartyname) +BUILDIN(getpartyname) { int party_id; struct party_data* p; - + party_id = script_getnum(st,2); - + if( ( p = party_search(party_id) ) != NULL ) { script_pushstrcopy(st,p->party.name); @@ -7094,7 +6668,7 @@ BUILDIN_FUNC(getpartyname) { script_pushconststr(st,"null"); } - return 0; + return true; } /*========================================== @@ -7105,64 +6679,64 @@ BUILDIN_FUNC(getpartyname) * 1 : char_id des membres * 2 : account_id des membres *------------------------------------------*/ -BUILDIN_FUNC(getpartymember) +BUILDIN(getpartymember) { struct party_data *p; int i,j=0,type=0; - + p=party_search(script_getnum(st,2)); - + if( script_hasdata(st,3) ) type=script_getnum(st,3); - + if(p!=NULL){ for(i=0;i<MAX_PARTY;i++){ if(p->party.member[i].account_id){ switch (type) { - case 2: - mapreg_setreg(reference_uid(add_str("$@partymemberaid"), j),p->party.member[i].account_id); - break; - case 1: - mapreg_setreg(reference_uid(add_str("$@partymembercid"), j),p->party.member[i].char_id); - break; - default: - mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name); + case 2: + mapreg_setreg(reference_uid(add_str("$@partymemberaid"), j),p->party.member[i].account_id); + break; + case 1: + mapreg_setreg(reference_uid(add_str("$@partymembercid"), j),p->party.member[i].char_id); + break; + default: + mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name); } j++; } } } mapreg_setreg(add_str("$@partymembercount"),j); - - return 0; + + return true; } /*========================================== * Retrieves party leader. if flag is specified, * return some of the leader data. Otherwise, return name. *------------------------------------------*/ -BUILDIN_FUNC(getpartyleader) +BUILDIN(getpartyleader) { int party_id, type = 0, i=0; struct party_data *p; - + party_id=script_getnum(st,2); if( script_hasdata(st,3) ) type=script_getnum(st,3); - + p=party_search(party_id); - + if (p) //Search leader - for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++); - + for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++); + if (!p || i == MAX_PARTY) { //leader not found if (type) script_pushint(st,-1); else script_pushconststr(st,"null"); - return 0; + return true; } - + switch (type) { case 1: script_pushint(st,p->party.member[i].account_id); break; case 2: script_pushint(st,p->party.member[i].char_id); break; @@ -7171,21 +6745,21 @@ BUILDIN_FUNC(getpartyleader) case 5: script_pushint(st,p->party.member[i].lv); break; default: script_pushstrcopy(st,p->party.member[i].name); break; } - return 0; + return true; } /*========================================== * Return the name of the @guild_id * null if not found *------------------------------------------*/ -BUILDIN_FUNC(getguildname) +BUILDIN(getguildname) { int guild_id; struct guild* g; - + guild_id = script_getnum(st,2); - - if( ( g = guild_search(guild_id) ) != NULL ) + + if( ( g = guild->search(guild_id) ) != NULL ) { script_pushstrcopy(st,g->name); } @@ -7193,21 +6767,21 @@ BUILDIN_FUNC(getguildname) { script_pushconststr(st,"null"); } - return 0; + return true; } /*========================================== * Return the name of the guild master of @guild_id * null if not found *------------------------------------------*/ -BUILDIN_FUNC(getguildmaster) +BUILDIN(getguildmaster) { int guild_id; struct guild* g; - + guild_id = script_getnum(st,2); - - if( ( g = guild_search(guild_id) ) != NULL ) + + if( ( g = guild->search(guild_id) ) != NULL ) { script_pushstrcopy(st,g->member[0].name); } @@ -7215,17 +6789,17 @@ BUILDIN_FUNC(getguildmaster) { script_pushconststr(st,"null"); } - return 0; + return true; } -BUILDIN_FUNC(getguildmasterid) +BUILDIN(getguildmasterid) { int guild_id; struct guild* g; - + guild_id = script_getnum(st,2); - - if( ( g = guild_search(guild_id) ) != NULL ) + + if( ( g = guild->search(guild_id) ) != NULL ) { script_pushint(st,g->member[0].char_id); } @@ -7233,7 +6807,7 @@ BUILDIN_FUNC(getguildmasterid) { script_pushint(st,0); } - return 0; + return true; } /*========================================== @@ -7245,17 +6819,17 @@ BUILDIN_FUNC(getguildmasterid) * 3 : map_name * - : "" *------------------------------------------*/ -BUILDIN_FUNC(strcharinfo) +BUILDIN(strcharinfo) { TBL_PC *sd; int num; struct guild* g; struct party_data* p; - + sd=script_rid2sd(st); if (!sd) { //Avoid crashing.... script_pushconststr(st,""); - return 0; + return true; } num=script_getnum(st,2); switch(num){ @@ -7263,22 +6837,16 @@ BUILDIN_FUNC(strcharinfo) script_pushstrcopy(st,sd->status.name); break; case 1: - if( ( p = party_search(sd->status.party_id) ) != NULL ) - { + if( ( p = party_search(sd->status.party_id) ) != NULL ) { script_pushstrcopy(st,p->party.name); - } - else - { + } else { script_pushconststr(st,""); } break; case 2: - if( ( g = guild_search(sd->status.guild_id) ) != NULL ) - { + if( ( g = sd->guild ) != NULL ) { script_pushstrcopy(st,g->name); - } - else - { + } else { script_pushconststr(st,""); } break; @@ -7290,8 +6858,8 @@ BUILDIN_FUNC(strcharinfo) script_pushconststr(st,""); break; } - - return 0; + + return true; } /*========================================== @@ -7303,18 +6871,18 @@ BUILDIN_FUNC(strcharinfo) * 3 : ::str * 4 : map name *------------------------------------------*/ -BUILDIN_FUNC(strnpcinfo) +BUILDIN(strnpcinfo) { TBL_NPC* nd; int num; char *buf,*name=NULL; - + nd = map_id2nd(st->oid); if (!nd) { script_pushconststr(st, ""); - return 0; + return true; } - + num = script_getnum(st,2); switch(num){ case 0: // display name @@ -7339,204 +6907,204 @@ BUILDIN_FUNC(strnpcinfo) name = aStrdup(map[nd->bl.m].name); break; } - + if(name) script_pushstr(st, name); else script_pushconststr(st, ""); - - return 0; + + return true; } // aegis->athena slot position conversion table -static unsigned int equip[] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW}; +static unsigned int equip[] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW,EQP_COSTUME_HEAD_LOW,EQP_COSTUME_HEAD_MID,EQP_COSTUME_HEAD_TOP,EQP_COSTUME_GARMENT}; /*========================================== * GetEquipID(Pos); Pos: 1-10 *------------------------------------------*/ -BUILDIN_FUNC(getequipid) +BUILDIN(getequipid) { int i, num; TBL_PC* sd; struct item_data* item; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + num = script_getnum(st,2) - 1; if( num < 0 || num >= ARRAYLENGTH(equip) ) { script_pushint(st,-1); - return 0; + return true; } - + // get inventory position of item i = pc_checkequip(sd,equip[num]); if( i < 0 ) { script_pushint(st,-1); - return 0; + return true; } - + item = sd->inventory_data[i]; if( item != 0 ) script_pushint(st,item->nameid); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== * Get the equipement name at pos * return item jname or "" *------------------------------------------*/ -BUILDIN_FUNC(getequipname) +BUILDIN(getequipname) { int i, num; TBL_PC* sd; struct item_data* item; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + num = script_getnum(st,2) - 1; if( num < 0 || num >= ARRAYLENGTH(equip) ) { script_pushconststr(st,""); - return 0; + return true; } - + // get inventory position of item i = pc_checkequip(sd,equip[num]); if( i < 0 ) { script_pushconststr(st,""); - return 0; + return true; } - + item = sd->inventory_data[i]; if( item != 0 ) script_pushstrcopy(st,item->jname); else script_pushconststr(st,""); - - return 0; + + return true; } /*========================================== * getbrokenid [Valaris] *------------------------------------------*/ -BUILDIN_FUNC(getbrokenid) +BUILDIN(getbrokenid) { int i,num,id=0,brokencounter=0; TBL_PC *sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + num=script_getnum(st,2); for(i=0; i<MAX_INVENTORY; i++) { if(sd->status.inventory[i].attribute){ - brokencounter++; - if(num==brokencounter){ - id=sd->status.inventory[i].nameid; - break; - } + brokencounter++; + if(num==brokencounter){ + id=sd->status.inventory[i].nameid; + break; + } } } - + script_pushint(st,id); - - return 0; + + return true; } /*========================================== * repair [Valaris] *------------------------------------------*/ -BUILDIN_FUNC(repair) +BUILDIN(repair) { int i,num; int repaircounter=0; TBL_PC *sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + num=script_getnum(st,2); for(i=0; i<MAX_INVENTORY; i++) { if(sd->status.inventory[i].attribute){ - repaircounter++; - if(num==repaircounter){ - sd->status.inventory[i].attribute=0; - clif_equiplist(sd); - clif_produceeffect(sd, 0, sd->status.inventory[i].nameid); - clif_misceffect(&sd->bl, 3); - break; - } + repaircounter++; + if(num==repaircounter){ + sd->status.inventory[i].attribute=0; + clif->equiplist(sd); + clif->produce_effect(sd, 0, sd->status.inventory[i].nameid); + clif->misceffect(&sd->bl, 3); + break; + } } } - - return 0; + + return true; } /*========================================== * repairall *------------------------------------------*/ -BUILDIN_FUNC(repairall) +BUILDIN(repairall) { int i, repaircounter = 0; TBL_PC *sd; - + sd = script_rid2sd(st); if(sd == NULL) - return 0; - + return true; + for(i = 0; i < MAX_INVENTORY; i++) { if(sd->status.inventory[i].nameid && sd->status.inventory[i].attribute) { sd->status.inventory[i].attribute = 0; - clif_produceeffect(sd,0,sd->status.inventory[i].nameid); + clif->produce_effect(sd,0,sd->status.inventory[i].nameid); repaircounter++; } } - + if(repaircounter) { - clif_misceffect(&sd->bl, 3); - clif_equiplist(sd); + clif->misceffect(&sd->bl, 3); + clif->equiplist(sd); } - - return 0; + + return true; } /*========================================== * Chk if player have something equiped at pos *------------------------------------------*/ -BUILDIN_FUNC(getequipisequiped) +BUILDIN(getequipisequiped) { int i = -1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); - + if(i >= 0) script_pushint(st,1); else - script_pushint(st,0); - return 0; + script_pushint(st,0); + return true; } /*========================================== @@ -7546,24 +7114,24 @@ BUILDIN_FUNC(getequipisequiped) * 1 : true * 0 : false *------------------------------------------*/ -BUILDIN_FUNC(getequipisenableref) +BUILDIN(getequipisenableref) { int i = -1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if( num > 0 && num <= ARRAYLENGTH(equip) ) i = pc_checkequip(sd,equip[num-1]); if( i >= 0 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine && !sd->status.inventory[i].expire_time ) script_pushint(st,1); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== @@ -7572,24 +7140,24 @@ BUILDIN_FUNC(getequipisenableref) * 1 : true * 0 : false *------------------------------------------*/ -BUILDIN_FUNC(getequipisidentify) +BUILDIN(getequipisidentify) { int i = -1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); if(i >= 0) script_pushint(st,sd->status.inventory[i].identify); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== @@ -7598,24 +7166,24 @@ BUILDIN_FUNC(getequipisidentify) * x : refine amount * 0 : false (not refined) *------------------------------------------*/ -BUILDIN_FUNC(getequiprefinerycnt) +BUILDIN(getequiprefinerycnt) { int i = -1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); if(i >= 0) script_pushint(st,sd->status.inventory[i].refine); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== @@ -7625,24 +7193,24 @@ BUILDIN_FUNC(getequiprefinerycnt) * x : weapon level * 0 : false *------------------------------------------*/ -BUILDIN_FUNC(getequipweaponlv) +BUILDIN(getequipweaponlv) { int i = -1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); if(i >= 0 && sd->inventory_data[i]) script_pushint(st,sd->inventory_data[i]->wlv); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== @@ -7651,63 +7219,63 @@ BUILDIN_FUNC(getequipweaponlv) * x : refine chance * 0 : false (max refine level or unequip..) *------------------------------------------*/ -BUILDIN_FUNC(getequippercentrefinery) +BUILDIN(getequippercentrefinery) { int i = -1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE) script_pushint(st,status_get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int)sd->status.inventory[i].refine)); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== * Refine +1 item at pos and log and display refine *------------------------------------------*/ -BUILDIN_FUNC(successrefitem) +BUILDIN(successrefitem) { int i=-1,num,ep; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); if(i >= 0) { ep=sd->status.inventory[i].equip; - + //Logs items, got from (N)PC scripts [Lupus] - log_pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i]); - + logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i],sd->inventory_data[i]); + sd->status.inventory[i].refine++; pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below - - clif_refine(sd->fd,0,i,sd->status.inventory[i].refine); - clif_delitem(sd,i,1,3); - + + clif->refine(sd->fd,0,i,sd->status.inventory[i].refine); + clif->delitem(sd,i,1,3); + //Logs items, got from (N)PC scripts [Lupus] - log_pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i]); - - clif_additem(sd,i,1,0); + logs->pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i],sd->inventory_data[i]); + + clif->additem(sd,i,1,0); pc_equipitem(sd,i,ep); - clif_misceffect(&sd->bl,3); + clif->misceffect(&sd->bl,3); if(sd->status.inventory[i].refine == MAX_REFINE && - sd->status.inventory[i].card[0] == CARD0_FORGE && - sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3]) - ){ // Fame point system [DracoRPG] + sd->status.inventory[i].card[0] == CARD0_FORGE && + sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3]) + ){ // Fame point system [DracoRPG] switch (sd->inventory_data[i]->wlv){ case 1: pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point @@ -7718,113 +7286,136 @@ BUILDIN_FUNC(successrefitem) case 3: pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point break; - } + } } } - - return 0; + + return true; } /*========================================== * Show a failed Refine +1 attempt *------------------------------------------*/ -BUILDIN_FUNC(failedrefitem) +BUILDIN(failedrefitem) { int i=-1,num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); if(i >= 0) { sd->status.inventory[i].refine = 0; pc_unequipitem(sd,i,3); //recalculate bonus - clif_refine(sd->fd,1,i,sd->status.inventory[i].refine); //notify client of failure - + clif->refine(sd->fd,1,i,sd->status.inventory[i].refine); //notify client of failure + pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); - - clif_misceffect(&sd->bl,2); // display failure effect + + clif->misceffect(&sd->bl,2); // display failure effect } - - return 0; + + return true; } /*========================================== * Downgrades an Equipment Part by -1 . [Masao] *------------------------------------------*/ -BUILDIN_FUNC(downrefitem) +BUILDIN(downrefitem) { int i = -1,num,ep; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if (num > 0 && num <= ARRAYLENGTH(equip)) i = pc_checkequip(sd,equip[num-1]); if(i >= 0) { ep = sd->status.inventory[i].equip; - + //Logs items, got from (N)PC scripts [Lupus] - log_pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i]); - + logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i],sd->inventory_data[i]); + sd->status.inventory[i].refine++; pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below - - clif_refine(sd->fd,2,i,sd->status.inventory[i].refine = sd->status.inventory[i].refine - 2); - clif_delitem(sd,i,1,3); - + + clif->refine(sd->fd,2,i,sd->status.inventory[i].refine = sd->status.inventory[i].refine - 2); + clif->delitem(sd,i,1,3); + //Logs items, got from (N)PC scripts [Lupus] - log_pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i]); - - clif_additem(sd,i,1,0); + logs->pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i],sd->inventory_data[i]); + + clif->additem(sd,i,1,0); pc_equipitem(sd,i,ep); - clif_misceffect(&sd->bl,2); + clif->misceffect(&sd->bl,2); } + + return true; +} - return 0; +/*========================================== + * Delete the item equipped at pos. + *------------------------------------------*/ +BUILDIN(delequip) +{ + int i=-1,num; + TBL_PC *sd; + + num = script_getnum(st,2); + sd = script_rid2sd(st); + if( sd == NULL ) + return true; + + if (num > 0 && num <= ARRAYLENGTH(equip)) + i=pc_checkequip(sd,equip[num-1]); + if(i >= 0) { + pc_unequipitem(sd,i,3); //recalculate bonus + pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); + } + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(statusup) +BUILDIN(statusup) { int type; TBL_PC *sd; - + type=script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pc_statusup(sd,type); - - return 0; + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(statusup2) +BUILDIN(statusup2) { int type,val; TBL_PC *sd; - + type=script_getnum(st,2); val=script_getnum(st,3); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pc_statusup2(sd,type,val); - - return 0; + + return true; } /// See 'doc/item_bonus.txt' @@ -7834,7 +7425,7 @@ BUILDIN_FUNC(statusup2) /// bonus3 <bonus type>,<val1>,<val2>,<val3>; /// bonus4 <bonus type>,<val1>,<val2>,<val3>,<val4>; /// bonus5 <bonus type>,<val1>,<val2>,<val3>,<val4>,<val5>; -BUILDIN_FUNC(bonus) +BUILDIN(bonus) { int type; int val1; @@ -7843,11 +7434,11 @@ BUILDIN_FUNC(bonus) int val4 = 0; int val5 = 0; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; // no player attached - + return true; // no player attached + type = script_getnum(st,2); switch( type ) { case SP_AUTOSPELL: @@ -7864,15 +7455,16 @@ BUILDIN_FUNC(bonus) case SP_SKILL_FIXEDCAST: case SP_SKILL_VARIABLECAST: case SP_VARCASTRATE: + case SP_FIXCASTRATE: case SP_SKILL_USE_SP: // these bonuses support skill names - val1 = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) ); + val1 = ( script_isstring(st,3) ? skill->name2id(script_getstr(st,3)) : script_getnum(st,3) ); break; default: val1 = script_getnum(st,3); break; } - + switch( script_lastdata(st)-2 ) { case 1: pc_bonus(sd, type, val1); @@ -7888,20 +7480,20 @@ BUILDIN_FUNC(bonus) break; case 4: if( type == SP_AUTOSPELL_ONSKILL && script_isstring(st,4) ) - val2 = skill_name2id(script_getstr(st,4)); // 2nd value can be skill name + val2 = skill->name2id(script_getstr(st,4)); // 2nd value can be skill name else val2 = script_getnum(st,4); - + val3 = script_getnum(st,5); val4 = script_getnum(st,6); pc_bonus4(sd, type, val1, val2, val3, val4); break; case 5: if( type == SP_AUTOSPELL_ONSKILL && script_isstring(st,4) ) - val2 = skill_name2id(script_getstr(st,4)); // 2nd value can be skill name + val2 = skill->name2id(script_getstr(st,4)); // 2nd value can be skill name else val2 = script_getnum(st,4); - + val3 = script_getnum(st,5); val4 = script_getnum(st,6); val5 = script_getnum(st,7); @@ -7911,117 +7503,117 @@ BUILDIN_FUNC(bonus) ShowDebug("buildin_bonus: unexpected number of arguments (%d)\n", (script_lastdata(st) - 1)); break; } - - return 0; + + return true; } -BUILDIN_FUNC(autobonus) +BUILDIN(autobonus) { unsigned int dur; short rate; short atk_type = 0; TBL_PC* sd; const char *bonus_script, *other_script = NULL; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; // no player attached - + return true; // no player attached + if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip ) - return 0; - + return true; + rate = script_getnum(st,3); dur = script_getnum(st,4); bonus_script = script_getstr(st,2); if( !rate || !dur || !bonus_script ) - return 0; - + return true; + if( script_hasdata(st,5) ) atk_type = script_getnum(st,5); if( script_hasdata(st,6) ) other_script = script_getstr(st,6); - + if( pc_addautobonus(sd->autobonus,ARRAYLENGTH(sd->autobonus), - bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) ) + bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) ) { script_add_autobonus(bonus_script); if( other_script ) script_add_autobonus(other_script); } - - return 0; + + return true; } -BUILDIN_FUNC(autobonus2) +BUILDIN(autobonus2) { unsigned int dur; short rate; short atk_type = 0; TBL_PC* sd; const char *bonus_script, *other_script = NULL; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; // no player attached - + return true; // no player attached + if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip ) - return 0; - + return true; + rate = script_getnum(st,3); dur = script_getnum(st,4); bonus_script = script_getstr(st,2); if( !rate || !dur || !bonus_script ) - return 0; - + return true; + if( script_hasdata(st,5) ) atk_type = script_getnum(st,5); if( script_hasdata(st,6) ) other_script = script_getstr(st,6); - + if( pc_addautobonus(sd->autobonus2,ARRAYLENGTH(sd->autobonus2), - bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) ) + bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) ) { script_add_autobonus(bonus_script); if( other_script ) script_add_autobonus(other_script); } - - return 0; + + return true; } -BUILDIN_FUNC(autobonus3) +BUILDIN(autobonus3) { unsigned int dur; short rate,atk_type; TBL_PC* sd; const char *bonus_script, *other_script = NULL; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; // no player attached - + return true; // no player attached + if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip ) - return 0; - + return true; + rate = script_getnum(st,3); dur = script_getnum(st,4); - atk_type = ( script_isstring(st,5) ? skill_name2id(script_getstr(st,5)) : script_getnum(st,5) ); + atk_type = ( script_isstring(st,5) ? skill->name2id(script_getstr(st,5)) : script_getnum(st,5) ); bonus_script = script_getstr(st,2); if( !rate || !dur || !atk_type || !bonus_script ) - return 0; - + return true; + if( script_hasdata(st,6) ) other_script = script_getstr(st,6); - + if( pc_addautobonus(sd->autobonus3,ARRAYLENGTH(sd->autobonus3), - bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,true) ) + bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,true) ) { script_add_autobonus(bonus_script); if( other_script ) script_add_autobonus(other_script); } - - return 0; + + return true; } /// Changes the level of a player skill. @@ -8034,24 +7626,24 @@ BUILDIN_FUNC(autobonus3) /// skill <skill id>,<level> /// skill "<skill name>",<level>,<flag> /// skill "<skill name>",<level> -BUILDIN_FUNC(skill) +BUILDIN(skill) { int id; int level; int flag = 1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - - id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + return true;// no player attached, report source + + id = ( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); level = script_getnum(st,3); if( script_hasdata(st,4) ) flag = script_getnum(st,4); pc_skill(sd, id, level, flag); - - return 0; + + return true; } /// Changes the level of a player skill. @@ -8063,87 +7655,87 @@ BUILDIN_FUNC(skill) /// addtoskill "<skill name>",<amount> /// /// @see skill -BUILDIN_FUNC(addtoskill) +BUILDIN(addtoskill) { int id; int level; int flag = 2; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - - id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + return true;// no player attached, report source + + id = ( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); level = script_getnum(st,3); if( script_hasdata(st,4) ) flag = script_getnum(st,4); pc_skill(sd, id, level, flag); - - return 0; + + return true; } /// Increases the level of a guild skill. /// /// guildskill <skill id>,<amount>; /// guildskill "<skill name>",<amount>; -BUILDIN_FUNC(guildskill) +BUILDIN(guildskill) { int id; int level; TBL_PC* sd; int i; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - - id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + return true;// no player attached, report source + + id = ( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); level = script_getnum(st,3); for( i=0; i < level; i++ ) - guild_skillup(sd, id); - - return 0; + guild->skillup(sd, id); + + return true; } /// Returns the level of the player skill. /// /// getskilllv(<skill id>) -> <level> /// getskilllv("<skill name>") -> <level> -BUILDIN_FUNC(getskilllv) +BUILDIN(getskilllv) { int id; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - - id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + return true;// no player attached, report source + + id = ( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); script_pushint(st, pc_checkskill(sd,id)); - - return 0; + + return true; } /// Returns the level of the guild skill. /// /// getgdskilllv(<guild id>,<skill id>) -> <level> /// getgdskilllv(<guild id>,"<skill name>") -> <level> -BUILDIN_FUNC(getgdskilllv) +BUILDIN(getgdskilllv) { int guild_id; uint16 skill_id; struct guild* g; - + guild_id = script_getnum(st,2); - skill_id = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) ); - g = guild_search(guild_id); + skill_id = ( script_isstring(st,3) ? skill->name2id(script_getstr(st,3)) : script_getnum(st,3) ); + g = guild->search(guild_id); if( g == NULL ) script_pushint(st, -1); else - script_pushint(st, guild_checkskill(g,skill_id)); - - return 0; + script_pushint(st, guild->checkskill(g,skill_id)); + + return true; } /// Returns the 'basic_skill_check' setting. @@ -8151,113 +7743,113 @@ BUILDIN_FUNC(getgdskilllv) /// before allowing the basic actions. /// /// basicskillcheck() -> <bool> -BUILDIN_FUNC(basicskillcheck) +BUILDIN(basicskillcheck) { script_pushint(st, battle_config.basic_skill_check); - return 0; + return true; } /// Returns the GM level of the player. /// /// getgmlevel() -> <level> -BUILDIN_FUNC(getgmlevel) +BUILDIN(getgmlevel) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + script_pushint(st, pc_get_group_level(sd)); - - return 0; + + return true; } /// Returns the group ID of the player. /// /// getgroupid() -> <int> -BUILDIN_FUNC(getgroupid) +BUILDIN(getgroupid) { TBL_PC* sd; - + sd = script_rid2sd(st); if (sd == NULL) - return 1; // no player attached, report source + return false; // no player attached, report source script_pushint(st, pc_get_group_id(sd)); - - return 0; + + return true; } /// Terminates the execution of this script instance. /// /// end -BUILDIN_FUNC(end) +BUILDIN(end) { st->state = END; - return 0; + return true; } /// Checks if the player has that effect state (option). /// /// checkoption(<option>) -> <bool> -BUILDIN_FUNC(checkoption) +BUILDIN(checkoption) { int option; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + option = script_getnum(st,2); if( sd->sc.option&option ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Checks if the player is in that body state (opt1). /// /// checkoption1(<opt1>) -> <bool> -BUILDIN_FUNC(checkoption1) +BUILDIN(checkoption1) { int opt1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + opt1 = script_getnum(st,2); if( sd->sc.opt1 == opt1 ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Checks if the player has that health state (opt2). /// /// checkoption2(<opt2>) -> <bool> -BUILDIN_FUNC(checkoption2) +BUILDIN(checkoption2) { int opt2; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + opt2 = script_getnum(st,2); if( sd->sc.opt2&opt2 ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Changes the effect state (option) of the player. @@ -8267,16 +7859,16 @@ BUILDIN_FUNC(checkoption2) /// /// setoption <option>,<flag>; /// setoption <option>; -BUILDIN_FUNC(setoption) +BUILDIN(setoption) { int option; int flag = 1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + option = script_getnum(st,2); if( script_hasdata(st,3) ) flag = script_getnum(st,3); @@ -8293,8 +7885,8 @@ BUILDIN_FUNC(setoption) pc_setoption(sd, sd->sc.option|option); } else// Remove option pc_setoption(sd, sd->sc.option&~option); - - return 0; + + return true; } /// Returns if the player has a cart. @@ -8302,20 +7894,20 @@ BUILDIN_FUNC(setoption) /// checkcart() -> <bool> /// /// @author Valaris -BUILDIN_FUNC(checkcart) +BUILDIN(checkcart) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( pc_iscarton(sd) ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Sets the cart of the player. @@ -8329,20 +7921,20 @@ BUILDIN_FUNC(checkcart) /// /// setcart <type>; /// setcart; -BUILDIN_FUNC(setcart) +BUILDIN(setcart) { int type = 1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( script_hasdata(st,2) ) type = script_getnum(st,2); pc_setcart(sd, type); - - return 0; + + return true; } /// Returns if the player has a falcon. @@ -8350,20 +7942,20 @@ BUILDIN_FUNC(setcart) /// checkfalcon() -> <bool> /// /// @author Valaris -BUILDIN_FUNC(checkfalcon) +BUILDIN(checkfalcon) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( pc_isfalcon(sd) ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Sets if the player has a falcon or not. @@ -8371,21 +7963,21 @@ BUILDIN_FUNC(checkfalcon) /// /// setfalcon <flag>; /// setfalcon; -BUILDIN_FUNC(setfalcon) +BUILDIN(setfalcon) { int flag = 1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( script_hasdata(st,2) ) flag = script_getnum(st,2); - + pc_setfalcon(sd, flag); - - return 0; + + return true; } /// Returns if the player is riding. @@ -8393,20 +7985,20 @@ BUILDIN_FUNC(setfalcon) /// checkriding() -> <bool> /// /// @author Valaris -BUILDIN_FUNC(checkriding) +BUILDIN(checkriding) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( pc_isriding(sd) || pc_isridingwug(sd) || pc_isridingdragon(sd) ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Sets if the player is riding. @@ -8414,60 +8006,60 @@ BUILDIN_FUNC(checkriding) /// /// setriding <flag>; /// setriding; -BUILDIN_FUNC(setriding) +BUILDIN(setriding) { int flag = 1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( script_hasdata(st,2) ) flag = script_getnum(st,2); pc_setriding(sd, flag); - - return 0; + + return true; } /// Returns if the player has a warg. /// /// checkwug() -> <bool> /// -BUILDIN_FUNC(checkwug) +BUILDIN(checkwug) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( pc_iswug(sd) || pc_isridingwug(sd) ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Returns if the player is wearing MADO Gear. /// /// checkmadogear() -> <bool> /// -BUILDIN_FUNC(checkmadogear) +BUILDIN(checkmadogear) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( pc_ismadogear(sd) ) script_pushint(st, 1); else script_pushint(st, 0); - - return 0; + + return true; } /// Sets if the player is riding MADO Gear. @@ -8475,78 +8067,78 @@ BUILDIN_FUNC(checkmadogear) /// /// setmadogear <flag>; /// setmadogear; -BUILDIN_FUNC(setmadogear) +BUILDIN(setmadogear) { int flag = 1; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + if( script_hasdata(st,2) ) flag = script_getnum(st,2); pc_setmadogear(sd, flag); - - return 0; + + return true; } /// Sets the save point of the player. /// /// save "<map name>",<x>,<y> /// savepoint "<map name>",<x>,<y> -BUILDIN_FUNC(savepoint) +BUILDIN(savepoint) { int x; int y; short map; const char* str; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached, report source - + return true;// no player attached, report source + str = script_getstr(st, 2); x = script_getnum(st,3); y = script_getnum(st,4); map = mapindex_name2id(str); if( map ) pc_setsavepoint(sd, map, x, y); - - return 0; + + return true; } /*========================================== * GetTimeTick(0: System Tick, 1: Time Second Tick) *------------------------------------------*/ -BUILDIN_FUNC(gettimetick) /* Asgard Version */ +BUILDIN(gettimetick) /* Asgard Version */ { int type; time_t timer; struct tm *t; - + type=script_getnum(st,2); - + switch(type){ - case 2: - //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC - // from the system clock.) - script_pushint(st,(int)time(NULL)); - break; - case 1: - //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59) - time(&timer); - t=localtime(&timer); - script_pushint(st,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec)); - break; - case 0: - default: - //type 0:(System Ticks) - script_pushint(st,gettick()); - break; + case 2: + //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC + // from the system clock.) + script_pushint(st,(int)time(NULL)); + break; + case 1: + //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59) + time(&timer); + t=localtime(&timer); + script_pushint(st,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec)); + break; + case 0: + default: + //type 0:(System Ticks) + script_pushint(st,gettick()); + break; } - return 0; + return true; } /*========================================== @@ -8555,250 +8147,255 @@ BUILDIN_FUNC(gettimetick) /* Asgard Version */ * 4: WeekDay 5: MonthDay 6: Month * 7: Year *------------------------------------------*/ -BUILDIN_FUNC(gettime) /* Asgard Version */ +BUILDIN(gettime) /* Asgard Version */ { int type; time_t timer; struct tm *t; - + type=script_getnum(st,2); - + time(&timer); t=localtime(&timer); - + switch(type){ - case 1://Sec(0~59) - script_pushint(st,t->tm_sec); - break; - case 2://Min(0~59) - script_pushint(st,t->tm_min); - break; - case 3://Hour(0~23) - script_pushint(st,t->tm_hour); - break; - case 4://WeekDay(0~6) - script_pushint(st,t->tm_wday); - break; - case 5://MonthDay(01~31) - script_pushint(st,t->tm_mday); - break; - case 6://Month(01~12) - script_pushint(st,t->tm_mon+1); - break; - case 7://Year(20xx) - script_pushint(st,t->tm_year+1900); - break; - case 8://Year Day(01~366) - script_pushint(st,t->tm_yday+1); - break; - default://(format error) - script_pushint(st,-1); - break; + case 1://Sec(0~59) + script_pushint(st,t->tm_sec); + break; + case 2://Min(0~59) + script_pushint(st,t->tm_min); + break; + case 3://Hour(0~23) + script_pushint(st,t->tm_hour); + break; + case 4://WeekDay(0~6) + script_pushint(st,t->tm_wday); + break; + case 5://MonthDay(01~31) + script_pushint(st,t->tm_mday); + break; + case 6://Month(01~12) + script_pushint(st,t->tm_mon+1); + break; + case 7://Year(20xx) + script_pushint(st,t->tm_year+1900); + break; + case 8://Year Day(01~366) + script_pushint(st,t->tm_yday+1); + break; + default://(format error) + script_pushint(st,-1); + break; } - return 0; + return true; } /*========================================== * GetTimeStr("TimeFMT", Length); *------------------------------------------*/ -BUILDIN_FUNC(gettimestr) +BUILDIN(gettimestr) { char *tmpstr; const char *fmtstr; int maxlen; time_t now = time(NULL); - + fmtstr=script_getstr(st,2); maxlen=script_getnum(st,3); - + tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char)); strftime(tmpstr,maxlen,fmtstr,localtime(&now)); tmpstr[maxlen]='\0'; - + script_pushstr(st,tmpstr); - return 0; + return true; } /*========================================== * Open player storage *------------------------------------------*/ -BUILDIN_FUNC(openstorage) +BUILDIN(openstorage) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + storage_storageopen(sd); - return 0; + return true; } -BUILDIN_FUNC(guildopenstorage) +BUILDIN(guildopenstorage) { TBL_PC* sd; int ret; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + ret = storage_guild_storageopen(sd); script_pushint(st,ret); - return 0; + return true; } /*========================================== * Make player use a skill trought item usage *------------------------------------------*/ -/// itemskill <skill id>,<level> -/// itemskill "<skill name>",<level> -BUILDIN_FUNC(itemskill) -{ +/// itemskill <skill id>,<level>{,flag +/// itemskill "<skill name>",<level>{,flag +BUILDIN(itemskill) { int id; int lv; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL || sd->ud.skilltimer != INVALID_TIMER ) - return 0; - - id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + return true; + + id = ( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); lv = script_getnum(st,3); - +/* temporarily disabled, awaiting for kenpachi to detail this so we can make it work properly */ +#if 0 + if( !script_hasdata(st, 4) ) { + if( !skill->check_condition_castbegin(sd,id,lv) || !skill->check_condition_castend(sd,id,lv) ) + return true; + } +#endif sd->skillitem=id; sd->skillitemlv=lv; - clif_item_skill(sd,id,lv); - return 0; + clif->item_skill(sd,id,lv); + return true; } /*========================================== * Attempt to create an item *------------------------------------------*/ -BUILDIN_FUNC(produce) +BUILDIN(produce) { int trigger; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + trigger=script_getnum(st,2); - clif_skill_produce_mix_list(sd, -1, trigger); - return 0; + clif->skill_produce_mix_list(sd, -1, trigger); + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(cooking) +BUILDIN(cooking) { int trigger; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + trigger=script_getnum(st,2); - clif_cooking_list(sd, trigger, AM_PHARMACY, 1, 1); - return 0; + clif->cooking_list(sd, trigger, AM_PHARMACY, 1, 1); + return true; } /*========================================== * Create a pet *------------------------------------------*/ -BUILDIN_FUNC(makepet) +BUILDIN(makepet) { TBL_PC* sd; int id,pet_id; - + id=script_getnum(st,2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pet_id = search_petDB_index(id, PET_CLASS); - + if (pet_id < 0) pet_id = search_petDB_index(id, PET_EGG); if (pet_id >= 0 && sd) { sd->catch_target_class = pet_db[pet_id].class_; intif_create_pet( - sd->status.account_id, sd->status.char_id, - (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv, - (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate, - 100, 0, 1, pet_db[pet_id].jname); + sd->status.account_id, sd->status.char_id, + (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv, + (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate, + 100, 0, 1, pet_db[pet_id].jname); } - - return 0; + + return true; } /*========================================== * Give player exp base,job * quest_exp_rate/100 *------------------------------------------*/ -BUILDIN_FUNC(getexp) +BUILDIN(getexp) { TBL_PC* sd; int base=0,job=0; double bonus; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + base=script_getnum(st,2); job =script_getnum(st,3); if(base<0 || job<0) - return 0; - + return true; + // bonus for npc-given exp bonus = battle_config.quest_exp_rate / 100.; base = (int) cap_value(base * bonus, 0, INT_MAX); job = (int) cap_value(job * bonus, 0, INT_MAX); - + pc_gainexp(sd, NULL, base, job, true); - - return 0; + + return true; } /*========================================== * Gain guild exp [Celest] *------------------------------------------*/ -BUILDIN_FUNC(guildgetexp) +BUILDIN(guildgetexp) { TBL_PC* sd; int exp; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + exp = script_getnum(st,2); if(exp < 0) - return 0; + return true; if(sd && sd->status.guild_id > 0) - guild_getexp (sd, exp); - - return 0; + guild->getexp (sd, exp); + + return true; } /*========================================== * Changes the guild master of a guild [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(guildchangegm) +BUILDIN(guildchangegm) { TBL_PC *sd; int guild_id; const char *name; - + guild_id = script_getnum(st,2); name = script_getstr(st,3); sd=map_nick2sd(name); - + if (!sd) script_pushint(st,0); else - script_pushint(st,guild_gm_change(guild_id, sd)); - - return 0; + script_pushint(st,guild->gm_change(guild_id, sd)); + + return true; } /*========================================== @@ -8809,7 +8406,7 @@ BUILDIN_FUNC(guildchangegm) @amount : nb to spawn @event : event to attach to mob *------------------------------------------*/ -BUILDIN_FUNC(monster) +BUILDIN(monster) { const char* mapn = script_getstr(st,2); int x = script_getnum(st,3); @@ -8820,44 +8417,44 @@ BUILDIN_FUNC(monster) const char* event = ""; unsigned int size = SZ_SMALL; unsigned int ai = AI_NONE; - + struct map_session_data* sd; int16 m; - + if (script_hasdata(st, 8)) { event = script_getstr(st, 8); check_event(st, event); } - + if (script_hasdata(st, 9)) { size = script_getnum(st, 9); if (size > 3) { ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_); - return 1; + return false; } } - + if (script_hasdata(st, 10)) { ai = script_getnum(st, 10); if (ai > 4) { ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_); - return 1; + return false; } } - + if (class_ >= 0 && !mobdb_checkid(class_)) { ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_); - return 1; + return false; } - + sd = map_id2sd(st->rid); - + if (sd && strcmp(mapn, "this") == 0) m = sd->bl.m; else @@ -8868,53 +8465,53 @@ BUILDIN_FUNC(monster) if ((m = instance_mapid2imapid(m, st->instance_id)) < 0) { ShowError("buildin_monster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn); - return 1; + return false; } } } - + mob_once_spawn(sd, m, x, y, str, class_, amount, event, size, ai); - return 0; + return true; } /*========================================== * Request List of Monster Drops *------------------------------------------*/ -BUILDIN_FUNC(getmobdrops) +BUILDIN(getmobdrops) { int class_ = script_getnum(st,2); int i, j = 0; struct mob_db *mob; - + if( !mobdb_checkid(class_) ) { script_pushint(st, 0); - return 0; + return true; } - + mob = mob_db(class_); - + for( i = 0; i < MAX_MOB_DROP; i++ ) { if( mob->dropitem[i].nameid < 1 ) continue; if( itemdb_exists(mob->dropitem[i].nameid) == NULL ) continue; - + mapreg_setreg(reference_uid(add_str("$@MobDrop_item"), j), mob->dropitem[i].nameid); mapreg_setreg(reference_uid(add_str("$@MobDrop_rate"), j), mob->dropitem[i].p); - + j++; } - + mapreg_setreg(add_str("$@MobDrop_count"), j); script_pushint(st, 1); - - return 0; + + return true; } /*========================================== * Same as monster but randomize location in x0,x1,y0,y1 area *------------------------------------------*/ -BUILDIN_FUNC(areamonster) +BUILDIN(areamonster) { const char* mapn = script_getstr(st,2); int x0 = script_getnum(st,3); @@ -8927,38 +8524,38 @@ BUILDIN_FUNC(areamonster) const char* event = ""; unsigned int size = SZ_SMALL; unsigned int ai = AI_NONE; - + struct map_session_data* sd; int16 m; - + if (script_hasdata(st,10)) { event = script_getstr(st, 10); check_event(st, event); } - + if (script_hasdata(st, 11)) { size = script_getnum(st, 11); if (size > 3) { ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_); - return 1; + return false; } } - + if (script_hasdata(st, 12)) { ai = script_getnum(st, 12); if (ai > 4) { ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_); - return 1; + return false; } } - + sd = map_id2sd(st->rid); - + if (sd && strcmp(mapn, "this") == 0) m = sd->bl.m; else @@ -8969,25 +8566,25 @@ BUILDIN_FUNC(areamonster) if ((m = instance_mapid2imapid(m, st->instance_id)) < 0) { ShowError("buildin_areamonster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn); - return 1; + return false; } } } - + mob_once_spawn_area(sd, m, x0, y0, x1, y1, str, class_, amount, event, size, ai); - return 0; + return true; } /*========================================== * KillMonster subcheck, verify if mob to kill ain't got an even to handle, could be force kill by allflag *------------------------------------------*/ - static int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap) +static int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap) { //same fix but with killmonster instead - stripping events from mobs. TBL_MOB* md = (TBL_MOB*)bl; char *event=va_arg(ap,char *); int allflag=va_arg(ap,int); - + md->state.npc_killmonster = 1; - + if(!allflag){ if(strcmp(event,md->npc_event)==0) status_kill(bl); @@ -9003,7 +8600,7 @@ static int buildin_killmonster_sub(struct block_list *bl,va_list ap) TBL_MOB* md = (TBL_MOB*)bl; char *event=va_arg(ap,char *); int allflag=va_arg(ap,int); - + if(!allflag){ if(strcmp(event,md->npc_event)==0) status_kill(bl); @@ -9013,7 +8610,7 @@ static int buildin_killmonster_sub(struct block_list *bl,va_list ap) } return 0; } -BUILDIN_FUNC(killmonster) +BUILDIN(killmonster) { const char *mapname,*event; int16 m,allflag=0; @@ -9023,34 +8620,34 @@ BUILDIN_FUNC(killmonster) allflag = 1; else check_event(st, event); - + if( (m=map_mapname2mapid(mapname))<0 ) - return 0; - + return true; + if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) - return 0; - + return true; + if( script_hasdata(st,4) ) { if ( script_getnum(st,4) == 1 ) { map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag); - return 0; + return true; } } - + map_freeblock_lock(); map_foreachinmap(buildin_killmonster_sub_strip, m, BL_MOB, event ,allflag); map_freeblock_unlock(); - return 0; + return true; } static int buildin_killmonsterall_sub_strip(struct block_list *bl,va_list ap) { //Strips the event from the mob if it's killed the old method. struct mob_data *md; - + md = BL_CAST(BL_MOB, bl); if (md->npc_event[0]) md->npc_event[0] = 0; - + status_kill(bl); return 0; } @@ -9059,65 +8656,65 @@ static int buildin_killmonsterall_sub(struct block_list *bl,va_list ap) status_kill(bl); return 0; } -BUILDIN_FUNC(killmonsterall) +BUILDIN(killmonsterall) { const char *mapname; int16 m; mapname=script_getstr(st,2); - + if( (m = map_mapname2mapid(mapname))<0 ) - return 0; - + return true; + if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) - return 0; - + return true; + if( script_hasdata(st,3) ) { if ( script_getnum(st,3) == 1 ) { map_foreachinmap(buildin_killmonsterall_sub,m,BL_MOB); - return 0; + return true; } } - + map_foreachinmap(buildin_killmonsterall_sub_strip,m,BL_MOB); - return 0; + return true; } /*========================================== * Creates a clone of a player. * clone map, x, y, event, char_id, master_id, mode, flag, duration *------------------------------------------*/ -BUILDIN_FUNC(clone) +BUILDIN(clone) { TBL_PC *sd, *msd=NULL; int char_id,master_id=0,x,y, mode = 0, flag = 0, m; unsigned int duration = 0; const char *map,*event=""; - + map=script_getstr(st,2); x=script_getnum(st,3); y=script_getnum(st,4); event=script_getstr(st,5); char_id=script_getnum(st,6); - + if( script_hasdata(st,7) ) master_id=script_getnum(st,7); - + if( script_hasdata(st,8) ) mode=script_getnum(st,8); - + if( script_hasdata(st,9) ) flag=script_getnum(st,9); - + if( script_hasdata(st,10) ) duration=script_getnum(st,10); - + check_event(st, event); - + m = map_mapname2mapid(map); - if (m < 0) return 0; - + if (m < 0) return true; + sd = map_charid2sd(char_id); - + if (master_id) { msd = map_charid2sd(master_id); if (msd) @@ -9129,28 +8726,28 @@ BUILDIN_FUNC(clone) script_pushint(st,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration)); else //Failed to create clone. script_pushint(st,0); - - return 0; + + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(doevent) +BUILDIN(doevent) { const char* event = script_getstr(st,2); struct map_session_data* sd; - + if( ( sd = script_rid2sd(st) ) == NULL ) { - return 0; + return true; } - + check_event(st, event); npc_event(sd, event, 0); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(donpcevent) +BUILDIN(donpcevent) { const char* event = script_getstr(st,2); check_event(st, event); @@ -9160,12 +8757,12 @@ BUILDIN_FUNC(donpcevent) script_pushint(st, 0); } else script_pushint(st, 1); - return 0; + return true; } /// for Aegis compatibility /// basically a specialized 'donpcevent', with the event specified as two arguments instead of one -BUILDIN_FUNC(cmdothernpc) // Added by RoVeRT +BUILDIN(cmdothernpc) // Added by RoVeRT { const char* npc = script_getstr(st,2); const char* command = script_getstr(st,3); @@ -9173,67 +8770,67 @@ BUILDIN_FUNC(cmdothernpc) // Added by RoVeRT snprintf(event, sizeof(event), "%s::OnCommand%s", npc, command); check_event(st, event); npc_event_do(event); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(addtimer) +BUILDIN(addtimer) { int tick = script_getnum(st,2); const char* event = script_getstr(st, 3); TBL_PC* sd; - + check_event(st, event); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pc_addeventtimer(sd,tick,event); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(deltimer) +BUILDIN(deltimer) { const char *event; TBL_PC* sd; - + event=script_getstr(st, 2); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + check_event(st, event); pc_deleventtimer(sd,event); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(addtimercount) +BUILDIN(addtimercount) { const char *event; int tick; TBL_PC* sd; - + event=script_getstr(st, 2); tick=script_getnum(st,3); sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + check_event(st, event); pc_addeventtimercount(sd,event,tick); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(initnpctimer) +BUILDIN(initnpctimer) { struct npc_data *nd; int flag = 0; - + if( script_hasdata(st,3) ) { //Two arguments: NPC name and attach flag. nd = npc_name2id(script_getstr(st, 2)); @@ -9245,43 +8842,43 @@ BUILDIN_FUNC(initnpctimer) data = script_getdata(st,2); get_val(st,data); if( data_isstring(data) ) //NPC name - nd = npc_name2id(conv_str(st, data)); + nd = npc_name2id(script->conv_str(st, data)); else if( data_isint(data) ) //Flag { nd = (struct npc_data *)map_id2bl(st->oid); - flag = conv_num(st,data); + flag = script->conv_num(st,data); } else { ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n"); - return 1; + return false; } } else nd = (struct npc_data *)map_id2bl(st->oid); - + if( !nd ) - return 0; + return true; if( flag ) //Attach { TBL_PC* sd = script_rid2sd(st); if( sd == NULL ) - return 0; + return true; nd->u.scr.rid = sd->bl.id; } - + nd->u.scr.timertick = 0; npc_settimerevent_tick(nd,0); npc_timerevent_start(nd, st->rid); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(startnpctimer) +BUILDIN(startnpctimer) { struct npc_data *nd; int flag = 0; - + if( script_hasdata(st,3) ) { //Two arguments: NPC name and attach flag. nd = npc_name2id(script_getstr(st, 2)); @@ -9293,41 +8890,41 @@ BUILDIN_FUNC(startnpctimer) data = script_getdata(st,2); get_val(st,data); if( data_isstring(data) ) //NPC name - nd = npc_name2id(conv_str(st, data)); + nd = npc_name2id(script->conv_str(st, data)); else if( data_isint(data) ) //Flag { nd = (struct npc_data *)map_id2bl(st->oid); - flag = conv_num(st,data); + flag = script->conv_num(st,data); } else { ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n"); - return 1; + return false; } } else nd=(struct npc_data *)map_id2bl(st->oid); - + if( !nd ) - return 0; + return true; if( flag ) //Attach { TBL_PC* sd = script_rid2sd(st); if( sd == NULL ) - return 0; + return true; nd->u.scr.rid = sd->bl.id; } - + npc_timerevent_start(nd, st->rid); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(stopnpctimer) +BUILDIN(stopnpctimer) { struct npc_data *nd; int flag = 0; - + if( script_hasdata(st,3) ) { //Two arguments: NPC name and attach flag. nd = npc_name2id(script_getstr(st, 2)); @@ -9339,152 +8936,152 @@ BUILDIN_FUNC(stopnpctimer) data = script_getdata(st,2); get_val(st,data); if( data_isstring(data) ) //NPC name - nd = npc_name2id(conv_str(st, data)); + nd = npc_name2id(script->conv_str(st, data)); else if( data_isint(data) ) //Flag { nd = (struct npc_data *)map_id2bl(st->oid); - flag = conv_num(st,data); + flag = script->conv_num(st,data); } else { ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n"); - return 1; + return false; } } else nd=(struct npc_data *)map_id2bl(st->oid); - + if( !nd ) - return 0; + return true; if( flag ) //Detach nd->u.scr.rid = 0; - + npc_timerevent_stop(nd); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(getnpctimer) +BUILDIN(getnpctimer) { struct npc_data *nd; TBL_PC *sd; int type = script_getnum(st,2); int val = 0; - + if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st,3)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,0); ShowError("getnpctimer: Invalid NPC.\n"); - return 1; + return false; } - + switch( type ) { - case 0: val = npc_gettimerevent_tick(nd); break; - case 1: - if( nd->u.scr.rid ) - { - sd = map_id2sd(nd->u.scr.rid); - if( !sd ) + case 0: val = npc_gettimerevent_tick(nd); break; + case 1: + if( nd->u.scr.rid ) { - ShowError("buildin_getnpctimer: Attached player not found!\n"); - break; + sd = map_id2sd(nd->u.scr.rid); + if( !sd ) + { + ShowError("buildin_getnpctimer: Attached player not found!\n"); + break; + } + val = (sd->npc_timer_id != INVALID_TIMER); } - val = (sd->npc_timer_id != INVALID_TIMER); - } - else - val = (nd->u.scr.timerid != INVALID_TIMER); - break; - case 2: val = nd->u.scr.timeramount; break; + else + val = (nd->u.scr.timerid != INVALID_TIMER); + break; + case 2: val = nd->u.scr.timeramount; break; } - + script_pushint(st,val); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(setnpctimer) +BUILDIN(setnpctimer) { int tick; struct npc_data *nd; - + tick = script_getnum(st,2); if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st,3)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,1); ShowError("setnpctimer: Invalid NPC.\n"); - return 1; + return false; } - + npc_settimerevent_tick(nd,tick); script_pushint(st,0); - return 0; + return true; } /*========================================== * attaches the player rid to the timer [Celest] *------------------------------------------*/ -BUILDIN_FUNC(attachnpctimer) +BUILDIN(attachnpctimer) { TBL_PC *sd; struct npc_data *nd = (struct npc_data *)map_id2bl(st->oid); - + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,1); ShowError("setnpctimer: Invalid NPC.\n"); - return 1; + return false; } - + if( script_hasdata(st,2) ) sd = map_nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); - + if( !sd ) { script_pushint(st,1); ShowWarning("attachnpctimer: Invalid player.\n"); - return 1; + return false; } - + nd->u.scr.rid = sd->bl.id; script_pushint(st,0); - return 0; + return true; } /*========================================== * detaches a player rid from the timer [Celest] *------------------------------------------*/ -BUILDIN_FUNC(detachnpctimer) +BUILDIN(detachnpctimer) { struct npc_data *nd; - + if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st,2)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,1); ShowError("detachnpctimer: Invalid NPC.\n"); - return 1; + return false; } - + nd->u.scr.rid = 0; script_pushint(st,0); - return 0; + return true; } /*========================================== @@ -9492,18 +9089,18 @@ BUILDIN_FUNC(detachnpctimer) * it checks if there is a player attached to the current script. [Skotlex] * If no, returns 0, if yes, returns the account_id of the attached player. *------------------------------------------*/ -BUILDIN_FUNC(playerattached) +BUILDIN(playerattached) { if(st->rid == 0 || map_id2sd(st->rid) == NULL) script_pushint(st,0); else script_pushint(st,st->rid); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(announce) +BUILDIN(announce) { const char *mes = script_getstr(st,2); int flag = script_getnum(st,3); @@ -9512,23 +9109,23 @@ BUILDIN_FUNC(announce) int fontSize = script_hasdata(st,6) ? script_getnum(st,6) : 12; // default fontSize int fontAlign = script_hasdata(st,7) ? script_getnum(st,7) : 0; // default fontAlign int fontY = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontY - + if (flag&0x0f) // Broadcast source or broadcast region defined { send_target target; struct block_list *bl = (flag&0x08) ? map_id2bl(st->oid) : (struct block_list *)script_rid2sd(st); // If bc_npc flag is set, use NPC as broadcast source if (bl == NULL) - return 0; - + return true; + flag &= 0x07; target = (flag == 1) ? ALL_SAMEMAP : - (flag == 2) ? AREA : - (flag == 3) ? SELF : - ALL_CLIENT; + (flag == 2) ? AREA : + (flag == 3) ? SELF : + ALL_CLIENT; if (fontColor) - clif_broadcast2(bl, mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, target); + clif->broadcast2(bl, mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, target); else - clif_broadcast(bl, mes, (int)strlen(mes)+1, flag&0xf0, target); + clif->broadcast(bl, mes, (int)strlen(mes)+1, flag&0xf0, target); } else { @@ -9537,7 +9134,7 @@ BUILDIN_FUNC(announce) else intif_broadcast(mes, (int)strlen(mes)+1, flag&0xf0); } - return 0; + return true; } /*========================================== *------------------------------------------*/ @@ -9552,13 +9149,51 @@ static int buildin_announce_sub(struct block_list *bl, va_list ap) short fontAlign = (short)va_arg(ap, int); short fontY = (short)va_arg(ap, int); if (fontColor) - clif_broadcast2(bl, mes, len, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, SELF); + clif->broadcast2(bl, mes, len, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, SELF); else - clif_broadcast(bl, mes, len, type, SELF); + clif->broadcast(bl, mes, len, type, SELF); return 0; } +/* Runs item effect on attached character. + * itemeffect <item id>; + * itemeffect "<item name>"; */ +BUILDIN(itemeffect) { + TBL_NPC *nd; + TBL_PC *sd; + struct script_data *data; + struct item_data *item_data; + + nullpo_retr( 1, ( sd = script_rid2sd( st ) ) ); + nullpo_retr( 1, ( nd = (TBL_NPC *)map_id2bl( sd->npc_id ) ) ); + + data = script_getdata( st, 2 ); + get_val( st, data ); + + if( data_isstring( data ) ){ + const char *name = script->conv_str( st, data ); + + if( ( item_data = itemdb_searchname( name ) ) == NULL ){ + ShowError( "buildin_itemeffect: Nonexistant item %s requested.\n", name ); + return false; + } + } else if( data_isint( data ) ){ + int nameid = script->conv_num( st, data ); + + if( ( item_data = itemdb_exists( nameid ) ) == NULL ){ + ShowError("buildin_itemeffect: Nonexistant item %d requested.\n", nameid ); + return false; + } + } else { + ShowError("buildin_itemeffect: invalid data type for argument #1 (%d).", data->type ); + return false; + } + + run_script( item_data->script, 0, sd->bl.id, nd->bl.id ); + + return true; +} -BUILDIN_FUNC(mapannounce) +BUILDIN(mapannounce) { const char *mapname = script_getstr(st,2); const char *mes = script_getstr(st,3); @@ -9569,17 +9204,17 @@ BUILDIN_FUNC(mapannounce) int fontAlign = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontAlign int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY int16 m; - + if ((m = map_mapname2mapid(mapname)) < 0) - return 0; - + return true; + map_foreachinmap(buildin_announce_sub, m, BL_PC, - mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); - return 0; + mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(areaannounce) +BUILDIN(areaannounce) { const char *mapname = script_getstr(st,2); int x0 = script_getnum(st,3); @@ -9594,25 +9229,25 @@ BUILDIN_FUNC(areaannounce) int fontAlign = script_hasdata(st,12) ? script_getnum(st,12) : 0; // default fontAlign int fontY = script_hasdata(st,13) ? script_getnum(st,13) : 0; // default fontY int16 m; - + if ((m = map_mapname2mapid(mapname)) < 0) - return 0; - + return true; + map_foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC, - mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); - return 0; + mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(getusers) +BUILDIN(getusers) { int flag, val = 0; struct map_session_data* sd; struct block_list* bl = NULL; - + flag = script_getnum(st,2); - + switch(flag&0x07) { case 0: @@ -9624,7 +9259,7 @@ BUILDIN_FUNC(getusers) {// pc bl = &sd->bl; } - + if(bl) { val = map[bl->m].users; @@ -9636,45 +9271,45 @@ BUILDIN_FUNC(getusers) default: ShowWarning("buildin_getusers: Unknown type %d.\n", flag); script_pushint(st,0); - return 1; + return false; } - + script_pushint(st,val); - return 0; + return true; } /*========================================== * Works like @WHO - displays all online users names in window *------------------------------------------*/ -BUILDIN_FUNC(getusersname) +BUILDIN(getusersname) { TBL_PC *sd, *pl_sd; int /*disp_num=1,*/ group_level = 0; struct s_mapiterator* iter; - + sd = script_rid2sd(st); - if (!sd) return 0; - + if (!sd) return true; + group_level = pc_get_group_level(sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > group_level) continue; // skip hidden sessions - + /* Temporary fix for bugreport:1023. * Do not uncomment unless you want thousands of 'next' buttons. - if((disp_num++)%10==0) - clif_scriptnext(sd,st->oid);*/ - clif_scriptmes(sd,st->oid,pl_sd->status.name); + if((disp_num++)%10==0) + clif->scriptnext(sd,st->oid);*/ + clif->scriptmes(sd,st->oid,pl_sd->status.name); } - mapit_free(iter); - - return 0; + mapit->free(iter); + + return true; } /*========================================== * getmapguildusers("mapname",guild ID) Returns the number guild members present on a map [Reddozen] *------------------------------------------*/ -BUILDIN_FUNC(getmapguildusers) +BUILDIN(getmapguildusers) { const char *str; int16 m; @@ -9685,10 +9320,10 @@ BUILDIN_FUNC(getmapguildusers) gid=script_getnum(st,3); if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server) script_pushint(st,-1); - return 0; + return true; } - g = guild_search(gid); - + g = guild->search(gid); + if (g){ for(i = 0; i < g->max_member; i++) { @@ -9696,23 +9331,23 @@ BUILDIN_FUNC(getmapguildusers) c++; } } - + script_pushint(st,c); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(getmapusers) +BUILDIN(getmapusers) { const char *str; int16 m; str=script_getstr(st,2); if( (m=map_mapname2mapid(str))< 0){ script_pushint(st,-1); - return 0; + return true; } script_pushint(st,map[m].users); - return 0; + return true; } /*========================================== *------------------------------------------*/ @@ -9722,7 +9357,7 @@ static int buildin_getareausers_sub(struct block_list *bl,va_list ap) (*users)++; return 0; } -BUILDIN_FUNC(getareausers) +BUILDIN(getareausers) { const char *str; int16 m,x0,y0,x1,y1,users=0; //doubt we can have more then 32k users on @@ -9733,12 +9368,12 @@ BUILDIN_FUNC(getareausers) y1=script_getnum(st,6); if( (m=map_mapname2mapid(str))< 0){ script_pushint(st,-1); - return 0; + return true; } map_foreachinarea(buildin_getareausers_sub, - m,x0,y0,x1,y1,BL_PC,&users); + m,x0,y0,x1,y1,BL_PC,&users); script_pushint(st,users); - return 0; + return true; } /*========================================== @@ -9748,94 +9383,94 @@ static int buildin_getareadropitem_sub(struct block_list *bl,va_list ap) int item=va_arg(ap,int); int *amount=va_arg(ap,int *); struct flooritem_data *drop=(struct flooritem_data *)bl; - + if(drop->item_data.nameid==item) (*amount)+=drop->item_data.amount; - + return 0; } -BUILDIN_FUNC(getareadropitem) +BUILDIN(getareadropitem) { const char *str; int16 m,x0,y0,x1,y1; int item,amount=0; struct script_data *data; - + str=script_getstr(st,2); x0=script_getnum(st,3); y0=script_getnum(st,4); x1=script_getnum(st,5); y1=script_getnum(st,6); - + data=script_getdata(st,7); get_val(st,data); if( data_isstring(data) ){ - const char *name=conv_str(st,data); + const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); item=UNKNOWN_ITEM_ID; if( item_data ) item=item_data->nameid; }else - item=conv_num(st,data); - + item=script->conv_num(st,data); + if( (m=map_mapname2mapid(str))< 0){ script_pushint(st,-1); - return 0; + return true; } map_foreachinarea(buildin_getareadropitem_sub, - m,x0,y0,x1,y1,BL_ITEM,item,&amount); + m,x0,y0,x1,y1,BL_ITEM,item,&amount); script_pushint(st,amount); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(enablenpc) +BUILDIN(enablenpc) { const char *str; str=script_getstr(st,2); npc_enable(str,1); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(disablenpc) +BUILDIN(disablenpc) { const char *str; str=script_getstr(st,2); npc_enable(str,0); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(hideoffnpc) +BUILDIN(hideoffnpc) { const char *str; str=script_getstr(st,2); npc_enable(str,2); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(hideonnpc) +BUILDIN(hideonnpc) { const char *str; str=script_getstr(st,2); npc_enable(str,4); - return 0; + return true; } /// Starts a status effect on the target unit or on the attached player. /// /// sc_start <effect_id>,<duration>,<val1>{,<unit_id>}; -BUILDIN_FUNC(sc_start) +BUILDIN(sc_start) { struct block_list* bl; enum sc_type type; int tick; int val1; int val4 = 0; - + type = (sc_type)script_getnum(st,2); tick = script_getnum(st,3); val1 = script_getnum(st,4); @@ -9843,29 +9478,29 @@ BUILDIN_FUNC(sc_start) bl = map_id2bl(script_getnum(st,5)); else bl = map_id2bl(st->rid); - + if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 ) {// When there isn't a duration specified, try to get it from the skill_db - tick = skill_get_time(status_sc2skill(type), val1); + tick = skill->get_time(status_sc2skill(type), val1); } - + if( potion_flag == 1 && potion_target ) { //skill.c set the flags before running the script, this must be a potion-pitched effect. bl = map_id2bl(potion_target); tick /= 2;// Thrown potions only last half. val4 = 1;// Mark that this was a thrown sc_effect } - + if( bl ) status_change_start(bl, type, 10000, val1, 0, 0, val4, tick, 2); - - return 0; + + return true; } /// Starts a status effect on the target unit or on the attached player. /// /// sc_start2 <effect_id>,<duration>,<val1>,<percent chance>{,<unit_id>}; -BUILDIN_FUNC(sc_start2) +BUILDIN(sc_start2) { struct block_list* bl; enum sc_type type; @@ -9873,7 +9508,7 @@ BUILDIN_FUNC(sc_start2) int val1; int val4 = 0; int rate; - + type = (sc_type)script_getnum(st,2); tick = script_getnum(st,3); val1 = script_getnum(st,4); @@ -9882,29 +9517,29 @@ BUILDIN_FUNC(sc_start2) bl = map_id2bl(script_getnum(st,6)); else bl = map_id2bl(st->rid); - + if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 ) {// When there isn't a duration specified, try to get it from the skill_db - tick = skill_get_time(status_sc2skill(type), val1); + tick = skill->get_time(status_sc2skill(type), val1); } - + if( potion_flag == 1 && potion_target ) { //skill.c set the flags before running the script, this must be a potion-pitched effect. bl = map_id2bl(potion_target); tick /= 2;// Thrown potions only last half. val4 = 1;// Mark that this was a thrown sc_effect } - + if( bl ) status_change_start(bl, type, rate, val1, 0, 0, val4, tick, 2); - - return 0; + + return true; } /// Starts a status effect on the target unit or on the attached player. /// /// sc_start4 <effect_id>,<duration>,<val1>,<val2>,<val3>,<val4>{,<unit_id>}; -BUILDIN_FUNC(sc_start4) +BUILDIN(sc_start4) { struct block_list* bl; enum sc_type type; @@ -9913,7 +9548,7 @@ BUILDIN_FUNC(sc_start4) int val2; int val3; int val4; - + type = (sc_type)script_getnum(st,2); tick = script_getnum(st,3); val1 = script_getnum(st,4); @@ -9924,125 +9559,125 @@ BUILDIN_FUNC(sc_start4) bl = map_id2bl(script_getnum(st,8)); else bl = map_id2bl(st->rid); - + if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 ) {// When there isn't a duration specified, try to get it from the skill_db - tick = skill_get_time(status_sc2skill(type), val1); + tick = skill->get_time(status_sc2skill(type), val1); } - + if( potion_flag == 1 && potion_target ) { //skill.c set the flags before running the script, this must be a potion-pitched effect. bl = map_id2bl(potion_target); tick /= 2;// Thrown potions only last half. } - + if( bl ) status_change_start(bl, type, 10000, val1, val2, val3, val4, tick, 2); - - return 0; + + return true; } /// Ends one or all status effects on the target unit or on the attached player. /// /// sc_end <effect_id>{,<unit_id>}; -BUILDIN_FUNC(sc_end) +BUILDIN(sc_end) { struct block_list* bl; int type; - + type = script_getnum(st, 2); if (script_hasdata(st, 3)) bl = map_id2bl(script_getnum(st, 3)); else bl = map_id2bl(st->rid); - + if (potion_flag == 1 && potion_target) //##TODO how does this work [FlavioJS] bl = map_id2bl(potion_target); - + if (!bl) - return 0; - + return true; + if (type >= 0 && type < SC_MAX) { struct status_change *sc = status_get_sc(bl); struct status_change_entry *sce = sc ? sc->data[type] : NULL; - + if (!sce) - return 0; - - + return true; + + switch (type) { case SC_WEIGHT50: case SC_WEIGHT90: case SC_NOCHAT: case SC_PUSH_CART: - return 0; - + return true; + default: break; } - + //This should help status_change_end force disabling the SC in case it has no limit. sce->val1 = sce->val2 = sce->val3 = sce->val4 = 0; status_change_end(bl, (sc_type)type, INVALID_TIMER); } else status_change_clear(bl, 3); // remove all effects - - return 0; + + return true; } /*========================================== * @FIXME atm will return reduced tick, 0 immune, 1 no tick *------------------------------------------*/ -BUILDIN_FUNC(getscrate) +BUILDIN(getscrate) { struct block_list *bl; int type,rate; - + type=script_getnum(st,2); rate=script_getnum(st,3); if( script_hasdata(st,4) ) //get for the bl assigned bl = map_id2bl(script_getnum(st,4)); else bl = map_id2bl(st->rid); - + if (bl) rate = status_get_sc_def(bl, (sc_type)type, 10000, 10000, 0); - + script_pushint(st,rate); - return 0; + return true; } /*========================================== * getstatus <type>{, <info>}; *------------------------------------------*/ -BUILDIN_FUNC(getstatus) +BUILDIN(getstatus) { int id, type; struct map_session_data* sd = script_rid2sd(st); - + if( sd == NULL ) {// no player attached - return 0; + return true; } - + id = script_getnum(st, 2); type = script_hasdata(st, 3) ? script_getnum(st, 3) : 0; - + if( id <= SC_NONE || id >= SC_MAX ) {// invalid status type given ShowWarning("script.c:getstatus: Invalid status type given (%d).\n", id); - return 0; + return true; } - + if( sd->sc.count == 0 || !sd->sc.data[id] ) {// no status is active script_pushint(st, 0); - return 0; + return true; } - + switch( type ) { case 1: script_pushint(st, sd->sc.data[id]->val1); break; @@ -10050,115 +9685,113 @@ BUILDIN_FUNC(getstatus) case 3: script_pushint(st, sd->sc.data[id]->val3); break; case 4: script_pushint(st, sd->sc.data[id]->val4); break; case 5: - { - struct TimerData* timer = (struct TimerData*)get_timer(sd->sc.data[id]->timer); - - if( timer ) - {// return the amount of time remaining - script_pushint(st, timer->tick - gettick()); - } + { + struct TimerData* timer = (struct TimerData*)get_timer(sd->sc.data[id]->timer); + + if( timer ) + {// return the amount of time remaining + script_pushint(st, timer->tick - gettick()); } + } break; default: script_pushint(st, 1); break; } - - return 0; + + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(debugmes) +BUILDIN(debugmes) { const char *str; str=script_getstr(st,2); ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,str); - return 0; + return true; } /*========================================== *------------------------------------------*/ -BUILDIN_FUNC(catchpet) +BUILDIN(catchpet) { int pet_id; TBL_PC *sd; - + pet_id= script_getnum(st,2); sd=script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pet_catch_process1(sd,pet_id); - return 0; + return true; } /*========================================== * [orn] *------------------------------------------*/ -BUILDIN_FUNC(homunculus_evolution) +BUILDIN(homunculus_evolution) { TBL_PC *sd; - + sd=script_rid2sd(st); if( sd == NULL ) - return 0; - - if(merc_is_hom_active(sd->hd)) - { + return true; + + if(homun_alive(sd->hd)) { if (sd->hd->homunculus.intimacy > 91000) - merc_hom_evolution(sd->hd); + homun->evolve(sd->hd); else - clif_emotion(&sd->hd->bl, E_SWT); + clif->emotion(&sd->hd->bl, E_SWT); } - return 0; + return true; } /*========================================== * [Xantara] *------------------------------------------*/ -BUILDIN_FUNC(homunculus_mutate) -{ - int homun_id, m_class, m_id; +BUILDIN(homunculus_mutate) { + int homun_id; + enum homun_type m_class, m_id; TBL_PC *sd; - + sd = script_rid2sd(st); - if( sd == NULL ) - return 0; - + if( sd == NULL || sd->hd == NULL ) + return true; + if(script_hasdata(st,2)) homun_id = script_getnum(st,2); else homun_id = 6048 + (rnd() % 4); - - if(merc_is_hom_active(sd->hd)) { - m_class = hom_class2mapid(sd->hd->homunculus.class_); - m_id = hom_class2mapid(homun_id); - - if ( m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99 ) - hom_mutate(sd->hd, homun_id); + + if(homun_alive(sd->hd)) { + m_class = homun->class2type(sd->hd->homunculus.class_); + m_id = homun->class2type(homun_id); + + if ( m_class != -1 && m_id != -1 && m_class == HT_EVO && m_id == HT_S && sd->hd->homunculus.level >= 99 ) + homun->mutate(sd->hd, homun_id); else - clif_emotion(&sd->hd->bl, E_SWT); + clif->emotion(&sd->hd->bl, E_SWT); } - return 0; + return true; } // [Zephyrus] -BUILDIN_FUNC(homunculus_shuffle) -{ +BUILDIN(homunculus_shuffle) { TBL_PC *sd; - + sd=script_rid2sd(st); if( sd == NULL ) - return 0; - - if(merc_is_hom_active(sd->hd)) - merc_hom_shuffle(sd->hd); - - return 0; + return true; + + if(homun_alive(sd->hd)) + homun->shuffle(sd->hd); + + return true; } //These two functions bring the eA MAPID_* class functionality to scripts. -BUILDIN_FUNC(eaclass) +BUILDIN(eaclass) { int class_; if( script_hasdata(st,2) ) @@ -10168,15 +9801,15 @@ BUILDIN_FUNC(eaclass) sd=script_rid2sd(st); if (!sd) { script_pushint(st,-1); - return 0; + return true; } class_ = sd->status.class_; } script_pushint(st,pc_jobid2mapid(class_)); - return 0; + return true; } -BUILDIN_FUNC(roclass) +BUILDIN(roclass) { int class_ =script_getnum(st,2); int sex; @@ -10190,26 +9823,26 @@ BUILDIN_FUNC(roclass) sex = 1; //Just use male when not found. } script_pushint(st,pc_mapid2jobid(class_, sex)); - return 0; + return true; } /*========================================== * Tells client to open a hatching window, used for pet incubator *------------------------------------------*/ -BUILDIN_FUNC(birthpet) +BUILDIN(birthpet) { TBL_PC *sd; sd=script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + if( sd->status.pet_id ) {// do not send egg list, when you already have a pet - return 0; + return true; } - - clif_sendegg(sd); - return 0; + + clif->sendegg(sd); + return true; } /*========================================== @@ -10220,128 +9853,128 @@ BUILDIN_FUNC(birthpet) * 3 : don't reset skill, blvl=1 * 4 : jlvl=0 *------------------------------------------*/ -BUILDIN_FUNC(resetlvl) +BUILDIN(resetlvl) { TBL_PC *sd; - + int type=script_getnum(st,2); - + sd=script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + pc_resetlvl(sd,type); - return 0; + return true; } /*========================================== * Reset a player status point *------------------------------------------*/ -BUILDIN_FUNC(resetstatus) +BUILDIN(resetstatus) { TBL_PC *sd; sd=script_rid2sd(st); pc_resetstate(sd); - return 0; + return true; } /*========================================== * script command resetskill *------------------------------------------*/ -BUILDIN_FUNC(resetskill) +BUILDIN(resetskill) { TBL_PC *sd; sd=script_rid2sd(st); pc_resetskill(sd,1); - return 0; + return true; } /*========================================== * Counts total amount of skill points. *------------------------------------------*/ -BUILDIN_FUNC(skillpointcount) +BUILDIN(skillpointcount) { TBL_PC *sd; sd=script_rid2sd(st); script_pushint(st,sd->status.skill_point + pc_resetskill(sd,2)); - return 0; + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(changebase) +BUILDIN(changebase) { TBL_PC *sd=NULL; int vclass; - + if( script_hasdata(st,3) ) sd=map_id2sd(script_getnum(st,3)); else - sd=script_rid2sd(st); - + sd=script_rid2sd(st); + if(sd == NULL) - return 0; - + return true; + vclass = script_getnum(st,2); if(vclass == JOB_WEDDING) { if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore. ) - return 0; + return true; } - - if(!sd->disguise && vclass != sd->vd.class_) { + + if(sd->disguise == -1 && vclass != sd->vd.class_) { status_set_viewdata(&sd->bl, vclass); //Updated client view. Base, Weapon and Cloth Colors. - clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_); - clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon); + clif->changelook(&sd->bl,LOOK_BASE,sd->vd.class_); + clif->changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon); if (sd->vd.cloth_color) - clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color); - clif_skillinfoblock(sd); + clif->changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color); + clif->skillinfoblock(sd); } - - return 0; + + return true; } /*========================================== * Unequip all item and request for a changesex to char-serv *------------------------------------------*/ -BUILDIN_FUNC(changesex) +BUILDIN(changesex) { int i; TBL_PC *sd = NULL; sd = script_rid2sd(st); - + pc_resetskill(sd,4); // to avoid any problem with equipment and invalid sex, equipment is unequiped. for( i=0; i<EQI_MAX; i++ ) if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3); chrif_changesex(sd); - return 0; + return true; } /*========================================== * Works like 'announce' but outputs in the common chat window *------------------------------------------*/ -BUILDIN_FUNC(globalmes) +BUILDIN(globalmes) { struct block_list *bl = map_id2bl(st->oid); struct npc_data *nd = (struct npc_data *)bl; const char *name=NULL,*mes; - + mes=script_getstr(st,2); - if(mes==NULL) return 0; - + if(mes==NULL) return true; + if(script_hasdata(st,3)){ // npc name to display name=script_getstr(st,3); } else { name=nd->name; //use current npc name } - + npc_globalmessage(name,mes); // broadcast to all players connected - - return 0; + + return true; } ///////////////////////////////////////////////////////////////////// @@ -10351,7 +9984,7 @@ BUILDIN_FUNC(globalmes) /// Creates a waiting room (chat room) for this npc. /// /// waitingroom "<title>",<limit>{,"<event>"{,<trigger>{,<zeny>{,<minlvl>{,<maxlvl>}}}}}; -BUILDIN_FUNC(waitingroom) +BUILDIN(waitingroom) { struct npc_data* nd; int pub = 1; @@ -10362,19 +9995,19 @@ BUILDIN_FUNC(waitingroom) int zeny = script_hasdata(st,6) ? script_getnum(st,6) : 0; int minLvl = script_hasdata(st,7) ? script_getnum(st,7) : 1; int maxLvl = script_hasdata(st,8) ? script_getnum(st,8) : MAX_LEVEL; - + nd = (struct npc_data *)map_id2bl(st->oid); if( nd != NULL ) chat_createnpcchat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl); - - return 0; + + return true; } /// Removes the waiting room of the current or target npc. /// /// delwaitingroom "<npc_name>"; /// delwaitingroom; -BUILDIN_FUNC(delwaitingroom) +BUILDIN(delwaitingroom) { struct npc_data* nd; if( script_hasdata(st,2) ) @@ -10383,64 +10016,64 @@ BUILDIN_FUNC(delwaitingroom) nd = (struct npc_data *)map_id2bl(st->oid); if( nd != NULL ) chat_deletenpcchat(nd); - return 0; + return true; } /// Kicks all the players from the waiting room of the current or target npc. /// /// kickwaitingroomall "<npc_name>"; /// kickwaitingroomall; -BUILDIN_FUNC(waitingroomkickall) +BUILDIN(waitingroomkickall) { struct npc_data* nd; struct chat_data* cd; - + if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st,2)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) chat_npckickall(cd); - return 0; + return true; } /// Enables the waiting room event of the current or target npc. /// /// enablewaitingroomevent "<npc_name>"; /// enablewaitingroomevent; -BUILDIN_FUNC(enablewaitingroomevent) +BUILDIN(enablewaitingroomevent) { struct npc_data* nd; struct chat_data* cd; - + if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st, 2)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) chat_enableevent(cd); - return 0; + return true; } /// Disables the waiting room event of the current or target npc. /// /// disablewaitingroomevent "<npc_name>"; /// disablewaitingroomevent; -BUILDIN_FUNC(disablewaitingroomevent) +BUILDIN(disablewaitingroomevent) { struct npc_data *nd; struct chat_data *cd; - + if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st, 2)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) chat_disableevent(cd); - return 0; + return true; } /// Returns info on the waiting room of the current or target npc. @@ -10457,38 +10090,38 @@ BUILDIN_FUNC(disablewaitingroomevent) /// /// getwaitingroomstate(<type>,"<npc_name>") -> <info> /// getwaitingroomstate(<type>) -> <info> -BUILDIN_FUNC(getwaitingroomstate) +BUILDIN(getwaitingroomstate) { struct npc_data *nd; struct chat_data *cd; int type; - + type = script_getnum(st,2); if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st, 3)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL ) { script_pushint(st, -1); - return 0; + return true; } - + switch(type) { - case 0: script_pushint(st, cd->users); break; - case 1: script_pushint(st, cd->limit); break; - case 2: script_pushint(st, cd->trigger&0x7f); break; - case 3: script_pushint(st, ((cd->trigger&0x80)!=0)); break; - case 4: script_pushstrcopy(st, cd->title); break; - case 5: script_pushstrcopy(st, cd->pass); break; - case 16: script_pushstrcopy(st, cd->npc_event);break; - case 32: script_pushint(st, (cd->users >= cd->limit)); break; - case 33: script_pushint(st, (cd->users >= cd->trigger)); break; - default: script_pushint(st, -1); break; + case 0: script_pushint(st, cd->users); break; + case 1: script_pushint(st, cd->limit); break; + case 2: script_pushint(st, cd->trigger&0x7f); break; + case 3: script_pushint(st, ((cd->trigger&0x80)!=0)); break; + case 4: script_pushstrcopy(st, cd->title); break; + case 5: script_pushstrcopy(st, cd->pass); break; + case 16: script_pushstrcopy(st, cd->npc_event);break; + case 32: script_pushint(st, (cd->users >= cd->limit)); break; + case 33: script_pushint(st, (cd->users >= cd->trigger)); break; + default: script_pushint(st, -1); break; } - return 0; + return true; } /// Warps the trigger or target amount of players to the target map and position. @@ -10503,7 +10136,7 @@ BUILDIN_FUNC(getwaitingroomstate) /// /// warpwaitingpc "<map name>",<x>,<y>,<number of players>; /// warpwaitingpc "<map name>",<x>,<y>; -BUILDIN_FUNC(warpwaitingpc) +BUILDIN(warpwaitingpc) { int x; int y; @@ -10513,28 +10146,28 @@ BUILDIN_FUNC(warpwaitingpc) struct npc_data* nd; struct chat_data* cd; TBL_PC* sd; - + nd = (struct npc_data *)map_id2bl(st->oid); if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL ) - return 0; - + return true; + map_name = script_getstr(st,2); x = script_getnum(st,3); y = script_getnum(st,4); n = cd->trigger&0x7f; - + if( script_hasdata(st,5) ) n = script_getnum(st,5); - + for( i = 0; i < n && cd->users > 0; i++ ) { sd = cd->usersd[0]; - + if( strcmp(map_name,"SavePoint") == 0 && map[sd->bl.m].flag.noteleport ) {// can't teleport on this map break; } - + if( cd->zeny ) {// fee set if( (uint32)sd->status.zeny < cd->zeny ) @@ -10543,9 +10176,9 @@ BUILDIN_FUNC(warpwaitingpc) } pc_payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL); } - + mapreg_setreg(reference_uid(add_str("$@warpwaitingpc"), i), sd->bl.id); - + if( strcmp(map_name,"Random") == 0 ) pc_randomwarp(sd,CLR_TELEPORT); else if( strcmp(map_name,"SavePoint") == 0 ) @@ -10554,7 +10187,7 @@ BUILDIN_FUNC(warpwaitingpc) pc_setpos(sd, mapindex_name2id(map_name), x, y, CLR_OUTSIGHT); } mapreg_setreg(add_str("$@warpwaitingpcnum"), i); - return 0; + return true; } ///////////////////////////////////////////////////////////////////// @@ -10576,77 +10209,76 @@ static void script_detach_rid(struct script_state* st) /*========================================== * Attach sd char id to script and detach current one if any *------------------------------------------*/ -BUILDIN_FUNC(attachrid) +BUILDIN(attachrid) { int rid = script_getnum(st,2); - struct map_session_data* sd; - - if ((sd = map_id2sd(rid))!=NULL) { + + if (map_id2sd(rid) != NULL) { script_detach_rid(st); - + st->rid = rid; script_attach_state(st); script_pushint(st,1); } else script_pushint(st,0); - return 0; + return true; } /*========================================== * Detach script to rid *------------------------------------------*/ -BUILDIN_FUNC(detachrid) +BUILDIN(detachrid) { script_detach_rid(st); - return 0; + return true; } /*========================================== * Chk if account connected, (and charid from account if specified) *------------------------------------------*/ -BUILDIN_FUNC(isloggedin) +BUILDIN(isloggedin) { TBL_PC* sd = map_id2sd(script_getnum(st,2)); if (script_hasdata(st,3) && sd && sd->status.char_id != script_getnum(st,3)) sd = NULL; push_val(st->stack,C_INT,sd!=NULL); - return 0; + return true; } /*========================================== * *------------------------------------------*/ -BUILDIN_FUNC(setmapflagnosave) +BUILDIN(setmapflagnosave) { int16 m,x,y; unsigned short mapindex; const char *str,*str2; - + str=script_getstr(st,2); str2=script_getstr(st,3); x=script_getnum(st,4); y=script_getnum(st,5); m = map_mapname2mapid(str); mapindex = mapindex_name2id(str2); - + if(m >= 0 && mapindex) { map[m].flag.nosave=1; map[m].save.map=mapindex; map[m].save.x=x; map[m].save.y=y; } - - return 0; + + return true; } -BUILDIN_FUNC(getmapflag) +BUILDIN(getmapflag) { int16 m,i; const char *str; - + str=script_getstr(st,2); i=script_getnum(st,3); - + m = map_mapname2mapid(str); if(m >= 0) { switch(i) { @@ -10670,11 +10302,6 @@ BUILDIN_FUNC(getmapflag) case MF_FOG: script_pushint(st,map[m].flag.fog); break; case MF_SAKURA: script_pushint(st,map[m].flag.sakura); break; case MF_LEAVES: script_pushint(st,map[m].flag.leaves); break; - /** - * No longer available, keeping here just in case it's back someday. [Ind] - **/ - //case MF_RAIN: script_pushint(st,map[m].flag.rain); break; - case MF_NOGO: script_pushint(st,map[m].flag.nogo); break; case MF_CLOUDS: script_pushint(st,map[m].flag.clouds); break; case MF_CLOUDS2: script_pushint(st,map[m].flag.clouds2); break; case MF_FIREWORKS: script_pushint(st,map[m].flag.fireworks); break; @@ -10688,7 +10315,6 @@ BUILDIN_FUNC(getmapflag) case MF_NORETURN: script_pushint(st,map[m].flag.noreturn); break; case MF_NOWARPTO: script_pushint(st,map[m].flag.nowarpto); break; case MF_NIGHTMAREDROP: script_pushint(st,map[m].flag.pvp_nightmaredrop); break; - case MF_RESTRICTED: script_pushint(st,map[m].flag.restricted); break; case MF_NOCOMMAND: script_pushint(st,map[m].nocommand); break; case MF_NODROP: script_pushint(st,map[m].flag.nodrop); break; case MF_JEXP: script_pushint(st,map[m].jexp); break; @@ -10707,8 +10333,8 @@ BUILDIN_FUNC(getmapflag) case MF_RESET: script_pushint(st,map[m].flag.reset); break; } } - - return 0; + + return true; } /* pvp timer handling */ static int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) { @@ -10721,21 +10347,34 @@ static int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) { sd->pvp_won = 0; sd->pvp_lost = 0; } - clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); + clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); + clif->maptypeproperty2(&sd->bl,SELF); return 0; } -BUILDIN_FUNC(setmapflag) +BUILDIN(setmapflag) { int16 m,i; - const char *str; + const char *str, *val2 = NULL; + struct script_data* data; int val=0; - + str=script_getstr(st,2); - i=script_getnum(st,3); + + i = script_getnum(st, 3); + if(script_hasdata(st,4)){ - val=script_getnum(st,4); + data = script_getdata(st,4); + get_val(st, data); + + + if( data_isstring(data) ) + val2 = script_getstr(st, 4); + else + val = script_getnum(st, 4); + } m = map_mapname2mapid(str); + if(m >= 0) { switch(i) { case MF_NOMEMO: map[m].flag.nomemo = 1; break; @@ -10752,9 +10391,14 @@ BUILDIN_FUNC(setmapflag) break; case MF_PVP_NOPARTY: map[m].flag.pvp_noparty = 1; break; case MF_PVP_NOGUILD: map[m].flag.pvp_noguild = 1; break; - case MF_GVG: + case MF_GVG: { + struct block_list bl; map[m].flag.gvg = 1; - clif_map_property_mapall(m, MAPPROPERTY_AGITZONE); + clif->map_property_mapall(m, MAPPROPERTY_AGITZONE); + bl.type = BL_NUL; + bl.m = m; + clif->maptypeproperty2(&bl,ALL_SAMEMAP); + } break; case MF_GVG_NOPARTY: map[m].flag.gvg_noparty = 1; break; case MF_NOTRADE: map[m].flag.notrade = 1; break; @@ -10766,11 +10410,6 @@ BUILDIN_FUNC(setmapflag) case MF_FOG: map[m].flag.fog = 1; break; case MF_SAKURA: map[m].flag.sakura = 1; break; case MF_LEAVES: map[m].flag.leaves = 1; break; - /** - * No longer available, keeping here just in case it's back someday. [Ind] - **/ - //case MF_RAIN: map[m].flag.rain = 1; break; - case MF_NOGO: map[m].flag.nogo = 1; break; case MF_CLOUDS: map[m].flag.clouds = 1; break; case MF_CLOUDS2: map[m].flag.clouds2 = 1; break; case MF_FIREWORKS: map[m].flag.fireworks = 1; break; @@ -10784,9 +10423,13 @@ BUILDIN_FUNC(setmapflag) case MF_NORETURN: map[m].flag.noreturn = 1; break; case MF_NOWARPTO: map[m].flag.nowarpto = 1; break; case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop = 1; break; - case MF_RESTRICTED: - map[m].zone |= 1<<(val+1); - map[m].flag.restricted=1; + case MF_ZONE: { + char zone[6] = "zone\0"; + char empty[1] = "\0"; + char params[MAP_ZONE_MAPFLAG_LENGTH]; + memcpy(params, val2, MAP_ZONE_MAPFLAG_LENGTH); + npc_parse_mapflag(map[m].name, empty, zone, params, empty, empty, empty); + } break; case MF_NOCOMMAND: map[m].nocommand = (val <= 0) ? 100 : val; break; case MF_NODROP: map[m].flag.nodrop = 1; break; @@ -10806,16 +10449,16 @@ BUILDIN_FUNC(setmapflag) case MF_RESET: map[m].flag.reset = 1; break; } } - - return 0; + + return true; } -BUILDIN_FUNC(removemapflag) +BUILDIN(removemapflag) { int16 m,i; const char *str; int val=0; - + str=script_getstr(st,2); i=script_getnum(st,3); if(script_hasdata(st,4)){ @@ -10830,15 +10473,25 @@ BUILDIN_FUNC(removemapflag) case MF_NOBRANCH: map[m].flag.nobranch = 0; break; case MF_NOPENALTY: map[m].flag.noexppenalty = 0; map[m].flag.nozenypenalty = 0; break; case MF_NOZENYPENALTY: map[m].flag.nozenypenalty = 0; break; - case MF_PVP: + case MF_PVP: { + struct block_list bl; + bl.type = BL_NUL; + bl.m = m; map[m].flag.pvp = 0; - clif_map_property_mapall(m, MAPPROPERTY_NOTHING); + clif->map_property_mapall(m, MAPPROPERTY_NOTHING); + clif->maptypeproperty2(&bl,ALL_SAMEMAP); + } break; case MF_PVP_NOPARTY: map[m].flag.pvp_noparty = 0; break; case MF_PVP_NOGUILD: map[m].flag.pvp_noguild = 0; break; - case MF_GVG: + case MF_GVG: { + struct block_list bl; + bl.type = BL_NUL; + bl.m = m; map[m].flag.gvg = 0; - clif_map_property_mapall(m, MAPPROPERTY_NOTHING); + clif->map_property_mapall(m, MAPPROPERTY_NOTHING); + clif->maptypeproperty2(&bl,ALL_SAMEMAP); + } break; case MF_GVG_NOPARTY: map[m].flag.gvg_noparty = 0; break; case MF_NOTRADE: map[m].flag.notrade = 0; break; @@ -10850,11 +10503,6 @@ BUILDIN_FUNC(removemapflag) case MF_FOG: map[m].flag.fog = 0; break; case MF_SAKURA: map[m].flag.sakura = 0; break; case MF_LEAVES: map[m].flag.leaves = 0; break; - /** - * No longer available, keeping here just in case it's back someday. [Ind] - **/ - //case MF_RAIN: map[m].flag.rain = 0; break; - case MF_NOGO: map[m].flag.nogo = 0; break; case MF_CLOUDS: map[m].flag.clouds = 0; break; case MF_CLOUDS2: map[m].flag.clouds2 = 0; break; case MF_FIREWORKS: map[m].flag.fireworks = 0; break; @@ -10868,11 +10516,8 @@ BUILDIN_FUNC(removemapflag) case MF_NORETURN: map[m].flag.noreturn = 0; break; case MF_NOWARPTO: map[m].flag.nowarpto = 0; break; case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop = 0; break; - case MF_RESTRICTED: - map[m].zone ^= 1<<(val+1); - if (map[m].zone == 0){ - map[m].flag.restricted=0; - } + case MF_ZONE: + map_zone_change2(m, map[m].prev_zone); break; case MF_NOCOMMAND: map[m].nocommand = 0; break; case MF_NODROP: map[m].flag.nodrop = 0; break; @@ -10892,34 +10537,40 @@ BUILDIN_FUNC(removemapflag) case MF_RESET: map[m].flag.reset = 0; break; } } - - return 0; + + return true; } -BUILDIN_FUNC(pvpon) +BUILDIN(pvpon) { int16 m; const char *str; TBL_PC* sd = NULL; struct s_mapiterator* iter; - + struct block_list bl; + str = script_getstr(st,2); m = map_mapname2mapid(str); if( m < 0 || map[m].flag.pvp ) - return 0; // nothing to do - + return true; // nothing to do + + map_zone_change2(m, strdb_get(zone_db, MAP_ZONE_PVP_NAME)); map[m].flag.pvp = 1; - clif_map_property_mapall(m, MAPPROPERTY_FREEPVPZONE); - + clif->map_property_mapall(m, MAPPROPERTY_FREEPVPZONE); + bl.type = BL_NUL; + bl.m = m; + clif->maptypeproperty2(&bl,ALL_SAMEMAP); + + if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris] - return 0; - + return true; + iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER ) continue; // not applicable - + sd->pvp_timer = add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0); sd->pvp_rank = 0; sd->pvp_lastusers = 0; @@ -10927,15 +10578,15 @@ BUILDIN_FUNC(pvpon) sd->pvp_won = 0; sd->pvp_lost = 0; } - mapit_free(iter); - - return 0; + mapit->free(iter); + + return true; } static int buildin_pvpoff_sub(struct block_list *bl,va_list ap) { TBL_PC* sd = (TBL_PC*)bl; - clif_pvpset(sd, 0, 0, 2); + clif->pvpset(sd, 0, 0, 2); if (sd->pvp_timer != INVALID_TIMER) { delete_timer(sd->pvp_timer, pc_calc_pvprank_timer); sd->pvp_timer = INVALID_TIMER; @@ -10943,71 +10594,86 @@ static int buildin_pvpoff_sub(struct block_list *bl,va_list ap) return 0; } -BUILDIN_FUNC(pvpoff) +BUILDIN(pvpoff) { int16 m; const char *str; - + struct block_list bl; + str=script_getstr(st,2); m = map_mapname2mapid(str); if(m < 0 || !map[m].flag.pvp) - return 0; //fixed Lupus - + return true; //fixed Lupus + + map_zone_change2(m, map[m].prev_zone); map[m].flag.pvp = 0; - clif_map_property_mapall(m, MAPPROPERTY_NOTHING); - + clif->map_property_mapall(m, MAPPROPERTY_NOTHING); + bl.type = BL_NUL; + bl.m = m; + clif->maptypeproperty2(&bl,ALL_SAMEMAP); + if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris] - return 0; - + return true; + map_foreachinmap(buildin_pvpoff_sub, m, BL_PC); - return 0; + return true; } -BUILDIN_FUNC(gvgon) +BUILDIN(gvgon) { int16 m; const char *str; - + str=script_getstr(st,2); m = map_mapname2mapid(str); if(m >= 0 && !map[m].flag.gvg) { + struct block_list bl; + map_zone_change2(m, strdb_get(zone_db, MAP_ZONE_GVG_NAME)); map[m].flag.gvg = 1; - clif_map_property_mapall(m, MAPPROPERTY_AGITZONE); + clif->map_property_mapall(m, MAPPROPERTY_AGITZONE); + bl.type = BL_NUL; + bl.m = m; + clif->maptypeproperty2(&bl,ALL_SAMEMAP); } - - return 0; + + return true; } -BUILDIN_FUNC(gvgoff) +BUILDIN(gvgoff) { int16 m; const char *str; - + str=script_getstr(st,2); m = map_mapname2mapid(str); if(m >= 0 && map[m].flag.gvg) { + struct block_list bl; + map_zone_change2(m, map[m].prev_zone); map[m].flag.gvg = 0; - clif_map_property_mapall(m, MAPPROPERTY_NOTHING); + clif->map_property_mapall(m, MAPPROPERTY_NOTHING); + bl.type = BL_NUL; + bl.m = m; + clif->maptypeproperty2(&bl,ALL_SAMEMAP); } - - return 0; + + return true; } /*========================================== * Shows an emoticon on top of the player/npc * emotion emotion#, <target: 0 - NPC, 1 - PC>, <NPC/PC name> *------------------------------------------*/ //Optional second parameter added by [Skotlex] -BUILDIN_FUNC(emotion) +BUILDIN(emotion) { int type; int player=0; - + type=script_getnum(st,2); if(type < 0 || type > 100) - return 0; - + return true; + if( script_hasdata(st,3) ) player=script_getnum(st,3); - + if (player) { TBL_PC *sd = NULL; if( script_hasdata(st,4) ) @@ -11015,17 +10681,17 @@ BUILDIN_FUNC(emotion) else sd = script_rid2sd(st); if (sd) - clif_emotion(&sd->bl,type); + clif->emotion(&sd->bl,type); } else if( script_hasdata(st,4) ) { TBL_NPC *nd = npc_name2id(script_getstr(st,4)); if(nd) - clif_emotion(&nd->bl,type); + clif->emotion(&nd->bl,type); } else - clif_emotion(map_id2bl(st->oid),type); - return 0; + clif->emotion(map_id2bl(st->oid),type); + return true; } static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap) @@ -11033,14 +10699,14 @@ static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list int16 m=va_arg(ap,int); int g_id=va_arg(ap,int); int flag=va_arg(ap,int); - + if(!sd || sd->bl.m != m) return 0; if( - (sd->status.guild_id == g_id && flag&1) || //Warp out owners - (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders - (sd->status.guild_id == 0) // Warp out players not in guild [Valaris] - ) + (sd->status.guild_id == g_id && flag&1) || //Warp out owners + (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders + (sd->status.guild_id == 0) // Warp out players not in guild [Valaris] + ) pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); return 1; } @@ -11048,91 +10714,91 @@ static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list static int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap) { struct mob_data *md=(struct mob_data *)bl; - + if(!md->guardian_data && md->class_ != MOBID_EMPERIUM) status_kill(bl); - + return 0; } -BUILDIN_FUNC(maprespawnguildid) +BUILDIN(maprespawnguildid) { const char *mapname=script_getstr(st,2); int g_id=script_getnum(st,3); int flag=script_getnum(st,4); - + int16 m=map_mapname2mapid(mapname); - + if(m == -1) - return 0; - + return true; + //Catch ALL players (in case some are 'between maps' on execution time) map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag); if (flag&4) //Remove script mobs. map_foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB); - return 0; + return true; } -BUILDIN_FUNC(agitstart) +BUILDIN(agitstart) { - if(agit_flag==1) return 0; // Agit already Start. + if(agit_flag==1) return true; // Agit already Start. agit_flag=1; - guild_agit_start(); - return 0; + guild->agit_start(); + return true; } -BUILDIN_FUNC(agitend) +BUILDIN(agitend) { - if(agit_flag==0) return 0; // Agit already End. + if(agit_flag==0) return true; // Agit already End. agit_flag=0; - guild_agit_end(); - return 0; + guild->agit_end(); + return true; } -BUILDIN_FUNC(agitstart2) +BUILDIN(agitstart2) { - if(agit2_flag==1) return 0; // Agit2 already Start. + if(agit2_flag==1) return true; // Agit2 already Start. agit2_flag=1; - guild_agit2_start(); - return 0; + guild->agit2_start(); + return true; } -BUILDIN_FUNC(agitend2) +BUILDIN(agitend2) { - if(agit2_flag==0) return 0; // Agit2 already End. + if(agit2_flag==0) return true; // Agit2 already End. agit2_flag=0; - guild_agit2_end(); - return 0; + guild->agit2_end(); + return true; } /*========================================== * Returns whether woe is on or off. // choice script *------------------------------------------*/ -BUILDIN_FUNC(agitcheck) +BUILDIN(agitcheck) { script_pushint(st,agit_flag); - return 0; + return true; } /*========================================== * Returns whether woese is on or off. // choice script *------------------------------------------*/ -BUILDIN_FUNC(agitcheck2) +BUILDIN(agitcheck2) { script_pushint(st,agit2_flag); - return 0; + return true; } /// Sets the guild_id of this npc. /// /// flagemblem <guild_id>; -BUILDIN_FUNC(flagemblem) +BUILDIN(flagemblem) { TBL_NPC* nd; int g_id = script_getnum(st,2); - - if(g_id < 0) return 0; - + + if(g_id < 0) return true; + nd = (TBL_NPC*)map_id2nd(st->oid); if( nd == NULL ) { ShowError("script:flagemblem: npc %d not found\n", st->oid); @@ -11141,37 +10807,37 @@ BUILDIN_FUNC(flagemblem) } else { bool changed = ( nd->u.scr.guild_id != g_id )?true:false; nd->u.scr.guild_id = g_id; - clif_guild_emblem_area(&nd->bl); + clif->guild_emblem_area(&nd->bl); /* guild flag caching */ if( g_id ) /* adding a id */ - guild_flag_add(nd); + guild->flag_add(nd); else if( changed ) /* removing a flag */ - guild_flag_remove(nd); + guild->flag_remove(nd); } - return 0; + return true; } -BUILDIN_FUNC(getcastlename) +BUILDIN(getcastlename) { const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL); - struct guild_castle* gc = guild_mapname2gc(mapname); + struct guild_castle* gc = guild->mapname2gc(mapname); const char* name = (gc) ? gc->castle_name : ""; script_pushstrcopy(st,name); - return 0; + return true; } -BUILDIN_FUNC(getcastledata) +BUILDIN(getcastledata) { const char *mapname = mapindex_getmapname(script_getstr(st,2),NULL); int index = script_getnum(st,3); - struct guild_castle *gc = guild_mapname2gc(mapname); - + struct guild_castle *gc = guild->mapname2gc(mapname); + if (gc == NULL) { script_pushint(st,0); ShowWarning("buildin_setcastledata: guild castle for map '%s' not found\n", mapname); - return 1; + return false; } - + switch (index) { case 1: script_pushint(st,gc->guild_id); break; @@ -11198,101 +10864,101 @@ BUILDIN_FUNC(getcastledata) } script_pushint(st,0); ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index); - return 1; + return false; } - return 0; + return true; } -BUILDIN_FUNC(setcastledata) +BUILDIN(setcastledata) { const char *mapname = mapindex_getmapname(script_getstr(st,2),NULL); int index = script_getnum(st,3); int value = script_getnum(st,4); - struct guild_castle *gc = guild_mapname2gc(mapname); - + struct guild_castle *gc = guild->mapname2gc(mapname); + if (gc == NULL) { ShowWarning("buildin_setcastledata: guild castle for map '%s' not found\n", mapname); - return 1; + return false; } - + if (index <= 0 || index > 9+MAX_GUARDIANS) { ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index); - return 1; + return false; } - - guild_castledatasave(gc->castle_id, index, value); - return 0; + + guild->castledatasave(gc->castle_id, index, value); + return true; } /* ===================================================================== * ---------------------------------------------------------------------*/ -BUILDIN_FUNC(requestguildinfo) +BUILDIN(requestguildinfo) { int guild_id=script_getnum(st,2); const char *event=NULL; - + if( script_hasdata(st,3) ){ event=script_getstr(st,3); check_event(st, event); } - + if(guild_id>0) - guild_npc_request_info(guild_id,event); - return 0; + guild->npc_request_info(guild_id,event); + return true; } /// Returns the number of cards that have been compounded onto the specified equipped item. /// getequipcardcnt(<equipment slot>); -BUILDIN_FUNC(getequipcardcnt) +BUILDIN(getequipcardcnt) { int i=-1,j,num; TBL_PC *sd; int count; - + num=script_getnum(st,2); sd=script_rid2sd(st); if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); - + if (i < 0 || !sd->inventory_data[i]) { script_pushint(st,0); - return 0; + return true; } - + if(itemdb_isspecial(sd->status.inventory[i].card[0])) { script_pushint(st,0); - return 0; + return true; } - + count = 0; for( j = 0; j < sd->inventory_data[i]->slot; j++ ) if( sd->status.inventory[i].card[j] && itemdb_type(sd->status.inventory[i].card[j]) == IT_CARD ) count++; - + script_pushint(st,count); - return 0; + return true; } /// Removes all cards from the item found in the specified equipment slot of the invoking character, /// and give them to the character. If any cards were removed in this manner, it will also show a success effect. /// successremovecards <slot>; -BUILDIN_FUNC(successremovecards) { +BUILDIN(successremovecards) { int i=-1,j,c,cardflag=0; - + TBL_PC* sd = script_rid2sd(st); int num = script_getnum(st,2); - + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); - + if (i < 0 || !sd->inventory_data[i]) { - return 0; + return true; } - + if(itemdb_isspecial(sd->status.inventory[i].card[0])) - return 0; - + return true; + for( c = sd->inventory_data[i]->slot - 1; c >= 0; --c ) { if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD ) {// extract this card from the item int flag; @@ -11301,37 +10967,37 @@ BUILDIN_FUNC(successremovecards) { cardflag = 1; item_tmp.nameid = sd->status.inventory[i].card[c]; item_tmp.identify = 1; - + if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ // get back the cart in inventory - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } - + if(cardflag == 1) {//if card was remove remplace item with no card int flag; struct item item_tmp; memset(&item_tmp,0,sizeof(item_tmp)); - + item_tmp.nameid = sd->status.inventory[i].nameid; item_tmp.identify = 1; item_tmp.refine = sd->status.inventory[i].refine; item_tmp.attribute = sd->status.inventory[i].attribute; item_tmp.expire_time = sd->status.inventory[i].expire_time; - + for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++) item_tmp.card[j]=sd->status.inventory[i].card[j]; - + pc_delitem(sd,i,1,0,3,LOG_TYPE_SCRIPT); if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ //chk if can be spawn in inventory otherwise put on floor - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } - - clif_misceffect(&sd->bl,3); + + clif->misceffect(&sd->bl,3); } - return 0; + return true; } /// Removes all cards from the item found in the specified equipment slot of the invoking character. @@ -11340,43 +11006,43 @@ BUILDIN_FUNC(successremovecards) { /// <type>=1 : will keep the item, but destroy the cards. /// <type>=2 : will keep the cards, but destroy the item. /// <type>=? : will just display the failure effect. -BUILDIN_FUNC(failedremovecards) { +BUILDIN(failedremovecards) { int i=-1,j,c,cardflag=0; - + TBL_PC* sd = script_rid2sd(st); int num = script_getnum(st,2); int typefail = script_getnum(st,3); - + if (num > 0 && num <= ARRAYLENGTH(equip)) i=pc_checkequip(sd,equip[num-1]); - + if (i < 0 || !sd->inventory_data[i]) - return 0; - + return true; + if(itemdb_isspecial(sd->status.inventory[i].card[0])) - return 0; - + return true; + for( c = sd->inventory_data[i]->slot - 1; c >= 0; --c ) { if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD ) { cardflag = 1; - + if(typefail == 2) {// add cards to inventory, clear int flag; struct item item_tmp; - + memset(&item_tmp,0,sizeof(item_tmp)); - + item_tmp.nameid = sd->status.inventory[i].card[c]; item_tmp.identify = 1; - + if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } } - + if(cardflag == 1) { if(typefail == 0 || typefail == 2){ // destroy the item pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); @@ -11384,29 +11050,29 @@ BUILDIN_FUNC(failedremovecards) { if(typefail == 1){ // destroy the card int flag; struct item item_tmp; - + memset(&item_tmp,0,sizeof(item_tmp)); - + item_tmp.nameid = sd->status.inventory[i].nameid; item_tmp.identify = 1; item_tmp.refine = sd->status.inventory[i].refine; item_tmp.attribute = sd->status.inventory[i].attribute; item_tmp.expire_time = sd->status.inventory[i].expire_time; - + for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++) item_tmp.card[j]=sd->status.inventory[i].card[j]; - + pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); - + if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } - clif_misceffect(&sd->bl,2); + clif->misceffect(&sd->bl,2); } - - return 0; + + return true; } /* ================================================================ @@ -11414,7 +11080,7 @@ BUILDIN_FUNC(failedremovecards) { * type: 0=everyone, 1=guild, 2=party; [Reddozen] * improved by [Lance] * ================================================================*/ -BUILDIN_FUNC(mapwarp) // Added by RoVeRT +BUILDIN(mapwarp) // Added by RoVeRT { int x,y,m,check_val=0,check_ID=0,i=0; struct guild *g = NULL; @@ -11430,16 +11096,16 @@ BUILDIN_FUNC(mapwarp) // Added by RoVeRT check_val=script_getnum(st,6); check_ID=script_getnum(st,7); } - + if((m=map_mapname2mapid(mapname))< 0) - return 0; - + return true; + if(!(index=mapindex_name2id(str))) - return 0; - + return true; + switch(check_val){ case 1: - g = guild_search(check_ID); + g = guild->search(check_ID); if (g){ for( i=0; i < g->max_member; i++) { @@ -11463,8 +11129,8 @@ BUILDIN_FUNC(mapwarp) // Added by RoVeRT map_foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y,0,0); break; } - - return 0; + + return true; } static int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT @@ -11476,218 +11142,218 @@ static int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by Ro return 0; } -BUILDIN_FUNC(mobcount) // Added by RoVeRT +BUILDIN(mobcount) // Added by RoVeRT { const char *mapname,*event; int16 m; mapname=script_getstr(st,2); event=script_getstr(st,3); - + if( strcmp(event, "all") == 0 ) event = NULL; else check_event(st, event); - + if( strcmp(mapname, "this") == 0 ) { struct map_session_data *sd = script_rid2sd(st); if( sd ) m = sd->bl.m; else { script_pushint(st,-1); - return 0; + return true; } } else if( (m = map_mapname2mapid(mapname)) < 0 ) { script_pushint(st,-1); - return 0; + return true; } - + if( map[m].flag.src4instance && map[m].instance_id == 0 && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) { script_pushint(st,-1); - return 0; + return true; } - + script_pushint(st,map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event)); - - return 0; + + return true; } -BUILDIN_FUNC(marriage) +BUILDIN(marriage) { const char *partner=script_getstr(st,2); TBL_PC *sd=script_rid2sd(st); TBL_PC *p_sd=map_nick2sd(partner); - + if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){ script_pushint(st,0); - return 0; + return true; } script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(wedding_effect) +BUILDIN(wedding_effect) { TBL_PC *sd=script_rid2sd(st); struct block_list *bl; - + if(sd==NULL) { bl=map_id2bl(st->oid); } else bl=&sd->bl; - clif_wedding_effect(bl); - return 0; + clif->wedding_effect(bl); + return true; } -BUILDIN_FUNC(divorce) +BUILDIN(divorce) { TBL_PC *sd=script_rid2sd(st); if(sd==NULL || pc_divorce(sd) < 0){ script_pushint(st,0); - return 0; + return true; } script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(ispartneron) +BUILDIN(ispartneron) { TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || !pc_ismarried(sd) || - map_charid2sd(sd->status.partner_id) == NULL) { + map_charid2sd(sd->status.partner_id) == NULL) { script_pushint(st,0); - return 0; + return true; } - + script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(getpartnerid) +BUILDIN(getpartnerid) { TBL_PC *sd=script_rid2sd(st); if (sd == NULL) { script_pushint(st,0); - return 0; + return true; } - + script_pushint(st,sd->status.partner_id); - return 0; + return true; } -BUILDIN_FUNC(getchildid) +BUILDIN(getchildid) { TBL_PC *sd=script_rid2sd(st); if (sd == NULL) { script_pushint(st,0); - return 0; + return true; } - + script_pushint(st,sd->status.child); - return 0; + return true; } -BUILDIN_FUNC(getmotherid) +BUILDIN(getmotherid) { TBL_PC *sd=script_rid2sd(st); if (sd == NULL) { script_pushint(st,0); - return 0; + return true; } - + script_pushint(st,sd->status.mother); - return 0; + return true; } -BUILDIN_FUNC(getfatherid) +BUILDIN(getfatherid) { TBL_PC *sd=script_rid2sd(st); if (sd == NULL) { script_pushint(st,0); - return 0; + return true; } - + script_pushint(st,sd->status.father); - return 0; + return true; } -BUILDIN_FUNC(warppartner) +BUILDIN(warppartner) { int x,y; unsigned short mapindex; const char *str; TBL_PC *sd=script_rid2sd(st); TBL_PC *p_sd=NULL; - + if(sd==NULL || !pc_ismarried(sd) || - (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) { + (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) { script_pushint(st,0); - return 0; + return true; } - + str=script_getstr(st,2); x=script_getnum(st,3); y=script_getnum(st,4); - + mapindex = mapindex_name2id(str); if (mapindex) { pc_setpos(p_sd,mapindex,x,y,CLR_OUTSIGHT); script_pushint(st,1); } else script_pushint(st,0); - return 0; + return true; } /*================================================ * Script for Displaying MOB Information [Valaris] *------------------------------------------------*/ -BUILDIN_FUNC(strmobinfo) +BUILDIN(strmobinfo) { - + int num=script_getnum(st,2); int class_=script_getnum(st,3); - + if(!mobdb_checkid(class_)) { if (num < 3) //requested a string script_pushconststr(st,""); else script_pushint(st,0); - return 0; + return true; } - + switch (num) { - case 1: script_pushstrcopy(st,mob_db(class_)->name); break; - case 2: script_pushstrcopy(st,mob_db(class_)->jname); break; - case 3: script_pushint(st,mob_db(class_)->lv); break; - case 4: script_pushint(st,mob_db(class_)->status.max_hp); break; - case 5: script_pushint(st,mob_db(class_)->status.max_sp); break; - case 6: script_pushint(st,mob_db(class_)->base_exp); break; - case 7: script_pushint(st,mob_db(class_)->job_exp); break; - default: - script_pushint(st,0); - break; + case 1: script_pushstrcopy(st,mob_db(class_)->name); break; + case 2: script_pushstrcopy(st,mob_db(class_)->jname); break; + case 3: script_pushint(st,mob_db(class_)->lv); break; + case 4: script_pushint(st,mob_db(class_)->status.max_hp); break; + case 5: script_pushint(st,mob_db(class_)->status.max_sp); break; + case 6: script_pushint(st,mob_db(class_)->base_exp); break; + case 7: script_pushint(st,mob_db(class_)->job_exp); break; + default: + script_pushint(st,0); + break; } - return 0; + return true; } /*========================================== * Summon guardians [Valaris] * guardian("<map name>",<x>,<y>,"<name to show>",<mob id>{,"<event label>"}{,<guardian index>}) -> <id> *------------------------------------------*/ -BUILDIN_FUNC(guardian) +BUILDIN(guardian) { int class_=0,x=0,y=0,guardian=0; const char *str,*map,*evt=""; struct script_data *data; bool has_index = false; - + map =script_getstr(st,2); x =script_getnum(st,3); y =script_getnum(st,4); str =script_getstr(st,5); class_=script_getnum(st,6); - + if( script_hasdata(st,8) ) {// "<event label>",<guardian index> evt=script_getstr(st,7); @@ -11706,24 +11372,24 @@ BUILDIN_FUNC(guardian) } else { ShowError("script:guardian: invalid data type for argument #6 (from 1)\n"); script_reportdata(data); - return 1; + return false; } } - + check_event(st, evt); script_pushint(st, mob_spawn_guardian(map,x,y,str,class_,evt,guardian,has_index)); - - return 0; + + return true; } /*========================================== * Invisible Walls [Zephyrus] *------------------------------------------*/ -BUILDIN_FUNC(setwall) +BUILDIN(setwall) { const char *map, *name; int x, y, m, size, dir; bool shootable; - + map = script_getstr(st,2); x = script_getnum(st,3); y = script_getnum(st,4); @@ -11731,19 +11397,19 @@ BUILDIN_FUNC(setwall) dir = script_getnum(st,6); shootable = script_getnum(st,7); name = script_getstr(st,8); - + if( (m = map_mapname2mapid(map)) < 0 ) - return 0; // Invalid Map - + return true; // Invalid Map + map_iwall_set(m, x, y, size, dir, shootable, name); - return 0; + return true; } -BUILDIN_FUNC(delwall) +BUILDIN(delwall) { const char *name = script_getstr(st,2); map_iwall_remove(name); - - return 0; + + return true; } /// Retrieves various information about the specified guardian. @@ -11753,90 +11419,90 @@ BUILDIN_FUNC(delwall) /// 1 - maximum hp /// 2 - current hp /// -BUILDIN_FUNC(guardianinfo) +BUILDIN(guardianinfo) { const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL); int id = script_getnum(st,3); int type = script_getnum(st,4); - - struct guild_castle* gc = guild_mapname2gc(mapname); + + struct guild_castle* gc = guild->mapname2gc(mapname); struct mob_data* gd; - + if( gc == NULL || id < 0 || id >= MAX_GUARDIANS ) { script_pushint(st,-1); - return 0; + return true; } - + if( type == 0 ) script_pushint(st, gc->guardian[id].visible); else - if( !gc->guardian[id].visible ) - script_pushint(st,-1); - else - if( (gd = map_id2md(gc->guardian[id].id)) == NULL ) - script_pushint(st,-1); - else - { - if ( type == 1 ) script_pushint(st,gd->status.max_hp); - else if( type == 2 ) script_pushint(st,gd->status.hp); - else + if( !gc->guardian[id].visible ) script_pushint(st,-1); - } - - return 0; + else + if( (gd = map_id2md(gc->guardian[id].id)) == NULL ) + script_pushint(st,-1); + else + { + if ( type == 1 ) script_pushint(st,gd->status.max_hp); + else if( type == 2 ) script_pushint(st,gd->status.hp); + else + script_pushint(st,-1); + } + + return true; } /*========================================== * Get the item name by item_id or null *------------------------------------------*/ -BUILDIN_FUNC(getitemname) +BUILDIN(getitemname) { int item_id=0; struct item_data *i_data; char *item_name; struct script_data *data; - + data=script_getdata(st,2); get_val(st,data); - + if( data_isstring(data) ){ - const char *name=conv_str(st,data); + const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); if( item_data ) item_id=item_data->nameid; }else - item_id=conv_num(st,data); - + item_id=script->conv_num(st,data); + i_data = itemdb_exists(item_id); if (i_data == NULL) { script_pushconststr(st,"null"); - return 0; + return true; } item_name=(char *)aMalloc(ITEM_NAME_LENGTH*sizeof(char)); - + memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH); script_pushstr(st,item_name); - return 0; + return true; } /*========================================== * Returns number of slots an item has. [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(getitemslots) +BUILDIN(getitemslots) { int item_id; struct item_data *i_data; - + item_id=script_getnum(st,2); - + i_data = itemdb_exists(item_id); - + if (i_data) script_pushint(st,i_data->slot); else script_pushint(st,-1); - return 0; + return true; } // TODO: add matk here if needed/once we get rid of RENEWAL @@ -11844,103 +11510,103 @@ BUILDIN_FUNC(getitemslots) /*========================================== * Returns some values of an item [Lupus] * Price, Weight, etc... - getiteminfo(itemID,n), where n - 0 value_buy; - 1 value_sell; - 2 type; - 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc.. - if = 0, then monsters don't drop it at all (rare or a quest item) - if = -1, then this item is sold in NPC shops only - 4 sex; - 5 equip; - 6 weight; - 7 atk; - 8 def; - 9 range; - 10 slot; - 11 look; - 12 elv; - 13 wlv; - 14 view id + getiteminfo(itemID,n), where n + 0 value_buy; + 1 value_sell; + 2 type; + 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc.. + if = 0, then monsters don't drop it at all (rare or a quest item) + if = -1, then this item is sold in NPC shops only + 4 sex; + 5 equip; + 6 weight; + 7 atk; + 8 def; + 9 range; + 10 slot; + 11 look; + 12 elv; + 13 wlv; + 14 view id *------------------------------------------*/ -BUILDIN_FUNC(getiteminfo) +BUILDIN(getiteminfo) { int item_id,n; int *item_arr; struct item_data *i_data; - + item_id = script_getnum(st,2); n = script_getnum(st,3); i_data = itemdb_exists(item_id); - + if (i_data && n>=0 && n<=14) { item_arr = (int*)&i_data->value_buy; script_pushint(st,item_arr[n]); } else script_pushint(st,-1); - return 0; + return true; } /*========================================== * Set some values of an item [Lupus] * Price, Weight, etc... - setiteminfo(itemID,n,Value), where n - 0 value_buy; - 1 value_sell; - 2 type; - 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc.. - if = 0, then monsters don't drop it at all (rare or a quest item) - if = -1, then this item is sold in NPC shops only - 4 sex; - 5 equip; - 6 weight; - 7 atk; - 8 def; - 9 range; - 10 slot; - 11 look; - 12 elv; - 13 wlv; - 14 view id - * Returns Value or -1 if the wrong field's been set + setiteminfo(itemID,n,Value), where n + 0 value_buy; + 1 value_sell; + 2 type; + 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc.. + if = 0, then monsters don't drop it at all (rare or a quest item) + if = -1, then this item is sold in NPC shops only + 4 sex; + 5 equip; + 6 weight; + 7 atk; + 8 def; + 9 range; + 10 slot; + 11 look; + 12 elv; + 13 wlv; + 14 view id + * Returns Value or -1 if the wrong field's been set *------------------------------------------*/ -BUILDIN_FUNC(setiteminfo) +BUILDIN(setiteminfo) { int item_id,n,value; int *item_arr; struct item_data *i_data; - + item_id = script_getnum(st,2); n = script_getnum(st,3); value = script_getnum(st,4); i_data = itemdb_exists(item_id); - + if (i_data && n>=0 && n<=14) { item_arr = (int*)&i_data->value_buy; item_arr[n] = value; script_pushint(st,value); } else script_pushint(st,-1); - return 0; + return true; } /*========================================== * Returns value from equipped item slot n [Lupus] - getequipcardid(num,slot) - where - num = eqip position slot - slot = 0,1,2,3 (Card Slot N) - - This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced) - it's useful when you want to check item cards or if it's signed - Useful for such quests as "Sign this refined item with players name" etc - Hat[0] +4 -> Player's Hat[0] +4 + getequipcardid(num,slot) + where + num = eqip position slot + slot = 0,1,2,3 (Card Slot N) + + This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced) + it's useful when you want to check item cards or if it's signed + Useful for such quests as "Sign this refined item with players name" etc + Hat[0] +4 -> Player's Hat[0] +4 *------------------------------------------*/ -BUILDIN_FUNC(getequipcardid) +BUILDIN(getequipcardid) { int i=-1,num,slot; TBL_PC *sd; - + num=script_getnum(st,2); slot=script_getnum(st,3); sd=script_rid2sd(st); @@ -11950,22 +11616,22 @@ BUILDIN_FUNC(getequipcardid) script_pushint(st,sd->status.inventory[i].card[slot]); else script_pushint(st,0); - - return 0; + + return true; } /*========================================== * petskillbonus [Valaris] //Rewritten by [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(petskillbonus) +BUILDIN(petskillbonus) { struct pet_data *pd; - + TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + pd=sd->pd; if (pd->bonus) { //Clear previous bonus @@ -11973,43 +11639,43 @@ BUILDIN_FUNC(petskillbonus) delete_timer(pd->bonus->timer, pet_skill_bonus_timer); } else //init pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus)); - + pd->bonus->type=script_getnum(st,2); pd->bonus->val=script_getnum(st,3); pd->bonus->duration=script_getnum(st,4); pd->bonus->delay=script_getnum(st,5); - + if (pd->state.skillbonus == 1) pd->state.skillbonus=0; // waiting state - + // wait for timer to start if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->bonus->timer = INVALID_TIMER; else pd->bonus->timer = add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0); - - return 0; + + return true; } /*========================================== * pet looting [Valaris] //Rewritten by [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(petloot) +BUILDIN(petloot) { int max; struct pet_data *pd; TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + max=script_getnum(st,2); - + if(max < 1) max = 1; //Let'em loot at least 1 item. else if (max > MAX_PETLOOT_SIZE) max = MAX_PETLOOT_SIZE; - + pd = sd->pd; if (pd->loot != NULL) { //Release whatever was there already and reallocate memory @@ -12018,14 +11684,14 @@ BUILDIN_FUNC(petloot) } else pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot)); - + pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item)); - + pd->loot->max=max; pd->loot->count = 0; pd->loot->weight = 0; - - return 0; + + return true; } /*========================================== * Set arrays with info of all sd inventory : @@ -12034,13 +11700,13 @@ BUILDIN_FUNC(petloot) * @inventorylist_card(0..3), @inventorylist_expire * @inventorylist_count = scalar *------------------------------------------*/ -BUILDIN_FUNC(getinventorylist) +BUILDIN(getinventorylist) { TBL_PC *sd=script_rid2sd(st); char card_var[NAME_LENGTH]; - + int i,j=0,k; - if(!sd) return 0; + if(!sd) return true; for(i=0;i<MAX_INVENTORY;i++){ if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){ pc_setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid); @@ -12059,14 +11725,14 @@ BUILDIN_FUNC(getinventorylist) } } pc_setreg(sd,add_str("@inventorylist_count"),j); - return 0; + return true; } -BUILDIN_FUNC(getskilllist) +BUILDIN(getskilllist) { TBL_PC *sd=script_rid2sd(st); int i,j=0; - if(!sd) return 0; + if(!sd) return true; for(i=0;i<MAX_SKILL;i++){ if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){ pc_setreg(sd,reference_uid(add_str("@skilllist_id"), j),sd->status.skill[i].id); @@ -12076,139 +11742,139 @@ BUILDIN_FUNC(getskilllist) } } pc_setreg(sd,add_str("@skilllist_count"),j); - return 0; + return true; } -BUILDIN_FUNC(clearitem) +BUILDIN(clearitem) { TBL_PC *sd=script_rid2sd(st); int i; - if(sd==NULL) return 0; + if(sd==NULL) return true; for (i=0; i<MAX_INVENTORY; i++) { if (sd->status.inventory[i].amount) { pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_SCRIPT); } } - return 0; + return true; } /*========================================== * Disguise Player (returns Mob/NPC ID if success, 0 on fail) *------------------------------------------*/ -BUILDIN_FUNC(disguise) +BUILDIN(disguise) { int id; TBL_PC* sd = script_rid2sd(st); - if (sd == NULL) return 0; - + if (sd == NULL) return true; + id = script_getnum(st,2); - + if (mobdb_checkid(id) || npcdb_checkid(id)) { pc_disguise(sd, id); script_pushint(st,id); } else script_pushint(st,0); - - return 0; + + return true; } /*========================================== * Undisguise Player (returns 1 if success, 0 on fail) *------------------------------------------*/ -BUILDIN_FUNC(undisguise) +BUILDIN(undisguise) { TBL_PC* sd = script_rid2sd(st); - if (sd == NULL) return 0; - - if (sd->disguise) { - pc_disguise(sd, 0); + if (sd == NULL) return true; + + if (sd->disguise != -1) { + pc_disguise(sd, -1); script_pushint(st,0); } else { script_pushint(st,1); } - return 0; + return true; } /*========================================== * Transform a bl to another _class, * @type unused *------------------------------------------*/ -BUILDIN_FUNC(classchange) +BUILDIN(classchange) { int _class,type; struct block_list *bl=map_id2bl(st->oid); - - if(bl==NULL) return 0; - + + if(bl==NULL) return true; + _class=script_getnum(st,2); type=script_getnum(st,3); - clif_class_change(bl,_class,type); - return 0; + clif->class_change(bl,_class,type); + return true; } /*========================================== * Display an effect *------------------------------------------*/ -BUILDIN_FUNC(misceffect) +BUILDIN(misceffect) { int type; - + type=script_getnum(st,2); if(st->oid && st->oid != fake_nd->bl.id) { struct block_list *bl = map_id2bl(st->oid); if (bl) - clif_specialeffect(bl,type,AREA); + clif->specialeffect(bl,type,AREA); } else{ TBL_PC *sd=script_rid2sd(st); if(sd) - clif_specialeffect(&sd->bl,type,AREA); + clif->specialeffect(&sd->bl,type,AREA); } - return 0; + return true; } /*========================================== * Play a BGM on a single client [Rikter/Yommy] *------------------------------------------*/ -BUILDIN_FUNC(playBGM) +BUILDIN(playBGM) { const char* name; struct map_session_data* sd; - + if( ( sd = script_rid2sd(st) ) != NULL ) { name = script_getstr(st,2); - - clif_playBGM(sd, name); + + clif->playBGM(sd, name); } - - return 0; + + return true; } static int playBGM_sub(struct block_list* bl,va_list ap) { const char* name = va_arg(ap,const char*); - - clif_playBGM(BL_CAST(BL_PC, bl), name); - + + clif->playBGM(BL_CAST(BL_PC, bl), name); + return 0; } static int playBGM_foreachpc_sub(struct map_session_data* sd, va_list args) { const char* name = va_arg(args, const char*); - - clif_playBGM(sd, name); + + clif->playBGM(sd, name); return 0; } /*========================================== * Play a BGM on multiple client [Rikter/Yommy] *------------------------------------------*/ -BUILDIN_FUNC(playBGMall) +BUILDIN(playBGMall) { const char* name; - + name = script_getstr(st,2); - + if( script_hasdata(st,7) ) {// specified part of map const char* map = script_getstr(st,3); @@ -12216,133 +11882,133 @@ BUILDIN_FUNC(playBGMall) int y0 = script_getnum(st,5); int x1 = script_getnum(st,6); int y1 = script_getnum(st,7); - + map_foreachinarea(playBGM_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name); } else if( script_hasdata(st,3) ) {// entire map const char* map = script_getstr(st,3); - + map_foreachinmap(playBGM_sub, map_mapname2mapid(map), BL_PC, name); } else {// entire server map_foreachpc(&playBGM_foreachpc_sub, name); } - - return 0; + + return true; } /*========================================== * Play a .wav sound for sd *------------------------------------------*/ -BUILDIN_FUNC(soundeffect) +BUILDIN(soundeffect) { TBL_PC* sd = script_rid2sd(st); const char* name = script_getstr(st,2); int type = script_getnum(st,3); - + if(sd) { - clif_soundeffect(sd,&sd->bl,name,type); + clif->soundeffect(sd,&sd->bl,name,type); } - return 0; + return true; } int soundeffect_sub(struct block_list* bl,va_list ap) { char* name = va_arg(ap,char*); int type = va_arg(ap,int); - - clif_soundeffect((TBL_PC *)bl, bl, name, type); - - return 0; + + clif->soundeffect((TBL_PC *)bl, bl, name, type); + + return true; } /*========================================== * Play a sound effect (.wav) on multiple clients * soundeffectall "<filepath>",<type>{,"<map name>"}{,<x0>,<y0>,<x1>,<y1>}; *------------------------------------------*/ -BUILDIN_FUNC(soundeffectall) +BUILDIN(soundeffectall) { struct block_list* bl; const char* name; int type; - + bl = (st->rid) ? &(script_rid2sd(st)->bl) : map_id2bl(st->oid); if (!bl) - return 0; - + return true; + name = script_getstr(st,2); type = script_getnum(st,3); - + //FIXME: enumerating map squares (map_foreach) is slower than enumerating the list of online players (map_foreachpc?) [ultramage] - + if(!script_hasdata(st,4)) { // area around - clif_soundeffectall(bl, name, type, AREA); - } - else - if(!script_hasdata(st,5)) - { // entire map - const char* map = script_getstr(st,4); - map_foreachinmap(soundeffect_sub, map_mapname2mapid(map), BL_PC, name, type); + clif->soundeffectall(bl, name, type, AREA); } else - if(script_hasdata(st,8)) - { // specified part of map - const char* map = script_getstr(st,4); - int x0 = script_getnum(st,5); - int y0 = script_getnum(st,6); - int x1 = script_getnum(st,7); - int y1 = script_getnum(st,8); - map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); - } - else - { - ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n"); - } - - return 0; + if(!script_hasdata(st,5)) + { // entire map + const char* map = script_getstr(st,4); + map_foreachinmap(soundeffect_sub, map_mapname2mapid(map), BL_PC, name, type); + } + else + if(script_hasdata(st,8)) + { // specified part of map + const char* map = script_getstr(st,4); + int x0 = script_getnum(st,5); + int y0 = script_getnum(st,6); + int x1 = script_getnum(st,7); + int y1 = script_getnum(st,8); + map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); + } + else + { + ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n"); + } + + return true; } /*========================================== * pet status recovery [Valaris] / Rewritten by [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(petrecovery) +BUILDIN(petrecovery) { struct pet_data *pd; TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + pd=sd->pd; - + if (pd->recovery) { //Halt previous bonus if (pd->recovery->timer != INVALID_TIMER) delete_timer(pd->recovery->timer, pet_recovery_timer); } else //Init pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery)); - + pd->recovery->type = (sc_type)script_getnum(st,2); pd->recovery->delay = script_getnum(st,3); pd->recovery->timer = INVALID_TIMER; - - return 0; + + return true; } /*========================================== * pet healing [Valaris] //Rewritten by [Skotlex] *------------------------------------------*/ -BUILDIN_FUNC(petheal) +BUILDIN(petheal) { struct pet_data *pd; TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + pd=sd->pd; if (pd->s_skill) { //Clear previous skill @@ -12355,21 +12021,21 @@ BUILDIN_FUNC(petheal) } } else //init memory pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); - + pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport //Use the lv as the amount to heal pd->s_skill->lv=script_getnum(st,2); pd->s_skill->delay=script_getnum(st,3); pd->s_skill->hp=script_getnum(st,4); pd->s_skill->sp=script_getnum(st,5); - + //Use delay as initial offset to avoid skill/heal exploits if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->s_skill->timer = INVALID_TIMER; else pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0); - - return 0; + + return true; } /*========================================== @@ -12377,25 +12043,25 @@ BUILDIN_FUNC(petheal) *------------------------------------------*/ /// petskillattack <skill id>,<level>,<rate>,<bonusrate> /// petskillattack "<skill name>",<level>,<rate>,<bonusrate> -BUILDIN_FUNC(petskillattack) +BUILDIN(petskillattack) { struct pet_data *pd; TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + pd=sd->pd; if (pd->a_skill == NULL) pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack)); - - pd->a_skill->id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + + pd->a_skill->id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); pd->a_skill->lv=script_getnum(st,3); pd->a_skill->div_ = 0; pd->a_skill->rate=script_getnum(st,4); pd->a_skill->bonusrate=script_getnum(st,5); - - return 0; + + return true; } /*========================================== @@ -12403,25 +12069,25 @@ BUILDIN_FUNC(petskillattack) *------------------------------------------*/ /// petskillattack2 <skill id>,<level>,<div>,<rate>,<bonusrate> /// petskillattack2 "<skill name>",<level>,<div>,<rate>,<bonusrate> -BUILDIN_FUNC(petskillattack2) +BUILDIN(petskillattack2) { struct pet_data *pd; TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + pd=sd->pd; if (pd->a_skill == NULL) pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack)); - - pd->a_skill->id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + + pd->a_skill->id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); pd->a_skill->lv=script_getnum(st,3); pd->a_skill->div_ = script_getnum(st,4); pd->a_skill->rate=script_getnum(st,5); pd->a_skill->bonusrate=script_getnum(st,6); - - return 0; + + return true; } /*========================================== @@ -12429,14 +12095,14 @@ BUILDIN_FUNC(petskillattack2) *------------------------------------------*/ /// petskillsupport <skill id>,<level>,<delay>,<hp>,<sp> /// petskillsupport "<skill name>",<level>,<delay>,<hp>,<sp> -BUILDIN_FUNC(petskillsupport) +BUILDIN(petskillsupport) { struct pet_data *pd; TBL_PC *sd=script_rid2sd(st); - + if(sd==NULL || sd->pd==NULL) - return 0; - + return true; + pd=sd->pd; if (pd->s_skill) { //Clear previous skill @@ -12449,20 +12115,20 @@ BUILDIN_FUNC(petskillsupport) } } else //init memory pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); - - pd->s_skill->id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + + pd->s_skill->id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); pd->s_skill->lv=script_getnum(st,3); pd->s_skill->delay=script_getnum(st,4); pd->s_skill->hp=script_getnum(st,5); pd->s_skill->sp=script_getnum(st,6); - + //Use delay as initial offset to avoid skill/heal exploits if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->s_skill->timer = INVALID_TIMER; else pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0); - - return 0; + + return true; } /*========================================== @@ -12470,17 +12136,17 @@ BUILDIN_FUNC(petskillsupport) *------------------------------------------*/ /// skilleffect <skill id>,<level> /// skilleffect "<skill name>",<level> -BUILDIN_FUNC(skilleffect) +BUILDIN(skilleffect) { TBL_PC *sd; - - uint16 skill_id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + + uint16 skill_id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); uint16 skill_lv=script_getnum(st,3); sd=script_rid2sd(st); - - clif_skill_nodamage(&sd->bl,&sd->bl,skill_id,skill_lv,1); - - return 0; + + clif->skill_nodamage(&sd->bl,&sd->bl,skill_id,skill_lv,1); + + return true; } /*========================================== @@ -12488,79 +12154,79 @@ BUILDIN_FUNC(skilleffect) *------------------------------------------*/ /// npcskilleffect <skill id>,<level>,<x>,<y> /// npcskilleffect "<skill name>",<level>,<x>,<y> -BUILDIN_FUNC(npcskilleffect) +BUILDIN(npcskilleffect) { struct block_list *bl= map_id2bl(st->oid); - - uint16 skill_id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) ); + + uint16 skill_id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); uint16 skill_lv=script_getnum(st,3); int x=script_getnum(st,4); int y=script_getnum(st,5); - + if (bl) - clif_skill_poseffect(bl,skill_id,skill_lv,x,y,gettick()); - - return 0; + clif->skill_poseffect(bl,skill_id,skill_lv,x,y,gettick()); + + return true; } /*========================================== * Special effects [Valaris] *------------------------------------------*/ -BUILDIN_FUNC(specialeffect) +BUILDIN(specialeffect) { struct block_list *bl=map_id2bl(st->oid); int type = script_getnum(st,2); enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA; - + if(bl==NULL) - return 0; - + return true; + if( script_hasdata(st,4) ) { TBL_NPC *nd = npc_name2id(script_getstr(st,4)); if(nd) - clif_specialeffect(&nd->bl, type, target); + clif->specialeffect(&nd->bl, type, target); } else { if (target == SELF) { TBL_PC *sd=script_rid2sd(st); if (sd) - clif_specialeffect_single(bl,type,sd->fd); + clif->specialeffect_single(bl,type,sd->fd); } else { - clif_specialeffect(bl, type, target); + clif->specialeffect(bl, type, target); } } - - return 0; + + return true; } -BUILDIN_FUNC(specialeffect2) +BUILDIN(specialeffect2) { TBL_PC *sd=script_rid2sd(st); int type = script_getnum(st,2); enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA; - + if( script_hasdata(st,4) ) sd = map_nick2sd(script_getstr(st,4)); - + if (sd) - clif_specialeffect(&sd->bl, type, target); - - return 0; + clif->specialeffect(&sd->bl, type, target); + + return true; } /*========================================== * Nude [Valaris] *------------------------------------------*/ -BUILDIN_FUNC(nude) +BUILDIN(nude) { TBL_PC *sd = script_rid2sd(st); int i, calcflag = 0; - + if( sd == NULL ) - return 0; - + return true; + for( i = 0 ; i < EQI_MAX; i++ ) { if( sd->equip_index[ i ] >= 0 ) { if( !calcflag ) @@ -12568,32 +12234,32 @@ BUILDIN_FUNC(nude) pc_unequipitem( sd , sd->equip_index[ i ] , 2); } } - + if( calcflag ) status_calc_pc(sd,0); - - return 0; + + return true; } /*========================================== * gmcommand [MouseJstr] *------------------------------------------*/ -BUILDIN_FUNC(atcommand) +BUILDIN(atcommand) { TBL_PC dummy_sd; TBL_PC* sd; int fd; const char* cmd; - + cmd = script_getstr(st,2); - + if (st->rid) { sd = script_rid2sd(st); fd = sd->fd; } else { //Use a dummy character. sd = &dummy_sd; fd = 0; - + memset(&dummy_sd, 0, sizeof(TBL_PC)); if (st->oid) { @@ -12603,67 +12269,67 @@ BUILDIN_FUNC(atcommand) safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); } } - - if (!is_atcommand(fd, sd, cmd, 0)) { + + if (!atcommand->parse(fd, sd, cmd, 0)) { ShowWarning("script: buildin_atcommand: failed to execute command '%s'\n", cmd); script_reportsrc(st); - return 1; + return false; } - - return 0; + + return true; } /*========================================== * Displays a message for the player only (like system messages like "you got an apple" ) *------------------------------------------*/ -BUILDIN_FUNC(dispbottom) +BUILDIN(dispbottom) { TBL_PC *sd=script_rid2sd(st); const char *message; message=script_getstr(st,2); if(sd) - clif_disp_onlyself(sd,message,(int)strlen(message)); - return 0; + clif->disp_onlyself(sd,message,(int)strlen(message)); + return true; } /*========================================== * All The Players Full Recovery * (HP/SP full restore and resurrect if need) *------------------------------------------*/ -BUILDIN_FUNC(recovery) +BUILDIN(recovery) { TBL_PC* sd; struct s_mapiterator* iter; - + iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if(pc_isdead(sd)) status_revive(&sd->bl, 100, 100); else status_percent_heal(&sd->bl, 100, 100); - clif_displaymessage(sd->fd,msg_txt(680)); + clif->message(sd->fd,msg_txt(680)); } - mapit_free(iter); - return 0; + mapit->free(iter); + return true; } /*========================================== * Get your pet info: getpetinfo(n) * n -> 0:pet_id 1:pet_class 2:pet_name * 3:friendly 4:hungry, 5: rename flag. *------------------------------------------*/ -BUILDIN_FUNC(getpetinfo) +BUILDIN(getpetinfo) { TBL_PC *sd=script_rid2sd(st); TBL_PET *pd; int type=script_getnum(st,2); - + if(!sd || !sd->pd) { if (type == 2) script_pushconststr(st,"null"); else script_pushint(st,0); - return 0; + return true; } pd = sd->pd; switch(type){ @@ -12677,7 +12343,7 @@ BUILDIN_FUNC(getpetinfo) script_pushint(st,0); break; } - return 0; + return true; } /*========================================== @@ -12686,22 +12352,22 @@ BUILDIN_FUNC(getpetinfo) * 3:friendly 4:hungry, 5: rename flag. * 6: level *------------------------------------------*/ -BUILDIN_FUNC(gethominfo) +BUILDIN(gethominfo) { TBL_PC *sd=script_rid2sd(st); TBL_HOM *hd; int type=script_getnum(st,2); - + hd = sd?sd->hd:NULL; - if(!merc_is_hom_active(hd)) + if(!homun_alive(hd)) { if (type == 2) script_pushconststr(st,"null"); else script_pushint(st,0); - return 0; + return true; } - + switch(type){ case 0: script_pushint(st,hd->homunculus.hom_id); break; case 1: script_pushint(st,hd->homunculus.class_); break; @@ -12714,28 +12380,28 @@ BUILDIN_FUNC(gethominfo) script_pushint(st,0); break; } - return 0; + return true; } /// Retrieves information about character's mercenary /// getmercinfo <type>[,<char id>]; -BUILDIN_FUNC(getmercinfo) +BUILDIN(getmercinfo) { int type, char_id; struct map_session_data* sd; struct mercenary_data* md; - + type = script_getnum(st,2); - + if( script_hasdata(st,3) ) { char_id = script_getnum(st,3); - + if( ( sd = map_charid2sd(char_id) ) == NULL ) { ShowError("buildin_getmercinfo: No such character (char_id=%d).\n", char_id); script_pushnil(st); - return 1; + return false; } } else @@ -12743,12 +12409,12 @@ BUILDIN_FUNC(getmercinfo) if( ( sd = script_rid2sd(st) ) == NULL ) { script_pushnil(st); - return 0; + return true; } } - + md = ( sd->status.mer_id && sd->md ) ? sd->md : NULL; - + switch( type ) { case 0: script_pushint(st,md ? md->mercenary.mercenary_id : 0); break; @@ -12767,25 +12433,25 @@ BUILDIN_FUNC(getmercinfo) default: ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id); script_pushnil(st); - return 1; + return false; } - - return 0; + + return true; } /*========================================== * Shows wether your inventory(and equips) contain - selected card or not. - checkequipedcard(4001); + selected card or not. + checkequipedcard(4001); *------------------------------------------*/ -BUILDIN_FUNC(checkequipedcard) +BUILDIN(checkequipedcard) { TBL_PC *sd=script_rid2sd(st); - + if(sd){ int n,i,c=0; c=script_getnum(st,2); - + for(i=0;i<MAX_INVENTORY;i++){ if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount && sd->inventory_data[i]){ if (itemdb_isspecial(sd->status.inventory[i].card[0])) @@ -12793,17 +12459,17 @@ BUILDIN_FUNC(checkequipedcard) for(n=0;n<sd->inventory_data[i]->slot;n++){ if(sd->status.inventory[i].card[n]==c){ script_pushint(st,1); - return 0; + return true; } } } } } script_pushint(st,0); - return 0; + return true; } -BUILDIN_FUNC(jump_zero) +BUILDIN(jump_zero) { int sel; sel=script_getnum(st,2); @@ -12812,104 +12478,104 @@ BUILDIN_FUNC(jump_zero) if( !data_islabel(script_getdata(st,3)) ){ ShowError("script: jump_zero: not label !\n"); st->state=END; - return 1; + return false; } - + pos=script_getnum(st,3); st->pos=pos; st->state=GOTO; } - return 0; + return true; } /*========================================== * movenpc [MouseJstr] *------------------------------------------*/ -BUILDIN_FUNC(movenpc) +BUILDIN(movenpc) { TBL_NPC *nd = NULL; const char *npc; int x,y; - + npc = script_getstr(st,2); x = script_getnum(st,3); y = script_getnum(st,4); - + if ((nd = npc_name2id(npc)) == NULL) return -1; - + if (script_hasdata(st,5)) nd->ud.dir = script_getnum(st,5) % 8; npc_movenpc(nd, x, y); - return 0; + return true; } /*========================================== * message [MouseJstr] *------------------------------------------*/ -BUILDIN_FUNC(message) +BUILDIN(message) { const char *msg,*player; TBL_PC *pl_sd = NULL; - + player = script_getstr(st,2); msg = script_getstr(st,3); - + if((pl_sd=map_nick2sd((char *) player)) == NULL) - return 0; - clif_displaymessage(pl_sd->fd, msg); - - return 0; + return true; + clif->message(pl_sd->fd, msg); + + return true; } /*========================================== * npctalk (sends message to surrounding area) *------------------------------------------*/ -BUILDIN_FUNC(npctalk) +BUILDIN(npctalk) { const char* str; char name[NAME_LENGTH], message[256]; - + struct npc_data* nd = (struct npc_data *)map_id2bl(st->oid); str = script_getstr(st,2); - + if(nd) { safestrncpy(name, nd->name, sizeof(name)); strtok(name, "#"); // discard extra name identifier if present safesnprintf(message, sizeof(message), "%s : %s", name, str); - clif_message(&nd->bl, message); + clif->disp_overhead(&nd->bl, message); } - - return 0; + + return true; } // change npc walkspeed [Valaris] -BUILDIN_FUNC(npcspeed) +BUILDIN(npcspeed) { struct npc_data* nd; int speed; - + speed = script_getnum(st,2); nd =(struct npc_data *)map_id2bl(st->oid); - + if( nd ) { nd->speed = speed; nd->ud.state.speed_changed = 1; } - - return 0; + + return true; } // make an npc walk to a position [Valaris] -BUILDIN_FUNC(npcwalkto) +BUILDIN(npcwalkto) { struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid); int x=0,y=0; - + x=script_getnum(st,2); y=script_getnum(st,3); - + if(nd) { if (!nd->status.hp) { status_calc_npc(nd, true); @@ -12918,65 +12584,66 @@ BUILDIN_FUNC(npcwalkto) } unit_walktoxy(&nd->bl,x,y,0); } - - return 0; + + return true; } // stop an npc's movement [Valaris] -BUILDIN_FUNC(npcstop) +BUILDIN(npcstop) { struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid); - + if(nd) { unit_stop_walking(&nd->bl,1|4); } - - return 0; + + return true; } /*========================================== * getlook char info. getlook(arg) *------------------------------------------*/ -BUILDIN_FUNC(getlook) -{ - int type,val; - TBL_PC *sd; - sd=script_rid2sd(st); - - type=script_getnum(st,2); - val=-1; - switch(type) { - case LOOK_HAIR: val=sd->status.hair; break; //1 - case LOOK_WEAPON: val=sd->status.weapon; break; //2 - case LOOK_HEAD_BOTTOM: val=sd->status.head_bottom; break; //3 - case LOOK_HEAD_TOP: val=sd->status.head_top; break; //4 - case LOOK_HEAD_MID: val=sd->status.head_mid; break; //5 - case LOOK_HAIR_COLOR: val=sd->status.hair_color; break; //6 - case LOOK_CLOTHES_COLOR: val=sd->status.clothes_color; break; //7 - case LOOK_SHIELD: val=sd->status.shield; break; //8 - case LOOK_SHOES: break; //9 - } - - script_pushint(st,val); - return 0; +BUILDIN(getlook) +{ + int type,val; + TBL_PC *sd; + sd=script_rid2sd(st); + + type=script_getnum(st,2); + val=-1; + switch(type) { + case LOOK_HAIR: val=sd->status.hair; break; //1 + case LOOK_WEAPON: val=sd->status.weapon; break; //2 + case LOOK_HEAD_BOTTOM: val=sd->status.head_bottom; break; //3 + case LOOK_HEAD_TOP: val=sd->status.head_top; break; //4 + case LOOK_HEAD_MID: val=sd->status.head_mid; break; //5 + case LOOK_HAIR_COLOR: val=sd->status.hair_color; break; //6 + case LOOK_CLOTHES_COLOR:val=sd->status.clothes_color; break; //7 + case LOOK_SHIELD: val=sd->status.shield; break; //8 + case LOOK_SHOES: break; //9 + case LOOK_ROBE: val=sd->status.robe; break; //12 + } + + script_pushint(st,val); + return true; } /*========================================== * get char save point. argument: 0- map name, 1- x, 2- y *------------------------------------------*/ -BUILDIN_FUNC(getsavepoint) +BUILDIN(getsavepoint) { TBL_PC* sd; int type; - + sd = script_rid2sd(st); if (sd == NULL) { script_pushint(st,0); - return 0; + return true; } - + type = script_getnum(st,2); - + switch(type) { case 0: script_pushstrcopy(st,mapindex_id2name(sd->status.save_point.map)); break; case 1: script_pushint(st,sd->status.save_point.x); break; @@ -12985,69 +12652,69 @@ BUILDIN_FUNC(getsavepoint) script_pushint(st,0); break; } - return 0; + return true; } /*========================================== - * Get position for char/npc/pet/mob objects. Added by Lorky - * - * int getMapXY(MapName$,MapX,MapY,type,[CharName$]); - * where type: - * MapName$ - String variable for output map name - * MapX - Integer variable for output coord X - * MapY - Integer variable for output coord Y - * type - type of object - * 0 - Character coord - * 1 - NPC coord - * 2 - Pet coord - * 3 - Mob coord (not released) - * 4 - Homun coord - * 5 - Mercenary coord - * 6 - Elemental coord - * CharName$ - Name object. If miss or "this" the current object - * - * Return: - * 0 - success - * -1 - some error, MapName$,MapX,MapY contains unknown value. - *------------------------------------------*/ -BUILDIN_FUNC(getmapxy) + * Get position for char/npc/pet/mob objects. Added by Lorky + * + * int getMapXY(MapName$,MapX,MapY,type,[CharName$]); + * where type: + * MapName$ - String variable for output map name + * MapX - Integer variable for output coord X + * MapY - Integer variable for output coord Y + * type - type of object + * 0 - Character coord + * 1 - NPC coord + * 2 - Pet coord + * 3 - Mob coord (not released) + * 4 - Homun coord + * 5 - Mercenary coord + * 6 - Elemental coord + * CharName$ - Name object. If miss or "this" the current object + * + * Return: + * 0 - success + * -1 - some error, MapName$,MapX,MapY contains unknown value. + *------------------------------------------*/ +BUILDIN(getmapxy) { struct block_list *bl = NULL; TBL_PC *sd=NULL; - + int num; const char *name; char prefix; - + int x,y,type; char mapname[MAP_NAME_LENGTH]; - + if( !data_isreference(script_getdata(st,2)) ){ ShowWarning("script: buildin_getmapxy: not mapname variable\n"); script_pushint(st,-1); - return 1; + return false; } if( !data_isreference(script_getdata(st,3)) ){ ShowWarning("script: buildin_getmapxy: not mapx variable\n"); script_pushint(st,-1); - return 1; + return false; } if( !data_isreference(script_getdata(st,4)) ){ ShowWarning("script: buildin_getmapxy: not mapy variable\n"); script_pushint(st,-1); - return 1; + return false; } - + // Possible needly check function parameters on C_STR,C_INT,C_INT type=script_getnum(st,5); - + switch (type){ case 0: //Get Character Position if( script_hasdata(st,6) ) sd=map_nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); - + if (sd) bl = &sd->bl; break; @@ -13066,7 +12733,7 @@ BUILDIN_FUNC(getmapxy) sd=map_nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); - + if (sd && sd->pd) bl = &sd->pd->bl; break; @@ -13077,7 +12744,7 @@ BUILDIN_FUNC(getmapxy) sd=map_nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); - + if (sd && sd->hd) bl = &sd->hd->bl; break; @@ -13086,7 +12753,7 @@ BUILDIN_FUNC(getmapxy) sd=map_nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); - + if (sd && sd->md) bl = &sd->md->bl; break; @@ -13095,90 +12762,90 @@ BUILDIN_FUNC(getmapxy) sd=map_nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); - + if (sd && sd->ed) bl = &sd->ed->bl; break; default: ShowWarning("script: buildin_getmapxy: Invalid type %d\n", type); script_pushint(st,-1); - return 1; + return false; } if (!bl) { //No object found. script_pushint(st,-1); - return 0; + return true; } - + x= bl->x; y= bl->y; safestrncpy(mapname, map[bl->m].name, MAP_NAME_LENGTH); - + //Set MapName$ num=st->stack->stack_data[st->start+2].u.num; name=get_str(num&0x00ffffff); prefix=*name; - + if(not_server_variable(prefix)) sd=script_rid2sd(st); else sd=NULL; set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2)); - + //Set MapX num=st->stack->stack_data[st->start+3].u.num; name=get_str(num&0x00ffffff); prefix=*name; - + if(not_server_variable(prefix)) sd=script_rid2sd(st); else sd=NULL; - set_reg(st,sd,num,name,(void*)__64BPRTSIZE(x),script_getref(st,3)); - + set_reg(st,sd,num,name,(void*)__64BPTRSIZE(x),script_getref(st,3)); + //Set MapY num=st->stack->stack_data[st->start+4].u.num; name=get_str(num&0x00ffffff); prefix=*name; - + if(not_server_variable(prefix)) sd=script_rid2sd(st); else sd=NULL; - set_reg(st,sd,num,name,(void*)__64BPRTSIZE(y),script_getref(st,4)); - + set_reg(st,sd,num,name,(void*)__64BPTRSIZE(y),script_getref(st,4)); + //Return Success value script_pushint(st,0); - return 0; + return true; } /*========================================== * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus] *------------------------------------------*/ -BUILDIN_FUNC(logmes) +BUILDIN(logmes) { const char *str; TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 1; - + return false; + str = script_getstr(st,2); - log_npc(sd,str); - return 0; + logs->npc(sd,str); + return true; } -BUILDIN_FUNC(summon) +BUILDIN(summon) { int _class, timeout=0; const char *str,*event=""; TBL_PC *sd; struct mob_data *md; int tick = gettick(); - + sd=script_rid2sd(st); - if (!sd) return 0; - + if (!sd) return true; + str =script_getstr(st,2); _class=script_getnum(st,3); if( script_hasdata(st,4) ) @@ -13187,9 +12854,9 @@ BUILDIN_FUNC(summon) event=script_getstr(st,5); check_event(st, event); } - - clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick); - + + clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick); + md = mob_once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event, SZ_SMALL, AI_NONE); if (md) { md->master_id=sd->bl.id; @@ -13198,48 +12865,48 @@ BUILDIN_FUNC(summon) delete_timer(md->deletetimer, mob_timer_delete); md->deletetimer = add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0); mob_spawn (md); //Now it is ready for spawning. - clif_specialeffect(&md->bl,344,AREA); + clif->specialeffect(&md->bl,344,AREA); sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); } - return 0; + return true; } /*========================================== * Checks whether it is daytime/nighttime *------------------------------------------*/ -BUILDIN_FUNC(isnight) +BUILDIN(isnight) { script_pushint(st,(night_flag == 1)); - return 0; + return true; } -BUILDIN_FUNC(isday) +BUILDIN(isday) { script_pushint(st,(night_flag == 0)); - return 0; + return true; } /*================================================ * Check how many items/cards in the list are * equipped - used for 2/15's cards patch [celest] *------------------------------------------------*/ -BUILDIN_FUNC(isequippedcnt) +BUILDIN(isequippedcnt) { TBL_PC *sd; int i, j, k, id = 1; int ret = 0; - + sd = script_rid2sd(st); if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing... script_pushint(st,0); - return 0; + return true; } - + for (i=0; id!=0; i++) { FETCH (i+2, id) else id = 0; if (id <= 0) continue; - + for (j=0; j<EQI_MAX; j++) { int index; index = sd->equip_index[j]; @@ -13247,10 +12914,10 @@ BUILDIN_FUNC(isequippedcnt) if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue; if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue; if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue; - + if(!sd->inventory_data[index]) continue; - + if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory. if (sd->inventory_data[index]->nameid == id) ret+= sd->status.inventory[index].amount; @@ -13264,9 +12931,9 @@ BUILDIN_FUNC(isequippedcnt) } } } - + script_pushint(st,ret); - return 0; + return true; } /*================================================ @@ -13275,7 +12942,7 @@ BUILDIN_FUNC(isequippedcnt) * -- Items checked cannot be reused in another * card set to prevent exploits *------------------------------------------------*/ -BUILDIN_FUNC(isequipped) +BUILDIN(isequipped) { TBL_PC *sd; int i, j, k, id = 1; @@ -13283,14 +12950,14 @@ BUILDIN_FUNC(isequipped) int ret = -1; //Original hash to reverse it when full check fails. unsigned int setitem_hash = 0, setitem_hash2 = 0; - + sd = script_rid2sd(st); - + if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing... script_pushint(st,0); - return 0; + return true; } - + setitem_hash = sd->bonus.setitem_hash; setitem_hash2 = sd->bonus.setitem_hash2; for (i=0; id!=0; i++) { @@ -13304,10 +12971,10 @@ BUILDIN_FUNC(isequipped) if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue; if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue; if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue; - + if(!sd->inventory_data[index]) continue; - + if (itemdb_type(id) != IT_CARD) { if (sd->inventory_data[index]->nameid != id) continue; @@ -13317,18 +12984,18 @@ BUILDIN_FUNC(isequipped) if (sd->inventory_data[index]->slot == 0 || itemdb_isspecial(sd->status.inventory[index].card[0])) continue; - + for (k = 0; k < sd->inventory_data[index]->slot; k++) { //New hash system which should support up to 4 slots on any equipment. [Skotlex] unsigned int hash = 0; if (sd->status.inventory[index].card[k] != id) continue; - + hash = 1<<((j<5?j:j-5)*4 + k); // check if card is already used by another set if ( ( j < 5 ? sd->bonus.setitem_hash : sd->bonus.setitem_hash2 ) & hash) continue; - + // We have found a match flag = 1; // Set hash so this card cannot be used by another @@ -13352,33 +13019,33 @@ BUILDIN_FUNC(isequipped) sd->bonus.setitem_hash2 = setitem_hash2; } script_pushint(st,ret); - return 0; + return true; } /*================================================ * Check how many given inserted cards in the CURRENT * weapon - used for 2/15's cards patch [Lupus] *------------------------------------------------*/ -BUILDIN_FUNC(cardscnt) +BUILDIN(cardscnt) { TBL_PC *sd; int i, k, id = 1; int ret = 0; int index; - + sd = script_rid2sd(st); - + for (i=0; id!=0; i++) { FETCH (i+2, id) else id = 0; if (id <= 0) continue; - + index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus] if(index < 0) continue; - + if(!sd->inventory_data[index]) continue; - + if(itemdb_type(id) != IT_CARD) { if (sd->inventory_data[index]->nameid == id) ret+= sd->status.inventory[index].amount; @@ -13392,47 +13059,47 @@ BUILDIN_FUNC(cardscnt) } } script_pushint(st,ret); -// script_pushint(st,current_equip_item_index); - return 0; + // script_pushint(st,current_equip_item_index); + return true; } /*======================================================= * Returns the refined number of the current item, or an * item with inventory index specified *-------------------------------------------------------*/ -BUILDIN_FUNC(getrefine) +BUILDIN(getrefine) { TBL_PC *sd; if ((sd = script_rid2sd(st))!= NULL) script_pushint(st,sd->status.inventory[current_equip_item_index].refine); else script_pushint(st,0); - return 0; + return true; } /*======================================================= * Day/Night controls *-------------------------------------------------------*/ -BUILDIN_FUNC(night) +BUILDIN(night) { if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1); - return 0; + return true; } -BUILDIN_FUNC(day) +BUILDIN(day) { if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1); - return 0; + return true; } //======================================================= // Unequip [Spectre] //------------------------------------------------------- -BUILDIN_FUNC(unequip) +BUILDIN(unequip) { int i; size_t num; TBL_PC *sd; - + num = script_getnum(st,2); sd = script_rid2sd(st); if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(equip) ) @@ -13441,138 +13108,138 @@ BUILDIN_FUNC(unequip) if (i >= 0) pc_unequipitem(sd,i,1|2); } - return 0; + return true; } -BUILDIN_FUNC(equip) +BUILDIN(equip) { int nameid=0,i; TBL_PC *sd; struct item_data *item_data; - + sd = script_rid2sd(st); - + nameid=script_getnum(st,2); if((item_data = itemdb_exists(nameid)) == NULL) { ShowError("wrong item ID : equipitem(%i)\n",nameid); - return 1; + return false; } ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid ); if( i < MAX_INVENTORY ) pc_equipitem(sd,i,item_data->equip); - - return 0; + + return true; } -BUILDIN_FUNC(autoequip) +BUILDIN(autoequip) { int nameid, flag; struct item_data *item_data; nameid=script_getnum(st,2); flag=script_getnum(st,3); - + if( ( item_data = itemdb_exists(nameid) ) == NULL ) { ShowError("buildin_autoequip: Invalid item '%d'.\n", nameid); - return 1; + return false; } - + if( !itemdb_isequip2(item_data) ) { ShowError("buildin_autoequip: Item '%d' cannot be equipped.\n", nameid); - return 1; + return false; } - + item_data->flag.autoequip = flag>0?1:0; - return 0; + return true; } -BUILDIN_FUNC(setbattleflag) +BUILDIN(setbattleflag) { const char *flag, *value; - + flag = script_getstr(st,2); value = script_getstr(st,3); // HACK: Retrieve number as string (auto-converted) for battle_set_value - - if (battle_set_value(flag, value) == 0) + + if (battle->config_set_value(flag, value) == 0) ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'\n",flag); else ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.\n",flag,value); - - return 0; + + return true; } -BUILDIN_FUNC(getbattleflag) +BUILDIN(getbattleflag) { const char *flag; flag = script_getstr(st,2); - script_pushint(st,battle_get_value(flag)); - return 0; + script_pushint(st,battle->config_get_value(flag)); + return true; } //======================================================= // strlen [Valaris] //------------------------------------------------------- -BUILDIN_FUNC(getstrlen) +BUILDIN(getstrlen) { - + const char *str = script_getstr(st,2); int len = (str) ? (int)strlen(str) : 0; - + script_pushint(st,len); - return 0; + return true; } //======================================================= // isalpha [Valaris] //------------------------------------------------------- -BUILDIN_FUNC(charisalpha) +BUILDIN(charisalpha) { const char *str=script_getstr(st,2); int pos=script_getnum(st,3); - + int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISALPHA( str[pos] ) != 0 : 0; - + script_pushint(st,val); - return 0; + return true; } //======================================================= // charisupper <str>, <index> //------------------------------------------------------- -BUILDIN_FUNC(charisupper) +BUILDIN(charisupper) { const char *str = script_getstr(st,2); int pos = script_getnum(st,3); - + int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISUPPER( str[pos] ) : 0; - + script_pushint(st,val); - return 0; + return true; } //======================================================= // charislower <str>, <index> //------------------------------------------------------- -BUILDIN_FUNC(charislower) +BUILDIN(charislower) { const char *str = script_getstr(st,2); int pos = script_getnum(st,3); - + int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISLOWER( str[pos] ) : 0; - + script_pushint(st,val); - return 0; + return true; } //======================================================= // charat <str>, <index> //------------------------------------------------------- -BUILDIN_FUNC(charat) { +BUILDIN(charat) { const char *str = script_getstr(st,2); int pos = script_getnum(st,3); - + if( pos >= 0 && (unsigned int)pos < strlen(str) ) { char output[2]; output[0] = str[pos]; @@ -13580,145 +13247,145 @@ BUILDIN_FUNC(charat) { script_pushstrcopy(st, output); } else script_pushconststr(st, ""); - return 0; + return true; } //======================================================= // setchar <string>, <char>, <index> //------------------------------------------------------- -BUILDIN_FUNC(setchar) +BUILDIN(setchar) { const char *str = script_getstr(st,2); const char *c = script_getstr(st,3); int index = script_getnum(st,4); char *output = aStrdup(str); - + if(index >= 0 && index < strlen(output)) output[index] = *c; - + script_pushstr(st, output); - return 0; + return true; } //======================================================= // insertchar <string>, <char>, <index> //------------------------------------------------------- -BUILDIN_FUNC(insertchar) +BUILDIN(insertchar) { const char *str = script_getstr(st,2); const char *c = script_getstr(st,3); int index = script_getnum(st,4); char *output; size_t len = strlen(str); - + if(index < 0) index = 0; else if(index > len) index = len; - + output = (char*)aMalloc(len + 2); - + memcpy(output, str, index); output[index] = c[0]; memcpy(&output[index+1], &str[index], len - index); output[len+1] = '\0'; - + script_pushstr(st, output); - return 0; + return true; } //======================================================= // delchar <string>, <index> //------------------------------------------------------- -BUILDIN_FUNC(delchar) +BUILDIN(delchar) { const char *str = script_getstr(st,2); int index = script_getnum(st,3); char *output; size_t len = strlen(str); - + if(index < 0 || index > len) { //return original output = aStrdup(str); script_pushstr(st, output); - return 0; + return true; } - + output = (char*)aMalloc(len); - + memcpy(output, str, index); memcpy(&output[index], &str[index+1], len - index); - + script_pushstr(st, output); - return 0; + return true; } //======================================================= // strtoupper <str> //------------------------------------------------------- -BUILDIN_FUNC(strtoupper) +BUILDIN(strtoupper) { const char *str = script_getstr(st,2); char *output = aStrdup(str); char *cursor = output; - + while (*cursor != '\0') { *cursor = TOUPPER(*cursor); cursor++; } - + script_pushstr(st, output); - return 0; + return true; } //======================================================= // strtolower <str> //------------------------------------------------------- -BUILDIN_FUNC(strtolower) +BUILDIN(strtolower) { const char *str = script_getstr(st,2); char *output = aStrdup(str); char *cursor = output; - + while (*cursor != '\0') { *cursor = TOLOWER(*cursor); cursor++; } - + script_pushstr(st, output); - return 0; + return true; } //======================================================= // substr <str>, <start>, <end> //------------------------------------------------------- -BUILDIN_FUNC(substr) +BUILDIN(substr) { const char *str = script_getstr(st,2); char *output; int start = script_getnum(st,3); int end = script_getnum(st,4); - + int len = 0; - + if(start >= 0 && end < strlen(str) && start <= end) { len = end - start + 1; output = (char*)aMalloc(len + 1); memcpy(output, &str[start], len); } else output = (char*)aMalloc(1); - + output[len] = '\0'; - + script_pushstr(st, output); - return 0; + return true; } //======================================================= // explode <dest_string_array>, <str>, <delimiter> // Note: delimiter is limited to 1 char //------------------------------------------------------- -BUILDIN_FUNC(explode) +BUILDIN(explode) { struct script_data* data = script_getdata(st, 2); const char *str = script_getstr(st,3); @@ -13727,50 +13394,50 @@ BUILDIN_FUNC(explode) size_t len = strlen(str); int i = 0, j = 0; int start; - - + + char *temp; const char* name; - + TBL_PC* sd = NULL; - + temp = (char*)aMalloc(len + 1); - + if( !data_isreference(data) ) { ShowError("script:explode: not a variable\n"); script_reportdata(data); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); start = reference_getindex(data); name = reference_getname(data); - + if( not_array_variable(*name) ) { ShowError("script:explode: illegal scope\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + if( !is_string_variable(name) ) { ShowError("script:explode: not string array\n"); script_reportdata(data); st->state = END; - return 1;// data type mismatch + return false;// data type mismatch } - + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + while(str[i] != '\0') { if(str[i] == delimiter && start < SCRIPT_MAX_ARRAYSIZE-1) { //break at delimiter but ignore after reaching last array index temp[j] = '\0'; @@ -13784,64 +13451,64 @@ BUILDIN_FUNC(explode) //set last string temp[j] = '\0'; set_reg(st, sd, reference_uid(id, start), name, (void*)temp, reference_getref(data)); - + aFree(temp); - return 0; + return true; } //======================================================= // implode <string_array> // implode <string_array>, <glue> //------------------------------------------------------- -BUILDIN_FUNC(implode) +BUILDIN(implode) { struct script_data* data = script_getdata(st, 2); const char *glue = NULL, *name, *temp; int32 glue_len = 0, array_size, id; size_t len = 0; int i, k = 0; - + TBL_PC* sd = NULL; - + char *output; - + if( !data_isreference(data) ) { ShowError("script:implode: not a variable\n"); script_reportdata(data); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); name = reference_getname(data); - + if( not_array_variable(*name) ) { ShowError("script:implode: illegal scope\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + if( !is_string_variable(name) ) { ShowError("script:implode: not string array\n"); script_reportdata(data); st->state = END; - return 1;// data type mismatch + return false;// data type mismatch } - + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + //count chars array_size = getarraysize(st, id, reference_getindex(data), is_string_variable(name), reference_getref(data)) - 1; - + if(array_size == -1) //empty array check (AmsTaff) { ShowWarning("script:implode: array length = 0\n"); @@ -13853,7 +13520,7 @@ BUILDIN_FUNC(implode) len += strlen(temp); script_removetop(st, -1, 0); } - + //allocate mem if( script_hasdata(st,3) ) { glue = script_getstr(st,3); @@ -13861,7 +13528,7 @@ BUILDIN_FUNC(implode) len += glue_len * (array_size); } output = (char*)aMalloc(len + 1); - + //build output for(i = 0; i < array_size; ++i) { temp = (char*) get_val2(st, reference_uid(id, i), reference_getref(data)); @@ -13879,12 +13546,12 @@ BUILDIN_FUNC(implode) memcpy(&output[k], temp, len); k += len; script_removetop(st, -1, 0); - + output[k] = '\0'; } - + script_pushstr(st, output); - return 0; + return true; } //======================================================= @@ -13892,7 +13559,7 @@ BUILDIN_FUNC(implode) // Implements C sprintf, except format %n. The resulting string is // returned, instead of being saved in variable by reference. //------------------------------------------------------- -BUILDIN_FUNC(sprintf) +BUILDIN(sprintf) { unsigned int len, argc = 0, arg = 0, buf2_len = 0; const char* format; @@ -13902,33 +13569,33 @@ BUILDIN_FUNC(sprintf) char* buf2 = NULL; struct script_data* data; StringBuf final_buf; - + // Fetch init data format = script_getstr(st, 2); argc = script_lastdata(st)-2; len = strlen(format); - + // Skip parsing, where no parsing is required. if(len==0){ script_pushconststr(st,""); - return 0; + return true; } - + // Pessimistic alloc CREATE(buf, char, len+1); - + // Need not be parsed, just solve stuff like %%. if(argc==0){ memcpy(buf,format,len+1); script_pushstrcopy(st, buf); aFree(buf); - return 0; + return true; } - + safestrncpy(buf, format, len+1); - + // Issue sprintf for each parameter - StringBuf_Init(&final_buf); + StrBuf->Init(&final_buf); q = buf; while((p = strchr(q, '%'))!=NULL){ if(p!=q){ @@ -13938,12 +13605,12 @@ BUILDIN_FUNC(sprintf) buf2_len = len; } safestrncpy(buf2, q, len); - StringBuf_AppendStr(&final_buf, buf2); + StrBuf->AppendStr(&final_buf, buf2); q = p; } p = q+1; if(*p=='%'){ // %% - StringBuf_AppendStr(&final_buf, "%"); + StrBuf->AppendStr(&final_buf, "%"); q+=2; continue; } @@ -13957,9 +13624,9 @@ BUILDIN_FUNC(sprintf) ShowError("buildin_sprintf: Not enough arguments passed!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); script_pushconststr(st,""); - return 1; + return false; } if((p = strchr(q+1, '%'))==NULL){ p = strchr(q, 0); // EOS @@ -13971,7 +13638,7 @@ BUILDIN_FUNC(sprintf) } safestrncpy(buf2, q, len); q = p; - + // Note: This assumes the passed value being the correct // type to the current format specifier. If not, the server // probably crashes or returns anything else, than expected, @@ -13979,52 +13646,52 @@ BUILDIN_FUNC(sprintf) // the scripter's responsibility. data = script_getdata(st, arg+3); if(data_isstring(data)){ // String - StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getstr(st, arg+3)); }else if(data_isint(data)){ // Number - StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getnum(st, arg+3)); }else if(data_isreference(data)){ // Variable char* name = reference_getname(data); if(name[strlen(name)-1]=='$'){ // var Str - StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getstr(st, arg+3)); }else{ // var Int - StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getnum(st, arg+3)); } }else{ // Unsupported type ShowError("buildin_sprintf: Unknown argument type!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); script_pushconststr(st,""); - return 1; + return false; } arg++; } - + // Append anything left if(*q){ - StringBuf_AppendStr(&final_buf, q); + StrBuf->AppendStr(&final_buf, q); } - + // Passed more, than needed if(arg<argc){ ShowWarning("buildin_sprintf: Unused arguments passed.\n"); script_reportsrc(st); } - - script_pushstrcopy(st, StringBuf_Value(&final_buf)); - + + script_pushstrcopy(st, StrBuf->Value(&final_buf)); + if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); - - return 0; + StrBuf->Destroy(&final_buf); + + return true; } //======================================================= // sscanf(<str>, <format>, ...); // Implements C sscanf. //------------------------------------------------------- -BUILDIN_FUNC(sscanf){ +BUILDIN(sscanf){ unsigned int argc, arg = 0, len; struct script_data* data; struct map_session_data* sd = NULL; @@ -14036,15 +13703,15 @@ BUILDIN_FUNC(sscanf){ char* buf_p; char* ref_str = NULL; int ref_int; - + // Get data str = script_getstr(st, 2); format = script_getstr(st, 3); argc = script_lastdata(st)-3; - + len = strlen(format); CREATE(buf, char, len*2+1); - + // Issue sscanf for each parameter *buf = 0; q = format; @@ -14064,7 +13731,7 @@ BUILDIN_FUNC(sscanf){ script_pushint(st, -1); if(buf) aFree(buf); if(ref_str) aFree(ref_str); - return 1; + return false; } if((p = strchr(q+1, '%'))==NULL){ p = strchr(q, 0); // EOS @@ -14072,7 +13739,7 @@ BUILDIN_FUNC(sscanf){ len = p-q; strncat(buf, q, len); q = p; - + // Validate output data = script_getdata(st, arg+4); if(!data_isreference(data) || !reference_tovariable(data)){ @@ -14080,16 +13747,16 @@ BUILDIN_FUNC(sscanf){ script_pushint(st, -1); if(buf) aFree(buf); if(ref_str) aFree(ref_str); - return 1; + return false; } buf_p = reference_getname(data); if(not_server_variable(*buf_p) && (sd = script_rid2sd(st))==NULL){ script_pushint(st, -1); if(buf) aFree(buf); if(ref_str) aFree(ref_str); - return 0; + return true; } - + // Save value if any if(buf_p[strlen(buf_p)-1]=='$'){ // String if(ref_str==NULL){ @@ -14098,26 +13765,26 @@ BUILDIN_FUNC(sscanf){ if(sscanf(str, buf, ref_str)==0){ break; } - set_reg(st, sd, add_str(buf_p), buf_p, (void *)(ref_str), reference_getref(data)); - }else{ // Number + set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data)); + } else { // Number if(sscanf(str, buf, &ref_int)==0){ break; } - set_reg(st, sd, add_str(buf_p), buf_p, (void *)__64BPRTSIZE(ref_int), reference_getref(data)); + set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)__64BPTRSIZE(ref_int), reference_getref(data)); } arg++; - + // Disable used format (%... -> %*...) buf_p = strchr(buf, 0); memmove(buf_p-len+2, buf_p-len+1, len); *(buf_p-len+1) = '*'; } - + script_pushint(st, arg); if(buf) aFree(buf); if(ref_str) aFree(ref_str); - - return 0; + + return true; } //======================================================= @@ -14127,22 +13794,22 @@ BUILDIN_FUNC(sscanf){ // Implements PHP style strpos. Adapted from code from // http://www.daniweb.com/code/snippet313.html, Dave Sinkula //------------------------------------------------------- -BUILDIN_FUNC(strpos) { +BUILDIN(strpos) { const char *haystack = script_getstr(st,2); const char *needle = script_getstr(st,3); int i; size_t len; - + if( script_hasdata(st,4) ) i = script_getnum(st,4); else i = 0; - + if (needle[0] == '\0') { script_pushint(st, -1); - return 0; + return true; } - + len = strlen(haystack); for ( ; i < len; ++i ) { if ( haystack[i] == *needle ) { @@ -14155,12 +13822,12 @@ BUILDIN_FUNC(strpos) { } if ( !*n ) { // matched all of 'needle' to null termination script_pushint(st, i); - return 0; + return true; } } } script_pushint(st, -1); - return 0; + return true; } //=============================================================== @@ -14171,7 +13838,7 @@ BUILDIN_FUNC(strpos) { // instances as specified in <count>. By default will be case // sensitive. //--------------------------------------------------------------- -BUILDIN_FUNC(replacestr) +BUILDIN(replacestr) { const char *input = script_getstr(st, 2); const char *find = script_getstr(st, 3); @@ -14180,73 +13847,73 @@ BUILDIN_FUNC(replacestr) size_t findlen = strlen(find); struct StringBuf output; bool usecase = true; - + int count = 0; int numFinds = 0; int i = 0, f = 0; - + if(findlen == 0) { ShowError("script:replacestr: Invalid search length.\n"); st->state = END; - return 1; + return false; } - + if(script_hasdata(st, 5)) { if( !script_isstring(st,5) ) usecase = script_getnum(st, 5) != 0; else { ShowError("script:replacestr: Invalid usecase value. Expected int got string\n"); st->state = END; - return 1; + return false; } } - + if(script_hasdata(st, 6)) { count = script_getnum(st, 6); if(count == 0) { ShowError("script:replacestr: Invalid count value. Expected int got string\n"); st->state = END; - return 1; + return false; } } - - StringBuf_Init(&output); - + + StrBuf->Init(&output); + for(; i < inputlen; i++) { if(count && count == numFinds) { //found enough, stop looking break; } - + for(f = 0; f <= findlen; f++) { if(f == findlen) { //complete match numFinds++; - StringBuf_AppendStr(&output, replace); - + StrBuf->AppendStr(&output, replace); + i += findlen - 1; break; } else { if(usecase) { if((i + f) > inputlen || input[i + f] != find[f]) { - StringBuf_Printf(&output, "%c", input[i]); + StrBuf->Printf(&output, "%c", input[i]); break; } } else { if(((i + f) > inputlen || input[i + f] != find[f]) && TOUPPER(input[i+f]) != TOUPPER(find[f])) { - StringBuf_Printf(&output, "%c", input[i]); + StrBuf->Printf(&output, "%c", input[i]); break; } } } } } - + //append excess after enough found if(i < inputlen) - StringBuf_AppendStr(&output, &(input[i])); - - script_pushstrcopy(st, StringBuf_Value(&output)); - StringBuf_Destroy(&output); - return 0; + StrBuf->AppendStr(&output, &(input[i])); + + script_pushstrcopy(st, StrBuf->Value(&output)); + StrBuf->Destroy(&output); + return true; } //======================================================== @@ -14255,33 +13922,33 @@ BUILDIN_FUNC(replacestr) // Note: Counts the number of times <search> occurs in // <input>. By default will be case sensitive. //-------------------------------------------------------- -BUILDIN_FUNC(countstr) +BUILDIN(countstr) { const char *input = script_getstr(st, 2); const char *find = script_getstr(st, 3); size_t inputlen = strlen(input); size_t findlen = strlen(find); bool usecase = true; - + int numFinds = 0; int i = 0, f = 0; - + if(findlen == 0) { ShowError("script:countstr: Invalid search length.\n"); st->state = END; - return 1; + return false; } - + if(script_hasdata(st, 4)) { if( !script_isstring(st,4) ) usecase = script_getnum(st, 4) != 0; else { ShowError("script:countstr: Invalid usecase value. Expected int got string\n"); st->state = END; - return 1; + return false; } } - + for(; i < inputlen; i++) { for(f = 0; f <= findlen; f++) { if(f == findlen) { //complete match @@ -14302,7 +13969,7 @@ BUILDIN_FUNC(countstr) } } script_pushint(st, numFinds); - return 0; + return true; } @@ -14313,158 +13980,158 @@ BUILDIN_FUNC(countstr) /// setnpcdisplay("<npc name>", "<new display name>", <new class id>) -> <int> /// setnpcdisplay("<npc name>", "<new display name>") -> <int> /// setnpcdisplay("<npc name>", <new class id>) -> <int> -BUILDIN_FUNC(setnpcdisplay) +BUILDIN(setnpcdisplay) { const char* name; const char* newname = NULL; int class_ = -1, size = -1; struct script_data* data; struct npc_data* nd; - + name = script_getstr(st,2); data = script_getdata(st,3); - + if( script_hasdata(st,4) ) class_ = script_getnum(st,4); if( script_hasdata(st,5) ) size = script_getnum(st,5); - + get_val(st, data); if( data_isstring(data) ) - newname = conv_str(st,data); + newname = script->conv_str(st,data); else if( data_isint(data) ) - class_ = conv_num(st,data); + class_ = script->conv_num(st,data); else { ShowError("script:setnpcdisplay: expected a string or number\n"); script_reportdata(data); - return 1; + return false; } - + nd = npc_name2id(name); if( nd == NULL ) {// not found script_pushint(st,1); - return 0; + return true; } - + // update npc if( newname ) npc_setdisplayname(nd, newname); - + if( size != -1 && size != (int)nd->size ) nd->size = size; else size = -1; - + if( class_ != -1 && nd->class_ != class_ ) npc_setclass(nd, class_); else if( size != -1 ) { // Required to update the visual size - clif_clearunit_area(&nd->bl, CLR_OUTSIGHT); - clif_spawn(&nd->bl); + clif->clearunit_area(&nd->bl, CLR_OUTSIGHT); + clif->spawn(&nd->bl); } - + script_pushint(st,0); - return 0; + return true; } -BUILDIN_FUNC(atoi) +BUILDIN(atoi) { const char *value; value = script_getstr(st,2); script_pushint(st,atoi(value)); - return 0; + return true; } // case-insensitive substring search [lordalfa] -BUILDIN_FUNC(compare) +BUILDIN(compare) { const char *message; const char *cmpstring; message = script_getstr(st,2); cmpstring = script_getstr(st,3); script_pushint(st,(stristr(message,cmpstring) != NULL)); - return 0; + return true; } // [zBuffer] List of mathematics commands ---> -BUILDIN_FUNC(sqrt) +BUILDIN(sqrt) { double i, a; i = script_getnum(st,2); a = sqrt(i); script_pushint(st,(int)a); - return 0; + return true; } -BUILDIN_FUNC(pow) +BUILDIN(pow) { double i, a, b; a = script_getnum(st,2); b = script_getnum(st,3); i = pow(a,b); script_pushint(st,(int)i); - return 0; + return true; } -BUILDIN_FUNC(distance) +BUILDIN(distance) { int x0, y0, x1, y1; - + x0 = script_getnum(st,2); y0 = script_getnum(st,3); x1 = script_getnum(st,4); y1 = script_getnum(st,5); - + script_pushint(st,distance_xy(x0,y0,x1,y1)); - return 0; + return true; } // <--- [zBuffer] List of mathematics commands -BUILDIN_FUNC(md5) +BUILDIN(md5) { const char *tmpstr; char *md5str; - + tmpstr = script_getstr(st,2); md5str = (char *)aMalloc((32+1)*sizeof(char)); MD5_String(tmpstr, md5str); script_pushstr(st, md5str); - return 0; + return true; } // [zBuffer] List of dynamic var commands ---> -BUILDIN_FUNC(setd) +BUILDIN(setd) { TBL_PC *sd=NULL; char varname[100]; const char *buffer; int elem; buffer = script_getstr(st, 2); - + if(sscanf(buffer, "%99[^[][%d]", varname, &elem) < 2) elem = 0; - + if( not_server_variable(*varname) ) { sd = script_rid2sd(st); if( sd == NULL ) { ShowError("script:setd: no player attached for player variable '%s'\n", buffer); - return 0; + return true; } } - + if( is_string_variable(varname) ) { setd_sub(st, sd, varname, elem, (void *)script_getstr(st, 3), NULL); } else { - setd_sub(st, sd, varname, elem, (void *)__64BPRTSIZE(script_getnum(st, 3)), NULL); + setd_sub(st, sd, varname, elem, (void *)__64BPTRSIZE(script_getnum(st, 3)), NULL); } - - return 0; + + return true; } int buildin_query_sql_sub(struct script_state* st, Sql* handle) @@ -14477,7 +14144,7 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) int max_rows = SCRIPT_MAX_ARRAYSIZE; // maximum number of rows int num_vars; int num_cols; - + // check target variables for( i = 3; script_hasdata(st,i); ++i ) { data = script_getdata(st, i); @@ -14488,7 +14155,7 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) if( sd == NULL ) { // no player attached script_reportdata(data); st->state = END; - return 1; + return false; } } if( not_array_variable(*name) ) @@ -14497,28 +14164,28 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) ShowError("script:query_sql: not a variable\n"); script_reportdata(data); st->state = END; - return 1; + return false; } } num_vars = i - 3; - + // Execute the query query = script_getstr(st,2); - - if( SQL_ERROR == Sql_QueryStr(handle, query) ) { + + if( SQL_ERROR == SQL->QueryStr(handle, query) ) { Sql_ShowDebug(handle); script_pushint(st, 0); - return 1; + return false; } - - if( Sql_NumRows(handle) == 0 ) { // No data received - Sql_FreeResult(handle); + + if( SQL->NumRows(handle) == 0 ) { // No data received + SQL->FreeResult(handle); script_pushint(st, 0); - return 0; + return true; } - + // Count the number of columns to store - num_cols = Sql_NumColumns(handle); + num_cols = SQL->NumColumns(handle); if( num_vars < num_cols ) { ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars)); script_reportsrc(st); @@ -14526,105 +14193,82 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) ShowWarning("script:query_sql: Too many variables (%u extra).\n", (unsigned int)(num_vars-num_cols)); script_reportsrc(st); } - + // Store data - for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(handle); ++i ) { + for( i = 0; i < max_rows && SQL_SUCCESS == SQL->NextRow(handle); ++i ) { for( j = 0; j < num_vars; ++j ) { char* str = NULL; - + if( j < num_cols ) - Sql_GetData(handle, j, &str, NULL); - + SQL->GetData(handle, j, &str, NULL); + data = script_getdata(st, j+3); name = reference_getname(data); if( is_string_variable(name) ) setd_sub(st, sd, name, i, (void *)(str?str:""), reference_getref(data)); else - setd_sub(st, sd, name, i, (void *)__64BPRTSIZE((str?atoi(str):0)), reference_getref(data)); + setd_sub(st, sd, name, i, (void *)__64BPTRSIZE((str?atoi(str):0)), reference_getref(data)); } } - if( i == max_rows && max_rows < Sql_NumRows(handle) ) { - ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(handle)); + if( i == max_rows && max_rows < SQL->NumRows(handle) ) { + ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)SQL->NumRows(handle)); script_reportsrc(st); } - + // Free data - Sql_FreeResult(handle); + SQL->FreeResult(handle); script_pushint(st, i); - - return 0; + + return true; } - -BUILDIN_FUNC(query_sql) { -#ifdef BETA_THREAD_TEST - if( st->state != RERUNLINE ) { - queryThread_add(st,false); - - st->state = RERUNLINE;/* will continue when the query is finished running. */ - } else - st->state = RUN; - - return 0; -#else +BUILDIN(query_sql) { return buildin_query_sql_sub(st, mmysql_handle); -#endif } -BUILDIN_FUNC(query_logsql) { - if( !log_config.sql_logs ) {// logmysql_handle == NULL +BUILDIN(query_logsql) { + if( !logs->config.sql_logs ) {// logmysql_handle == NULL ShowWarning("buildin_query_logsql: SQL logs are disabled, query '%s' will not be executed.\n", script_getstr(st,2)); script_pushint(st,-1); - return 1; + return false; } -#ifdef BETA_THREAD_TEST - if( st->state != RERUNLINE ) { - queryThread_add(st,true); - - st->state = RERUNLINE;/* will continue when the query is finished running. */ - } else - st->state = RUN; - - return 0; -#else return buildin_query_sql_sub(st, logmysql_handle); -#endif } //Allows escaping of a given string. -BUILDIN_FUNC(escape_sql) +BUILDIN(escape_sql) { const char *str; char *esc_str; size_t len; - + str = script_getstr(st,2); len = strlen(str); esc_str = (char*)aMalloc(len*2+1); - Sql_EscapeStringLen(mmysql_handle, esc_str, str, len); + SQL->EscapeStringLen(mmysql_handle, esc_str, str, len); script_pushstr(st, esc_str); - return 0; + return true; } -BUILDIN_FUNC(getd) +BUILDIN(getd) { char varname[100]; const char *buffer; int elem; - + buffer = script_getstr(st, 2); - + if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2) elem = 0; - + // Push the 'pointer' so it's more flexible [Lance] push_val(st->stack, C_NAME, reference_uid(add_str(varname), elem)); - - return 0; + + return true; } // <--- [zBuffer] List of dynamic var commands // Pet stat [Lance] -BUILDIN_FUNC(petstat) +BUILDIN(petstat) { TBL_PC *sd = NULL; struct pet_data *pd; @@ -14635,7 +14279,7 @@ BUILDIN_FUNC(petstat) script_pushconststr(st, ""); else script_pushint(st,0); - return 0; + return true; } pd = sd->pd; switch(flag){ @@ -14648,10 +14292,10 @@ BUILDIN_FUNC(petstat) script_pushint(st,0); break; } - return 0; + return true; } -BUILDIN_FUNC(callshop) +BUILDIN(callshop) { TBL_PC *sd = NULL; struct npc_data *nd; @@ -14660,7 +14304,7 @@ BUILDIN_FUNC(callshop) sd = script_rid2sd(st); if (!sd) { script_pushint(st,0); - return 0; + return true; } shopname = script_getstr(st, 2); if( script_hasdata(st,3) ) @@ -14670,45 +14314,45 @@ BUILDIN_FUNC(callshop) { ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)\n", shopname); script_pushint(st,0); - return 1; + return false; } - + if( nd->subtype == SHOP ) { // flag the user as using a valid script call for opening the shop (for floating NPCs) sd->state.callshop = 1; - + switch( flag ) { case 1: npc_buysellsel(sd,nd->bl.id,0); break; //Buy window case 2: npc_buysellsel(sd,nd->bl.id,1); break; //Sell window - default: clif_npcbuysell(sd,nd->bl.id); break; //Show menu + default: clif->npcbuysell(sd,nd->bl.id); break; //Show menu } } else - clif_cashshop_show(sd, nd); - + clif->cashshop_show(sd, nd); + sd->npc_shopid = nd->bl.id; script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(npcshopitem) +BUILDIN(npcshopitem) { const char* npcname = script_getstr(st, 2); struct npc_data* nd = npc_name2id(npcname); int n, i; int amount; - + if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP ) ) { //Not found. script_pushint(st,0); - return 0; + return true; } - + // get the count of new entries amount = (script_lastdata(st)-2)/2; - + // generate new shop item list RECREATE(nd->u.shop.shop_item, struct npc_item_list, amount); for( n = 0, i = 3; n < amount; n++, i+=2 ) @@ -14717,27 +14361,27 @@ BUILDIN_FUNC(npcshopitem) nd->u.shop.shop_item[n].value = script_getnum(st,i+1); } nd->u.shop.count = n; - + script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(npcshopadditem) +BUILDIN(npcshopadditem) { const char* npcname = script_getstr(st,2); struct npc_data* nd = npc_name2id(npcname); int n, i; int amount; - + if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP ) ) { //Not found. script_pushint(st,0); - return 0; + return true; } - + // get the count of new entries amount = (script_lastdata(st)-2)/2; - + // append new items to existing shop item list RECREATE(nd->u.shop.shop_item, struct npc_item_list, nd->u.shop.count+amount); for( n = nd->u.shop.count, i = 3; n < nd->u.shop.count+amount; n++, i+=2 ) @@ -14746,12 +14390,12 @@ BUILDIN_FUNC(npcshopadditem) nd->u.shop.shop_item[n].value = script_getnum(st,i+1); } nd->u.shop.count = n; - + script_pushint(st,1); - return 0; + return true; } -BUILDIN_FUNC(npcshopdelitem) +BUILDIN(npcshopdelitem) { const char* npcname = script_getstr(st,2); struct npc_data* nd = npc_name2id(npcname); @@ -14759,21 +14403,21 @@ BUILDIN_FUNC(npcshopdelitem) int n, i; int amount; int size; - + if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP ) ) { //Not found. script_pushint(st,0); - return 0; + return true; } - + amount = script_lastdata(st)-2; size = nd->u.shop.count; - + // remove specified items from the shop item list for( i = 3; i < 3 + amount; i++ ) { nameid = script_getnum(st,i); - + ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == nameid ); if( n < size ) { @@ -14781,121 +14425,121 @@ BUILDIN_FUNC(npcshopdelitem) size--; } } - + RECREATE(nd->u.shop.shop_item, struct npc_item_list, size); nd->u.shop.count = size; - + script_pushint(st,1); - return 0; + return true; } //Sets a script to attach to a shop npc. -BUILDIN_FUNC(npcshopattach) +BUILDIN(npcshopattach) { const char* npcname = script_getstr(st,2); struct npc_data* nd = npc_name2id(npcname); int flag = 1; - + if( script_hasdata(st,3) ) flag = script_getnum(st,3); - + if( !nd || nd->subtype != SHOP ) { //Not found. script_pushint(st,0); - return 0; + return true; } - + if (flag) nd->master_nd = ((struct npc_data *)map_id2bl(st->oid)); else nd->master_nd = NULL; - + script_pushint(st,1); - return 0; + return true; } /*========================================== * Returns some values of an item [Lupus] * Price, Weight, etc... - setitemscript(itemID,"{new item bonus script}",[n]); - Where n: - 0 - script - 1 - Equip script - 2 - Unequip script + setitemscript(itemID,"{new item bonus script}",[n]); + Where n: + 0 - script + 1 - Equip script + 2 - Unequip script *------------------------------------------*/ -BUILDIN_FUNC(setitemscript) +BUILDIN(setitemscript) { int item_id,n=0; - const char *script; + const char *new_bonus_script; struct item_data *i_data; struct script_code **dstscript; - + item_id = script_getnum(st,2); - script = script_getstr(st,3); + new_bonus_script = script_getstr(st,3); if( script_hasdata(st,4) ) n=script_getnum(st,4); i_data = itemdb_exists(item_id); - - if (!i_data || script==NULL || ( script[0] && script[0]!='{' )) { + + if (!i_data || new_bonus_script==NULL || ( new_bonus_script[0] && new_bonus_script[0]!='{' )) { script_pushint(st,0); - return 0; + return true; } switch (n) { - case 2: - dstscript = &i_data->unequip_script; - break; - case 1: - dstscript = &i_data->equip_script; - break; - default: - dstscript = &i_data->script; - break; + case 2: + dstscript = &i_data->unequip_script; + break; + case 1: + dstscript = &i_data->equip_script; + break; + default: + dstscript = &i_data->script; + break; } if(*dstscript) script_free_code(*dstscript); - - *dstscript = script[0] ? parse_script(script, "script_setitemscript", 0, 0) : NULL; + + *dstscript = new_bonus_script[0] ? parse_script(new_bonus_script, "script_setitemscript", 0, 0) : NULL; script_pushint(st,1); - return 0; + return true; } /* Work In Progress [Lupus] -BUILDIN_FUNC(addmonsterdrop) -{ - int class_,item_id,chance; - class_=script_getnum(st,2); - item_id=script_getnum(st,3); - chance=script_getnum(st,4); - if(class_>1000 && item_id>500 && chance>0) { - script_pushint(st,1); - } else { - script_pushint(st,0); - } -} - -BUILDIN_FUNC(delmonsterdrop) -{ - int class_,item_id; - class_=script_getnum(st,2); - item_id=script_getnum(st,3); - if(class_>1000 && item_id>500) { - script_pushint(st,1); - } else { - script_pushint(st,0); - } -} -*/ + BUILDIN(addmonsterdrop) + { + int class_,item_id,chance; + class_=script_getnum(st,2); + item_id=script_getnum(st,3); + chance=script_getnum(st,4); + if(class_>1000 && item_id>500 && chance>0) { + script_pushint(st,1); + } else { + script_pushint(st,0); + } + } + + BUILDIN(delmonsterdrop) + { + int class_,item_id; + class_=script_getnum(st,2); + item_id=script_getnum(st,3); + if(class_>1000 && item_id>500) { + script_pushint(st,1); + } else { + script_pushint(st,0); + } + } + */ /*========================================== * Returns some values of a monster [Lupus] * Name, Level, race, size, etc... - getmonsterinfo(monsterID,queryIndex); + getmonsterinfo(monsterID,queryIndex); *------------------------------------------*/ -BUILDIN_FUNC(getmonsterinfo) +BUILDIN(getmonsterinfo) { struct mob_db *mob; int mob_id; - + mob_id = script_getnum(st,2); if (!mobdb_checkid(mob_id)) { ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i\n", mob_id); @@ -14932,77 +14576,94 @@ BUILDIN_FUNC(getmonsterinfo) case 22: script_pushint(st,mob->mexp); break; default: script_pushint(st,-1); //wrong Index } - return 0; + return true; } -BUILDIN_FUNC(checkvending) // check vending [Nab4] +BUILDIN(checkvending) // check vending [Nab4] { TBL_PC *sd = NULL; - + if(script_hasdata(st,2)) sd = map_nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); - + if(sd) script_pushint(st, sd->state.autotrade ? 2 : sd->state.vending); else script_pushint(st,0); - - return 0; + + return true; } -BUILDIN_FUNC(checkchatting) // check chatting [Marka] +BUILDIN(checkchatting) // check chatting [Marka] { TBL_PC *sd = NULL; - + if(script_hasdata(st,2)) sd = map_nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); - + if(sd) script_pushint(st,(sd->chatID != 0)); else script_pushint(st,0); + + return true; +} - return 0; +BUILDIN(checkidle) +{ + TBL_PC *sd = NULL; + + if (script_hasdata(st, 2)) + sd = map_nick2sd(script_getstr(st, 2)); + else + sd = script_rid2sd(st); + + if (sd) + script_pushint(st, DIFF_TICK(last_tick, sd->idletime)); + else + script_pushint(st, 0); + + return true; } -BUILDIN_FUNC(searchitem) +BUILDIN(searchitem) { struct script_data* data = script_getdata(st, 2); const char *itemname = script_getstr(st,3); struct item_data *items[MAX_SEARCH]; int count; - + char* name; int32 start; int32 id; int32 i; TBL_PC* sd = NULL; - + if ((items[0] = itemdb_exists(atoi(itemname)))) count = 1; else { count = itemdb_searchname_array(items, ARRAYLENGTH(items), itemname); if (count > MAX_SEARCH) count = MAX_SEARCH; } - + if (!count) { script_pushint(st, 0); - return 0; + return true; } - + if( !data_isreference(data) ) { ShowError("script:searchitem: not a variable\n"); script_reportdata(data); st->state = END; - return 1;// not a variable + return false;// not a variable } - + id = reference_getid(data); start = reference_getindex(data); name = reference_getname(data); @@ -15011,32 +14672,32 @@ BUILDIN_FUNC(searchitem) ShowError("script:searchitem: illegal scope\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) - return 0;// no player attached + return true;// no player attached } - + if( is_string_variable(name) ) {// string array ShowError("script:searchitem: not an integer array reference\n"); script_reportdata(data); st->state = END; - return 1;// not supported + return false;// not supported } - + for( i = 0; i < count; ++start, ++i ) {// Set array - void* v = (void*)__64BPRTSIZE((int)items[i]->nameid); + void* v = (void*)__64BPTRSIZE((int)items[i]->nameid); set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data)); } - + script_pushint(st, count); - return 0; + return true; } int axtoi(const char *hexStg) @@ -15073,15 +14734,15 @@ int axtoi(const char *hexStg) } // [Lance] Hex string to integer converter -BUILDIN_FUNC(axtoi) +BUILDIN(axtoi) { const char *hex = script_getstr(st,2); script_pushint(st,axtoi(hex)); - return 0; + return true; } // [zBuffer] List of player cont commands ---> -BUILDIN_FUNC(rid2name) +BUILDIN(rid2name) { struct block_list *bl = NULL; int rid = script_getnum(st,2); @@ -15103,65 +14764,65 @@ BUILDIN_FUNC(rid2name) ShowError("buildin_rid2name: invalid RID\n"); script_pushconststr(st,"(null)"); } - return 0; + return true; } -BUILDIN_FUNC(pcblockmove) +BUILDIN(pcblockmove) { int id, flag; TBL_PC *sd = NULL; - + id = script_getnum(st,2); flag = script_getnum(st,3); - + if(id) sd = map_id2sd(id); else sd = script_rid2sd(st); - + if(sd) sd->state.blockedmove = flag > 0; - - return 0; + + return true; } -BUILDIN_FUNC(pcfollow) +BUILDIN(pcfollow) { int id, targetid; TBL_PC *sd = NULL; - - + + id = script_getnum(st,2); targetid = script_getnum(st,3); - + if(id) sd = map_id2sd(id); else sd = script_rid2sd(st); - + if(sd) pc_follow(sd, targetid); - - return 0; + + return true; } -BUILDIN_FUNC(pcstopfollow) +BUILDIN(pcstopfollow) { int id; TBL_PC *sd = NULL; - - + + id = script_getnum(st,2); - + if(id) sd = map_id2sd(id); else sd = script_rid2sd(st); - + if(sd) pc_stop_following(sd); - - return 0; + + return true; } // <--- [zBuffer] List of player cont commands // [zBuffer] List of mob control commands ---> @@ -15172,10 +14833,10 @@ BUILDIN_FUNC(pcstopfollow) /// /// unitwalk(<unit_id>,<x>,<y>) -> <bool> /// unitwalk(<unit_id>,<map_id>) -> <bool> -BUILDIN_FUNC(unitwalk) +BUILDIN(unitwalk) { struct block_list* bl; - + bl = map_id2bl(script_getnum(st,2)); if( bl == NULL ) { @@ -15192,27 +14853,27 @@ BUILDIN_FUNC(unitwalk) int map_id = script_getnum(st,3); script_pushint(st, unit_walktobl(bl,map_id2bl(map_id),65025,1)); } - - return 0; + + return true; } /// Kills the unit /// /// unitkill <unit_id>; -BUILDIN_FUNC(unitkill) +BUILDIN(unitkill) { struct block_list* bl = map_id2bl(script_getnum(st,2)); if( bl != NULL ) status_kill(bl); - - return 0; + + return true; } /// Warps the unit to the target position in the target map /// Returns if it was successfull /// /// unitwarp(<unit_id>,"<map name>",<x>,<y>) -> <bool> -BUILDIN_FUNC(unitwarp) +BUILDIN(unitwarp) { int unit_id; int map; @@ -15220,28 +14881,28 @@ BUILDIN_FUNC(unitwarp) short y; struct block_list* bl; const char *mapname; - + unit_id = script_getnum(st,2); mapname = script_getstr(st, 3); x = (short)script_getnum(st,4); y = (short)script_getnum(st,5); - + if (!unit_id) //Warp the script's runner bl = map_id2bl(st->rid); else bl = map_id2bl(unit_id); - + if( strcmp(mapname,"this") == 0 ) map = bl?bl->m:-1; else map = map_mapname2mapid(mapname); - + if( map >= 0 && bl != NULL ) script_pushint(st, unit_warp(bl,map,x,y,CLR_OUTSIGHT)); else script_pushint(st, 0); - - return 0; + + return true; } /// Makes the unit attack the target. @@ -15251,71 +14912,71 @@ BUILDIN_FUNC(unitwarp) /// /// unitattack(<unit_id>,"<target name>"{,<action type>}) -> <bool> /// unitattack(<unit_id>,<target_id>{,<action type>}) -> <bool> -BUILDIN_FUNC(unitattack) +BUILDIN(unitattack) { struct block_list* unit_bl; struct block_list* target_bl = NULL; struct script_data* data; int actiontype = 0; - + // get unit unit_bl = map_id2bl(script_getnum(st,2)); if( unit_bl == NULL ) { script_pushint(st, 0); - return 0; + return true; } - + data = script_getdata(st, 3); get_val(st, data); if( data_isstring(data) ) { - TBL_PC* sd = map_nick2sd(conv_str(st, data)); + TBL_PC* sd = map_nick2sd(script->conv_str(st, data)); if( sd != NULL ) target_bl = &sd->bl; } else - target_bl = map_id2bl(conv_num(st, data)); + target_bl = map_id2bl(script->conv_num(st, data)); // request the attack if( target_bl == NULL ) { script_pushint(st, 0); - return 0; + return true; } - + // get actiontype if( script_hasdata(st,4) ) actiontype = script_getnum(st,4); - + switch( unit_bl->type ) { - case BL_PC: - clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick()); - script_pushint(st, 1); - return 0; - case BL_MOB: - ((TBL_MOB *)unit_bl)->target_id = target_bl->id; - break; - case BL_PET: - ((TBL_PET *)unit_bl)->target_id = target_bl->id; - break; - default: - ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type); - script_pushint(st, 0); - return 1; + case BL_PC: + clif->pActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick()); + script_pushint(st, 1); + return true; + case BL_MOB: + ((TBL_MOB *)unit_bl)->target_id = target_bl->id; + break; + case BL_PET: + ((TBL_PET *)unit_bl)->target_id = target_bl->id; + break; + default: + ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type); + script_pushint(st, 0); + return false; } script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2)); - return 0; + return true; } /// Makes the unit stop attacking and moving /// /// unitstop <unit_id>; -BUILDIN_FUNC(unitstop) +BUILDIN(unitstop) { int unit_id; struct block_list* bl; - + unit_id = script_getnum(st,2); - + bl = map_id2bl(unit_id); if( bl != NULL ) { @@ -15324,35 +14985,35 @@ BUILDIN_FUNC(unitstop) if( bl->type == BL_MOB ) ((TBL_MOB*)bl)->target_id = 0; } - - return 0; + + return true; } /// Makes the unit say the message /// /// unittalk <unit_id>,"<message>"; -BUILDIN_FUNC(unittalk) +BUILDIN(unittalk) { int unit_id; const char* message; struct block_list* bl; - + unit_id = script_getnum(st,2); message = script_getstr(st, 3); - + bl = map_id2bl(unit_id); if( bl != NULL ) { struct StringBuf sbuf; - StringBuf_Init(&sbuf); - StringBuf_Printf(&sbuf, "%s : %s", status_get_name(bl), message); - clif_message(bl, StringBuf_Value(&sbuf)); + StrBuf->Init(&sbuf); + StrBuf->Printf(&sbuf, "%s : %s", status_get_name(bl), message); + clif->disp_overhead(bl, StrBuf->Value(&sbuf)); if( bl->type == BL_PC ) - clif_displaymessage(((TBL_PC*)bl)->fd, StringBuf_Value(&sbuf)); - StringBuf_Destroy(&sbuf); + clif->message(((TBL_PC*)bl)->fd, StrBuf->Value(&sbuf)); + StrBuf->Destroy(&sbuf); } - - return 0; + + return true; } /// Makes the unit do an emotion @@ -15360,50 +15021,50 @@ BUILDIN_FUNC(unittalk) /// unitemote <unit_id>,<emotion>; /// /// @see e_* in const.txt -BUILDIN_FUNC(unitemote) +BUILDIN(unitemote) { int unit_id; int emotion; struct block_list* bl; - + unit_id = script_getnum(st,2); emotion = script_getnum(st,3); bl = map_id2bl(unit_id); if( bl != NULL ) - clif_emotion(bl, emotion); - - return 0; + clif->emotion(bl, emotion); + + return true; } /// Makes the unit cast the skill on the target or self if no target is specified /// /// unitskilluseid <unit_id>,<skill_id>,<skill_lv>{,<target_id>}; /// unitskilluseid <unit_id>,"<skill name>",<skill_lv>{,<target_id>}; -BUILDIN_FUNC(unitskilluseid) +BUILDIN(unitskilluseid) { int unit_id; uint16 skill_id; uint16 skill_lv; int target_id; struct block_list* bl; - + unit_id = script_getnum(st,2); - skill_id = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) ); + skill_id = ( script_isstring(st,3) ? skill->name2id(script_getstr(st,3)) : script_getnum(st,3) ); skill_lv = script_getnum(st,4); target_id = ( script_hasdata(st,5) ? script_getnum(st,5) : unit_id ); - + bl = map_id2bl(unit_id); if( bl != NULL ) unit_skilluse_id(bl, target_id, skill_id, skill_lv); - - return 0; + + return true; } /// Makes the unit cast the skill on the target position. /// /// unitskillusepos <unit_id>,<skill_id>,<skill_lv>,<target_x>,<target_y>; /// unitskillusepos <unit_id>,"<skill name>",<skill_lv>,<target_x>,<target_y>; -BUILDIN_FUNC(unitskillusepos) +BUILDIN(unitskillusepos) { int unit_id; uint16 skill_id; @@ -15411,18 +15072,18 @@ BUILDIN_FUNC(unitskillusepos) int skill_x; int skill_y; struct block_list* bl; - + unit_id = script_getnum(st,2); - skill_id = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) ); + skill_id = ( script_isstring(st,3) ? skill->name2id(script_getstr(st,3)) : script_getnum(st,3) ); skill_lv = script_getnum(st,4); skill_x = script_getnum(st,5); skill_y = script_getnum(st,6); - + bl = map_id2bl(unit_id); if( bl != NULL ) unit_skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv); - - return 0; + + return true; } // <--- [zBuffer] List of mob control commands @@ -15430,15 +15091,15 @@ BUILDIN_FUNC(unitskillusepos) /// Pauses the execution of the script, detaching the player /// /// sleep <mili seconds>; -BUILDIN_FUNC(sleep) +BUILDIN(sleep) { int ticks; - + ticks = script_getnum(st,2); - + // detach the player script_detach_rid(st); - + if( ticks <= 0 ) {// do nothing } @@ -15452,19 +15113,19 @@ BUILDIN_FUNC(sleep) st->state = RUN; st->sleep.tick = 0; } - return 0; + return true; } /// Pauses the execution of the script, keeping the player attached /// Returns if a player is still attached /// /// sleep2(<mili secconds>) -> <bool> -BUILDIN_FUNC(sleep2) +BUILDIN(sleep2) { int ticks; - + ticks = script_getnum(st,2); - + if( ticks <= 0 ) {// do nothing script_pushint(st, (map_id2sd(st->rid)!=NULL)); @@ -15480,30 +15141,30 @@ BUILDIN_FUNC(sleep2) st->sleep.tick = 0; script_pushint(st, (map_id2sd(st->rid)!=NULL)); } - return 0; + return true; } /// Awakes all the sleep timers of the target npc /// /// awake "<npc name>"; -BUILDIN_FUNC(awake) +BUILDIN(awake) { struct npc_data* nd; struct linkdb_node *node = (struct linkdb_node *)sleep_db; - + nd = npc_name2id(script_getstr(st, 2)); if( nd == NULL ) { ShowError("awake: NPC \"%s\" not found\n", script_getstr(st, 2)); - return 1; + return false; } - + while( node ) { - if( (int)__64BPRTSIZE(node->key) == nd->bl.id ) + if( (int)__64BPTRSIZE(node->key) == nd->bl.id ) {// sleep timer for the npc struct script_state* tst = (struct script_state*)node->data; TBL_PC* sd = map_id2sd(tst->rid); - + if( tst->sleep.timer == INVALID_TIMER ) {// already awake ??? node = node->next; @@ -15514,7 +15175,7 @@ BUILDIN_FUNC(awake) tst->state = END; tst->rid = 0; } - + delete_timer(tst->sleep.timer, run_script_timer); node = script_erase_sleepdb(node); tst->sleep.timer = INVALID_TIMER; @@ -15527,19 +15188,19 @@ BUILDIN_FUNC(awake) node = node->next; } } - return 0; + return true; } /// Returns a reference to a variable of the target NPC. /// Returns 0 if an error occurs. /// /// getvariableofnpc(<variable>, "<npc name>") -> <reference> -BUILDIN_FUNC(getvariableofnpc) +BUILDIN(getvariableofnpc) { struct script_data* data; const char* name; struct npc_data* nd; - + data = script_getdata(st,2); if( !data_isreference(data) ) {// Not a reference (aka varaible name) @@ -15547,9 +15208,9 @@ BUILDIN_FUNC(getvariableofnpc) script_reportdata(data); script_pushnil(st); st->state = END; - return 1; + return false; } - + name = reference_getname(data); if( *name != '.' || name[1] == '@' ) {// not a npc variable @@ -15557,20 +15218,20 @@ BUILDIN_FUNC(getvariableofnpc) script_reportdata(data); script_pushnil(st); st->state = END; - return 1; + return false; } - + nd = npc_name2id(script_getstr(st,3)); if( nd == NULL || nd->subtype != SCRIPT || nd->u.scr.script == NULL ) {// NPC not found or has no script ShowError("script:getvariableofnpc: can't find npc %s\n", script_getstr(st,3)); script_pushnil(st); st->state = END; - return 1; + return false; } - + push_val2(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->script_vars ); - return 0; + return true; } /// Opens a warp portal. @@ -15579,7 +15240,7 @@ BUILDIN_FUNC(getvariableofnpc) /// warpportal <source x>,<source y>,"<target map>",<target x>,<target y>; /// /// @author blackhole89 -BUILDIN_FUNC(warpportal) +BUILDIN(warpportal) { int spx; int spy; @@ -15588,56 +15249,57 @@ BUILDIN_FUNC(warpportal) int tpy; struct skill_unit_group* group; struct block_list* bl; - + bl = map_id2bl(st->oid); if( bl == NULL ) { ShowError("script:warpportal: npc is needed\n"); - return 1; + return false; } - + spx = script_getnum(st,2); spy = script_getnum(st,3); mapindex = mapindex_name2id(script_getstr(st, 4)); tpx = script_getnum(st,5); tpy = script_getnum(st,6); - + if( mapindex == 0 ) - return 0;// map not found - - group = skill_unitsetting(bl, AL_WARP, 4, spx, spy, 0); + return true;// map not found + + group = skill->unitsetting(bl, AL_WARP, 4, spx, spy, 0); if( group == NULL ) - return 0;// failed + return true;// failed + group->val1 = (group->val1<<16)|(short)0; group->val2 = (tpx<<16) | tpy; group->val3 = mapindex; - - return 0; + + return true; } -BUILDIN_FUNC(openmail) +BUILDIN(openmail) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - + return true; + mail_openmail(sd); - - return 0; + + return true; } -BUILDIN_FUNC(openauction) +BUILDIN(openauction) { TBL_PC* sd; - + sd = script_rid2sd(st); if( sd == NULL ) - return 0; - - clif_Auction_openwindow(sd); - - return 0; + return true; + + clif->auction_openwindow(sd); + + return true; } /// Retrieves the value of the specified flag of the specified cell. @@ -15645,16 +15307,16 @@ BUILDIN_FUNC(openauction) /// checkcell("<map name>",<x>,<y>,<type>) -> <bool> /// /// @see cell_chk* constants in const.txt for the types -BUILDIN_FUNC(checkcell) +BUILDIN(checkcell) { int16 m = map_mapname2mapid(script_getstr(st,2)); int16 x = script_getnum(st,3); int16 y = script_getnum(st,4); cell_chk type = (cell_chk)script_getnum(st,5); - + script_pushint(st, map_getcell(m, x, y, type)); - - return 0; + + return true; } /// Modifies flags of cells in the specified area. @@ -15662,7 +15324,7 @@ BUILDIN_FUNC(checkcell) /// setcell "<map name>",<x1>,<y1>,<x2>,<y2>,<type>,<flag>; /// /// @see cell_* constants in const.txt for the types -BUILDIN_FUNC(setcell) +BUILDIN(setcell) { int16 m = map_mapname2mapid(script_getstr(st,2)); int16 x1 = script_getnum(st,3); @@ -15671,79 +15333,79 @@ BUILDIN_FUNC(setcell) int16 y2 = script_getnum(st,6); cell_t type = (cell_t)script_getnum(st,7); bool flag = (bool)script_getnum(st,8); - + int x,y; - + if( x1 > x2 ) swap(x1,x2); if( y1 > y2 ) swap(y1,y2); - + for( y = y1; y <= y2; ++y ) for( x = x1; x <= x2; ++x ) map_setcell(m, x, y, type, flag); - - return 0; + + return true; } /*========================================== * Mercenary Commands *------------------------------------------*/ -BUILDIN_FUNC(mercenary_create) +BUILDIN(mercenary_create) { struct map_session_data *sd; int class_, contract_time; - + if( (sd = script_rid2sd(st)) == NULL || sd->md || sd->status.mer_id != 0 ) - return 0; - + return true; + class_ = script_getnum(st,2); - + if( !merc_class(class_) ) - return 0; - + return true; + contract_time = script_getnum(st,3); merc_create(sd, class_, contract_time); - return 0; + return true; } -BUILDIN_FUNC(mercenary_heal) +BUILDIN(mercenary_heal) { struct map_session_data *sd = script_rid2sd(st); int hp, sp; - + if( sd == NULL || sd->md == NULL ) - return 0; + return true; hp = script_getnum(st,2); sp = script_getnum(st,3); - + status_heal(&sd->md->bl, hp, sp, 0); - return 0; + return true; } -BUILDIN_FUNC(mercenary_sc_start) +BUILDIN(mercenary_sc_start) { struct map_session_data *sd = script_rid2sd(st); enum sc_type type; int tick, val1; - + if( sd == NULL || sd->md == NULL ) - return 0; - + return true; + type = (sc_type)script_getnum(st,2); tick = script_getnum(st,3); val1 = script_getnum(st,4); - + status_change_start(&sd->md->bl, type, 10000, val1, 0, 0, 0, tick, 2); - return 0; + return true; } -BUILDIN_FUNC(mercenary_get_calls) +BUILDIN(mercenary_get_calls) { struct map_session_data *sd = script_rid2sd(st); int guild; - + if( sd == NULL ) - return 0; - + return true; + guild = script_getnum(st,2); switch( guild ) { @@ -15760,21 +15422,21 @@ BUILDIN_FUNC(mercenary_get_calls) script_pushint(st,0); break; } - - return 0; + + return true; } -BUILDIN_FUNC(mercenary_set_calls) +BUILDIN(mercenary_set_calls) { struct map_session_data *sd = script_rid2sd(st); int guild, value, *calls; - + if( sd == NULL ) - return 0; - + return true; + guild = script_getnum(st,2); value = script_getnum(st,3); - + switch( guild ) { case ARCH_MERC_GUILD: @@ -15787,23 +15449,23 @@ BUILDIN_FUNC(mercenary_set_calls) calls = &sd->status.sword_calls; break; default: - return 0; // Invalid Guild + return true; // Invalid Guild } - + *calls += value; *calls = cap_value(*calls, 0, INT_MAX); - - return 0; + + return true; } -BUILDIN_FUNC(mercenary_get_faith) +BUILDIN(mercenary_get_faith) { struct map_session_data *sd = script_rid2sd(st); int guild; - + if( sd == NULL ) - return 0; - + return true; + guild = script_getnum(st,2); switch( guild ) { @@ -15820,21 +15482,21 @@ BUILDIN_FUNC(mercenary_get_faith) script_pushint(st,0); break; } - - return 0; + + return true; } -BUILDIN_FUNC(mercenary_set_faith) +BUILDIN(mercenary_set_faith) { struct map_session_data *sd = script_rid2sd(st); int guild, value, *calls; - + if( sd == NULL ) - return 0; - + return true; + guild = script_getnum(st,2); value = script_getnum(st,3); - + switch( guild ) { case ARCH_MERC_GUILD: @@ -15847,130 +15509,130 @@ BUILDIN_FUNC(mercenary_set_faith) calls = &sd->status.sword_faith; break; default: - return 0; // Invalid Guild + return true; // Invalid Guild } - + *calls += value; *calls = cap_value(*calls, 0, INT_MAX); if( mercenary_get_guild(sd->md) == guild ) - clif_mercenary_updatestatus(sd,SP_MERCFAITH); - - return 0; + clif->mercenary_updatestatus(sd,SP_MERCFAITH); + + return true; } /*------------------------------------------ * Book Reading *------------------------------------------*/ -BUILDIN_FUNC(readbook) +BUILDIN(readbook) { struct map_session_data *sd; int book_id, page; - + if( (sd = script_rid2sd(st)) == NULL ) - return 0; - + return true; + book_id = script_getnum(st,2); page = script_getnum(st,3); - - clif_readbook(sd->fd, book_id, page); - return 0; + + clif->readbook(sd->fd, book_id, page); + return true; } /****************** -Questlog script commands -*******************/ + Questlog script commands + *******************/ -BUILDIN_FUNC(setquest) +BUILDIN(setquest) { struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - + quest_add(sd, script_getnum(st, 2)); - return 0; + return true; } -BUILDIN_FUNC(erasequest) +BUILDIN(erasequest) { struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - + quest_delete(sd, script_getnum(st, 2)); - return 0; + return true; } -BUILDIN_FUNC(completequest) +BUILDIN(completequest) { struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - + quest_update_status(sd, script_getnum(st, 2), Q_COMPLETE); - return 0; + return true; } -BUILDIN_FUNC(changequest) +BUILDIN(changequest) { struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - + quest_change(sd, script_getnum(st, 2),script_getnum(st, 3)); - return 0; + return true; } -BUILDIN_FUNC(checkquest) +BUILDIN(checkquest) { struct map_session_data *sd = script_rid2sd(st); quest_check_type type = HAVEQUEST; - + nullpo_ret(sd); - + if( script_hasdata(st, 3) ) type = (quest_check_type)script_getnum(st, 3); - + script_pushint(st, quest_check(sd, script_getnum(st, 2), type)); - - return 0; + + return true; } -BUILDIN_FUNC(showevent) +BUILDIN(showevent) { TBL_PC *sd = script_rid2sd(st); struct npc_data *nd = map_id2nd(st->oid); int state, color; - + if( sd == NULL || nd == NULL ) - return 0; + return true; state = script_getnum(st, 2); color = script_getnum(st, 3); - + if( color < 0 || color > 3 ) - color = 0; // set default color - - clif_quest_show_event(sd, &nd->bl, state, color); - return 0; + color = 0; // set default color + + clif->quest_show_event(sd, &nd->bl, state, color); + return true; } /*========================================== * BattleGround System *------------------------------------------*/ -BUILDIN_FUNC(waitingroom2bg) +BUILDIN(waitingroom2bg) { struct npc_data *nd; struct chat_data *cd; const char *map_name, *ev = "", *dev = ""; int x, y, i, mapindex = 0, bg_id, n; struct map_session_data *sd; - + if( script_hasdata(st,7) ) nd = npc_name2id(script_getstr(st,7)); else nd = (struct npc_data *)map_id2bl(st->oid); - + if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL ) { script_pushint(st,0); - return 0; + return true; } - + map_name = script_getstr(st,2); if( strcmp(map_name,"-") != 0 ) { @@ -15978,21 +15640,21 @@ BUILDIN_FUNC(waitingroom2bg) if( mapindex == 0 ) { // Invalid Map script_pushint(st,0); - return 0; + return true; } } - + x = script_getnum(st,3); y = script_getnum(st,4); ev = script_getstr(st,5); // Logout Event dev = script_getstr(st,6); // Die Event - + if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 ) { // Creation failed script_pushint(st,0); - return 0; + return true; } - + n = cd->users; for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ ) { @@ -16001,35 +15663,35 @@ BUILDIN_FUNC(waitingroom2bg) else mapreg_setreg(reference_uid(add_str("$@arenamembers"), i), 0); } - + mapreg_setreg(add_str("$@arenamembersnum"), i); script_pushint(st,bg_id); - return 0; + return true; } -BUILDIN_FUNC(waitingroom2bg_single) +BUILDIN(waitingroom2bg_single) { const char* map_name; struct npc_data *nd; struct chat_data *cd; struct map_session_data *sd; int x, y, mapindex, bg_id; - + bg_id = script_getnum(st,2); map_name = script_getstr(st,3); if( (mapindex = mapindex_name2id(map_name)) == 0 ) - return 0; // Invalid Map - + return true; // Invalid Map + x = script_getnum(st,4); y = script_getnum(st,5); nd = npc_name2id(script_getstr(st,6)); - + if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL || cd->users <= 0 ) - return 0; - + return true; + if( (sd = cd->usersd[0]) == NULL ) - return 0; - + return true; + if( bg_team_join(bg_id, sd) ) { pc_setpos(sd, mapindex, x, y, CLR_TELEPORT); @@ -16037,44 +15699,44 @@ BUILDIN_FUNC(waitingroom2bg_single) } else script_pushint(st,0); - - return 0; + + return true; } -BUILDIN_FUNC(bg_team_setxy) +BUILDIN(bg_team_setxy) { struct battleground_data *bg; int bg_id; - + bg_id = script_getnum(st,2); if( (bg = bg_team_search(bg_id)) == NULL ) - return 0; - + return true; + bg->x = script_getnum(st,3); bg->y = script_getnum(st,4); - return 0; + return true; } -BUILDIN_FUNC(bg_warp) +BUILDIN(bg_warp) { int x, y, mapindex, bg_id; const char* map_name; - + bg_id = script_getnum(st,2); map_name = script_getstr(st,3); if( (mapindex = mapindex_name2id(map_name)) == 0 ) - return 0; // Invalid Map + return true; // Invalid Map x = script_getnum(st,4); y = script_getnum(st,5); bg_team_warp(bg_id, mapindex, x, y); - return 0; + return true; } -BUILDIN_FUNC(bg_monster) +BUILDIN(bg_monster) { int class_ = 0, x = 0, y = 0, bg_id = 0; const char *str,*map, *evt=""; - + bg_id = script_getnum(st,2); map = script_getstr(st,3); x = script_getnum(st,4); @@ -16084,47 +15746,47 @@ BUILDIN_FUNC(bg_monster) if( script_hasdata(st,8) ) evt = script_getstr(st,8); check_event(st, evt); script_pushint(st, mob_spawn_bg(map,x,y,str,class_,evt,bg_id)); - return 0; + return true; } -BUILDIN_FUNC(bg_monster_set_team) +BUILDIN(bg_monster_set_team) { struct mob_data *md; struct block_list *mbl; int id = script_getnum(st,2), - bg_id = script_getnum(st,3); - + bg_id = script_getnum(st,3); + if( (mbl = map_id2bl(id)) == NULL || mbl->type != BL_MOB ) - return 0; + return true; md = (TBL_MOB *)mbl; md->bg_id = bg_id; - + mob_stop_attack(md); mob_stop_walking(md, 0); md->target_id = md->attacked_id = 0; - clif_charnameack(0, &md->bl); - - return 0; + clif->charnameack(0, &md->bl); + + return true; } -BUILDIN_FUNC(bg_leave) +BUILDIN(bg_leave) { struct map_session_data *sd = script_rid2sd(st); if( sd == NULL || !sd->bg_id ) - return 0; - + return true; + bg_team_leave(sd,0); - return 0; + return true; } -BUILDIN_FUNC(bg_destroy) +BUILDIN(bg_destroy) { int bg_id = script_getnum(st,2); bg_team_delete(bg_id); - return 0; + return true; } -BUILDIN_FUNC(bg_getareausers) +BUILDIN(bg_getareausers) { const char *str; int16 m, x0, y0, x1, y1; @@ -16132,21 +15794,21 @@ BUILDIN_FUNC(bg_getareausers) int i = 0, c = 0; struct battleground_data *bg = NULL; struct map_session_data *sd; - + bg_id = script_getnum(st,2); str = script_getstr(st,3); - + if( (bg = bg_team_search(bg_id)) == NULL || (m = map_mapname2mapid(str)) < 0 ) { script_pushint(st,0); - return 0; + return true; } - + x0 = script_getnum(st,4); y0 = script_getnum(st,5); x1 = script_getnum(st,6); y1 = script_getnum(st,7); - + for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (sd = bg->members[i].sd) == NULL ) @@ -16155,39 +15817,39 @@ BUILDIN_FUNC(bg_getareausers) continue; c++; } - + script_pushint(st,c); - return 0; + return true; } -BUILDIN_FUNC(bg_updatescore) +BUILDIN(bg_updatescore) { const char *str; int16 m; - + str = script_getstr(st,2); if( (m = map_mapname2mapid(str)) < 0 ) - return 0; - + return true; + map[m].bgscore_lion = script_getnum(st,3); map[m].bgscore_eagle = script_getnum(st,4); - - clif_bg_updatescore(m); - return 0; + + clif->bg_updatescore(m); + return true; } -BUILDIN_FUNC(bg_get_data) +BUILDIN(bg_get_data) { struct battleground_data *bg; int bg_id = script_getnum(st,2), - type = script_getnum(st,3); - + type = script_getnum(st,3); + if( (bg = bg_team_search(bg_id)) == NULL ) { script_pushint(st,0); - return 0; + return true; } - + switch( type ) { case 0: script_pushint(st, bg->count); break; @@ -16195,102 +15857,102 @@ BUILDIN_FUNC(bg_get_data) ShowError("script:bg_get_data: unknown data identifier %d\n", type); break; } - - return 0; + + return true; } /*========================================== * Instancing Script Commands *------------------------------------------*/ -BUILDIN_FUNC(instance_create) +BUILDIN(instance_create) { const char *name; int party_id, res; - + name = script_getstr(st, 2); party_id = script_getnum(st, 3); - + res = instance_create(party_id, name); if( res == -4 ) // Already exists { script_pushint(st, -1); - return 0; + return true; } else if( res < 0 ) { const char *err; switch(res) { - case -3: err = "No free instances"; break; - case -2: err = "Invalid party ID"; break; - case -1: err = "Invalid type"; break; - default: err = "Unknown"; break; + case -3: err = "No free instances"; break; + case -2: err = "Invalid party ID"; break; + case -1: err = "Invalid type"; break; + default: err = "Unknown"; break; } ShowError("buildin_instance_create: %s [%d].\n", err, res); script_pushint(st, -2); - return 0; + return true; } - + script_pushint(st, res); - return 0; + return true; } -BUILDIN_FUNC(instance_destroy) +BUILDIN(instance_destroy) { int instance_id; struct map_session_data *sd; struct party_data *p; - + if( script_hasdata(st, 2) ) instance_id = script_getnum(st, 2); else if( st->instance_id ) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - else return 0; - + else return true; + if( instance_id <= 0 || instance_id >= MAX_INSTANCE ) { ShowError("buildin_instance_destroy: Trying to destroy invalid instance %d.\n", instance_id); - return 0; + return true; } - + instance_destroy(instance_id); - return 0; + return true; } -BUILDIN_FUNC(instance_attachmap) +BUILDIN(instance_attachmap) { const char *name; int16 m; int instance_id; bool usebasename = false; - + name = script_getstr(st,2); instance_id = script_getnum(st,3); if( script_hasdata(st,4) && script_getnum(st,4) > 0) usebasename = true; - + if( (m = instance_add_map(name, instance_id, usebasename)) < 0 ) // [Saithis] { ShowError("buildin_instance_attachmap: instance creation failed (%s): %d\n", name, m); script_pushconststr(st, ""); - return 0; + return true; } script_pushconststr(st, map[m].name); - - return 0; + + return true; } -BUILDIN_FUNC(instance_detachmap) +BUILDIN(instance_detachmap) { struct map_session_data *sd; struct party_data *p; const char *str; int16 m; int instance_id; - + str = script_getstr(st, 2); if( script_hasdata(st, 3) ) instance_id = script_getnum(st, 3); @@ -16298,38 +15960,39 @@ BUILDIN_FUNC(instance_detachmap) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - else return 0; - + else return true; + if( (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m,instance_id)) < 0 ) { ShowError("buildin_instance_detachmap: Trying to detach invalid map %s\n", str); - return 0; + return true; } - + instance_del_map(m); - return 0; + return true; } -BUILDIN_FUNC(instance_attach) +BUILDIN(instance_attach) { int instance_id; - + instance_id = script_getnum(st, 2); if( instance_id <= 0 || instance_id >= MAX_INSTANCE ) - return 0; - + return true; + st->instance_id = instance_id; - return 0; + return true; } -BUILDIN_FUNC(instance_id) +BUILDIN(instance_id) { - int type, instance_id; - struct map_session_data *sd; - struct party_data *p; - + int instance_id; + if( script_hasdata(st, 2) ) { + struct party_data *p; + struct map_session_data *sd; + int type; type = script_getnum(st, 2); if( type == 0 ) instance_id = st->instance_id; @@ -16340,50 +16003,50 @@ BUILDIN_FUNC(instance_id) } else instance_id = st->instance_id; - + script_pushint(st, instance_id); - return 0; + return true; } -BUILDIN_FUNC(instance_set_timeout) +BUILDIN(instance_set_timeout) { int progress_timeout, idle_timeout; int instance_id; struct map_session_data *sd; struct party_data *p; - + progress_timeout = script_getnum(st, 2); idle_timeout = script_getnum(st, 3); - + if( script_hasdata(st, 4) ) instance_id = script_getnum(st, 4); else if( st->instance_id ) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - else return 0; - + else return true; + if( instance_id > 0 ) instance_set_timeout(instance_id, progress_timeout, idle_timeout); - - return 0; + + return true; } -BUILDIN_FUNC(instance_init) +BUILDIN(instance_init) { int instance_id = script_getnum(st, 2); - + if( instance[instance_id].state != INSTANCE_IDLE ) { ShowError("instance_init: instance already initialized.\n"); - return 0; + return true; } - + instance_init(instance_id); - return 0; + return true; } -BUILDIN_FUNC(instance_announce) +BUILDIN(instance_announce) { int instance_id = script_getnum(st,2); const char *mes = script_getstr(st,3); @@ -16393,39 +16056,39 @@ BUILDIN_FUNC(instance_announce) int fontSize = script_hasdata(st,7) ? script_getnum(st,7) : 12; // default fontSize int fontAlign = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontAlign int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY - + int i; struct map_session_data *sd; struct party_data *p; - + if( instance_id == 0 ) { if( st->instance_id ) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - else return 0; + else return true; } - + if( instance_id <= 0 || instance_id >= MAX_INSTANCE ) - return 0; - + return true; + for( i = 0; i < instance[instance_id].num_map; i++ ) map_foreachinmap(buildin_announce_sub, instance[instance_id].map[i], BL_PC, - mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); - - return 0; + mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); + + return true; } -BUILDIN_FUNC(instance_npcname) +BUILDIN(instance_npcname) { const char *str; int instance_id = 0; - + struct map_session_data *sd; struct party_data *p; struct npc_data *nd; - + str = script_getstr(st, 2); if( script_hasdata(st, 3) ) instance_id = script_getnum(st, 3); @@ -16433,7 +16096,7 @@ BUILDIN_FUNC(instance_npcname) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - + if( instance_id && (nd = npc_name2id(str)) != NULL ) { static char npcname[NAME_LENGTH]; @@ -16444,20 +16107,20 @@ BUILDIN_FUNC(instance_npcname) { ShowError("script:instance_npcname: invalid instance NPC (instance_id: %d, NPC name: \"%s\".)\n", instance_id, str); st->state = END; - return 1; + return false; } - - return 0; + + return true; } -BUILDIN_FUNC(has_instance) +BUILDIN(has_instance) { struct map_session_data *sd; struct party_data *p; const char *str; int16 m; int instance_id = 0; - + str = script_getstr(st, 2); if( script_hasdata(st, 3) ) instance_id = script_getnum(st, 3); @@ -16465,18 +16128,18 @@ BUILDIN_FUNC(has_instance) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - + if( !instance_id || (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m, instance_id)) < 0 ) { script_pushconststr(st, ""); - return 0; + return true; } - + script_pushconststr(st, map[m].name); - return 0; + return true; } -BUILDIN_FUNC(instance_warpall) +BUILDIN(instance_warpall) { struct map_session_data *pl_sd; int16 m, i; @@ -16485,7 +16148,7 @@ BUILDIN_FUNC(instance_warpall) int x, y; unsigned short mapindex; struct party_data *p = NULL; - + mapn = script_getstr(st,2); x = script_getnum(st,3); y = script_getnum(st,4); @@ -16495,19 +16158,19 @@ BUILDIN_FUNC(instance_warpall) instance_id = st->instance_id; else if( (pl_sd = script_rid2sd(st)) != NULL && pl_sd->status.party_id && (p = party_search(pl_sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - else return 0; - + else return true; + if( (m = map_mapname2mapid(mapn)) < 0 || (map[m].flag.src4instance && (m = instance_mapid2imapid(m, instance_id)) < 0) ) - return 0; - + return true; + if( !(p = party_search(instance[instance_id].party_id)) ) - return 0; - + return true; + mapindex = map_id2index(m); for( i = 0; i < MAX_PARTY; i++ ) if( (pl_sd = p->data[i].sd) && map[pl_sd->bl.m].instance_id == st->instance_id ) pc_setpos(pl_sd,mapindex,x,y,CLR_TELEPORT); - - return 0; + + return true; } /*========================================== @@ -16520,71 +16183,71 @@ BUILDIN_FUNC(instance_warpall) * Example: instance_check_party (getcharid(1){,amount}{,min}{,max}); * Example 2: instance_check_party (getcharid(1),1,1,99); *------------------------------------------*/ -BUILDIN_FUNC(instance_check_party) +BUILDIN(instance_check_party) { struct map_session_data *pl_sd; int amount, min, max, i, party_id, c = 0; struct party_data *p = NULL; - + amount = script_hasdata(st,3) ? script_getnum(st,3) : 1; // Amount of needed Partymembers for the Instance. min = script_hasdata(st,4) ? script_getnum(st,4) : 1; // Minimum Level needed to join the Instance. max = script_hasdata(st,5) ? script_getnum(st,5) : MAX_LEVEL; // Maxium Level allowed to join the Instance. - + if( min < 1 || min > MAX_LEVEL){ ShowError("instance_check_party: Invalid min level, %d\n", min); - return 0; + return true; }else if( max < 1 || max > MAX_LEVEL){ ShowError("instance_check_party: Invalid max level, %d\n", max); - return 0; + return true; } - + if( script_hasdata(st,2) ) party_id = script_getnum(st,2); - else return 0; - + else return true; + if( !(p = party_search(party_id)) ){ script_pushint(st, 0); // Returns false if party does not exist. - return 0; + return true; } - + for( i = 0; i < MAX_PARTY; i++ ) if( (pl_sd = p->data[i].sd) ) if(map_id2bl(pl_sd->bl.id)){ if(pl_sd->status.base_level < min){ script_pushint(st, 0); - return 0; + return true; }else if(pl_sd->status.base_level > max){ script_pushint(st, 0); - return 0; + return true; } - c++; + c++; } - + if(c < amount){ script_pushint(st, 0); // Not enough Members in the Party to join Instance. }else script_pushint(st, 1); - - return 0; + + return true; } /*========================================== * Custom Fonts *------------------------------------------*/ -BUILDIN_FUNC(setfont) +BUILDIN(setfont) { struct map_session_data *sd = script_rid2sd(st); int font = script_getnum(st,2); if( sd == NULL ) - return 0; - + return true; + if( sd->user_font != font ) sd->user_font = font; else sd->user_font = 0; - - clif_font(sd); - return 0; + + clif->font(sd); + return true; } static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap) @@ -16598,231 +16261,228 @@ static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap) int cancel = va_arg(ap,int); int emotion = va_arg(ap,int); int target = va_arg(ap,int); - + if( md->class_ != mobid ) return 0; - + // 0:self, 1:target, 2:master, default:random switch( target ) { case 0: tbl = map_id2bl(md->bl.id); break; case 1: tbl = map_id2bl(md->target_id); break; case 2: tbl = map_id2bl(md->master_id); break; - default:tbl = battle_getenemy(&md->bl, DEFAULT_ENEMY_TYPE(md),skill_get_range2(&md->bl, skill_id, skill_lv)); break; + default:tbl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md),skill->get_range2(&md->bl, skill_id, skill_lv)); break; } - + if( !tbl ) return 0; - + if( md->ud.skilltimer != INVALID_TIMER ) // Cancel the casting skill. unit_skillcastcancel(bl,0); - - if( skill_get_casttype(skill_id) == CAST_GROUND ) + + if( skill->get_casttype(skill_id) == CAST_GROUND ) unit_skilluse_pos2(&md->bl, tbl->x, tbl->y, skill_id, skill_lv, casttime, cancel); else unit_skilluse_id2(&md->bl, tbl->id, skill_id, skill_lv, casttime, cancel); - - clif_emotion(&md->bl, emotion); - + + clif->emotion(&md->bl, emotion); + return 0; } /*========================================== * areamobuseskill "Map Name",<x>,<y>,<range>,<Mob ID>,"Skill Name"/<Skill ID>,<Skill Lv>,<Cast Time>,<Cancelable>,<Emotion>,<Target Type>; *------------------------------------------*/ -BUILDIN_FUNC(areamobuseskill) +BUILDIN(areamobuseskill) { struct block_list center; int16 m; int range,mobid,skill_id,skill_lv,casttime,emotion,target,cancel; - + if( (m = map_mapname2mapid(script_getstr(st,2))) < 0 ) { ShowError("areamobuseskill: invalid map name.\n"); - return 0; + return true; } - + if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) - return 0; - + return true; + center.m = m; center.x = script_getnum(st,3); center.y = script_getnum(st,4); range = script_getnum(st,5); mobid = script_getnum(st,6); - skill_id = ( script_isstring(st,7) ? skill_name2id(script_getstr(st,7)) : script_getnum(st,7) ); - if( (skill_lv = script_getnum(st,8)) > battle_config.mob_max_skilllvl ) - skill_lv = battle_config.mob_max_skilllvl; - + skill_id = ( script_isstring(st,7) ? skill->name2id(script_getstr(st,7)) : script_getnum(st,7) ); + skill_lv = script_getnum(st,8); casttime = script_getnum(st,9); cancel = script_getnum(st,10); emotion = script_getnum(st,11); target = script_getnum(st,12); - + map_foreachinrange(buildin_mobuseskill_sub, ¢er, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target); - return 0; + return true; } -BUILDIN_FUNC(progressbar) +BUILDIN(progressbar) { struct map_session_data * sd = script_rid2sd(st); const char * color; unsigned int second; - + if( !st || !sd ) - return 0; - + return true; + st->state = STOP; - + color = script_getstr(st,2); second = script_getnum(st,3); - + sd->progressbar.npc_id = st->oid; sd->progressbar.timeout = gettick() + second*1000; - - clif_progressbar(sd, strtol(color, (char **)NULL, 0), second); - return 0; + + clif->progressbar(sd, strtol(color, (char **)NULL, 0), second); + return true; } -BUILDIN_FUNC(pushpc) +BUILDIN(pushpc) { uint8 dir; int cells, dx, dy; struct map_session_data* sd; - + if((sd = script_rid2sd(st))==NULL) { - return 0; + return true; } - + dir = script_getnum(st,2); cells = script_getnum(st,3); - + if(dir>7) { ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", dir); script_reportsrc(st); - + dir%= 8; // trim spin-over } - + if(!cells) {// zero distance - return 0; + return true; } else if(cells<0) {// pushing backwards dir = (dir+4)%8; // turn around cells = -cells; } - + dx = dirx[dir]; dy = diry[dir]; - + unit_blown(&sd->bl, dx, dy, cells, 0); - return 0; + return true; } /// Invokes buying store preparation window /// buyingstore <slots>; -BUILDIN_FUNC(buyingstore) +BUILDIN(buyingstore) { struct map_session_data* sd; - - if( ( sd = script_rid2sd(st) ) == NULL ) - { - return 0; + + if( ( sd = script_rid2sd(st) ) == NULL ) { + return true; } - - buyingstore_setup(sd, script_getnum(st,2)); - return 0; + + buyingstore->setup(sd, script_getnum(st,2)); + return true; } /// Invokes search store info window /// searchstores <uses>,<effect>; -BUILDIN_FUNC(searchstores) +BUILDIN(searchstores) { unsigned short effect; unsigned int uses; struct map_session_data* sd; - + if( ( sd = script_rid2sd(st) ) == NULL ) { - return 0; + return true; } - + uses = script_getnum(st,2); effect = script_getnum(st,3); - + if( !uses ) { ShowError("buildin_searchstores: Amount of uses cannot be zero.\n"); - return 1; + return false; } - + if( effect > 1 ) { ShowError("buildin_searchstores: Invalid effect id %hu, specified.\n", effect); - return 1; + return false; } - - searchstore_open(sd, uses, effect); - return 0; + + searchstore->open(sd, uses, effect); + return true; } /// Displays a number as large digital clock. /// showdigit <value>[,<type>]; -BUILDIN_FUNC(showdigit) +BUILDIN(showdigit) { unsigned int type = 0; int value; struct map_session_data* sd; - + if( ( sd = script_rid2sd(st) ) == NULL ) { - return 0; + return true; } - + value = script_getnum(st,2); - + if( script_hasdata(st,3) ) { type = script_getnum(st,3); - + if( type > 3 ) { ShowError("buildin_showdigit: Invalid type %u.\n", type); - return 1; + return false; } } - - clif_showdigit(sd, (unsigned char)type, value); - return 0; + + clif->showdigit(sd, (unsigned char)type, value); + return true; } /** * Rune Knight **/ -BUILDIN_FUNC(makerune) { +BUILDIN(makerune) { TBL_PC* sd; if( (sd = script_rid2sd(st)) == NULL ) - return 0; - clif_skill_produce_mix_list(sd,RK_RUNEMASTERY,24); + return true; + clif->skill_produce_mix_list(sd,RK_RUNEMASTERY,24); sd->itemid = script_getnum(st,2); - return 0; + return true; } /** * checkdragon() returns 1 if mounting a dragon or 0 otherwise. **/ -BUILDIN_FUNC(checkdragon) { +BUILDIN(checkdragon) { TBL_PC* sd; if( (sd = script_rid2sd(st)) == NULL ) - return 0; + return true; if( pc_isridingdragon(sd) ) script_pushint(st,1); else script_pushint(st,0); - return 0; + return true; } /** * setdragon({optional Color}) returns 1 on success or 0 otherwise @@ -16834,24 +16494,25 @@ BUILDIN_FUNC(checkdragon) { * - 4 : Blue Dragon * - 5 : Red Dragon **/ -BUILDIN_FUNC(setdragon) { +BUILDIN(setdragon) { TBL_PC* sd; int color = script_hasdata(st,2) ? script_getnum(st,2) : 0; - unsigned int option = OPTION_DRAGON1; + if( (sd = script_rid2sd(st)) == NULL ) - return 0; + return true; if( !pc_checkskill(sd,RK_DRAGONTRAINING) || (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT ) script_pushint(st,0);//Doesn't have the skill or it's not a Rune Knight else if ( pc_isridingdragon(sd) ) {//Is mounted; release pc_setoption(sd, sd->sc.option&~OPTION_DRAGON); script_pushint(st,1); } else {//Not mounted; Mount now. + unsigned int option = OPTION_DRAGON1; if( color ) { option = ( color == 1 ? OPTION_DRAGON1 : - color == 2 ? OPTION_DRAGON2 : - color == 3 ? OPTION_DRAGON3 : - color == 4 ? OPTION_DRAGON4 : - color == 5 ? OPTION_DRAGON5 : 0); + color == 2 ? OPTION_DRAGON2 : + color == 3 ? OPTION_DRAGON3 : + color == 4 ? OPTION_DRAGON4 : + color == 5 ? OPTION_DRAGON5 : 0); if( !option ) { ShowWarning("script_setdragon: Unknown Color %d used; changing to green (1)\n",color); option = OPTION_DRAGON1; @@ -16860,21 +16521,21 @@ BUILDIN_FUNC(setdragon) { pc_setoption(sd, sd->sc.option|option); script_pushint(st,1); } - return 0; + return true; } /** * ismounting() returns 1 if mounting a new mount or 0 otherwise **/ -BUILDIN_FUNC(ismounting) { +BUILDIN(ismounting) { TBL_PC* sd; if( (sd = script_rid2sd(st)) == NULL ) - return 0; - if( sd->sc.option&OPTION_MOUNTING ) + return true; + if( sd->sc.data[SC_ALL_RIDING] ) script_pushint(st,1); else script_pushint(st,0); - return 0; + return true; } /** @@ -16883,47 +16544,46 @@ BUILDIN_FUNC(ismounting) { * - Will fail if the player is mounting a non-new mount, e.g. dragon, peco, wug, etc. * - Will unmount the player is he is already mounting **/ -BUILDIN_FUNC(setmounting) { +BUILDIN(setmounting) { TBL_PC* sd; if( (sd = script_rid2sd(st)) == NULL ) - return 0; + return true; if( sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR) ) script_pushint(st,0);//can't mount with one of these else { - if( sd->sc.option&OPTION_MOUNTING ) - pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);//release mount + if( sd->sc.data[SC_ALL_RIDING] ) + status_change_end(&sd->bl, SC_ALL_RIDING, INVALID_TIMER); else - pc_setoption(sd, sd->sc.option|OPTION_MOUNTING);//mount + sc_start(&sd->bl, SC_ALL_RIDING, 100, 0, -1); script_pushint(st,1);//in both cases, return 1. } - return 0; + return true; } /** * Retrieves quantity of arguments provided to callfunc/callsub. * getargcount() -> amount of arguments received in a function **/ -BUILDIN_FUNC(getargcount) { +BUILDIN(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; + return false; } ri = st->stack->stack_data[st->stack->defsp - 1].u.ri; - + script_pushint(st, ri->nargs); - - return 0; + + return true; } /** * getcharip(<account ID>/<character ID>/<character name>) **/ -BUILDIN_FUNC(getcharip) +BUILDIN(getcharip) { struct map_session_data* sd = NULL; - int id = 0; - + /* check if a character name is specified */ if( script_hasdata(st, 2) ) { @@ -16931,175 +16591,181 @@ BUILDIN_FUNC(getcharip) sd = map_nick2sd(script_getstr(st, 2)); else if (script_isint(st, 2) || script_getnum(st, 2)) { + int id; id = script_getnum(st, 2); sd = (map_id2sd(id) ? map_id2sd(id) : map_charid2sd(id)); } } else sd = script_rid2sd(st); - + /* check for sd and IP */ if (!sd || !session[sd->fd]->client_addr) { script_pushconststr(st, ""); - return 0; + return true; } - + /* return the client ip_addr converted for output */ if (sd && sd->fd && session[sd->fd]) { /* initiliaze */ const char *ip_addr = NULL; uint32 ip; - + /* set ip, ip_addr and convert to ip and push str */ ip = session[sd->fd]->client_addr; ip_addr = ip2str(ip, NULL); script_pushstrcopy(st, ip_addr); } - - return 0; + + return true; } /** * is_function(<function name>) -> 1 if function exists, 0 otherwise **/ -BUILDIN_FUNC(is_function) { +BUILDIN(is_function) { const char* str = script_getstr(st,2); - + if( strdb_exists(userfunc_db, str) ) script_pushint(st,1); else script_pushint(st,0); - - return 0; + + return true; } /** * get_revision() -> retrieves the current svn revision (if available) **/ -BUILDIN_FUNC(get_revision) { - const char * revision; - - if ( (revision = get_svn_revision()) != 0 ) - script_pushint(st,atoi(revision)); +BUILDIN(get_revision) { + const char *svn = get_svn_revision(); + + if ( svn[0] != HERC_UNKNOWN_VER ) + script_pushint(st,atoi(svn)); else script_pushint(st,-1);//unknown - - return 0; + + return true; } /** * freeloop(<toggle>) -> toggles this script instance's looping-check ability **/ -BUILDIN_FUNC(freeloop) { - +BUILDIN(freeloop) { + if( script_getnum(st,2) ) st->freeloop = 1; else st->freeloop = 0; - + script_pushint(st, st->freeloop); - - return 0; + + return true; } /** * @commands (script based) **/ -BUILDIN_FUNC(bindatcmd) { +BUILDIN(bindatcmd) { const char* atcmd; const char* eventName; - int i, level = 0, level2 = 0; + int i, group_lv = 0, group_lv_char = 99; + bool log = false; bool create = false; - + atcmd = script_getstr(st,2); eventName = script_getstr(st,3); - - if( *atcmd == atcommand_symbol || *atcmd == charcommand_symbol ) + + if( *atcmd == atcommand->at_symbol || *atcmd == atcommand->char_symbol ) atcmd++; - - if( script_hasdata(st,4) ) level = script_getnum(st,4); - if( script_hasdata(st,5) ) level2 = script_getnum(st,5); - - if( atcmd_binding_count == 0 ) { - CREATE(atcmd_binding,struct atcmd_binding_data*,1); - + + if( script_hasdata(st,4) ) group_lv = script_getnum(st,4); + if( script_hasdata(st,5) ) group_lv_char = script_getnum(st,5); + if( script_hasdata(st,6) ) log = script_getnum(st,6) ? true : false; + + + if( atcommand->binding_count == 0 ) { + CREATE(atcommand->binding,struct atcmd_binding_data*,1); + create = true; } else { - ARR_FIND(0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command,atcmd) == 0); - if( i < atcmd_binding_count ) {/* update existent entry */ - safestrncpy(atcmd_binding[i]->npc_event, eventName, 50); - atcmd_binding[i]->level = level; - atcmd_binding[i]->level2 = level2; + ARR_FIND(0, atcommand->binding_count, i, strcmp(atcommand->binding[i]->command,atcmd) == 0); + if( i < atcommand->binding_count ) {/* update existent entry */ + safestrncpy(atcommand->binding[i]->npc_event, eventName, ATCOMMAND_LENGTH); + atcommand->binding[i]->group_lv = group_lv; + atcommand->binding[i]->group_lv_char = group_lv_char; + atcommand->binding[i]->log = log; } else create = true; } - + if( create ) { - i = atcmd_binding_count; - - if( atcmd_binding_count++ != 0 ) - RECREATE(atcmd_binding,struct atcmd_binding_data*,atcmd_binding_count); - - CREATE(atcmd_binding[i],struct atcmd_binding_data,1); - - safestrncpy(atcmd_binding[i]->command, atcmd, 50); - safestrncpy(atcmd_binding[i]->npc_event, eventName, 50); - atcmd_binding[i]->level = level; - atcmd_binding[i]->level2 = level2; - } - - return 0; + i = atcommand->binding_count; + + if( atcommand->binding_count++ != 0 ) + RECREATE(atcommand->binding,struct atcmd_binding_data*,atcommand->binding_count); + + CREATE(atcommand->binding[i],struct atcmd_binding_data,1); + + safestrncpy(atcommand->binding[i]->command, atcmd, 50); + safestrncpy(atcommand->binding[i]->npc_event, eventName, 50); + atcommand->binding[i]->group_lv = group_lv; + atcommand->binding[i]->group_lv_char = group_lv_char; + atcommand->binding[i]->log = log; + } + + return true; } -BUILDIN_FUNC(unbindatcmd) { +BUILDIN(unbindatcmd) { const char* atcmd; int i = 0; - + atcmd = script_getstr(st, 2); - - if( *atcmd == atcommand_symbol || *atcmd == charcommand_symbol ) + + if( *atcmd == atcommand->at_symbol || *atcmd == atcommand->char_symbol ) atcmd++; - - if( atcmd_binding_count == 0 ) { + + if( atcommand->binding_count == 0 ) { script_pushint(st, 0); - return 0; + return true; } - - ARR_FIND(0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command, atcmd) == 0); - if( i < atcmd_binding_count ) { + + ARR_FIND(0, atcommand->binding_count, i, strcmp(atcommand->binding[i]->command, atcmd) == 0); + if( i < atcommand->binding_count ) { int cursor = 0; - aFree(atcmd_binding[i]); - atcmd_binding[i] = NULL; + aFree(atcommand->binding[i]); + atcommand->binding[i] = NULL; /* compact the list now that we freed a slot somewhere */ - for( i = 0, cursor = 0; i < atcmd_binding_count; i++ ) { - if( atcmd_binding[i] == NULL ) + for( i = 0, cursor = 0; i < atcommand->binding_count; i++ ) { + if( atcommand->binding[i] == NULL ) continue; - + if( cursor != i ) { - memmove(&atcmd_binding[cursor], &atcmd_binding[i], sizeof(struct atcmd_binding_data*)); + memmove(&atcommand->binding[cursor], &atcommand->binding[i], sizeof(struct atcmd_binding_data*)); } - + cursor++; } - - if( (atcmd_binding_count = cursor) == 0 ) - aFree(atcmd_binding); - + + if( (atcommand->binding_count = cursor) == 0 ) + aFree(atcommand->binding); + script_pushint(st, 1); } else script_pushint(st, 0);/* not found */ - - return 0; + + return true; } -BUILDIN_FUNC(useatcmd) +BUILDIN(useatcmd) { TBL_PC dummy_sd; TBL_PC* sd; int fd; const char* cmd; - + cmd = script_getstr(st,2); - + if( st->rid ) { sd = script_rid2sd(st); @@ -17109,7 +16775,7 @@ BUILDIN_FUNC(useatcmd) { // Use a dummy character. sd = &dummy_sd; fd = 0; - + memset(&dummy_sd, 0, sizeof(TBL_PC)); if( st->oid ) { @@ -17119,121 +16785,127 @@ BUILDIN_FUNC(useatcmd) safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); } } - + // compatibility with previous implementation (deprecated!) - if( cmd[0] != atcommand_symbol ) - { + if( cmd[0] != atcommand->at_symbol ) { cmd += strlen(sd->status.name); - while( *cmd != atcommand_symbol && *cmd != 0 ) + while( *cmd != atcommand->at_symbol && *cmd != 0 ) cmd++; } - - is_atcommand(fd, sd, cmd, 1); - return 0; + + atcommand->parse(fd, sd, cmd, 1); + return true; } -BUILDIN_FUNC(checkre) +BUILDIN(checkre) { int num; - + num=script_getnum(st,2); switch(num){ case 0: - #ifdef RENEWAL - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; case 1: - #ifdef RENEWAL_CAST - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL_CAST + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; case 2: - #ifdef RENEWAL_DROP - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL_DROP + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; case 3: - #ifdef RENEWAL_EXP - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL_EXP + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; case 4: - #ifdef RENEWAL_LVDMG - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL_LVDMG + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; case 5: - #ifdef RENEWAL_EDP - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL_EDP + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; case 6: - #ifdef RENEWAL_ASPD - script_pushint(st, 1); - #else - script_pushint(st, 0); - #endif +#ifdef RENEWAL_ASPD + script_pushint(st, 1); +#else + script_pushint(st, 0); +#endif break; default: ShowWarning("buildin_checkre: unknown parameter.\n"); break; } - return 0; + return true; } /* getrandgroupitem <group_id>,<quantity> */ -BUILDIN_FUNC(getrandgroupitem) { +BUILDIN(getrandgroupitem) { TBL_PC* sd; int i, get_count = 0, flag, nameid, group = script_getnum(st, 2), qty = script_getnum(st,3); struct item item_tmp; - + if( !( sd = script_rid2sd(st) ) ) - return 0; - + return true; + if( qty <= 0 ) { ShowError("getrandgroupitem: qty is <= 0!\n"); - return 1; + return false; } - if( (nameid = itemdb_searchrandomid(group)) == UNKNOWN_ITEM_ID ) { - return 1;/* itemdb_searchrandomid will already scream a error */ + + if(group < 1 || group >= MAX_ITEMGROUP) { + ShowError("getrandgroupitem: Invalid group id %d\n", group); + return false; } - + if (!itemgroup_db[group].qty) { + ShowError("getrandgroupitem: group id %d is empty!\n", group); + return false; + } + + nameid = itemdb_searchrandomid(group); memset(&item_tmp,0,sizeof(item_tmp)); - + item_tmp.nameid = nameid; item_tmp.identify = itemdb_isidentified(nameid); - + //Check if it's stackable. if (!itemdb_isstackable(nameid)) get_count = 1; else get_count = qty; - + for (i = 0; i < qty; i += get_count) { // if not pet egg if (!pet_create_egg(sd, nameid)) { if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { - clif_additem(sd, 0, 0, flag); + clif->additem(sd, 0, 0, flag); if( pc_candrop(sd,&item_tmp) ) map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } - - return 0; + + return true; } /* cleanmap <map_name>; @@ -17242,21 +16914,21 @@ static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap) { nullpo_ret(bl); map_clearflooritem(bl); - + return 0; } -BUILDIN_FUNC(cleanmap) +BUILDIN(cleanmap) { const char *map; int16 m = -1; int16 x0 = 0, y0 = 0, x1 = 0, y1 = 0; - + map = script_getstr(st, 2); m = map_mapname2mapid(map); if (!m) - return 1; - + return false; + if ((script_lastdata(st) - 2) < 4) { map_foreachinmap(atcommand_cleanfloor_sub, m, BL_ITEM); } else { @@ -17268,16 +16940,16 @@ BUILDIN_FUNC(cleanmap) map_foreachinarea(atcommand_cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM); } else { ShowError("cleanarea: invalid coordinate defined!\n"); - return 1; + return false; } } - - return 0; + + return true; } /* Cast a skill on the attached player. * npcskill <skill id>, <skill lvl>, <stat point>, <NPC level>; * npcskill "<skill name>", <skill lvl>, <stat point>, <NPC level>; */ -BUILDIN_FUNC(npcskill) +BUILDIN(npcskill) { uint16 skill_id; unsigned short skill_level; @@ -17285,500 +16957,602 @@ BUILDIN_FUNC(npcskill) unsigned int npc_level; struct npc_data *nd; struct map_session_data *sd; - - skill_id = script_isstring(st, 2) ? skill_name2id(script_getstr(st, 2)) : script_getnum(st, 2); + + skill_id = script_isstring(st, 2) ? skill->name2id(script_getstr(st, 2)) : script_getnum(st, 2); skill_level = script_getnum(st, 3); stat_point = script_getnum(st, 4); npc_level = script_getnum(st, 5); sd = script_rid2sd(st); nd = (struct npc_data *)map_id2bl(sd->npc_id); - + if (stat_point > battle_config.max_third_parameter) { ShowError("npcskill: stat point exceeded maximum of %d.\n",battle_config.max_third_parameter ); - return 1; + return false; } if (npc_level > MAX_LEVEL) { ShowError("npcskill: level exceeded maximum of %d.\n", MAX_LEVEL); - return 1; + return false; } if (sd == NULL || nd == NULL) { //ain't possible, but I don't trust people. - return 1; + return false; } - + nd->level = npc_level; nd->stat_point = stat_point; - + if (!nd->status.hp) { status_calc_npc(nd, true); } else { status_calc_npc(nd, false); } - - if (skill_get_inf(skill_id)&INF_GROUND_SKILL) { + + if (skill->get_inf(skill_id)&INF_GROUND_SKILL) { unit_skilluse_pos(&nd->bl, sd->bl.x, sd->bl.y, skill_id, skill_level); } else { unit_skilluse_id(&nd->bl, sd->bl.id, skill_id, skill_level); } - - return 0; + + return true; } - // declarations that were supposed to be exported from npc_chat.c #ifdef PCRE_SUPPORT -BUILDIN_FUNC(defpattern); -BUILDIN_FUNC(activatepset); -BUILDIN_FUNC(deactivatepset); -BUILDIN_FUNC(deletepset); + BUILDIN(defpattern); + BUILDIN(activatepset); + BUILDIN(deactivatepset); + BUILDIN(deletepset); #endif -/// script command definitions -/// for an explanation on args, see add_buildin_func -struct script_function buildin_func[] = { - // NPC interaction - BUILDIN_DEF(mes,"s*"), - BUILDIN_DEF(next,""), - BUILDIN_DEF(close,""), - BUILDIN_DEF(close2,""), - BUILDIN_DEF(menu,"sl*"), - BUILDIN_DEF(select,"s*"), //for future jA script compatibility - BUILDIN_DEF(prompt,"s*"), - // - BUILDIN_DEF(goto,"l"), - BUILDIN_DEF(callsub,"l*"), - BUILDIN_DEF(callfunc,"s*"), - BUILDIN_DEF(return,"?"), - BUILDIN_DEF(getarg,"i?"), - BUILDIN_DEF(jobchange,"i?"), - BUILDIN_DEF(jobname,"i"), - BUILDIN_DEF(input,"r??"), - BUILDIN_DEF(warp,"sii"), - BUILDIN_DEF(areawarp,"siiiisii??"), - BUILDIN_DEF(warpchar,"siii"), // [LuzZza] - BUILDIN_DEF(warpparty,"siii?"), // [Fredzilla] [Paradox924X] - BUILDIN_DEF(warpguild,"siii"), // [Fredzilla] - BUILDIN_DEF(setlook,"ii"), - BUILDIN_DEF(changelook,"ii"), // Simulates but don't Store it - BUILDIN_DEF(set,"rv"), - BUILDIN_DEF(setarray,"rv*"), - BUILDIN_DEF(cleararray,"rvi"), - BUILDIN_DEF(copyarray,"rri"), - BUILDIN_DEF(getarraysize,"r"), - BUILDIN_DEF(deletearray,"r?"), - BUILDIN_DEF(getelementofarray,"ri"), - BUILDIN_DEF(getitem,"vi?"), - BUILDIN_DEF(rentitem,"vi"), - BUILDIN_DEF(getitem2,"viiiiiiii?"), - BUILDIN_DEF(getnameditem,"vv"), - BUILDIN_DEF2(grouprandomitem,"groupranditem","i"), - BUILDIN_DEF(makeitem,"visii"), - BUILDIN_DEF(delitem,"vi?"), - BUILDIN_DEF(delitem2,"viiiiiiii?"), - BUILDIN_DEF2(enableitemuse,"enable_items",""), - BUILDIN_DEF2(disableitemuse,"disable_items",""), - BUILDIN_DEF(cutin,"si"), - BUILDIN_DEF(viewpoint,"iiiii"), - BUILDIN_DEF(heal,"ii"), - BUILDIN_DEF(itemheal,"ii"), - BUILDIN_DEF(percentheal,"ii"), - BUILDIN_DEF(rand,"i?"), - BUILDIN_DEF(countitem,"v"), - BUILDIN_DEF(countitem2,"viiiiiii"), - BUILDIN_DEF(checkweight,"vi*"), - BUILDIN_DEF(checkweight2,"rr"), - BUILDIN_DEF(readparam,"i?"), - BUILDIN_DEF(getcharid,"i?"), - BUILDIN_DEF(getnpcid,"i?"), - BUILDIN_DEF(getpartyname,"i"), - BUILDIN_DEF(getpartymember,"i?"), - BUILDIN_DEF(getpartyleader,"i?"), - BUILDIN_DEF(getguildname,"i"), - BUILDIN_DEF(getguildmaster,"i"), - BUILDIN_DEF(getguildmasterid,"i"), - BUILDIN_DEF(strcharinfo,"i"), - BUILDIN_DEF(strnpcinfo,"i"), - BUILDIN_DEF(getequipid,"i"), - BUILDIN_DEF(getequipname,"i"), - BUILDIN_DEF(getbrokenid,"i"), // [Valaris] - BUILDIN_DEF(repair,"i"), // [Valaris] - BUILDIN_DEF(repairall,""), - BUILDIN_DEF(getequipisequiped,"i"), - BUILDIN_DEF(getequipisenableref,"i"), - BUILDIN_DEF(getequipisidentify,"i"), - BUILDIN_DEF(getequiprefinerycnt,"i"), - BUILDIN_DEF(getequipweaponlv,"i"), - BUILDIN_DEF(getequippercentrefinery,"i"), - BUILDIN_DEF(successrefitem,"i"), - BUILDIN_DEF(failedrefitem,"i"), - BUILDIN_DEF(downrefitem,"i"), - BUILDIN_DEF(statusup,"i"), - BUILDIN_DEF(statusup2,"ii"), - BUILDIN_DEF(bonus,"iv"), - BUILDIN_DEF2(bonus,"bonus2","ivi"), - BUILDIN_DEF2(bonus,"bonus3","ivii"), - BUILDIN_DEF2(bonus,"bonus4","ivvii"), - BUILDIN_DEF2(bonus,"bonus5","ivviii"), - BUILDIN_DEF(autobonus,"sii??"), - BUILDIN_DEF(autobonus2,"sii??"), - BUILDIN_DEF(autobonus3,"siiv?"), - BUILDIN_DEF(skill,"vi?"), - BUILDIN_DEF(addtoskill,"vi?"), // [Valaris] - BUILDIN_DEF(guildskill,"vi"), - BUILDIN_DEF(getskilllv,"v"), - BUILDIN_DEF(getgdskilllv,"iv"), - BUILDIN_DEF(basicskillcheck,""), - BUILDIN_DEF(getgmlevel,""), - BUILDIN_DEF(getgroupid,""), - BUILDIN_DEF(end,""), - BUILDIN_DEF(checkoption,"i"), - BUILDIN_DEF(setoption,"i?"), - BUILDIN_DEF(setcart,"?"), - BUILDIN_DEF(checkcart,""), - BUILDIN_DEF(setfalcon,"?"), - BUILDIN_DEF(checkfalcon,""), - BUILDIN_DEF(setriding,"?"), - BUILDIN_DEF(checkriding,""), - BUILDIN_DEF(checkwug,""), - BUILDIN_DEF(checkmadogear,""), - BUILDIN_DEF(setmadogear,"?"), - BUILDIN_DEF2(savepoint,"save","sii"), - BUILDIN_DEF(savepoint,"sii"), - BUILDIN_DEF(gettimetick,"i"), - BUILDIN_DEF(gettime,"i"), - BUILDIN_DEF(gettimestr,"si"), - BUILDIN_DEF(openstorage,""), - BUILDIN_DEF(guildopenstorage,""), - BUILDIN_DEF(itemskill,"vi"), - BUILDIN_DEF(produce,"i"), - BUILDIN_DEF(cooking,"i"), - BUILDIN_DEF(monster,"siisii???"), - BUILDIN_DEF(getmobdrops,"i"), - BUILDIN_DEF(areamonster,"siiiisii???"), - BUILDIN_DEF(killmonster,"ss?"), - BUILDIN_DEF(killmonsterall,"s?"), - BUILDIN_DEF(clone,"siisi????"), - BUILDIN_DEF(doevent,"s"), - BUILDIN_DEF(donpcevent,"s"), - BUILDIN_DEF(cmdothernpc,"ss"), - BUILDIN_DEF(addtimer,"is"), - BUILDIN_DEF(deltimer,"s"), - BUILDIN_DEF(addtimercount,"si"), - BUILDIN_DEF(initnpctimer,"??"), - BUILDIN_DEF(stopnpctimer,"??"), - BUILDIN_DEF(startnpctimer,"??"), - BUILDIN_DEF(setnpctimer,"i?"), - BUILDIN_DEF(getnpctimer,"i?"), - BUILDIN_DEF(attachnpctimer,"?"), // attached the player id to the npc timer [Celest] - BUILDIN_DEF(detachnpctimer,"?"), // detached the player id from the npc timer [Celest] - BUILDIN_DEF(playerattached,""), // returns id of the current attached player. [Skotlex] - BUILDIN_DEF(announce,"si?????"), - BUILDIN_DEF(mapannounce,"ssi?????"), - BUILDIN_DEF(areaannounce,"siiiisi?????"), - BUILDIN_DEF(getusers,"i"), - BUILDIN_DEF(getmapguildusers,"si"), - BUILDIN_DEF(getmapusers,"s"), - BUILDIN_DEF(getareausers,"siiii"), - BUILDIN_DEF(getareadropitem,"siiiiv"), - BUILDIN_DEF(enablenpc,"s"), - BUILDIN_DEF(disablenpc,"s"), - BUILDIN_DEF(hideoffnpc,"s"), - BUILDIN_DEF(hideonnpc,"s"), - BUILDIN_DEF(sc_start,"iii?"), - BUILDIN_DEF(sc_start2,"iiii?"), - BUILDIN_DEF(sc_start4,"iiiiii?"), - BUILDIN_DEF(sc_end,"i?"), - BUILDIN_DEF(getstatus, "i?"), - BUILDIN_DEF(getscrate,"ii?"), - BUILDIN_DEF(debugmes,"s"), - BUILDIN_DEF2(catchpet,"pet","i"), - BUILDIN_DEF2(birthpet,"bpet",""), - BUILDIN_DEF(resetlvl,"i"), - BUILDIN_DEF(resetstatus,""), - BUILDIN_DEF(resetskill,""), - BUILDIN_DEF(skillpointcount,""), - BUILDIN_DEF(changebase,"i?"), - BUILDIN_DEF(changesex,""), - BUILDIN_DEF(waitingroom,"si?????"), - BUILDIN_DEF(delwaitingroom,"?"), - BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","?"), - BUILDIN_DEF(enablewaitingroomevent,"?"), - BUILDIN_DEF(disablewaitingroomevent,"?"), - BUILDIN_DEF2(enablewaitingroomevent,"enablearena",""), // Added by RoVeRT - BUILDIN_DEF2(disablewaitingroomevent,"disablearena",""), // Added by RoVeRT - BUILDIN_DEF(getwaitingroomstate,"i?"), - BUILDIN_DEF(warpwaitingpc,"sii?"), - BUILDIN_DEF(attachrid,"i"), - BUILDIN_DEF(detachrid,""), - BUILDIN_DEF(isloggedin,"i?"), - BUILDIN_DEF(setmapflagnosave,"ssii"), - BUILDIN_DEF(getmapflag,"si"), - BUILDIN_DEF(setmapflag,"si?"), - BUILDIN_DEF(removemapflag,"si?"), - BUILDIN_DEF(pvpon,"s"), - BUILDIN_DEF(pvpoff,"s"), - BUILDIN_DEF(gvgon,"s"), - BUILDIN_DEF(gvgoff,"s"), - BUILDIN_DEF(emotion,"i??"), - BUILDIN_DEF(maprespawnguildid,"sii"), - BUILDIN_DEF(agitstart,""), // <Agit> - BUILDIN_DEF(agitend,""), - BUILDIN_DEF(agitcheck,""), // <Agitcheck> - BUILDIN_DEF(flagemblem,"i"), // Flag Emblem - BUILDIN_DEF(getcastlename,"s"), - BUILDIN_DEF(getcastledata,"si"), - BUILDIN_DEF(setcastledata,"sii"), - BUILDIN_DEF(requestguildinfo,"i?"), - BUILDIN_DEF(getequipcardcnt,"i"), - BUILDIN_DEF(successremovecards,"i"), - BUILDIN_DEF(failedremovecards,"ii"), - BUILDIN_DEF(marriage,"s"), - BUILDIN_DEF2(wedding_effect,"wedding",""), - BUILDIN_DEF(divorce,""), - BUILDIN_DEF(ispartneron,""), - BUILDIN_DEF(getpartnerid,""), - BUILDIN_DEF(getchildid,""), - BUILDIN_DEF(getmotherid,""), - BUILDIN_DEF(getfatherid,""), - BUILDIN_DEF(warppartner,"sii"), - BUILDIN_DEF(getitemname,"v"), - BUILDIN_DEF(getitemslots,"i"), - BUILDIN_DEF(makepet,"i"), - BUILDIN_DEF(getexp,"ii"), - BUILDIN_DEF(getinventorylist,""), - BUILDIN_DEF(getskilllist,""), - BUILDIN_DEF(clearitem,""), - BUILDIN_DEF(classchange,"ii"), - BUILDIN_DEF(misceffect,"i"), - BUILDIN_DEF(playBGM,"s"), - BUILDIN_DEF(playBGMall,"s?????"), - BUILDIN_DEF(soundeffect,"si"), - BUILDIN_DEF(soundeffectall,"si?????"), // SoundEffectAll [Codemaster] - BUILDIN_DEF(strmobinfo,"ii"), // display mob data [Valaris] - BUILDIN_DEF(guardian,"siisi??"), // summon guardians - BUILDIN_DEF(guardianinfo,"sii"), // display guardian data [Valaris] - BUILDIN_DEF(petskillbonus,"iiii"), // [Valaris] - BUILDIN_DEF(petrecovery,"ii"), // [Valaris] - BUILDIN_DEF(petloot,"i"), // [Valaris] - BUILDIN_DEF(petheal,"iiii"), // [Valaris] - BUILDIN_DEF(petskillattack,"viii"), // [Skotlex] - BUILDIN_DEF(petskillattack2,"viiii"), // [Valaris] - BUILDIN_DEF(petskillsupport,"viiii"), // [Skotlex] - BUILDIN_DEF(skilleffect,"vi"), // skill effect [Celest] - BUILDIN_DEF(npcskilleffect,"viii"), // npc skill effect [Valaris] - BUILDIN_DEF(specialeffect,"i??"), // npc skill effect [Valaris] - BUILDIN_DEF(specialeffect2,"i??"), // skill effect on players[Valaris] - BUILDIN_DEF(nude,""), // nude command [Valaris] - BUILDIN_DEF(mapwarp,"ssii??"), // Added by RoVeRT - BUILDIN_DEF(atcommand,"s"), // [MouseJstr] - BUILDIN_DEF2(atcommand,"charcommand","s"), // [MouseJstr] - BUILDIN_DEF(movenpc,"sii?"), // [MouseJstr] - BUILDIN_DEF(message,"ss"), // [MouseJstr] - BUILDIN_DEF(npctalk,"s"), // [Valaris] - BUILDIN_DEF(mobcount,"ss"), - BUILDIN_DEF(getlook,"i"), - BUILDIN_DEF(getsavepoint,"i"), - BUILDIN_DEF(npcspeed,"i"), // [Valaris] - BUILDIN_DEF(npcwalkto,"ii"), // [Valaris] - BUILDIN_DEF(npcstop,""), // [Valaris] - BUILDIN_DEF(getmapxy,"rrri?"), //by Lorky [Lupus] - BUILDIN_DEF(checkoption1,"i"), - BUILDIN_DEF(checkoption2,"i"), - BUILDIN_DEF(guildgetexp,"i"), - BUILDIN_DEF(guildchangegm,"is"), - BUILDIN_DEF(logmes,"s"), //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus] - BUILDIN_DEF(summon,"si??"), // summons a slave monster [Celest] - BUILDIN_DEF(isnight,""), // check whether it is night time [Celest] - BUILDIN_DEF(isday,""), // check whether it is day time [Celest] - BUILDIN_DEF(isequipped,"i*"), // check whether another item/card has been equipped [Celest] - BUILDIN_DEF(isequippedcnt,"i*"), // check how many items/cards are being equipped [Celest] - BUILDIN_DEF(cardscnt,"i*"), // check how many items/cards are being equipped in the same arm [Lupus] - BUILDIN_DEF(getrefine,""), // returns the refined number of the current item, or an item with index specified [celest] - BUILDIN_DEF(night,""), // sets the server to night time - BUILDIN_DEF(day,""), // sets the server to day time +bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)) { + int n = add_str(name), i = 0; + + if( str_data[n].type == C_FUNC ) { + str_data[n].func = func; + i = str_data[n].val; + if( args ) { + int slen = strlen(args); + if( script->buildin[i] ) { + aFree(script->buildin[i]); + } + CREATE(script->buildin[i], char, slen + 1); + safestrncpy(script->buildin[i], args, slen + 1); + } else { + if( script->buildin[i] ) + aFree(script->buildin[i]); + script->buildin[i] = NULL; + } + + } else { + i = script->buildin_count; + str_data[n].type = C_FUNC; + str_data[n].val = i; + str_data[n].func = func; + + RECREATE(script->buildin, char *, ++script->buildin_count); + + /* we only store the arguments, its the only thing used out of this */ + if( args != NULL ) { + int slen = strlen(args); + CREATE(script->buildin[i], char, slen + 1); + safestrncpy(script->buildin[i], args, slen + 1); + } else + script->buildin[i] = NULL; + } + + return true; +} + +void script_parse_builtin(void) { + struct script_function BUILDIN[] = { + // NPC interaction + BUILDIN_DEF(mes,"s*"), + BUILDIN_DEF(next,""), + BUILDIN_DEF(close,""), + BUILDIN_DEF(close2,""), + BUILDIN_DEF(menu,"sl*"), + BUILDIN_DEF(select,"s*"), //for future jA script compatibility + BUILDIN_DEF(prompt,"s*"), + // + BUILDIN_DEF(goto,"l"), + BUILDIN_DEF(callsub,"l*"), + BUILDIN_DEF(callfunc,"s*"), + BUILDIN_DEF(return,"?"), + BUILDIN_DEF(getarg,"i?"), + BUILDIN_DEF(jobchange,"i?"), + BUILDIN_DEF(jobname,"i"), + BUILDIN_DEF(input,"r??"), + BUILDIN_DEF(warp,"sii"), + BUILDIN_DEF(areawarp,"siiiisii??"), + BUILDIN_DEF(warpchar,"siii"), // [LuzZza] + BUILDIN_DEF(warpparty,"siii?"), // [Fredzilla] [Paradox924X] + BUILDIN_DEF(warpguild,"siii"), // [Fredzilla] + BUILDIN_DEF(setlook,"ii"), + BUILDIN_DEF(changelook,"ii"), // Simulates but don't Store it + BUILDIN_DEF(set,"rv"), + BUILDIN_DEF(setarray,"rv*"), + BUILDIN_DEF(cleararray,"rvi"), + BUILDIN_DEF(copyarray,"rri"), + BUILDIN_DEF(getarraysize,"r"), + BUILDIN_DEF(deletearray,"r?"), + BUILDIN_DEF(getelementofarray,"ri"), + BUILDIN_DEF(getitem,"vi?"), + BUILDIN_DEF(rentitem,"vi"), + BUILDIN_DEF(getitem2,"viiiiiiii?"), + BUILDIN_DEF(getnameditem,"vv"), + BUILDIN_DEF2(grouprandomitem,"groupranditem","i"), + BUILDIN_DEF(makeitem,"visii"), + BUILDIN_DEF(delitem,"vi?"), + BUILDIN_DEF(delitem2,"viiiiiiii?"), + BUILDIN_DEF2(enableitemuse,"enable_items",""), + BUILDIN_DEF2(disableitemuse,"disable_items",""), + BUILDIN_DEF(cutin,"si"), + BUILDIN_DEF(viewpoint,"iiiii"), + BUILDIN_DEF(heal,"ii"), + BUILDIN_DEF(itemheal,"ii"), + BUILDIN_DEF(percentheal,"ii"), + BUILDIN_DEF(rand,"i?"), + BUILDIN_DEF(countitem,"v"), + BUILDIN_DEF(countitem2,"viiiiiii"), + BUILDIN_DEF(checkweight,"vi*"), + BUILDIN_DEF(checkweight2,"rr"), + BUILDIN_DEF(readparam,"i?"), + BUILDIN_DEF(getcharid,"i?"), + BUILDIN_DEF(getnpcid,"i?"), + BUILDIN_DEF(getpartyname,"i"), + BUILDIN_DEF(getpartymember,"i?"), + BUILDIN_DEF(getpartyleader,"i?"), + BUILDIN_DEF(getguildname,"i"), + BUILDIN_DEF(getguildmaster,"i"), + BUILDIN_DEF(getguildmasterid,"i"), + BUILDIN_DEF(strcharinfo,"i"), + BUILDIN_DEF(strnpcinfo,"i"), + BUILDIN_DEF(getequipid,"i"), + BUILDIN_DEF(getequipname,"i"), + BUILDIN_DEF(getbrokenid,"i"), // [Valaris] + BUILDIN_DEF(repair,"i"), // [Valaris] + BUILDIN_DEF(repairall,""), + BUILDIN_DEF(getequipisequiped,"i"), + BUILDIN_DEF(getequipisenableref,"i"), + BUILDIN_DEF(getequipisidentify,"i"), + BUILDIN_DEF(getequiprefinerycnt,"i"), + BUILDIN_DEF(getequipweaponlv,"i"), + BUILDIN_DEF(getequippercentrefinery,"i"), + BUILDIN_DEF(successrefitem,"i"), + BUILDIN_DEF(failedrefitem,"i"), + BUILDIN_DEF(downrefitem,"i"), + BUILDIN_DEF(statusup,"i"), + BUILDIN_DEF(statusup2,"ii"), + BUILDIN_DEF(bonus,"iv"), + BUILDIN_DEF2(bonus,"bonus2","ivi"), + BUILDIN_DEF2(bonus,"bonus3","ivii"), + BUILDIN_DEF2(bonus,"bonus4","ivvii"), + BUILDIN_DEF2(bonus,"bonus5","ivviii"), + BUILDIN_DEF(autobonus,"sii??"), + BUILDIN_DEF(autobonus2,"sii??"), + BUILDIN_DEF(autobonus3,"siiv?"), + BUILDIN_DEF(skill,"vi?"), + BUILDIN_DEF(addtoskill,"vi?"), // [Valaris] + BUILDIN_DEF(guildskill,"vi"), + BUILDIN_DEF(getskilllv,"v"), + BUILDIN_DEF(getgdskilllv,"iv"), + BUILDIN_DEF(basicskillcheck,""), + BUILDIN_DEF(getgmlevel,""), + BUILDIN_DEF(getgroupid,""), + BUILDIN_DEF(end,""), + BUILDIN_DEF(checkoption,"i"), + BUILDIN_DEF(setoption,"i?"), + BUILDIN_DEF(setcart,"?"), + BUILDIN_DEF(checkcart,""), + BUILDIN_DEF(setfalcon,"?"), + BUILDIN_DEF(checkfalcon,""), + BUILDIN_DEF(setriding,"?"), + BUILDIN_DEF(checkriding,""), + BUILDIN_DEF(checkwug,""), + BUILDIN_DEF(checkmadogear,""), + BUILDIN_DEF(setmadogear,"?"), + BUILDIN_DEF2(savepoint,"save","sii"), + BUILDIN_DEF(savepoint,"sii"), + BUILDIN_DEF(gettimetick,"i"), + BUILDIN_DEF(gettime,"i"), + BUILDIN_DEF(gettimestr,"si"), + BUILDIN_DEF(openstorage,""), + BUILDIN_DEF(guildopenstorage,""), + BUILDIN_DEF(itemskill,"vi?"), + BUILDIN_DEF(produce,"i"), + BUILDIN_DEF(cooking,"i"), + BUILDIN_DEF(monster,"siisii???"), + BUILDIN_DEF(getmobdrops,"i"), + BUILDIN_DEF(areamonster,"siiiisii???"), + BUILDIN_DEF(killmonster,"ss?"), + BUILDIN_DEF(killmonsterall,"s?"), + BUILDIN_DEF(clone,"siisi????"), + BUILDIN_DEF(doevent,"s"), + BUILDIN_DEF(donpcevent,"s"), + BUILDIN_DEF(cmdothernpc,"ss"), + BUILDIN_DEF(addtimer,"is"), + BUILDIN_DEF(deltimer,"s"), + BUILDIN_DEF(addtimercount,"si"), + BUILDIN_DEF(initnpctimer,"??"), + BUILDIN_DEF(stopnpctimer,"??"), + BUILDIN_DEF(startnpctimer,"??"), + BUILDIN_DEF(setnpctimer,"i?"), + BUILDIN_DEF(getnpctimer,"i?"), + BUILDIN_DEF(attachnpctimer,"?"), // attached the player id to the npc timer [Celest] + BUILDIN_DEF(detachnpctimer,"?"), // detached the player id from the npc timer [Celest] + BUILDIN_DEF(playerattached,""), // returns id of the current attached player. [Skotlex] + BUILDIN_DEF(announce,"si?????"), + BUILDIN_DEF(mapannounce,"ssi?????"), + BUILDIN_DEF(areaannounce,"siiiisi?????"), + BUILDIN_DEF(getusers,"i"), + BUILDIN_DEF(getmapguildusers,"si"), + BUILDIN_DEF(getmapusers,"s"), + BUILDIN_DEF(getareausers,"siiii"), + BUILDIN_DEF(getareadropitem,"siiiiv"), + BUILDIN_DEF(enablenpc,"s"), + BUILDIN_DEF(disablenpc,"s"), + BUILDIN_DEF(hideoffnpc,"s"), + BUILDIN_DEF(hideonnpc,"s"), + BUILDIN_DEF(sc_start,"iii?"), + BUILDIN_DEF(sc_start2,"iiii?"), + BUILDIN_DEF(sc_start4,"iiiiii?"), + BUILDIN_DEF(sc_end,"i?"), + BUILDIN_DEF(getstatus, "i?"), + BUILDIN_DEF(getscrate,"ii?"), + BUILDIN_DEF(debugmes,"s"), + BUILDIN_DEF2(catchpet,"pet","i"), + BUILDIN_DEF2(birthpet,"bpet",""), + BUILDIN_DEF(resetlvl,"i"), + BUILDIN_DEF(resetstatus,""), + BUILDIN_DEF(resetskill,""), + BUILDIN_DEF(skillpointcount,""), + BUILDIN_DEF(changebase,"i?"), + BUILDIN_DEF(changesex,""), + BUILDIN_DEF(waitingroom,"si?????"), + BUILDIN_DEF(delwaitingroom,"?"), + BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","?"), + BUILDIN_DEF(enablewaitingroomevent,"?"), + BUILDIN_DEF(disablewaitingroomevent,"?"), + BUILDIN_DEF2(enablewaitingroomevent,"enablearena",""), // Added by RoVeRT + BUILDIN_DEF2(disablewaitingroomevent,"disablearena",""), // Added by RoVeRT + BUILDIN_DEF(getwaitingroomstate,"i?"), + BUILDIN_DEF(warpwaitingpc,"sii?"), + BUILDIN_DEF(attachrid,"i"), + BUILDIN_DEF(detachrid,""), + BUILDIN_DEF(isloggedin,"i?"), + BUILDIN_DEF(setmapflagnosave,"ssii"), + BUILDIN_DEF(getmapflag,"si"), + BUILDIN_DEF(setmapflag,"si?"), + BUILDIN_DEF(removemapflag,"si?"), + BUILDIN_DEF(pvpon,"s"), + BUILDIN_DEF(pvpoff,"s"), + BUILDIN_DEF(gvgon,"s"), + BUILDIN_DEF(gvgoff,"s"), + BUILDIN_DEF(emotion,"i??"), + BUILDIN_DEF(maprespawnguildid,"sii"), + BUILDIN_DEF(agitstart,""), // <Agit> + BUILDIN_DEF(agitend,""), + BUILDIN_DEF(agitcheck,""), // <Agitcheck> + BUILDIN_DEF(flagemblem,"i"), // Flag Emblem + BUILDIN_DEF(getcastlename,"s"), + BUILDIN_DEF(getcastledata,"si"), + BUILDIN_DEF(setcastledata,"sii"), + BUILDIN_DEF(requestguildinfo,"i?"), + BUILDIN_DEF(getequipcardcnt,"i"), + BUILDIN_DEF(successremovecards,"i"), + BUILDIN_DEF(failedremovecards,"ii"), + BUILDIN_DEF(marriage,"s"), + BUILDIN_DEF2(wedding_effect,"wedding",""), + BUILDIN_DEF(divorce,""), + BUILDIN_DEF(ispartneron,""), + BUILDIN_DEF(getpartnerid,""), + BUILDIN_DEF(getchildid,""), + BUILDIN_DEF(getmotherid,""), + BUILDIN_DEF(getfatherid,""), + BUILDIN_DEF(warppartner,"sii"), + BUILDIN_DEF(getitemname,"v"), + BUILDIN_DEF(getitemslots,"i"), + BUILDIN_DEF(makepet,"i"), + BUILDIN_DEF(getexp,"ii"), + BUILDIN_DEF(getinventorylist,""), + BUILDIN_DEF(getskilllist,""), + BUILDIN_DEF(clearitem,""), + BUILDIN_DEF(classchange,"ii"), + BUILDIN_DEF(misceffect,"i"), + BUILDIN_DEF(playBGM,"s"), + BUILDIN_DEF(playBGMall,"s?????"), + BUILDIN_DEF(soundeffect,"si"), + BUILDIN_DEF(soundeffectall,"si?????"), // SoundEffectAll [Codemaster] + BUILDIN_DEF(strmobinfo,"ii"), // display mob data [Valaris] + BUILDIN_DEF(guardian,"siisi??"), // summon guardians + BUILDIN_DEF(guardianinfo,"sii"), // display guardian data [Valaris] + BUILDIN_DEF(petskillbonus,"iiii"), // [Valaris] + BUILDIN_DEF(petrecovery,"ii"), // [Valaris] + BUILDIN_DEF(petloot,"i"), // [Valaris] + BUILDIN_DEF(petheal,"iiii"), // [Valaris] + BUILDIN_DEF(petskillattack,"viii"), // [Skotlex] + BUILDIN_DEF(petskillattack2,"viiii"), // [Valaris] + BUILDIN_DEF(petskillsupport,"viiii"), // [Skotlex] + BUILDIN_DEF(skilleffect,"vi"), // skill effect [Celest] + BUILDIN_DEF(npcskilleffect,"viii"), // npc skill effect [Valaris] + BUILDIN_DEF(specialeffect,"i??"), // npc skill effect [Valaris] + BUILDIN_DEF(specialeffect2,"i??"), // skill effect on players[Valaris] + BUILDIN_DEF(nude,""), // nude command [Valaris] + BUILDIN_DEF(mapwarp,"ssii??"), // Added by RoVeRT + BUILDIN_DEF(atcommand,"s"), // [MouseJstr] + BUILDIN_DEF2(atcommand,"charcommand","s"), // [MouseJstr] + BUILDIN_DEF(movenpc,"sii?"), // [MouseJstr] + BUILDIN_DEF(message,"ss"), // [MouseJstr] + BUILDIN_DEF(npctalk,"s"), // [Valaris] + BUILDIN_DEF(mobcount,"ss"), + BUILDIN_DEF(getlook,"i"), + BUILDIN_DEF(getsavepoint,"i"), + BUILDIN_DEF(npcspeed,"i"), // [Valaris] + BUILDIN_DEF(npcwalkto,"ii"), // [Valaris] + BUILDIN_DEF(npcstop,""), // [Valaris] + BUILDIN_DEF(getmapxy,"rrri?"), //by Lorky [Lupus] + BUILDIN_DEF(checkoption1,"i"), + BUILDIN_DEF(checkoption2,"i"), + BUILDIN_DEF(guildgetexp,"i"), + BUILDIN_DEF(guildchangegm,"is"), + BUILDIN_DEF(logmes,"s"), //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus] + BUILDIN_DEF(summon,"si??"), // summons a slave monster [Celest] + BUILDIN_DEF(isnight,""), // check whether it is night time [Celest] + BUILDIN_DEF(isday,""), // check whether it is day time [Celest] + BUILDIN_DEF(isequipped,"i*"), // check whether another item/card has been equipped [Celest] + BUILDIN_DEF(isequippedcnt,"i*"), // check how many items/cards are being equipped [Celest] + BUILDIN_DEF(cardscnt,"i*"), // check how many items/cards are being equipped in the same arm [Lupus] + BUILDIN_DEF(getrefine,""), // returns the refined number of the current item, or an item with index specified [celest] + BUILDIN_DEF(night,""), // sets the server to night time + BUILDIN_DEF(day,""), // sets the server to day time #ifdef PCRE_SUPPORT - BUILDIN_DEF(defpattern,"iss"), // Define pattern to listen for [MouseJstr] - BUILDIN_DEF(activatepset,"i"), // Activate a pattern set [MouseJstr] - BUILDIN_DEF(deactivatepset,"i"), // Deactive a pattern set [MouseJstr] - BUILDIN_DEF(deletepset,"i"), // Delete a pattern set [MouseJstr] + BUILDIN_DEF(defpattern,"iss"), // Define pattern to listen for [MouseJstr] + BUILDIN_DEF(activatepset,"i"), // Activate a pattern set [MouseJstr] + BUILDIN_DEF(deactivatepset,"i"), // Deactive a pattern set [MouseJstr] + BUILDIN_DEF(deletepset,"i"), // Delete a pattern set [MouseJstr] #endif - BUILDIN_DEF(dispbottom,"s"), //added from jA [Lupus] - BUILDIN_DEF(getusersname,""), - BUILDIN_DEF(recovery,""), - BUILDIN_DEF(getpetinfo,"i"), - BUILDIN_DEF(gethominfo,"i"), - BUILDIN_DEF(getmercinfo,"i?"), - BUILDIN_DEF(checkequipedcard,"i"), - BUILDIN_DEF(jump_zero,"il"), //for future jA script compatibility - BUILDIN_DEF(globalmes,"s?"), //end jA addition - BUILDIN_DEF(unequip,"i"), // unequip command [Spectre] - BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris] - BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris] - BUILDIN_DEF(charat,"si"), - BUILDIN_DEF(setchar,"ssi"), - BUILDIN_DEF(insertchar,"ssi"), - BUILDIN_DEF(delchar,"si"), - BUILDIN_DEF(strtoupper,"s"), - BUILDIN_DEF(strtolower,"s"), - BUILDIN_DEF(charisupper, "si"), - BUILDIN_DEF(charislower, "si"), - BUILDIN_DEF(substr,"sii"), - BUILDIN_DEF(explode, "rss"), - BUILDIN_DEF(implode, "r?"), - BUILDIN_DEF(sprintf,"s*"), // [Mirei] - BUILDIN_DEF(sscanf,"ss*"), // [Mirei] - BUILDIN_DEF(strpos,"ss?"), - BUILDIN_DEF(replacestr,"sss??"), - BUILDIN_DEF(countstr,"ss?"), - BUILDIN_DEF(setnpcdisplay,"sv??"), - BUILDIN_DEF(compare,"ss"), // Lordalfa - To bring strstr to scripting Engine. - BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info - BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info - BUILDIN_DEF(getequipcardid,"ii"), //[Lupus] returns CARD ID or other info from CARD slot N of equipped item - // [zBuffer] List of mathematics commands ---> - BUILDIN_DEF(sqrt,"i"), - BUILDIN_DEF(pow,"ii"), - BUILDIN_DEF(distance,"iiii"), - // <--- [zBuffer] List of mathematics commands - BUILDIN_DEF(md5,"s"), - // [zBuffer] List of dynamic var commands ---> - BUILDIN_DEF(getd,"s"), - BUILDIN_DEF(setd,"sv"), - // <--- [zBuffer] List of dynamic var commands - BUILDIN_DEF(petstat,"i"), - BUILDIN_DEF(callshop,"s?"), // [Skotlex] - BUILDIN_DEF(npcshopitem,"sii*"), // [Lance] - BUILDIN_DEF(npcshopadditem,"sii*"), - BUILDIN_DEF(npcshopdelitem,"si*"), - BUILDIN_DEF(npcshopattach,"s?"), - BUILDIN_DEF(equip,"i"), - BUILDIN_DEF(autoequip,"ii"), - BUILDIN_DEF(setbattleflag,"si"), - BUILDIN_DEF(getbattleflag,"s"), - BUILDIN_DEF(setitemscript,"is?"), //Set NEW item bonus script. Lupus - BUILDIN_DEF(disguise,"i"), //disguise player. Lupus - BUILDIN_DEF(undisguise,""), //undisguise player. Lupus - BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus - BUILDIN_DEF(axtoi,"s"), - BUILDIN_DEF(query_sql,"s*"), - BUILDIN_DEF(query_logsql,"s*"), - BUILDIN_DEF(escape_sql,"v"), - BUILDIN_DEF(atoi,"s"), - // [zBuffer] List of player cont commands ---> - BUILDIN_DEF(rid2name,"i"), - BUILDIN_DEF(pcfollow,"ii"), - BUILDIN_DEF(pcstopfollow,"i"), - BUILDIN_DEF(pcblockmove,"ii"), - // <--- [zBuffer] List of player cont commands - // [zBuffer] List of mob control commands ---> - BUILDIN_DEF(unitwalk,"ii?"), - BUILDIN_DEF(unitkill,"i"), - BUILDIN_DEF(unitwarp,"isii"), - BUILDIN_DEF(unitattack,"iv?"), - BUILDIN_DEF(unitstop,"i"), - BUILDIN_DEF(unittalk,"is"), - BUILDIN_DEF(unitemote,"ii"), - BUILDIN_DEF(unitskilluseid,"ivi?"), // originally by Qamera [Celest] - BUILDIN_DEF(unitskillusepos,"iviii"), // [Celest] -// <--- [zBuffer] List of mob control commands - BUILDIN_DEF(sleep,"i"), - BUILDIN_DEF(sleep2,"i"), - BUILDIN_DEF(awake,"s"), - BUILDIN_DEF(getvariableofnpc,"rs"), - BUILDIN_DEF(warpportal,"iisii"), - BUILDIN_DEF2(homunculus_evolution,"homevolution",""), //[orn] - BUILDIN_DEF2(homunculus_mutate,"hommutate","?"), - BUILDIN_DEF2(homunculus_shuffle,"homshuffle",""), //[Zephyrus] - BUILDIN_DEF(eaclass,"?"), //[Skotlex] - BUILDIN_DEF(roclass,"i?"), //[Skotlex] - BUILDIN_DEF(checkvending,"?"), - BUILDIN_DEF(checkchatting,"?"), - BUILDIN_DEF(openmail,""), - BUILDIN_DEF(openauction,""), - BUILDIN_DEF(checkcell,"siii"), - BUILDIN_DEF(setcell,"siiiiii"), - BUILDIN_DEF(setwall,"siiiiis"), - BUILDIN_DEF(delwall,"s"), - BUILDIN_DEF(searchitem,"rs"), - BUILDIN_DEF(mercenary_create,"ii"), - BUILDIN_DEF(mercenary_heal,"ii"), - BUILDIN_DEF(mercenary_sc_start,"iii"), - BUILDIN_DEF(mercenary_get_calls,"i"), - BUILDIN_DEF(mercenary_get_faith,"i"), - BUILDIN_DEF(mercenary_set_calls,"ii"), - BUILDIN_DEF(mercenary_set_faith,"ii"), - BUILDIN_DEF(readbook,"ii"), - BUILDIN_DEF(setfont,"i"), - BUILDIN_DEF(areamobuseskill,"siiiiviiiii"), - BUILDIN_DEF(progressbar,"si"), - BUILDIN_DEF(pushpc,"ii"), - BUILDIN_DEF(buyingstore,"i"), - BUILDIN_DEF(searchstores,"ii"), - BUILDIN_DEF(showdigit,"i?"), - // WoE SE - BUILDIN_DEF(agitstart2,""), - BUILDIN_DEF(agitend2,""), - BUILDIN_DEF(agitcheck2,""), - // BattleGround - BUILDIN_DEF(waitingroom2bg,"siiss?"), - BUILDIN_DEF(waitingroom2bg_single,"isiis"), - BUILDIN_DEF(bg_team_setxy,"iii"), - BUILDIN_DEF(bg_warp,"isii"), - BUILDIN_DEF(bg_monster,"isiisi?"), - BUILDIN_DEF(bg_monster_set_team,"ii"), - BUILDIN_DEF(bg_leave,""), - BUILDIN_DEF(bg_destroy,"i"), - BUILDIN_DEF(areapercentheal,"siiiiii"), - BUILDIN_DEF(bg_get_data,"ii"), - BUILDIN_DEF(bg_getareausers,"isiiii"), - BUILDIN_DEF(bg_updatescore,"sii"), - - // Instancing - BUILDIN_DEF(instance_create,"si"), - BUILDIN_DEF(instance_destroy,"?"), - BUILDIN_DEF(instance_attachmap,"si?"), - BUILDIN_DEF(instance_detachmap,"s?"), - BUILDIN_DEF(instance_attach,"i"), - BUILDIN_DEF(instance_id,"?"), - BUILDIN_DEF(instance_set_timeout,"ii?"), - BUILDIN_DEF(instance_init,"i"), - BUILDIN_DEF(instance_announce,"isi?????"), - BUILDIN_DEF(instance_npcname,"s?"), - BUILDIN_DEF(has_instance,"s?"), - BUILDIN_DEF(instance_warpall,"sii?"), - BUILDIN_DEF(instance_check_party,"i???"), - /** - * 3rd-related - **/ - BUILDIN_DEF(makerune,"i"), - BUILDIN_DEF(checkdragon,""),//[Ind] - BUILDIN_DEF(setdragon,"?"),//[Ind] - BUILDIN_DEF(ismounting,""),//[Ind] - BUILDIN_DEF(setmounting,""),//[Ind] - BUILDIN_DEF(checkre,"i"), - /** - * rAthena and beyond! - **/ - BUILDIN_DEF(getargcount,""), - BUILDIN_DEF(getcharip,"?"), - BUILDIN_DEF(is_function,"s"), - BUILDIN_DEF(get_revision,""), - BUILDIN_DEF(freeloop,"i"), - BUILDIN_DEF(getrandgroupitem,"ii"), - BUILDIN_DEF(cleanmap,"s"), - BUILDIN_DEF2(cleanmap,"cleanarea","siiii"), - BUILDIN_DEF(npcskill,"viii"), - /** - * @commands (script based) - **/ - BUILDIN_DEF(bindatcmd, "ss??"), - BUILDIN_DEF(unbindatcmd, "s"), - BUILDIN_DEF(useatcmd, "s"), - - //Quest Log System [Inkfish] - BUILDIN_DEF(setquest, "i"), - BUILDIN_DEF(erasequest, "i"), - BUILDIN_DEF(completequest, "i"), - BUILDIN_DEF(checkquest, "i?"), - BUILDIN_DEF(changequest, "ii"), - BUILDIN_DEF(showevent, "ii"), - {NULL,NULL,NULL}, -}; + BUILDIN_DEF(dispbottom,"s"), //added from jA [Lupus] + BUILDIN_DEF(getusersname,""), + BUILDIN_DEF(recovery,""), + BUILDIN_DEF(getpetinfo,"i"), + BUILDIN_DEF(gethominfo,"i"), + BUILDIN_DEF(getmercinfo,"i?"), + BUILDIN_DEF(checkequipedcard,"i"), + BUILDIN_DEF(jump_zero,"il"), //for future jA script compatibility + BUILDIN_DEF(globalmes,"s?"), //end jA addition + BUILDIN_DEF(unequip,"i"), // unequip command [Spectre] + BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris] + BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris] + BUILDIN_DEF(charat,"si"), + BUILDIN_DEF(setchar,"ssi"), + BUILDIN_DEF(insertchar,"ssi"), + BUILDIN_DEF(delchar,"si"), + BUILDIN_DEF(strtoupper,"s"), + BUILDIN_DEF(strtolower,"s"), + BUILDIN_DEF(charisupper, "si"), + BUILDIN_DEF(charislower, "si"), + BUILDIN_DEF(substr,"sii"), + BUILDIN_DEF(explode, "rss"), + BUILDIN_DEF(implode, "r?"), + BUILDIN_DEF(sprintf,"s*"), // [Mirei] + BUILDIN_DEF(sscanf,"ss*"), // [Mirei] + BUILDIN_DEF(strpos,"ss?"), + BUILDIN_DEF(replacestr,"sss??"), + BUILDIN_DEF(countstr,"ss?"), + BUILDIN_DEF(setnpcdisplay,"sv??"), + BUILDIN_DEF(compare,"ss"), // Lordalfa - To bring strstr to scripting Engine. + BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info + BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info + BUILDIN_DEF(getequipcardid,"ii"), //[Lupus] returns CARD ID or other info from CARD slot N of equipped item + // [zBuffer] List of mathematics commands ---> + BUILDIN_DEF(sqrt,"i"), + BUILDIN_DEF(pow,"ii"), + BUILDIN_DEF(distance,"iiii"), + // <--- [zBuffer] List of mathematics commands + BUILDIN_DEF(md5,"s"), + // [zBuffer] List of dynamic var commands ---> + BUILDIN_DEF(getd,"s"), + BUILDIN_DEF(setd,"sv"), + // <--- [zBuffer] List of dynamic var commands + BUILDIN_DEF(petstat,"i"), + BUILDIN_DEF(callshop,"s?"), // [Skotlex] + BUILDIN_DEF(npcshopitem,"sii*"), // [Lance] + BUILDIN_DEF(npcshopadditem,"sii*"), + BUILDIN_DEF(npcshopdelitem,"si*"), + BUILDIN_DEF(npcshopattach,"s?"), + BUILDIN_DEF(equip,"i"), + BUILDIN_DEF(autoequip,"ii"), + BUILDIN_DEF(setbattleflag,"si"), + BUILDIN_DEF(getbattleflag,"s"), + BUILDIN_DEF(setitemscript,"is?"), //Set NEW item bonus script. Lupus + BUILDIN_DEF(disguise,"i"), //disguise player. Lupus + BUILDIN_DEF(undisguise,""), //undisguise player. Lupus + BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus + BUILDIN_DEF(axtoi,"s"), + BUILDIN_DEF(query_sql,"s*"), + BUILDIN_DEF(query_logsql,"s*"), + BUILDIN_DEF(escape_sql,"v"), + BUILDIN_DEF(atoi,"s"), + // [zBuffer] List of player cont commands ---> + BUILDIN_DEF(rid2name,"i"), + BUILDIN_DEF(pcfollow,"ii"), + BUILDIN_DEF(pcstopfollow,"i"), + BUILDIN_DEF(pcblockmove,"ii"), + // <--- [zBuffer] List of player cont commands + // [zBuffer] List of mob control commands ---> + BUILDIN_DEF(unitwalk,"ii?"), + BUILDIN_DEF(unitkill,"i"), + BUILDIN_DEF(unitwarp,"isii"), + BUILDIN_DEF(unitattack,"iv?"), + BUILDIN_DEF(unitstop,"i"), + BUILDIN_DEF(unittalk,"is"), + BUILDIN_DEF(unitemote,"ii"), + BUILDIN_DEF(unitskilluseid,"ivi?"), // originally by Qamera [Celest] + BUILDIN_DEF(unitskillusepos,"iviii"), // [Celest] + // <--- [zBuffer] List of mob control commands + BUILDIN_DEF(sleep,"i"), + BUILDIN_DEF(sleep2,"i"), + BUILDIN_DEF(awake,"s"), + BUILDIN_DEF(getvariableofnpc,"rs"), + BUILDIN_DEF(warpportal,"iisii"), + BUILDIN_DEF2(homunculus_evolution,"homevolution",""), //[orn] + BUILDIN_DEF2(homunculus_mutate,"hommutate","?"), + BUILDIN_DEF2(homunculus_shuffle,"homshuffle",""), //[Zephyrus] + BUILDIN_DEF(eaclass,"?"), //[Skotlex] + BUILDIN_DEF(roclass,"i?"), //[Skotlex] + BUILDIN_DEF(checkvending,"?"), + BUILDIN_DEF(checkchatting,"?"), + BUILDIN_DEF(checkidle,"?"), + BUILDIN_DEF(openmail,""), + BUILDIN_DEF(openauction,""), + BUILDIN_DEF(checkcell,"siii"), + BUILDIN_DEF(setcell,"siiiiii"), + BUILDIN_DEF(setwall,"siiiiis"), + BUILDIN_DEF(delwall,"s"), + BUILDIN_DEF(searchitem,"rs"), + BUILDIN_DEF(mercenary_create,"ii"), + BUILDIN_DEF(mercenary_heal,"ii"), + BUILDIN_DEF(mercenary_sc_start,"iii"), + BUILDIN_DEF(mercenary_get_calls,"i"), + BUILDIN_DEF(mercenary_get_faith,"i"), + BUILDIN_DEF(mercenary_set_calls,"ii"), + BUILDIN_DEF(mercenary_set_faith,"ii"), + BUILDIN_DEF(readbook,"ii"), + BUILDIN_DEF(setfont,"i"), + BUILDIN_DEF(areamobuseskill,"siiiiviiiii"), + BUILDIN_DEF(progressbar,"si"), + BUILDIN_DEF(pushpc,"ii"), + BUILDIN_DEF(buyingstore,"i"), + BUILDIN_DEF(searchstores,"ii"), + BUILDIN_DEF(showdigit,"i?"), + // WoE SE + BUILDIN_DEF(agitstart2,""), + BUILDIN_DEF(agitend2,""), + BUILDIN_DEF(agitcheck2,""), + // BattleGround + BUILDIN_DEF(waitingroom2bg,"siiss?"), + BUILDIN_DEF(waitingroom2bg_single,"isiis"), + BUILDIN_DEF(bg_team_setxy,"iii"), + BUILDIN_DEF(bg_warp,"isii"), + BUILDIN_DEF(bg_monster,"isiisi?"), + BUILDIN_DEF(bg_monster_set_team,"ii"), + BUILDIN_DEF(bg_leave,""), + BUILDIN_DEF(bg_destroy,"i"), + BUILDIN_DEF(areapercentheal,"siiiiii"), + BUILDIN_DEF(bg_get_data,"ii"), + BUILDIN_DEF(bg_getareausers,"isiiii"), + BUILDIN_DEF(bg_updatescore,"sii"), + + // Instancing + BUILDIN_DEF(instance_create,"si"), + BUILDIN_DEF(instance_destroy,"?"), + BUILDIN_DEF(instance_attachmap,"si?"), + BUILDIN_DEF(instance_detachmap,"s?"), + BUILDIN_DEF(instance_attach,"i"), + BUILDIN_DEF(instance_id,"?"), + BUILDIN_DEF(instance_set_timeout,"ii?"), + BUILDIN_DEF(instance_init,"i"), + BUILDIN_DEF(instance_announce,"isi?????"), + BUILDIN_DEF(instance_npcname,"s?"), + BUILDIN_DEF(has_instance,"s?"), + BUILDIN_DEF(instance_warpall,"sii?"), + BUILDIN_DEF(instance_check_party,"i???"), + /** + * 3rd-related + **/ + BUILDIN_DEF(makerune,"i"), + BUILDIN_DEF(checkdragon,""),//[Ind] + BUILDIN_DEF(setdragon,"?"),//[Ind] + BUILDIN_DEF(ismounting,""),//[Ind] + BUILDIN_DEF(setmounting,""),//[Ind] + BUILDIN_DEF(checkre,"i"), + /** + * rAthena and beyond! + **/ + BUILDIN_DEF(getargcount,""), + BUILDIN_DEF(getcharip,"?"), + BUILDIN_DEF(is_function,"s"), + BUILDIN_DEF(get_revision,""), + BUILDIN_DEF(freeloop,"i"), + BUILDIN_DEF(getrandgroupitem,"ii"), + BUILDIN_DEF(cleanmap,"s"), + BUILDIN_DEF2(cleanmap,"cleanarea","siiii"), + BUILDIN_DEF(npcskill,"viii"), + BUILDIN_DEF(itemeffect,"v"), + BUILDIN_DEF(delequip,"i"), + /** + * @commands (script based) + **/ + BUILDIN_DEF(bindatcmd, "ss???"), + BUILDIN_DEF(unbindatcmd, "s"), + BUILDIN_DEF(useatcmd, "s"), + + //Quest Log System [Inkfish] + BUILDIN_DEF(setquest, "i"), + BUILDIN_DEF(erasequest, "i"), + BUILDIN_DEF(completequest, "i"), + BUILDIN_DEF(checkquest, "i?"), + BUILDIN_DEF(changequest, "ii"), + BUILDIN_DEF(showevent, "ii"), + }; + int i,n, len = ARRAYLENGTH(BUILDIN), start = script->buildin_count; + char* p; + RECREATE(script->buildin, char *, start + len); + for( i = 0; i < len; i++ ) { + // arg must follow the pattern: (v|s|i|r|l)*\?*\*? + // 'v' - value (either string or int or reference) + // 's' - string + // 'i' - int + // 'r' - reference (of a variable) + // 'l' - label + // '?' - one optional parameter + // '*' - unknown number of optional parameters + p = BUILDIN[i].arg; + while( *p == 'v' || *p == 's' || *p == 'i' || *p == 'r' || *p == 'l' ) ++p; + while( *p == '?' ) ++p; + if( *p == '*' ) ++p; + if( *p != 0 ){ + ShowWarning("script_parse_builtin: ignoring function \"%s\" with invalid arg \"%s\".\n", BUILDIN[i].name, BUILDIN[i].arg); + } else if( *skip_word(BUILDIN[i].name) != 0 ){ + ShowWarning("script_parse_builtin: ignoring function with invalid name \"%s\" (must be a word).\n", BUILDIN[i].name); + } else { + int slen = strlen(BUILDIN[i].arg), offset = start + i; + n = add_str(BUILDIN[i].name); + + if (!strcmp(BUILDIN[i].name, "set")) buildin_set_ref = n; + else if (!strcmp(BUILDIN[i].name, "callsub")) buildin_callsub_ref = n; + else if (!strcmp(BUILDIN[i].name, "callfunc")) buildin_callfunc_ref = n; + else if (!strcmp(BUILDIN[i].name, "getelementofarray") ) buildin_getelementofarray_ref = n; + + if( str_data[n].func && str_data[n].func != BUILDIN[i].func ) + continue;/* something replaced it, skip. */ + + str_data[n].type = C_FUNC; + str_data[n].val = offset; + str_data[n].func = BUILDIN[i].func; + + /* we only store the arguments, its the only thing used out of this */ + if( slen ) { + CREATE(script->buildin[offset], char, slen + 1); + safestrncpy(script->buildin[offset], BUILDIN[i].arg, slen + 1); + } else + script->buildin[offset] = NULL; + + script->buildin_count++; + + } + } +} + +void script_defaults(void) { + script = &script_s; + + script->buildin_count = 0; + script->buildin = NULL; + + script->init = do_init_script; + script->final = do_final_script; + + script->parse_builtin = script_parse_builtin; + script->addScript = script_hp_add; + script->conv_num = conv_num; + script->conv_str = conv_str; +} |