@@ -316,6 +316,71 @@ namespace LuaPlayer
316316 return 1 ;
317317 }
318318
319+ /* *
320+ * Returns the number of free slots in the [Player]'s inventory (backpack and equipped bags).
321+ *
322+ * @return uint32 freeSlots
323+ */
324+ int GetInventoryFreeSlots (lua_State* L, Player* player)
325+ {
326+ uint32 freeSlots = 0 ;
327+
328+ // Backpack (Bolsa principal 0, slots 0 al 18)
329+ for (uint8 i = INVENTORY_SLOT_ITEM_START ; i < INVENTORY_SLOT_ITEM_END ; ++i)
330+ {
331+ if (!player->GetItemByPos (INVENTORY_SLOT_BAG_0 , i))
332+ ++freeSlots;
333+ }
334+
335+ // Bolsas equipadas (Slots 19 al 22)
336+ for (uint8 i = INVENTORY_SLOT_BAG_START ; i < INVENTORY_SLOT_BAG_END ; ++i)
337+ {
338+ if (Bag* bag = player->GetBagByPos (i))
339+ {
340+ for (uint32 j = 0 ; j < bag->GetBagSize (); ++j)
341+ {
342+ if (!player->GetItemByPos (i, j))
343+ ++freeSlots;
344+ }
345+ }
346+ }
347+
348+ ALE::Push (L, freeSlots);
349+ return 1 ;
350+ }
351+
352+ /* *
353+ * Returns the number of free slots in the [Player]'s bank (main bank and bank bags).
354+ *
355+ * @return uint32 freeSlots
356+ */
357+ int GetBankFreeSlots (lua_State* L, Player* player)
358+ {
359+ uint32 freeSlots = 0 ;
360+
361+ for (uint8 i = BANK_SLOT_ITEM_START ; i < BANK_SLOT_ITEM_END ; ++i)
362+ {
363+ if (!player->GetItemByPos (INVENTORY_SLOT_BAG_0 , i))
364+ ++freeSlots;
365+ }
366+
367+ for (uint8 i = BANK_SLOT_BAG_START ; i < BANK_SLOT_BAG_END ; ++i)
368+ {
369+ if (Bag* bag = player->GetBagByPos (i))
370+ {
371+ for (uint32 j = 0 ; j < bag->GetBagSize (); ++j)
372+ {
373+ if (!player->GetItemByPos (i, j))
374+ ++freeSlots;
375+ }
376+ }
377+ }
378+
379+ ALE::Push (L, freeSlots);
380+ return 1 ;
381+ }
382+
383+
319384 /* *
320385 * Returns `true` if the [Player] has a Tank Specialization, `false` otherwise.
321386 *
0 commit comments