Hey guys,
The code below should spawn a unit when an enemy is killed by a specific unit (The Ghoul)
My initial "Now Loading" prints in the log, but nothing else. The function doesn't seem to be calling.
Hope you can help!
Edit:
Anyone looking at this thread to do something similar, here is the final working code:
The code below should spawn a unit when an enemy is killed by a specific unit (The Ghoul)
My initial "Now Loading" prints in the log, but nothing else. The function doesn't seem to be calling.
Code:
--- ScourgeRacial
-- Author: Michael
-- DateCreated: 8/5/2013 11:16:42 AM
--------------------------------------------------------------
print("Now loading Scourge Racial ability script");
local uGHOUL = GameInfoTypes.UNIT_GHOUL
GameEvents.EndCombatSim.Add(
function(attackingPlayer, attackingUnit, defendingUnit)
local pPlayer = Players[attackingPlayer];
local attackUnit = attackingUnit;
local defendUnit = defendingUnit;
print("Function Starts");
--Checking that attacking player is scourge
if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_SCOURGE and (attackUnit:GetUnitType() == uGHOUL) and (defendUnit:IsDead())) then
print("Attacker is Scourge + Ghoul");
--Spawn new unit on loser.
local iRand = math.random(1, 100)
if (iRand <33 ) then -- GHOUL
local pNewUnit = attackPlayer:InitUnit(GameInfoTypes.UNIT_GHOUL, defendUnit:GetX(), defendUnit:GetY());
Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "A Ghoul arises from your foe!", "Victory");
print("Function Complete");
end
end
end
)
Hope you can help!
Edit:
Anyone looking at this thread to do something similar, here is the final working code:
Code:
--- ScourgeRacial
-- Author: Sigmaflux
-- DateCreated: 8/5/2013 11:16:42 AM
--------------------------------------------------------------
print("Now loading Scourge Racial ability script");
local uGHOUL = GameInfoTypes.UNIT_GHOUL
Events.EndCombatSim.Add(
function(attackingPlayer, attackingUnit, attackingUnitDamage, attackingUnitFinalDamage, attackingUnitMaxHitPoints, defendingPlayer, defendingUnit, defendingUnitDamage, defendingUnitFinalDamage, defendingUnitMaxHitPoints)
--local pAttackingPlayer = Players[attackingPlayer];
-- local pDefendingPlayer = Players[defendingPlayer];
--local attackUnit = pAttackingPlayer:GetUnitByID(attackingUnit);
--local defendUnit = pDefendingPlayer:GetUnitByID(defendingUnit);
--Retrieve attacking and defending players from the player list using IDs
local pAttackingPlayer = Players[attackingPlayer];
local pDefendingPlayer = Players[defendingPlayer];
--If either player is not in the game, end.
if (not pAttackingPlayer or not pDefendingPlayer) then
return
end
print("Both Players Alive");
--Retrieve both units from the unit lists for each player.
local attackUnit = pAttackingPlayer:GetUnitByID(attackingUnit);
local defendUnit = pDefendingPlayer:GetUnitByID(defendingUnit);
--If the attackingUnit does not exist, don't bother.
if (not attackUnit) then
return
end
print("Function Starts");
--Checking that attacking player is scourge
if (pAttackingPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_SCOURGE and (attackUnit:GetUnitType() == uGHOUL) and (not defendUnit)) then
print("Attacker is Scourge, Ghoul, and enemy is dead.");
--Spawn new unit on loser.
local iRand = math.random(1, 100)
if (iRand <100 ) then -- GHOUL
print("Trying to spawn ghoul, please work! defendUnit:GetX()!");
local pNewUnit = pAttackingPlayer:InitUnit(GameInfoTypes.UNIT_GHOUL, attackUnit:GetX(), attackUnit:GetY());
Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "A Ghoul arises from your foe!", "Victory");
print("Function Complete");
end
end
end
)