add getammo function

This commit is contained in:
avitasia
2026-02-07 09:02:55 -08:00
parent 9a340d6357
commit 453e656e3e
7 changed files with 4589 additions and 4489 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ This includes functions for:
- Spell casting and queuing (QueueSpellByName, QueueScript, etc.)
- Cast information (GetCastInfo, GetCurrentCastingInfo)
- Cooldown tracking (GetSpellIdCooldown, GetItemIdCooldown), including item metadata on cooldown detail tables
- Inventory helpers (GetTrinketCooldown, GetTrinkets)
- Inventory helpers (GetTrinketCooldown, GetTrinkets, GetAmmo)
- Spell lookups and utilities
Cooldown detail tables now also expose `itemId`, `itemHasActiveSpell`, and `itemActiveSpellId` alongside the existing per-category timing data.
+30
View File
@@ -16,6 +16,7 @@ For installation, configuration, and general usage information, see the main [RE
- [GetEquippedItem](#getequippeditemunittoken-slot)
- [GetBagItems](#getbagitemsbagindex)
- [GetBagItem](#getbagitembagindex-slot)
- [GetAmmo](#getammo)
- [GetSpellRec](#getspellrecspellid-copy)
- [GetSpellRecField](#getspellrecfieldspellid-fieldname-copy)
- [GetSpellModifiers](#getspellmodifiersspellid-modifiertype)
@@ -433,6 +434,35 @@ if bankItem then
end
```
#### GetAmmo()
Returns the player's currently equipped ammo item ID and the total quantity remaining across all bags.
**Parameters:**
- None
**Returns:**
- If no ammo is equipped: returns `nil`
- Otherwise returns two values:
- 1st param (number): The ammo item ID
- 2nd param (number): Total ammo count across backpack and bags 1-4
**Examples:**
```lua
-- Check current ammo
local ammoId, count = GetAmmo()
if ammoId then
print("Ammo ID: " .. ammoId .. " Count: " .. count)
else
print("No ammo equipped")
end
-- Low ammo warning
local ammoId, count = GetAmmo()
if ammoId and count < 200 then
print("Low ammo! Only " .. count .. " remaining")
end
```
#### GetSpellRec(spellId, [copy])
Returns a Lua table reference containing all fields for the spell's `SpellRec` record (including localized `name` and `rank`). Returns nil if the spell cannot be found.
+4488 -4487
View File
File diff suppressed because it is too large Load Diff
+65
View File
@@ -1084,5 +1084,70 @@ namespace Nampower {
return GetAllBagItems(luaState);
}
uint32_t Script_GetAmmo(uintptr_t *luaState) {
luaState = GetLuaStatePtr();
auto playerGuid = game::ClntObjMgrGetActivePlayerGuid();
auto playerUnit = game::GetObjectPtr(playerGuid);
if (!playerUnit) {
lua_pushnil(luaState);
return 1;
}
// Get player fields pointer at byte offset 0xe68
auto playerFields = *reinterpret_cast<uint8_t **>(reinterpret_cast<uint8_t *>(playerUnit) + 0xe68);
if (!playerFields) {
lua_pushnil(luaState);
return 1;
}
// Get PLAYER_AMMO_ID at byte offset 0x102c from player fields
auto ammoId = *reinterpret_cast<uint32_t *>(playerFields + 0x102c);
if (ammoId == 0) {
lua_pushnil(luaState);
return 1;
}
// Search player bags for the ammo item and sum stack counts
auto const getBagItem = reinterpret_cast<CGBag_C_GetItemAtSlotT>(Offsets::CGBag_C_GetItemAtSlot);
auto const getContainerGuid = reinterpret_cast<GetContainerGuidT>(Offsets::GetContainerGuid);
auto inventory = game::GetPlayerInventoryPtr(playerUnit);
uint32_t totalCount = 0;
// Search backpack (absolute slots 23-38)
for (uint32_t slot = 23; slot <= 38; slot++) {
auto item = getBagItem(inventory, slot);
if (item && game::GetItemId(item) == ammoId && item->itemFields) {
totalCount += item->itemFields->stackCount;
}
}
// Search bags 1-4
for (int32_t bagIndex = 1; bagIndex <= 4; bagIndex++) {
uint64_t containerGuid = getContainerGuid(bagIndex - 1);
if (containerGuid == 0) continue;
auto containerPtr = game::ClntObjMgrObjectPtr(game::TYPEMASK_CONTAINER, containerGuid);
if (!containerPtr) continue;
auto bagPtr = GetBagPtrFromContainer(containerPtr);
if (!bagPtr) continue;
auto bagSize = *bagPtr;
for (uint32_t slot = 0; slot < bagSize; slot++) {
auto item = getBagItem(bagPtr, slot);
if (item && game::GetItemId(item) == ammoId && item->itemFields) {
totalCount += item->itemFields->stackCount;
}
}
}
lua_pushnumber(luaState, static_cast<double>(ammoId));
lua_pushnumber(luaState, static_cast<double>(totalCount));
return 2;
}
}
+1
View File
@@ -15,4 +15,5 @@ namespace Nampower {
uint32_t Script_GetEquippedItem(uintptr_t *luaState);
uint32_t Script_GetBagItem(uintptr_t *luaState);
uint32_t Script_GetBagItems(uintptr_t *luaState);
uint32_t Script_GetAmmo(uintptr_t *luaState);
}
+3
View File
@@ -1658,6 +1658,9 @@ namespace Nampower {
char getSpellIconTexture[] = "GetSpellIconTexture";
RegisterLuaFunction(getSpellIconTexture, reinterpret_cast<uintptr_t *>(Script_GetSpellIconTexture));
char getAmmo[] = "GetAmmo";
RegisterLuaFunction(getAmmo, reinterpret_cast<uintptr_t *>(Script_GetAmmo));
}
void load() {
+1 -1
View File
@@ -25,7 +25,7 @@ namespace Nampower {
constexpr uint32_t DISENCHANT_QUALITY_PURPLE = 0x04; // Epic
constexpr uint32_t MAJOR_VERSION = 2;
constexpr uint32_t MINOR_VERSION = 28;
constexpr uint32_t MINOR_VERSION = 29;
constexpr uint32_t PATCH_VERSION = 0;
constexpr int32_t LUA_REGISTRYINDEX = -10000;