SHARE
TWEET

gadget

a guest Aug 17th, 2015 194 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function gadget:GetInfo()
  2.     return {
  3.         name      = "mo_transportenemy_t1trans",
  4.         desc      = "Allow transport enemy units with t1 trans when mo_transportenemy set to t1trans",
  5.         author    = "[teh]decay + thx [BoS]nixtux for help",
  6.         date      = "16 Aug 2015",
  7.         license   = "public domain",
  8.         layer     = 0,
  9.         enabled   = true  --  loaded by default?
  10.     }
  11. end
  12.  
  13. -------------------------------------------------------------------------------------------------------------------------
  14. -------------------------------------------------------------------------------------------------------------------------
  15. local enabled = (tostring(Spring.GetModOptions().mo_transportenemy) == "t1trans") or false
  16. if not enabled then
  17.     return false
  18. end
  19.  
  20. if not (gadgetHandler:IsSyncedCode()) then --synced only
  21.     return false
  22. end
  23.  
  24. -- Constants
  25. local LOAD_UNITS = CMD.LOAD_UNITS
  26.  
  27. local spGetUnitTeam = Spring.GetUnitTeam
  28. local spGetUnitDefID = Spring.GetUnitDefID
  29. local spValidUnitID = Spring.ValidUnitID
  30.  
  31. -- armsl = Seahook - Assault Transport (http://springrts.ru:8080/ba901/armsl.html)
  32. -- armdfly = Dragonfly - Stealthy Armed Transport (http://springrts.ru:8080/ba901/armdfly.html)
  33.  
  34. -- armatlas = Atlas - Air Transport (http://springrts.ru:8080/ba901/armatlas.html)
  35. -- corvalk = Valkyrie - Air Transport (http://springrts.ru:8080/ba901/corvalk.html)
  36.  
  37. local t1Transports = {
  38.     [UnitDefNames["armatlas"].id] = true,
  39.     [UnitDefNames["corvalk"].id] = true,
  40. }
  41.  
  42. function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions, cmdTag, synced)
  43.     if cmdID == LOAD_UNITS then
  44.         Spring.Echo(to_string(cmdParams))
  45.         if #cmdParams==1 then -- if unit is target
  46.             if (spValidUnitID(cmdParams[1]) and spGetUnitTeam(cmdParams[1]) ~= teamID and not t1Transports[unitDefID]) then
  47.                 return false
  48.             end
  49.         end
  50.     end
  51.     return true
  52. end
  53.  
  54. function to_string(data, indent)
  55.     local str = ""
  56.  
  57.     if(indent == nil) then
  58.         indent = 0
  59.     end
  60.  
  61.     -- Check the type
  62.     if(type(data) == "string") then
  63.         str = str .. (" "):rep(indent) .. data .. "\n"
  64.     elseif(type(data) == "number") then
  65.         str = str .. (" "):rep(indent) .. data .. "\n"
  66.     elseif(type(data) == "boolean") then
  67.         if(data == true) then
  68.             str = str .. "true"
  69.         else
  70.             str = str .. "false"
  71.         end
  72.     elseif(type(data) == "table") then
  73.         local i, v
  74.         for i, v in pairs(data) do
  75.             -- Check for a table in a table
  76.             if(type(v) == "table") then
  77.                 str = str .. (" "):rep(indent) .. i .. ":\n"
  78.                 str = str .. to_string(v, indent + 2)
  79.             else
  80.                 str = str .. (" "):rep(indent) .. i .. ": " ..to_string(v, 0)
  81.             end
  82.         end
  83.     elseif (data ==nil) then
  84.         str=str..'nil'
  85.     else
  86.         -- print_debug(1, "Error: unknown data type: %s", type(data))
  87.         --str=str.. "Error: unknown data type:" .. type(data)
  88.         Spring.Echo(type(data) .. 'X data type')
  89.     end
  90.  
  91.     return str
  92. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top