Advertisement
Guest User

Untitled

a guest
Dec 11th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. function gadget:GetInfo()
  2.     return {
  3.         name      = "base spawner",
  4.         desc      = "spawn start units based on config files (rather then on startpos set in lobby)",
  5.         author    = "knorke (inspired by game_spawn.lua by Tobi Vollebregt and reusing parts)",
  6.         date      = "May 2011",
  7.         license   = "GNU GPL, v2 or later or a horse",
  8.         layer     = -9000, --so unitscripts works
  9.         enabled   = true,
  10.     }
  11. end
  12. --------------------------------------------------------------------------------
  13. -- synced only
  14. if (not gadgetHandler:IsSyncedCode()) then
  15.     return false
  16. end
  17. --------------------------------------------------------------------------------
  18. luamsgpre = "tpMSGBOX"
  19. local mapconfig_fn = Game.mapName .. "_startpos.lua"        --name of map config files
  20. if (VFS.FileExists(mapconfig_fn)) then
  21.     Spring.Echo ("tp_startbase_spawn.lua: found" .. mapconfig_fn .." in mod root folder or map")
  22.     startpos = VFS.Include(mapconfig_fn)
  23. else
  24.     if (VFS.FileExists("mapconfigs\\" .. mapconfig_fn)) then
  25.         Spring.Echo ("tp_startbase_spawn.lua: found " .. mapconfig_fn .. " in mod mapconfigs folder")
  26.         startpos = VFS.Include("mapconfigs\\" .. mapconfig_fn)
  27.     else
  28.         Spring.Echo ("tp_startbase_spawn.lua: found " .. mapconfig_fn .. " NOT FOUND AT ALL.")
  29.         Spring.Echo ("THIS MAP IS NOT SUPPORTED")
  30.         Spring.SendLuaUIMsg (luamsgpre .. "THIS MAP IS NOT SUPPORTED")
  31.     end
  32. end
  33.  
  34.  
  35. function spawn_player (x, z, teamID)
  36.     x, z = 8*math.floor((x+4)/8) , 8*math.floor((z+4)/8)
  37.     y = Spring.GetGroundHeight(x, z)
  38.     local facing = math.abs(Game.mapSizeX/2 - x) > math.abs(Game.mapSizeZ/2 - z)
  39.         and ((x>Game.mapSizeX/2) and "west" or "east")
  40.         or ((z>Game.mapSizeZ/2) and "north" or "south")
  41.     Spring.CreateUnit("tphq", x, y, z, facing, teamID)
  42.     local dx,dz=0,0
  43.     if (facing=="north") then dz=-200 end
  44.     if (facing=="south") then dz=200 end
  45.     if (facing=="west") then dx=-200 end
  46.     if (facing=="east") then dx=200 end
  47.     Spring.CreateUnit("tpgripper", x+dx, y, z+dz, facing, teamID)
  48.     Spring.SetTeamResource(teamID, "ms", 99999999999999999999999)
  49.     local startingmetal=4000
  50.     local modOptions = Spring.GetModOptions()
  51.     if (modOptions) then startingmetal = modOptions.startingmetal or 4000 end
  52.     Spring.SetTeamResource(teamID, "m", startingmetal)
  53. end
  54.  
  55. --function gadget:GameStart()
  56. function gadget:Initialize()
  57.     --Spring.SendCommands ("cheat") --***
  58.     if (startpos == nil) then Spring.Echo ("tp_startbase_spawn.lua: Did not find startpositions. No units are spawned.") return end
  59.     local gaiaTeamID = Spring.GetGaiaTeamID()
  60.     local i = 1
  61.     local gm = get_game_mode ()
  62.     if (not startpos[gm]) then
  63.         Spring.Echo ("NO SUPPORT FOR THIS MATCH SETUP:" .. gm)
  64.         Spring.SendLuaUIMsg (luamsgpre .. "NO SUPPORT FOR THIS MATCH SETUP:" .. gm)
  65.     end
  66.     for _,teamID in ipairs(Spring.GetTeamList()) do
  67.         if teamID~=gaiaTeamID then -- don't spawn a start unit for the Gaia team           
  68.             local teamNum,leader,isDead,isAiTeam,side,allyTeam = Spring.GetTeamInfo(teamID)    
  69.             --local x,y,z = Spring.GetTeamStartPosition(teamID)
  70.             local x,z = startpos[gm][i].x, startpos[gm][i].z
  71.             spawn_player (x, z, teamID)
  72.             i=i+1
  73.         end
  74.     end
  75. end
  76.  
  77. function get_game_mode ()
  78.     teamn = #Spring.GetTeamList() -1
  79.     if teamn == 2 then return "1v1" end
  80.     if teamn == 3 then return "1v1v1" end
  81.     if teamn == 4 then return "4" end
  82.     return "UKNOWN"
  83. end
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement