Page 1 of 1

Reclaim FX Gadget

Posted: 20 Dec 2008, 04:13
by Argh
Here's a simple Gadget, designed to show a CEG event if certain objects are reclaimed, as opposed to killed. It uses customParams in the Unit FBI:

Code: Select all

	[customParams] 
	{
		reclaim_fx=yes;
		reclaim_fx_type=tree_reclaim_fx;
	}
Credit to jK, for giving me a clue how to find out that Reclaim had occurred.

Code: Select all

function gadget:GetInfo()
	return {
		name = "Reclaim FX",
		desc = "Generates effect if certain objects are reclaimed.",
		author = "Argh",
		date = "December 18th, 2008",
		license = "Public Domain, or the least-restrictive rights of your country of residence",
		layer = 1,
		enabled = true,
	}
end

local GetUnitHealth = Spring.GetUnitHealth
local GetUnitPosition = Spring.GetUnitPosition
local SpawnCEG = Spring.SpawnCEG

local ReclaimFXList = {}

if (gadgetHandler:IsSyncedCode()) then
--/////////////////////////////////////////////////////////////////////////////////////////////////////////////
--/////////////////////////////////////////////////////////////////////////////////////////////////////////////
--/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	for ud,_ in pairs(UnitDefs) do
		if UnitDefs[ud].customParams.reclaim_fx == 'yes' then
			table.insert(ReclaimFXList,ud,1)
		end
	end
end

function gadget:AllowUnitBuildStep(builderID, builderTeam, unitID, unitDefID, part)
	if part < 0 then
		health = GetUnitHealth(unitID)
		if health < 10 and ReclaimFXList[unitDefID] then
			x,y,z = GetUnitPosition(unitID)
			SpawnCEG(UnitDefs[unitDefID].customParams.reclaim_fx_type, x, y, z, 0, 1.0, 0,0,0)
		end
	end
	return true
end
--/////////////////////////////////////////////////////////////////////////////////////////////////////////////
--/////////////////////////////////////////////////////////////////////////////////////////////////////////////
--/////////////////////////////////////////////////////////////////////////////////////////////////////////////
end
Obviously, tacking on more complex visual behavior is really easy- for example, you could call an animation through Spring.CallCOBScript(), which could call a sound, spawn more CEGs, etc.

But just having a CEG beats the heck out've just seeing stuff disappear, though :-)

Re: Reclaim FX Gadget

Posted: 20 Dec 2008, 09:23
by REVENGE
Looks great. :P