diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-12 01:48:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-12 01:48:43 +0300 |
commit | 32edcdcf47c804d0bb40299fad5d184b558bb76c (patch) | |
tree | 279589abd15ec4d939cf251125ea29aee035596a | |
parent | 0055aac688833a01cbe2b3e6b951bb162a80b474 (diff) | |
download | evol-hercules-32edcdcf47c804d0bb40299fad5d184b558bb76c.tar.gz evol-hercules-32edcdcf47c804d0bb40299fad5d184b558bb76c.tar.bz2 evol-hercules-32edcdcf47c804d0bb40299fad5d184b558bb76c.tar.xz evol-hercules-32edcdcf47c804d0bb40299fad5d184b558bb76c.zip |
Add script command for get item id from one craft slot.
New script command: getcraftslotid id, slot
-rw-r--r-- | src/emap/craft.c | 16 | ||||
-rw-r--r-- | src/emap/craft.h | 1 | ||||
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/script.c | 23 | ||||
-rw-r--r-- | src/emap/script.h | 1 |
5 files changed, 42 insertions, 0 deletions
diff --git a/src/emap/craft.c b/src/emap/craft.c index c790836..8ad8633 100644 --- a/src/emap/craft.c +++ b/src/emap/craft.c @@ -274,3 +274,19 @@ void craft_delete(const int id) delete_craft_var(craft); idb_remove(craftvar_db, id); } + +struct craft_slot *craft_get_slot(const int id, const int slot) +{ + struct craft_vardata *craft = idb_get(craftvar_db, id); + if (!craft) + { + ShowError("Craft object with id %d not exists.\n", id); + return NULL; + } + if (slot < 0 || slot > craft_inventory_size) + { + ShowError("Wrong slot %d for craft with id %d.\n", slot, id); + return NULL; + } + return &craft->slots[slot]; +} diff --git a/src/emap/craft.h b/src/emap/craft.h index fd9c3d2..8c63546 100644 --- a/src/emap/craft.h +++ b/src/emap/craft.h @@ -33,5 +33,6 @@ int str_to_craftvar(TBL_PC *sd, const char *craftstr); struct craft_vardata *craft_str_to_craft(const char *craftstr); void craft_dump(TBL_PC *sd, const int id); void craft_delete(const int id); +struct craft_slot *craft_get_slot(const int id, const int slot); #endif // EVOL_MAP_CRAFT diff --git a/src/emap/init.c b/src/emap/init.c index 6719503..7a00569 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -103,6 +103,7 @@ HPExport void plugin_init (void) addScriptCommand("initcraft", "s", initCraft); addScriptCommand("dumpcraft", "i", dumpCraft); addScriptCommand("deletecraft", "i", deleteCraft); + addScriptCommand("getcraftslotid", "ii", getCraftSlotId); addScriptCommand("getq", "i", getq); addScriptCommand("setq", "ii", setq); addScriptCommand("setnpcdir", "*", setNpcDir); diff --git a/src/emap/script.c b/src/emap/script.c index 6cf911c..07950ab 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -1895,3 +1895,26 @@ BUILDIN(deleteCraft) craft_delete(script_getnum(st, 2)); return true; } + +BUILDIN(getCraftSlotId) +{ + getSD() + + const struct craft_slot *crslot = craft_get_slot(script_getnum(st, 2), + script_getnum(st, 3)); + if (!crslot) + return false; + const int len = VECTOR_LENGTH(crslot->items); + if (len > 0) + { + struct item_pair *pair = &VECTOR_INDEX(crslot->items, 0); + const int invIndex = pair->index; + const int item_id = sd->status.inventory[invIndex].nameid; + script_pushint(st, item_id); + } + else + { + script_pushint(st, 0); + } + return true; +} diff --git a/src/emap/script.h b/src/emap/script.h index 1c4b846..c74a09b 100644 --- a/src/emap/script.h +++ b/src/emap/script.h @@ -68,5 +68,6 @@ BUILDIN(setSkin); BUILDIN(initCraft); BUILDIN(dumpCraft); BUILDIN(deleteCraft); +BUILDIN(getCraftSlotId); #endif // EVOL_MAP_SCRIPT |