Advertisement
kensuaga

MothershipGlobalScript

Sep 10th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.45 KB | None | 0 0
  1. --Most the code was writen by Mr.Stump - To him I am greatful!
  2.  
  3. function onLoad()
  4.     --Starts a repeating timer that goes off once per second
  5.     Timer.create({
  6.         identifier="statusReportTimer",
  7.         function_name = "updateCounts_timer",
  8.         function_owner = Global, --If this script is on an object, use self
  9.         delay = 1,
  10.         repetitions = 0
  11.     })
  12.  
  13.     --Creates buttons that will be used as displays
  14.     --The first for loop goes through the main entries (YELLOW/BLUE/RED/GREEN)
  15.     --The second for loop goes through each entry for that color
  16.     for color, dataTable in pairs(ref_playerZones) do
  17.         for _, entries in ipairs(dataTable) do
  18.             local obj = getObjectFromGUID(entries.guid_button)
  19.             obj.createButton({
  20.                 click_function="none", function_owner=Global,
  21.                 position=entries.pos_button, height=0, width=0,
  22.                 font_size=entries.font_size, scale = {0.45,0.45,0.45}
  23.             })
  24.         end
  25.     end
  26. end
  27.  
  28. --Goes off once per second
  29. function updateCounts_timer()
  30.     --Go through every zone in ref_playerData
  31.     for color, dataTable in pairs(ref_playerZones) do
  32.         for i, entries in ipairs(dataTable) do
  33.             local zone = getObjectFromGUID(entries.guid_zone)
  34.             --Finds object types by their tag
  35.             --Whatever the tag of your markers are, that is what you use here
  36.             --I looked, it was Tile
  37.             local zoneObjList = getObjectTypesInZone(zone, "Tile")
  38.             --This adds the # of entries in zone object list to ref_playerZones
  39.             ref_playerZones[color][i].total = #zoneObjList
  40.         end
  41.     end
  42.  
  43.     updateDisplays()
  44. end
  45.  
  46. function updateDisplays()
  47.     for color, dataTable in pairs(ref_playerZones) do
  48.         for i, entries in ipairs(dataTable) do
  49.             local obj = getObjectFromGUID(entries.guid_button)
  50.             -- Checks to see if lable is ment for weapons or colony station hp
  51.             --If it is not will format normally otherwise it will change the values
  52.             if i ~= 2 and i ~= 5 then
  53.                 obj.editButton({
  54.                     index = i-1,
  55.                     label = entries.total
  56.                 })
  57.             else
  58.                 --Finds the corisponding weapon lable for die value
  59.                 if i == 2 then
  60.                     if entries.total < 1 then
  61.                         label = "X"
  62.                     else
  63.                         if entries.total < 4 then
  64.                            label = "D2"
  65.                         else
  66.                             if entries.total < 6 then
  67.                                 label = "D4"
  68.                             else
  69.                                 if entries.total < 8 then
  70.                                     label = "D6"
  71.                                 else
  72.                                     if entries.total < 10 then
  73.                                         label = "D8"
  74.                                     else
  75.                                         if entries.total < 12 then
  76.                                             label = "D10"
  77.                                         else
  78.                                             label = "D12"
  79.                                         end
  80.                                     end
  81.                                 end
  82.                             end
  83.                         end
  84.                     end
  85.                 else
  86.                     --Fins the corisponing life value for the colony station
  87.                     if entries.total == 4 then
  88.                         label = "100%"
  89.                     else
  90.                         if entries.total == 3 then
  91.                            label = "75%"
  92.                         else
  93.                             if entries.total == 2 then
  94.                                 label = "50%"
  95.                             else
  96.                                 if entries.total == 1 then
  97.                                     label = "25%"
  98.                                 else
  99.                                     label = "XXX"
  100.                                 end
  101.                             end
  102.                         end
  103.                     end
  104.  
  105.                 end
  106.  
  107.                 obj.editButton({
  108.                     index = i-1,
  109.                     label = label,
  110.                 })
  111.             end
  112.  
  113.         end
  114.     end
  115. end
  116.  
  117. --Returns table of objects of given types using their tags
  118. function getObjectTypesInZone(zone, ...)
  119.     local foundTypes, tagList = {}, {...}
  120.     for _, object in ipairs(zone.getObjects()) do
  121.         for _, tag in ipairs(tagList) do
  122.             if object.tag == tag then
  123.                 table.insert(foundTypes, object)
  124.                 break
  125.             end
  126.         end
  127.     end
  128.     return foundTypes
  129. end
  130.  
  131.  
  132. --Each player color's scripting zone
  133. --You would need to change the colors to match your table's player colors
  134. --You would need to enter the GUID for the item that gets the button on it
  135. --You would need to enter the guid for the script zone for that buttons
  136. --You would need to enter the position for that button on that object.
  137. --Remember these buttons are displays to show the totals
  138.  
  139. --Zone Ref Scale 5.18 - .08 .14
  140. ref_playerZones = {
  141.     ["Yellow"] = {
  142.         {guid_button="0e46ea", guid_zone="18c7ed", pos_button={-1.71,0.12,-0.32}, total=0, font_size=220},
  143.         {guid_button="0e46ea", guid_zone="88fcfc", pos_button={-1.57,0.12,-0.09}, total=0, font_size=180},
  144.         {guid_button="0e46ea", guid_zone="b73789", pos_button={-1.71,0.12, 0.16}, total=0, font_size=220},
  145.         {guid_button="0e46ea", guid_zone="45ac57", pos_button={-1.57,0.12, 0.38}, total=0, font_size=220},
  146.         {guid_button="0e46ea", guid_zone="06a0e3", pos_button={-1.55,0.12, 0.73}, total=0, font_size=180},
  147.     },
  148.  
  149.     ["Blue"] = {
  150.         {guid_button="e29147", guid_zone="b9cbf9", pos_button={-1.71,0.12,-0.32}, total=0, font_size=220},
  151.         {guid_button="e29147", guid_zone="960736", pos_button={-1.57,0.12,-0.09}, total=0, font_size=180},
  152.         {guid_button="e29147", guid_zone="92ce0f", pos_button={-1.71,0.12, 0.16}, total=0, font_size=220},
  153.         {guid_button="e29147", guid_zone="f6b3e5", pos_button={-1.57,0.12, 0.38}, total=0, font_size=220},
  154.         {guid_button="e29147", guid_zone="3e96b2", pos_button={-1.55,0.12, 0.73}, total=0, font_size=180},
  155.     },
  156.  
  157.     ["Red"] = {
  158.         {guid_button="ed2021", guid_zone="60667f", pos_button={-1.71,0.12,-0.32}, total=0, font_size=220},
  159.         {guid_button="ed2021", guid_zone="004da6", pos_button={-1.57,0.12,-0.09}, total=0, font_size=180},
  160.         {guid_button="ed2021", guid_zone="931665", pos_button={-1.71,0.12, 0.16}, total=0, font_size=220},
  161.         {guid_button="ed2021", guid_zone="819a0c", pos_button={-1.57,0.12, 0.38}, total=0, font_size=220},
  162.         {guid_button="ed2021", guid_zone="ec3d94", pos_button={-1.55,0.12, 0.73}, total=0, font_size=180},
  163.     },
  164.  
  165.     ["Green"] = {
  166.         {guid_button="7fee02", guid_zone="c33ccf", pos_button={-1.71,0.12,-0.32}, total=0, font_size=220},
  167.         {guid_button="7fee02", guid_zone="fdf690", pos_button={-1.57,0.12,-0.09}, total=0, font_size=180},
  168.         {guid_button="7fee02", guid_zone="d30b05", pos_button={-1.71,0.12, 0.16}, total=0, font_size=220},
  169.         {guid_button="7fee02", guid_zone="2a1bc7", pos_button={-1.57,0.12, 0.38}, total=0, font_size=220},
  170.         {guid_button="7fee02", guid_zone="27087b", pos_button={-1.55,0.12, 0.73}, total=0, font_size=180},
  171.     },
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement