summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorgumi <mekolat@users.noreply.github.com>2017-02-26 12:04:23 -0500
committergumi <mekolat@users.noreply.github.com>2017-02-26 13:38:18 -0500
commit1b0d3bd8f84db5b471646e0404193759afb908db (patch)
tree56b26ab76f9a20a3306267e52aa8759840408c33 /src/map/script.c
parenta16fbb3c0abe63587280bb9ec744b8f65b4c8e38 (diff)
downloadhercules-1b0d3bd8f84db5b471646e0404193759afb908db.tar.gz
hercules-1b0d3bd8f84db5b471646e0404193759afb908db.tar.bz2
hercules-1b0d3bd8f84db5b471646e0404193759afb908db.tar.xz
hercules-1b0d3bd8f84db5b471646e0404193759afb908db.zip
add getvariableofpc() buildin
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 6c0fdfb22..faaadb560 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2944,8 +2944,7 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) {
data->u.num = script->get_val_ref_num(st, data->ref, data);
} else if (name[1] == '@') {
data->u.num = script->get_val_scope_num(st, &st->stack->scope, data);
- }
- else {
+ } else {
data->u.num = script->get_val_npc_num(st, &st->script->local, data);
}
break;
@@ -17595,6 +17594,55 @@ BUILDIN(getvariableofnpc)
return true;
}
+BUILDIN(getvariableofpc)
+{
+ const char* name;
+ struct script_data* data = script_getdata(st, 2);
+ struct map_session_data *sd = map->id2sd(script_getnum(st, 3));
+
+ if (!data_isreference(data)) {
+ ShowError("script:getvariableofpc: not a variable\n");
+ script->reportdata(data);
+ script_pushnil(st);
+ st->state = END;
+ return false;
+ }
+
+ name = reference_getname(data);
+
+ switch (*name)
+ {
+ case '#':
+ case '$':
+ case '.':
+ case '\'':
+ ShowError("script:getvariableofpc: illegal scope (not pc variable)\n");
+ script->reportdata(data);
+ script_pushnil(st);
+ st->state = END;
+ return false;
+ }
+
+ if (sd == NULL)
+ {
+ // player not found, return default value
+ if (script_hasdata(st, 4)) {
+ script_pushcopy(st, 4);
+ } else if (is_string_variable(name)) {
+ script_pushconststr(st, "");
+ } else {
+ script_pushint(st, 0);
+ }
+ return true;
+ }
+
+ if (!sd->regs.vars)
+ sd->regs.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
+
+ script->push_val(st->stack, C_NAME, reference_getuid(data), &sd->regs);
+ return true;
+}
+
/// Opens a warp portal.
/// Has no "portal opening" effect/sound, it opens the portal immediately.
///
@@ -21254,6 +21302,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(sleep2,"i"),
BUILDIN_DEF(awake,"s"),
BUILDIN_DEF(getvariableofnpc,"rs"),
+ BUILDIN_DEF(getvariableofpc,"ri?"),
BUILDIN_DEF(warpportal,"iisii"),
BUILDIN_DEF2(homunculus_evolution,"homevolution",""), //[orn]
BUILDIN_DEF2(homunculus_mutate,"hommutate","?"),