Code: Select all
function gadget:GetInfo()
return {
name = "Box collector",
desc = "removes box features and gives resources to collecting player",
author = "MrSpontaneous (ak Pasha Wrangell) with help from JK",
date = "Nov 11 2007",
license = "GPL",
layer = 1,
enabled = true
}
end
if (gadgetHandler:IsSyncedCode()) then
---synced----
local Box="ammobox"
local BoxId=FeatureDefNames[ammobox].id
local BoxesOnMap={}
local unitInRange={}
local Resources={}
function gadget:initialize()
ud = spring.GetAllFeatures ()
for n,u in ipairs(ud) do
if spring.GetFeatureDefID(u) == BoxId
then table.insert(BoxesOnMap, u) end
end
end
function gadget:GameFrame(f)
for n,u in ipairs(BoxesOnMap) do
local x,y,z = spring.GetFeaturePosition(u)
local unitInRange = spring.GetUnitsInSphere(x,y,z, 100)--at x , y , z with radius 100
if (unitInRange and #unitInRange>0 and unitInRange[1].CustomParams["CanCollect"]) then
local remM, maxM, remE, maxE, left = Spring.GetFeatureResources(u) --- [1] is metal, [3] is energy
Spring.AddTeamResource(Spring.GetUnitTeam(UnitInRange[1]) , "m", remM)
Spring.AddTeamResource(Spring.GetUnitTeam(UnitInRange[1]) , "e", remE)
Spring.DestroyFeature(u)
BoxesOnMap[n] = nil
end
end
end
function gadgetHandler:FeatureDestroyed(FeatureID, _)
if (BoxesOnMap[FeatureID] and BoxesOnMap[FeatureID].expiry) then
BoxesOnMap[FeatureID] = nil
end
end
function gadgetHandler:FeatureCreated(featureID, allyTeam)
if (featureID == BoxId) then
table.insert(BoxesOnMap, featureID)
end
end
end
Code: Select all
-- setup the FeatureDefNames{} table
do
local tbl = {}
for _,def in pairs(FeatureDefs) do
tbl[def.name] = def
end
FeatureDefNames = tbl
end
could not load FeatureDefNames as it = nil
so for some reason the table is not getting any values of the def names from the preloaded feature list.
Thank you