From 1af2a074bd643a5564a9911ee6cc9356673182be Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Jun 2016 21:54:18 +0300 Subject: Add script command for get card from item by inventory index. New script command: getcardbyindex itemIndex, cardIndex --- src/emap/script_buildins.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/emap/script_buildins.c') diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 6a34298..7b5a224 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -1333,6 +1333,43 @@ BUILDIN(failedRemoveCardsIndex) return true; } +BUILDIN(getCardByIndex) +{ + getSD() + getInventoryIndex(2) + + if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0) + { + script_pushint(st, 0); + return false; + } + + const int c = script_getnum(st, 3); + if (c < 0 || c >= MAX_SLOTS) + { + script_pushint(st, 0); + return false; + } + + if (itemdb_isspecial(sd->status.inventory[n].card[0])) + { + script_pushint(st, 0); + return true; + } + + const int card = sd->status.inventory[n].card[c]; + if (card && itemdb_type(card) == IT_CARD) + { + script_pushint(st, card); + } + else + { + script_pushint(st, 0); + } + + return true; +} + // return paramater type // 0 - int // 1 - string -- cgit v1.2.3-70-g09d2