From 537296dd156e22592606eedf539395288855639b Mon Sep 17 00:00:00 2001 From: ai4rei Date: Tue, 21 Dec 2010 23:23:06 +0000 Subject: * Added script_setarray_pc for setting temporary character array variables outside of script.c without requiring them to use script-interal code (add_str and reference_uid). - Applied script_setarray_pc to assignment of dynamic shop arrays (related r5841). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14613 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/script.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/map/script.c') diff --git a/src/map/script.c b/src/map/script.c index 6d0f8d81a..725ef0204 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3579,6 +3579,42 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void } +/// sets a temporary character array variable element idx to given value +/// @param refcache Pointer to an int variable, which keeps a copy of the reference to varname and must be initialized to 0. Can be NULL if only one element is set. +void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache) +{ + int key; + + if( not_array_variable(varname[0]) || !not_server_variable(varname[0]) ) + { + ShowError("script_setarray_pc: Variable '%s' has invalid scope (char_id=%d).\n", varname, sd->status.char_id); + return; + } + + if( idx >= SCRIPT_MAX_ARRAYSIZE ) + { + ShowError("script_setarray_pc: Variable '%s' has invalid index '%d' (char_id=%d).\n", varname, (int)idx, sd->status.char_id); + return; + } + + key = ( refcache && refcache[0] ) ? refcache[0] : add_str(varname); + + if( is_string_variable(varname) ) + { + pc_setregstr(sd, reference_uid(key, idx), (const char*)value); + } + else + { + pc_setreg(sd, reference_uid(key, idx), (int)value); + } + + if( refcache ) + {// save to avoid repeated add_str calls + refcache[0] = key; + } +} + + /*========================================== * I *------------------------------------------*/ -- cgit v1.2.3-70-g09d2