On unit death, spawn a new unit?

Yugian

Chieftain
Joined
May 6, 2014
Messages
2
Hey, i've been working for making a mod for my friend, and i've hit a bit of a stumbling block. I've got a few things down, but im still a rookie and well... yeah. i could use a second over.

What i want to do for this civilization is have a UU that is a Mounted Dragon. The first half of what i want to do isnt a problem (Stronger Bazooka), but the second part is sticking me up bad.

Upon its death, it will drop its Rider, Which is in turn ANOTHER UU for the Civ. Only thing is, im having trouble writing out a 'On Death' condition. Could someone check my work? I would be most applicative!

Code:
function DragonFlyz_FreeUnit (PlayerID killer, PlayerID killee, UnitType killeeUnitType)
	if PlayerID Killee then
		local joshua = GetJoshua()
		if joshua then
			if killeeUnitType(UNIT_DRAGON_FLYZ_DRAGONMOUNT)
				player:AddFreeUnit(GameInfoTypes["UNIT_DRAGON_FLYZ_DRAGONRIDER], UNITAI_ATTACK )	
				end
			end
		end
 
Code:
local iUUType = GameInfoTypes.UNIT_DRAGON_FLYZ_DRAGONMOUNT
local iUUType2 = GameInfoTypes.UNIT_DRAGON_FLYZ_DRAGONRIDER

local iSavedX = 0
local iSavedY = 0



function SaveKilledUnitLocation(iPlayer, iUnitID)
	local pPlayer = Players[iPlayer]
	local pUnit = pPlayer:GetUnitByID(iUnitID)
	if pUnit:GetUnitType() == iUUType then
		iSavedX = pUnit:GetX()
		iSavedY = pUnit:GetY()
	end
end

GameEvents.CanSaveUnit.Add(SaveKilledUnitLocation)

function OnDeathSpawnUnit(iKiller, iKilled, iUnitType)
	if iUnitType == iUUType then
		local pKilled = Players[iKilled]
		pKilled:InitUnit(iUUType2, iSavedX, iSavedY, UNITAI_ATTACK)
	end
end

GameEvents.UnitKilledInCombat.Add(OnDeathSpawnUnit)

Untested in-game, let me know if there are problems.

Speaking of "untested," those Dragon Flyz toys were really cheap and easy-to-break for how expensive they were...
 
Holy crap, er, thank you very much! That helps me a lot. I'll let you know if anything breaks.

I am actually not familiar with the toys personally, but that kinda blows. Then again, I imagine the parts used for flying had to be a bit thinner and were moving constantly- and if one part breaks... :V
 
Then again, I imagine the parts used for flying had to be a bit thinner and were moving constantly- and if one part breaks... :V

The wings were made of styrofoam and were essentially just to-go boxes from a burger joint which had been cut, rounded, and spray-painted. I had exactly one of them. It's telling that when I was told I would not get a second one, I wholeheartedly agreed with my parents' decision even at the time. :lol:
 
Back
Top Bottom