diff options
author | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2010-12-21 23:23:06 +0000 |
---|---|---|
committer | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2010-12-21 23:23:06 +0000 |
commit | 537296dd156e22592606eedf539395288855639b (patch) | |
tree | 32b88c8962f5b02e3f243f9461b4cb699ba6f908 /src/map/script.c | |
parent | 8cd45c468ef250dde8ac68e9c9d4ad30da9cf351 (diff) | |
download | hercules-537296dd156e22592606eedf539395288855639b.tar.gz hercules-537296dd156e22592606eedf539395288855639b.tar.bz2 hercules-537296dd156e22592606eedf539395288855639b.tar.xz hercules-537296dd156e22592606eedf539395288855639b.zip |
* 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
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 36 |
1 files changed, 36 insertions, 0 deletions
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—¹ *------------------------------------------*/ |