Unit ability idea...

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
Simply put - how can I, if possible, make so that upon killing an enemy unit, a certain unit type (to be used as a UU) generates 1 version of a unique resource for its empire?

e.g. A UU kills an enemy unit and the empire now has an extra 1 iron at its disposal.
 
I tried doing something similar with the Unit Killed In Combat event but was never able to find a way to determine which unit did the killing. The only way I found around it was to give the <CaptureDefeatedEnemy>true</CaptureDefeatedEnemy> ability as part of a unit promotion, and then deal with the lua as a unit created event, taking the action I wanted from there. But I think the only reason that worked was that I was interested in whether or not a specific special barbarian unit had been captured in combat.
 
I'm not sure that making the code fire on a unit being killed is the problem. But then again, 90% of my lua never works...

I'm mostly worried about the part of the coding that gives the extra resource. It can be done by adding a dummy building in the capital every time it kills a unit, as this is a new strategic resource I'm going to add that, but if you're a really good tactician and not running the Invisibility Patch...

Hence I try to not use dummy buildings for such stacking things. But I'm not sure what else can add another resource...

EDIT: Idea! Maybe we could add 1 more version of that resource to the plot that the capital city is on using Plot.ChangeNumResource. The downside is if the player decides to wander around a lot and then settle on a resource (which actually, based on the civ's UA (The unit in question will be a UU) I'm planning, would be inanely stupid), or if the player's capital is stolen, in which case all their strat resource disappears. Maybe it's possible to transfer it over to its next capital then? But then it may conflict with Indonesia...
 
:crazyeye: Derp. Not sure how I missed that. Then the real problem is getting the code to fire on killing an enemy unit?

The parameters of GameEvents.UnitKilledInCombat are (playerID Killer, playerID Killee, unitType KilleeUnit)... hmm...
I guess if we iterate through Killer's units?
 
Isn't unitID instead of unitType?
Not sure, I didn't check, just typed it all out from what I remembered from the last time I looked the parameters up.
 
True. This is a mock-code I can work off of, but it's based on a function that doesn't exist but it would help if it did. Maybe you know anything that can replace it?
Code:
GameEvents.UnitKilledInCombat.Add(
function(iPlayer, mPlayer, mUnit)

	for iPlayer, mPlayer in pairs(Players) do
		if iPlayer ~= mPlayer then -- not sure if this line is necessary
			mUnit = Game.GetUnitKilledInCombat() -- Wouldn't it be so helpful
							     -- this was a real function...
							     -- but it's not...
			if not (mUnit:GetOwner() == iPlayer) then
				iPlayer:ChangeNumResourceTotal(GameInfoTypes.RESOURCE_NEWSTRATRES, 1)
			else
				return;
			end
		else
			return;
		end
	end
end)
EDIT: Whoops, forgot to put "if iUnit:GetUnitType() == GameInfoTypes.UNIT_NEWUNIT then" in there... but on second thought, where would that fit?
 
That if statement needs to be a pointer, so you need to get the unit first by the ID provided by the event with Player:GetUnitByID(iUnit).
In all honesty, most of the codes in my Total Conversion need 'on kill' or 'during combat' and I could only start on that by using whoward's DLL which has R.E.D.'s combat-related GameEvents.

I really don't know how to help you here. :(
 
Back
Top Bottom