mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
feat: add Unit:GetAttackers (#116)
This commit is contained in:
@@ -101,6 +101,7 @@ Eluna API for AC:
|
|||||||
|
|
||||||
### Unit
|
### Unit
|
||||||
- Added `Unit:ModifyThreatPct()`: https://github.com/azerothcore/mod-eluna/pull/25
|
- Added `Unit:ModifyThreatPct()`: https://github.com/azerothcore/mod-eluna/pull/25
|
||||||
|
- Added `Unit:GetAttackers()`: https://github.com/azerothcore/mod-eluna/pull/116
|
||||||
|
|
||||||
### GameObject
|
### GameObject
|
||||||
- Added `GameObject:AddLoot()` to add loot at runtime to an **empty** container: https://github.com/azerothcore/mod-eluna/pull/52
|
- Added `GameObject:AddLoot()` to add loot at runtime to an **empty** container: https://github.com/azerothcore/mod-eluna/pull/52
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ ElunaRegister<Unit> UnitMethods[] =
|
|||||||
// {"GetVehicle", &LuaUnit::GetVehicle}, // :GetVehicle() - UNDOCUMENTED - Gets the Vehicle kit of the vehicle the unit is on
|
// {"GetVehicle", &LuaUnit::GetVehicle}, // :GetVehicle() - UNDOCUMENTED - Gets the Vehicle kit of the vehicle the unit is on
|
||||||
#endif
|
#endif
|
||||||
{ "GetMovementType", &LuaUnit::GetMovementType },
|
{ "GetMovementType", &LuaUnit::GetMovementType },
|
||||||
|
{ "GetAttackers", &LuaUnit::GetAttackers },
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
{ "SetFaction", &LuaUnit::SetFaction },
|
{ "SetFaction", &LuaUnit::SetFaction },
|
||||||
|
|||||||
@@ -1437,6 +1437,34 @@ namespace LuaUnit
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the [Unit]'s attackers.
|
||||||
|
*
|
||||||
|
* @return table attackers : table of [Unit]s attacking the unit
|
||||||
|
*/
|
||||||
|
int GetAttackers(lua_State* L, Unit* unit)
|
||||||
|
{
|
||||||
|
const Unit::AttackerSet& attackers = unit->getAttackers();
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
int table = lua_gettop(L);
|
||||||
|
uint32 i = 1;
|
||||||
|
for (Unit* attacker : attackers)
|
||||||
|
{
|
||||||
|
if (!attacker)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Eluna::Push(L, attacker);
|
||||||
|
lua_rawseti(L, table, i);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_settop(L, table); // push table to top of stack
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the [Unit]'s owner GUID to given GUID.
|
* Sets the [Unit]'s owner GUID to given GUID.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user