Advertisement
Guest User

Untitled

a guest
May 25th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. -- $Id$
  2. function gadget:GetInfo()
  3. return {
  4. name = "Space Rock",
  5. desc = "Spawns rocks from space.",
  6. author = "oksnoop2",
  7. date = "4/24/2010",
  8. license = "GNU GPL, v2 or later",
  9. layer = 0,
  10. enabled = false, -- loaded by default?
  11. }
  12. end
  13.  
  14. if (not gadgetHandler:IsSyncedCode()) then
  15. return false -- no unsynced code
  16. end
  17. local oldUnitName = "meteor"
  18. local testUnitName = "meteor"
  19. local testUnitDefID = UnitDefNames[testUnitName].id
  20.  
  21. function gadget:UnitCreated(unitID, unitDefID, unitTeam)
  22. local name = UnitDefs[unitDefID].name
  23. if (name == "meteor" ) then
  24. local x, y, z = Spring.GetUnitPosition(unitID)
  25. Spring.CreateUnit(testUnitName, x, y, z, 0, unitTeam)
  26. end
  27. end
  28.  
  29.  
  30. function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
  31. if UnitDefNames[oldUnitName].id == unitDefID then
  32. local x, y, z = Spring.GetUnitPosition(unitID)
  33. Spring.CreateUnit(testUnitName, x, y, z, 0, unitTeam)
  34. end
  35. end
  36.  
  37.  
  38. function gadget:GameFrame(frame)
  39. if frame % 30 == 0 then -- every second
  40. local x = math.random(Game.mapSizeX)
  41. local z = math.random(Game.mapSizeZ)
  42. local unitID = Spring.CreateUnit("meteor", x, 0, z, "n", Spring.GetGaiaTeamID)
  43. Spring.MoveCtrl.Enable(unitID)
  44. Spring.MoveCtrl.SetPosition(unitID, x, Spring.GetGroundHeight(x, z) + 10000, z)
  45. Spring.MoveCtrl.SetGravity(unitID, 100)
  46.  
  47. end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement