From 4393d2fb8ada596e724aa633b9ad8584df7a3578 Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Mon, 14 Dec 2015 14:16:08 +0800 Subject: Add script->id2sd function to throw error properly if player not found - included script->charid2sd and script->nick2sd --- src/map/script.c | 33 +++++++++++++++++++++++++++++++++ src/map/script.h | 3 +++ 2 files changed, 36 insertions(+) (limited to 'src/map') diff --git a/src/map/script.c b/src/map/script.c index 00985c2a5..c1787d1a2 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2644,6 +2644,36 @@ TBL_PC *script_rid2sd(struct script_state *st) { return sd; } +TBL_PC *script_id2sd(struct script_state *st, int account_id) { + TBL_PC *sd; + if ((sd = map->id2sd(account_id)) == NULL) { + ShowWarning("script_id2sd: Player with account ID '%d' not found!\n", account_id); + script->reportfunc(st); + script->reportsrc(st); + } + return sd; +} + +TBL_PC *script_charid2sd(struct script_state *st, int char_id) { + TBL_PC *sd; + if ((sd = map->charid2sd(char_id)) == NULL) { + ShowWarning("script_charid2sd: Player with char ID '%d' not found!\n", char_id); + script->reportfunc(st); + script->reportsrc(st); + } + return sd; +} + +TBL_PC *script_nick2sd(struct script_state *st, const char *name) { + TBL_PC *sd; + if ((sd = map->nick2sd(name)) == NULL) { + ShowWarning("script_nick2sd: Player name '%s' not found!\n", name); + script->reportfunc(st); + script->reportsrc(st); + } + return sd; +} + char *get_val_npcscope_str(struct script_state* st, struct reg_db *n, struct script_data* data) { if (n) return (char*)i64db_get(n->vars, reference_getuid(data)); @@ -20855,6 +20885,9 @@ void script_defaults(void) { script->conv_num = conv_num; script->conv_str = conv_str; script->rid2sd = script_rid2sd; + script->id2sd = script_id2sd; + script->charid2sd = script_charid2sd; + script->nick2sd = script_nick2sd; script->detach_rid = script_detach_rid; script->push_val = push_val; script->get_val = get_val; diff --git a/src/map/script.h b/src/map/script.h index c47956eeb..36b7edef3 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -647,6 +647,9 @@ struct script_interface { int (*conv_num) (struct script_state *st,struct script_data *data); const char* (*conv_str) (struct script_state *st,struct script_data *data); TBL_PC *(*rid2sd) (struct script_state *st); + TBL_PC *(*id2sd) (struct script_state *st, int account_id); + TBL_PC *(*charid2sd) (struct script_state *st, int char_id); + TBL_PC *(*nick2sd) (struct script_state *st, const char *name); void (*detach_rid) (struct script_state* st); struct script_data* (*push_val)(struct script_stack* stack, enum c_op type, int64 val, struct reg_db *ref); struct script_data *(*get_val) (struct script_state* st, struct script_data* data); -- cgit v1.2.3-60-g2f50