Small isequippedcnt script command update (#4229)

* Updated the command to only count the unique ID

Thanks to @cydh, @secretdataz and @aleos89 for the reviews !
This commit is contained in:
Atemo
2019-08-14 23:27:09 +02:00
committed by GitHub
parent a83e9f34e7
commit 786186f728
2 changed files with 21 additions and 19 deletions

View File

@@ -15407,38 +15407,41 @@ BUILDIN_FUNC(isday)
BUILDIN_FUNC(isequippedcnt)
{
TBL_PC *sd;
int i, id = 1;
int ret = 0;
if (!script_rid2sd(sd)) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
if (!script_rid2sd(sd)) {
script_pushint(st,0);
return SCRIPT_CMD_SUCCESS;
}
for (i=0; id!=0; i++) {
short j;
FETCH (i+2, id) else id = 0;
int ret = 0;
int total = script_lastdata(st);
std::vector<int32> list(total);
for (int i = 2; i <= total; ++i) {
int id = script_getnum(st,i);
if (id <= 0)
continue;
if (std::find(list.begin(), list.end(), id) != list.end())
continue;
list.push_back(id);
for (j=0; j<EQI_MAX; j++) {
for (short j = 0; j < EQI_MAX; j++) {
short index = sd->equip_index[j];
if(index < 0)
if (index < 0)
continue;
if (pc_is_same_equip_index((enum equip_index)j, sd->equip_index, index))
continue;
if(!sd->inventory_data[index])
if (!sd->inventory_data[index])
continue;
if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
if (sd->inventory_data[index]->nameid == id)
ret+= sd->inventory.u.items_inventory[index].amount;
ret += sd->inventory.u.items_inventory[index].amount;
} else { //Count cards.
short k;
if (itemdb_isspecial(sd->inventory.u.items_inventory[index].card[0]))
continue; //No cards
for(k=0; k<sd->inventory_data[index]->slot; k++) {
for (short k = 0; k < sd->inventory_data[index]->slot; k++) {
if (sd->inventory.u.items_inventory[index].card[k] == id)
ret++; //[Lupus]
}