Reclaim FX Gadget

Reclaim FX Gadget

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Reclaim FX Gadget

Post 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 :-)
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Reclaim FX Gadget

Post by REVENGE »

Looks great. :P
Post Reply

Return to “Lua Scripts”