summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnnieRuru <jeankof@ymail.com>2015-12-14 14:16:08 +0800
committerHaru <haru@dotalux.com>2015-12-20 15:44:17 +0100
commit4393d2fb8ada596e724aa633b9ad8584df7a3578 (patch)
treee39542d172908476c21840592c1a3225484669a3
parente1da188f662d32e2e737beef5aea5b0ca0a586e5 (diff)
downloadhercules-4393d2fb8ada596e724aa633b9ad8584df7a3578.tar.gz
hercules-4393d2fb8ada596e724aa633b9ad8584df7a3578.tar.bz2
hercules-4393d2fb8ada596e724aa633b9ad8584df7a3578.tar.xz
hercules-4393d2fb8ada596e724aa633b9ad8584df7a3578.zip
Add script->id2sd function to throw error properly if player not found
- included script->charid2sd and script->nick2sd
-rw-r--r--src/map/script.c33
-rw-r--r--src/map/script.h3
2 files changed, 36 insertions, 0 deletions
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);