Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. function gadget:GetInfo()
  2.     return {
  3.         name      = "feature placer",
  4.         desc      = "Spawns Features and Units",
  5.         author    = "Gnome, Smoth",
  6.         date      = "August 2008, updated 7/11/2014",
  7.         license   = "PD",
  8.         layer     = 0,
  9.         enabled   = true  --  loaded by default?
  10.     }
  11. end
  12.  
  13. if (not gadgetHandler:IsSyncedCode()) then
  14.   return false
  15. end
  16.  
  17. -- these are here because I like the way they look
  18. local   spSetUnitNeutral        = Spring.SetUnitNeutral
  19. local   spSetUnitBlocking       = Spring.SetUnitBlocking
  20. local   spSetUnitRotation       = Spring.SetUnitRotation
  21. local   spSetUnitLosState       = Spring.SetUnitLosState
  22. local   spSetUnitAlwaysVisible  = Spring.SetUnitAlwaysVisible
  23. local   spCreateUnit            = Spring.CreateUnit
  24. local   spGetGaiaTeamID         = Spring.GetGaiaTeamID
  25. local   spCreateFeature         = Spring.CreateFeature
  26. local   spGetGroundHeight       = Spring.GetGroundHeight
  27. local   spEcho                  = Spring.Echo
  28.  
  29. local   featurecfg
  30. local   featureslist    = {}
  31. local   buildinglist    = {}
  32. local   unitlist        = {}   
  33.  
  34. local   rotationMultiplier  = math.pi / 32768
  35.  
  36. if VFS.FileExists("config/featureconfig.lua") then
  37.     featurecfg = VFS.Include("config/featureconfig.lua")
  38.  
  39.     featureslist    = featurecfg.objectlist
  40.     buildinglist    = featurecfg.buildinglist
  41.     unitlist        = featurecfg.unitlist
  42. else
  43.     spEcho("No gamename specific features loaded")
  44. end
  45.        
  46.  
  47. if ( featurecfg ~= nil ) then
  48.     gaiaTeamID = spGetGaiaTeamID()
  49.        
  50.     if ( featureslist ) then
  51.         for _,fDef in pairs(featureslist) do
  52.             if FeatureDefNames[fDef.name] then
  53.                     spCreateFeature(fDef.name, fDef.x, spGetGroundHeight(fDef.x,fDef.z)+5, fDef.z, fDef.rot)
  54.             else
  55.                 spEcho("featureplacer warning: invalid feature name", fDef.name)
  56.             end
  57.         end
  58.     end
  59.                
  60.     if ( unitlist ) then   
  61.         for _,uDef in pairs(unitlist) do
  62.             if UnitDefNames[uDef.name] then
  63.                 local unitId = spCreateUnit(uDef.name, uDef.x, 0, uDef.z, 0, gaiaTeamID)
  64.                 if unitId ~= nil then
  65.                     spSetUnitRotation(unitId, 0, -uDef.rot * rotationMultiplier, 0)
  66.                     spSetUnitNeutral(unitId,true)
  67.                     spSetUnitBlocking(unitId,true)
  68.                     spSetUnitAlwaysVisible(unitId,true)
  69.                     spSetUnitLosState(unitId,0,{los=true, prevLos=true, contRadar=true, radar=true})
  70.                 end
  71.             else
  72.                 spEcho("featureplacer warning: invalid unit def name", bDef.name)
  73.             end
  74.         end
  75.     end
  76.                
  77.     if ( buildinglist ) then
  78.         for _,bDef in pairs(buildinglist) do
  79.             if UnitDefNames[bDef.name] then
  80.                 local buildingId = spCreateUnit(bDef.name, bDef.x, 0, bDef.z, bDef.rot, gaiaTeamID)
  81.                 if buildingId ~= nil then
  82.                     spSetUnitNeutral(buildingId,true)
  83.                     spSetUnitBlocking(buildingId,true)
  84.                     spSetUnitAlwaysVisible(buildingId,true)
  85.                     spSetUnitLosState(buildingId,0,{los=true, prevLos=true, contRadar=true, radar=true})
  86.                 end
  87.             else
  88.                 spEcho("featureplacer warning: invalid building def name", bDef.name)
  89.             end
  90.         end
  91.     end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement