From 8226a31d9c46950df20afaad08c2f22745f74088 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 9 May 2020 20:44:00 +0200 Subject: Add script_is_permanent_variable() function --- src/map/script.c | 27 +++++++++++++++++++++++++++ src/map/script.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/map/script.c b/src/map/script.c index c08f5e829..e5c407cc7 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3394,6 +3394,32 @@ static void set_reg_instance_num(struct script_state *st, int64 num, const char } } +/** + * Validates if a variable is permanent (stored in database) by passed variable name. + * + * @param name The variable name to validate. + * @return True if variable is permanent, otherwise false. + * + **/ +static bool script_is_permanent_variable(const char *name) +{ + nullpo_retr(false, name); + + if (strlen(name) == 0) + return false; + + if (ISALNUM(name[0]) != 0) + return true; // Permanent characater variable. + + if (name[0] == '#') + return true; // Permanent (global) account variable. + + if (strlen(name) > 1 && name[0] == '$' && ISALNUM(name[1]) != 0) + return true; // Permanent server variable. + + return false; +} + /** * Stores the value of a script variable * @@ -28250,6 +28276,7 @@ void script_defaults(void) script->load_parameters = script_load_parameters; script->print_line = script_print_line; script->errorwarning_sub = script_errorwarning_sub; + script->is_permanent_variable = script_is_permanent_variable; script->set_reg = set_reg; script->set_reg_ref_str = set_reg_npcscope_str; script->set_reg_pc_ref_str = set_reg_pc_ref_str; diff --git a/src/map/script.h b/src/map/script.h index 511497a66..5fa81dc0e 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -984,6 +984,7 @@ struct script_interface { void (*load_parameters) (void); const char* (*print_line) (StringBuf *buf, const char *p, const char *mark, int line); void (*errorwarning_sub) (StringBuf *buf, const char *src, const char *file, int start_line, const char *error_msg, const char *error_pos); + bool (*is_permanent_variable) (const char *name); int (*set_reg) (struct script_state *st, struct map_session_data *sd, int64 num, const char *name, const void *value, struct reg_db *ref); void (*set_reg_ref_str) (struct script_state* st, struct reg_db *n, int64 num, const char* name, const char *str); void (*set_reg_pc_ref_str) (struct script_state* st, struct reg_db *n, int64 num, const char* name, const char *str); -- cgit v1.2.3-60-g2f50