Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.66 KB | None | 0 0
  1. -- Author: DracoNB
  2. -- Version: 1.0
  3. -- Requires MoveUI - Dirtyredz|David McClain
  4. package.path = package.path .. ";mods/MoveUI/scripts/lib/?.lua"
  5. local MoveUI = require('MoveUI')
  6.  
  7. package.path = package.path .. ";data/scripts/lib/?.lua"
  8. FactionsMap = require ("factionsmap")
  9. require ("stringutility")
  10.  
  11. -- namespace ShipNotifier
  12. ShipNotifier = {}
  13.  
  14. local OverridePosition
  15.  
  16. local Title = 'ShipNotifier'
  17. local Icon = "data/textures/icons/fighter.png"
  18. local Description = "Will display ships in the current sector."
  19. local DefaultOptions = {
  20.     AllowStations = true,
  21.     AllowFriendlyShips = true,
  22.     AllowCivilianShips = true,
  23.     AllowClickable = true,
  24.     FriendlyRelationAmount = 0,
  25.     FS = 15 -- Font Size
  26. }
  27. local AllowStations_OnOff
  28. local AllowFriendlyShips_OnOff
  29. local AllowCivilianShips_OnOff
  30. local AllowClickable_OnOff
  31. local FriendlyRelationAmount_Slide
  32. local FS_Slide
  33.  
  34. local ShipData
  35.  
  36. local FactionData
  37. local rect
  38. local res
  39. local DefaulPosition
  40. local LoadedOptions
  41. local AllowMoving
  42. local ScanSectorTimer = 5
  43. local player
  44. local RelationColors = {
  45.     {Relation = -100000, R = 0.9, G = 0, B = 0.1},
  46.     {Relation = -90000, R = 0.9, G = 0, B = 0},
  47.     {Relation = -80000, R = 0.9, G = 0, B = 0},
  48.     {Relation = -70000, R = 0.9, G = 0, B = 0},
  49.     {Relation = -60000, R = 0.9, G = 0, B = 0},
  50.     {Relation = -50000, R = 0.75, G = 0.1, B = 0.3},
  51.     {Relation = -40000, R = 0.6, G = 0.1, B = 0.4},
  52.     {Relation = -30000, R = 0.5, G = 0.2, B = 0.5},
  53.     {Relation = -20000, R = 0.4, G = 0.3, B = 0.8},
  54.     {Relation = -10000, R = 0.4, G = 0.4, B = 0.9},
  55.     {Relation = 0, R = 0.4, G = 0.4, B = 0.9},
  56.     {Relation = 10000, R = 0.4, G = 1, B = 0.9},
  57.     {Relation = 20000, R = 0.3, G = 1, B = 0.8},
  58.     {Relation = 30000, R = 0.2, G = 1, B = 0.7},
  59.     {Relation = 40000, R = 0.1, G = 1, B = 0.6},
  60.     {Relation = 50000, R = 0, G = 1, B = 0.5},
  61.     {Relation = 60000, R = 0, G = 1, B = 0.4},
  62.     {Relation = 70000, R = 0, G = 1, B = 0.3},
  63.     {Relation = 80000, R = 0, G = 1, B = 0.2},
  64.     {Relation = 90000, R = 0, G = 1, B = 0.1},
  65.     {Relation = 100000, R = 0, G = 1, B = 0}
  66. }
  67. function ShipNotifier.initialize()
  68.     if onClient() then
  69.         player = Player()
  70.  
  71.         player:registerCallback("onPreRenderHud", "onPreRenderHud")
  72.         ShipNotifier.detect()
  73.         LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  74.  
  75.         rect = Rect(vec2(), vec2(150, 200))
  76.         res = getResolution();
  77.         DefaulPosition = vec2(res.x * 0.73, res.y * 0.85)
  78.         rect.position = MoveUI.CheckOverride(player, DefaulPosition, OverridePosition, Title)
  79.     end
  80. end
  81.  
  82. function ShipNotifier.buildTab(tabbedWindow)
  83.     local FileTab = tabbedWindow:createTab("", Icon, Title)
  84.     local container = FileTab:createContainer(Rect(vec2(0, 0), FileTab.size));
  85.  
  86.     --split it 30/70
  87.     local mainSplit = UIHorizontalSplitter(Rect(vec2(0, 0), FileTab.size), 0, 0, 0.3)
  88.  
  89.     --Top Message
  90.     local TopHSplit = UIHorizontalSplitter(mainSplit.top, 0, 0, 0.3)
  91.     local TopMessage = container:createLabel(TopHSplit.top.lower + vec2(10, 10), Title, 16)
  92.     TopMessage.centered = 1
  93.     TopMessage.size = vec2(FileTab.size.x - 40, 20)
  94.  
  95.     local Description = container:createTextField(TopHSplit.bottom, Description)
  96.  
  97.     local OptionsSplit = UIHorizontalMultiSplitter(mainSplit.bottom, 0, 0, 8)
  98.  
  99.     local TextVSplit = UIVerticalSplitter(OptionsSplit:partition(0), 0, 5, 0.65)
  100.     local name = container:createLabel(TextVSplit.left.lower, "Show Stations", 16)
  101.     AllowStations_OnOff = container:createCheckBox(TextVSplit.right, "On / Off", 'onAllowStations')
  102.     AllowStations_OnOff.tooltip = 'Will show stations as well.'
  103.  
  104.     local TextVSplit = UIVerticalSplitter(OptionsSplit:partition(1), 0, 5, 0.65)
  105.     local name = container:createLabel(TextVSplit.left.lower, "Show Friendly Ships", 16)
  106.     AllowFriendlyShips_OnOff = container:createCheckBox(TextVSplit.right, "On / Off", 'onAllowFriendlyShips')
  107.     AllowFriendlyShips_OnOff.tooltip = 'Will show friendly ships as well.'
  108.  
  109.     local TextVSplit = UIVerticalSplitter(OptionsSplit:partition(2), 0, 5, 0.65)
  110.     local name = container:createLabel(TextVSplit.left.lower, "Show Civilian Ships", 16)
  111.     AllowCivilianShips_OnOff = container:createCheckBox(TextVSplit.right, "On / Off", 'onAllowCivilianShips')
  112.     AllowCivilianShips_OnOff.tooltip = 'Will show civilian ships as well.'
  113.  
  114.     local TextVSplit = UIVerticalSplitter(OptionsSplit:partition(3), 0, 5, 0.65)
  115.     local name = container:createLabel(TextVSplit.left.lower, "Allow Clicking to select Ship", 16)
  116.     AllowClickable_OnOff = container:createCheckBox(TextVSplit.right, "On / Off", 'onAllowClickable')
  117.     AllowClickable_OnOff.tooltip = 'Select ships by clicking on them in mouse mode (will sometimes trigger while panning mouse).'
  118.  
  119.     local TextVSplit = UIVerticalSplitter(OptionsSplit:partition(4), 0, 5, 0.65)
  120.     local name = container:createLabel(TextVSplit.left.lower, "Friendly Faction Amount", 16)
  121.     FriendlyRelationAmount_Slide = container:createSlider(TextVSplit.right, - 100000, 100000, 80, "Faction Amount", 'onChangeFriendlyRelationAmount')
  122.     FriendlyRelationAmount_Slide.tooltip = 'What relation amount you want to show as friendly faction (Default 0 for Neutral).'
  123.  
  124.     local TextVSplit = UIVerticalSplitter(OptionsSplit:partition(6), 0, 5, 0.65)
  125.     local name = container:createLabel(TextVSplit.left.lower, "Font Size", 16)
  126.     FS_Slide = container:createSlider(TextVSplit.right, 10, 30, 20, "Font Size", 'onChangeFont')
  127.     FS_Slide.tooltip = 'Changes the Font size and rect size.'
  128.  
  129.     --Pass the name of the function, and the checkbox
  130.     return {checkbox = {onAllowStations = AllowStations_OnOff, onAllowFriendlyShips = AllowFriendlyShips_OnOff, onAllowCivilianShips = AllowCivilianShips_OnOff, onAllowClickable = AllowClickable_OnOff}, button = {}, slider = {onChangeFont = FS_Slide, onChangeFriendlyRelationAmount = FriendlyRelationAmount_Slide}}
  131. end
  132.  
  133. function ShipNotifier.onChangeFont(slider)
  134.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  135.     MoveUI.SetVariable(Title.."_Opt", {FS = slider.value, AllowStations = LoadedOptions.AllowStations, AllowFriendlyShips = LoadedOptions.AllowFriendlyShips, AllowCivilianShips = LoadedOptions.AllowCivilianShips, AllowClickable = LoadedOptions.AllowClickable, FriendlyRelationAmount = LoadedOptions.FriendlyRelationAmount})
  136. end
  137.  
  138. function ShipNotifier.onAllowStations(checkbox, value)
  139.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  140.     MoveUI.SetVariable(Title.."_Opt", {AllowStations = value, AllowFriendlyShips = value, FS = LoadedOptions.FS, AllowCivilianShips = LoadedOptions.AllowCivilianShips, AllowClickable = LoadedOptions.AllowClickable, FriendlyRelationAmount = LoadedOptions.FriendlyRelationAmount})
  141. end
  142.  
  143. function ShipNotifier.onAllowFriendlyShips(checkbox, value)
  144.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  145.     MoveUI.SetVariable(Title.."_Opt", {AllowStations = value, AllowFriendlyShips = value, FS = LoadedOptions.FS, AllowCivilianShips = LoadedOptions.AllowCivilianShips, AllowClickable = LoadedOptions.AllowClickable, FriendlyRelationAmount = LoadedOptions.FriendlyRelationAmount})
  146. end
  147.  
  148. function ShipNotifier.onAllowCivilianShips(checkbox, value)
  149.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  150.     MoveUI.SetVariable(Title.."_Opt", {AllowStations = LoadedOptions.AllowStations, AllowFriendlyShips = LoadedOptions.AllowFriendlyShips, FS = LoadedOptions.FS, AllowCivilianShips = value, AllowClickable = LoadedOptions.AllowClickable, FriendlyRelationAmount = LoadedOptions.FriendlyRelationAmount})
  151. end
  152.  
  153. function ShipNotifier.onAllowClickable(checkbox, value)
  154.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  155.     MoveUI.SetVariable(Title.."_Opt", {AllowStations = LoadedOptions.AllowStations, AllowFriendlyShips = LoadedOptions.AllowFriendlyShips,  FS = LoadedOptions.FS, AllowCivilianShips = LoadedOptions.AllowCivilianShips, AllowClickable = value, FriendlyRelationAmount = LoadedOptions.FriendlyRelationAmount})
  156. end
  157.  
  158. function ShipNotifier.onChangeFriendlyRelationAmount(slider)
  159.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  160.     MoveUI.SetVariable(Title.."_Opt", {AllowStations = LoadedOptions.AllowStations, AllowFriendlyShips = LoadedOptions.AllowFriendlyShips, FS = LoadedOptions.FS, AllowCivilianShips = LoadedOptions.AllowCivilianShips, AllowClickable = LoadedOptions.AllowClickable, FriendlyRelationAmount = slider.value})
  161. end
  162.  
  163. --Executed when the Main UI Interface is opened.
  164. function ShipNotifier.onShowWindow()
  165.     --Get the player options
  166.     local LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  167.     AllowStations_OnOff.checked = LoadedOptions.AllowStations
  168.     AllowFriendlyShips_OnOff.checked = LoadedOptions.AllowFriendlyShips
  169.     AllowCivilianShips_OnOff.checked = LoadedOptions.AllowCivilianShips
  170.     AllowClickable_OnOff.checked = LoadedOptions.AllowClickable
  171.     FriendlyRelationAmount_Slide:setValueNoCallback(LoadedOptions.FriendlyRelationAmount)
  172.     FS_Slide:setValueNoCallback(LoadedOptions.FS)
  173. end
  174.  
  175. function ShipNotifier.onPreRenderHud()
  176.     if onClient() then
  177.         if not LoadedOptions.FS then LoadedOptions.FS = 15 end
  178.         local NewRect = Rect(rect.lower, rect.upper + vec2(22 * (LoadedOptions.FS - 10), 8 * (LoadedOptions.FS - 10)))
  179.  
  180.         if ShipData then
  181.             local Length = #ShipData.Ships - 1
  182.             Length = Length * 15
  183.             NewRect = Rect(rect.lower, rect.upper + vec2(22 * (LoadedOptions.FS - 10), Length + 8 * (LoadedOptions.FS - 10)))
  184.         end
  185.  
  186.         if OverridePosition then
  187.             rect.position = OverridePosition
  188.         end
  189.  
  190.         if AllowMoving then
  191.             OverridePosition, Moving = MoveUI.Enabled(NewRect, OverridePosition)
  192.             if OverridePosition and not Moving then
  193.                 MoveUI.AssignPlayerOverride(Title, OverridePosition)
  194.                 OverridePosition = nil
  195.             end
  196.  
  197.             drawTextRect(Title, NewRect, 0, 0, ColorRGB(1, 1, 1), 10, 0, 0, 0)
  198.             return
  199.         end
  200.  
  201.         drawRect(NewRect, ColorARGB(0.2, 0.1, 0.1, 0.1))
  202.         if not ShipData then return end
  203.  
  204.         local enemySstations = {}
  205.         local enemyShips = {}
  206.         local enemyCivShips = {}
  207.         local friendlyStations = {}
  208.         local friendlyShips = {}
  209.         local friendlyCivShips = {}
  210.         local FontSize = LoadedOptions.FS or 15
  211.  
  212.         if (#ShipData.Ships < 2) then -- We don't count
  213.             drawTextRect("No Ships Detected", NewRect, - 1, 0, ColorRGB(0, 1, 0), FontSize, 0, 0, 0)
  214.             return
  215.         end
  216.  
  217.         local maxSize = -1 -- We don't want to count the player
  218.        
  219.         local sort_func = function( a,b ) return (a.title < b.title) or (a.title == b.title and a.name < b.name) end
  220.         table.sort(ShipData.Ships, sort_func)
  221.        
  222.         -- We can't split these on the server side due to the options not being there.. doh!
  223.         for _, ship in pairs(ShipData.Ships) do
  224.             local isPlayersShip = ship.index == player.craftIndex
  225.             if (not isPlayersShip) then
  226.                 if (ship.relation >= LoadedOptions.FriendlyRelationAmount) then
  227.                     if (ship.civilship) then
  228.                         table.insert(friendlyCivShips, ship)
  229.                     else
  230.                         table.insert(friendlyShips, ship)
  231.                         table.insert(friendlyStations, ship)
  232.                     end
  233.                 else
  234.                     if (ship.civilship) then
  235.                         table.insert(enemyCivShips, ship)
  236.                     else
  237.                         table.insert(enemyShips, ship)
  238.                         table.insert(enemyStations, ship)
  239.                     end
  240.                 end
  241.             end
  242.         end
  243.  
  244.         -- We need to get the count, plus a header for each
  245.         if (#friendlyCivShips > 0) then
  246.             maxSize = maxSize + #friendlyCivShips + 1
  247.         end
  248.  
  249.         if (#friendlyShips > 0) then
  250.             maxSize = maxSize + #friendlyShips + 1
  251.         end
  252.        
  253.         if (#friendlyStations > 0) then
  254.             maxSize = maxSize + #friendlyStations + 1
  255.         end
  256.         if (#enemyCivShips > 0) then
  257.             maxSize = maxSize + #enemyCivShips + 1
  258.         end
  259.         if (#enemyShips > 0) then
  260.             maxSize = maxSize + #enemyShips + 1
  261.         end
  262.         if (#enemyStations > 0) then
  263.             maxSize = maxSize + #enemyStations + 1
  264.         end
  265.  
  266.         local HSplit = UIHorizontalMultiSplitter(NewRect, 5, 5, math.max(maxSize, 10))
  267.  
  268.         local textPlane = 0
  269.  
  270.         if #enemyShips > 0 then
  271.             drawTextRect("Enemy Ships:", HSplit:partition(textPlane), - 1, 0, ColorRGB(0.8, 0, 0.1), FontSize, 0, 0, 0)
  272.             textPlane = textPlane + 1
  273.            
  274.             for _, shipData in pairs(enemyShips) do
  275.                 local MainVSplit = UIVerticalSplitter(HSplit:partition(textPlane), 5, 5, 0.80)
  276.                 drawTextRect(shipData.bulletin .. shipData.title .. " (" .. shipData.name .. ")", MainVSplit.left, - 1, 0, ColorRGB(GetRelationColor(shipData.relation)), FontSize - 2, 0, 0, 0)
  277.                 --drawRect(HSplit:partition(textPlane), ColorARGB(0.2, 0.1, 0.1, 0.1))
  278.                 if LoadedOptions.AllowClickable then
  279.                     ShipNotifier.AllowClick(player, HSplit:partition(textPlane), (function () Player().selectedObject = Entity(shipData.index) end))
  280.                 end
  281.                 textPlane = textPlane + 1
  282.             end
  283.         end
  284.  
  285.         if LoadedOptions.AllowCivilianShips and #enemyCivShips > 0 then
  286.             drawTextRect("Enemy Civilian Ships: ", HSplit:partition(textPlane), - 1, 0, ColorRGB(0.9, 0, 0.1), FontSize, 0, 0, 0)
  287.             textPlane = textPlane + 1
  288.            
  289.             for _, shipData in pairs(enemyCivShips) do
  290.                 local MainVSplit = UIVerticalSplitter(HSplit:partition(textPlane), 5, 5, 0.80)
  291.                 drawTextRect(shipData.bulletin .. shipData.title .. " (" .. shipData.name .. ")", MainVSplit.left, - 1, 0, ColorRGB(GetRelationColor(shipData.relation)), FontSize - 2, 0, 0, 0)
  292.                 if LoadedOptions.AllowClickable then
  293.                     ShipNotifier.AllowClick(player, HSplit:partition(textPlane), (function () Player().selectedObject = Entity(shipData.index) end))
  294.                 end
  295.                 textPlane = textPlane + 1
  296.             end
  297.         end
  298.  
  299.         if LoadedOptions.AllowFriendlyShips and #friendlyShips > 1 then
  300.             drawTextRect("Friendly Ships:", HSplit:partition(textPlane), - 1, 0, ColorRGB(0, 1, 0), FontSize, 0, 0, 0)
  301.             textPlane = textPlane + 1
  302.            
  303.             for _, shipData in pairs(friendlyShips) do
  304.                 local MainVSplit = UIVerticalSplitter(HSplit:partition(textPlane), 5, 5, 0.80)
  305.                 drawTextRect(shipData.bulletin .. shipData.title .. " (" .. shipData.name .. ")", MainVSplit.left, - 1, 0, ColorRGB(GetRelationColor(shipData.relation)), FontSize - 2, 0, 0, 0)
  306.                 if LoadedOptions.AllowClickable then
  307.                     ShipNotifier.AllowClick(player, HSplit:partition(textPlane), (function () Player().selectedObject = Entity(shipData.index) end))
  308.                 end
  309.                 textPlane = textPlane + 1
  310.             end
  311.         end
  312.        
  313.         if LoadedOptions.AllowStations and #friendlyStations > 1 then
  314.             drawTextRect("Friendly Stations:", HSplit:partition(textPlane), - 1, 0, ColorRGB(0, 1, 0), FontSize, 0, 0, 0)
  315.             textPlane = textPlane + 1
  316.            
  317.             for _, shipData in pairs(friendlyStations) do
  318.                 local MainVSplit = UIVerticalSplitter(HSplit:partition(textPlane), 5, 5, 0.80)
  319.                 drawTextRect(shipData.bulletin .. shipData.title .. " (" .. shipData.name .. ")", MainVSplit.left, - 1, 0, ColorRGB(GetRelationColor(shipData.relation)), FontSize - 2, 0, 0, 0)
  320.                 if LoadedOptions.AllowClickable then
  321.                     ShipNotifier.AllowClick(player, HSplit:partition(textPlane), (function () Player().selectedObject = Entity(shipData.index) end))
  322.                 end
  323.                 textPlane = textPlane + 1
  324.             end
  325.         end
  326.  
  327.         if LoadedOptions.AllowStations and LoadedOptions.AllowFriendlyShips and LoadedOptions.AllowCivilianShips and #friendlyCivShips > 0 then
  328.             drawTextRect("Civilian Ships: ", HSplit:partition(textPlane), - 1, 0, ColorRGB(0, 1, 0), FontSize, 0, 0, 0)
  329.             textPlane = textPlane + 1
  330.            
  331.             for _, shipData in pairs(friendlyCivShips) do
  332.                 local MainVSplit = UIVerticalSplitter(HSplit:partition(textPlane), 5, 5, 0.80)
  333.                 drawTextRect(shipData.bulletin .. shipData.title .. " (" .. shipData.name .. ")", MainVSplit.left, - 1, 0, ColorRGB(GetRelationColor(shipData.relation)), FontSize - 2, 0, 0, 0)
  334.                 if LoadedOptions.AllowClickable then
  335.                     ShipNotifier.AllowClick(player, HSplit:partition(textPlane), (function () Player().selectedObject = Entity(shipData.index) end))
  336.                 end
  337.                 textPlane = textPlane + 1
  338.             end
  339.         end
  340.     end
  341. end
  342.  
  343. function ShipNotifier.AllowClick(player, rect, func)
  344.     local mouse = Mouse()
  345.     local Inside = false
  346.  
  347.     if mouse.position.x < rect.upper.x and mouse.position.x > rect.lower.x then
  348.         if mouse.position.y < rect.upper.y and mouse.position.y > rect.lower.y then
  349.             Inside = true
  350.             drawRect(rect, ColorARGB(0.2, 0.1, 0.1, 0.1))
  351.         end
  352.     end
  353.  
  354.     if Inside and (mouse:mouseDown(3) or mouse:mouseDown(1)) then -- middle mouse button deselects right away :(
  355.         func()
  356.     end
  357.     --end
  358. end
  359.  
  360. function ShipNotifier.updateClient(timeStep)
  361.     ScanSectorTimer = ScanSectorTimer - timeStep
  362.     if ScanSectorTimer < 0 then
  363.         ShipNotifier.detect()
  364.     end
  365.     LoadedOptions = MoveUI.GetVariable(Title.."_Opt", DefaultOptions)
  366.     AllowMoving = MoveUI.AllowedMoving()
  367. end
  368.  
  369. function ShipNotifier.getUpdateInterval()
  370.     return 1
  371. end
  372.  
  373. function ShipNotifier.onSectorEntered(playerIndex)
  374.     ShipNotifier.detect()
  375. end
  376.  
  377. function ShipNotifier.detect()
  378.     if onClient() then
  379.         invokeServerFunction('detect')
  380.         return
  381.     end
  382.  
  383.     local ships = {Sector():getEntitiesByType(EntityType.Ship)}
  384.     local stations = {Sector():getEntitiesByType(EntityType.Station)}
  385.  
  386.     local playerFaction = Faction()
  387.  
  388.     ShipData = {}
  389.     ShipData.Ships = {}
  390.  
  391.     for _, ship in pairs(ships) do
  392.         local index = ship.index
  393.         local name = ship.name
  394.         local title = ship.translatedTitle
  395.         local factionIndex = ship.factionIndex
  396.         local civilship = ship:hasScript("civilship.lua")
  397.         local relation = playerFaction:getRelations(factionIndex)
  398.        
  399.         local bulletin = ship:getValue("hasBulletin")
  400.        
  401.         if bulletin == 1 then
  402.             bulletin = "[!] "
  403.         else
  404.             bulletin = ""
  405.         end
  406.        
  407.         --print (tostring(name) .. " | " .. tostring(title) .. " | " .. tostring(factionIndex) .. " | " .. tostring(civilship) .. " | " .. tostring(relation))
  408.         local shipData = {index = index, name = name, title = title, factionIndex = factionIndex, civilship = civilship, relation = relation, bulletin = bulletin}
  409.         table.insert(ShipData.Ships, shipData)
  410.     end
  411.    
  412.     for _, station in pairs(stations) do
  413.         local index = station.index
  414.         local name = station.name
  415.         local title = station.translatedTitle
  416.         local factionIndex = station.factionIndex
  417.         local civilship = station:hasScript("civilship.lua")
  418.         local relation = playerFaction:getRelations(factionIndex)
  419.        
  420.         local bulletin = station:getValue("hasBulletin")
  421.        
  422.         if bulletin == 1 then
  423.             bulletin = "[!]"
  424.         else
  425.             bulletin = ""
  426.         end
  427.        
  428.         --print (tostring(name) .. " | " .. tostring(title) .. " | " .. tostring(factionIndex) .. " | " .. tostring(civilship) .. " | " .. tostring(relation))
  429.         local shipData = {index = index, name = name, title = title, factionIndex = factionIndex, civilship = civilship, relation = relation, bulletin = bulletin}
  430.         table.insert(ShipData.Ships, shipData)
  431.     end
  432.  
  433.     ShipNotifier.sync()
  434. end
  435.  
  436. function ShipNotifier.sync(values)
  437.     if onClient() then
  438.         if values then
  439.             ShipData = values.ShipData
  440.             return
  441.         end
  442.         invokeServerFunction('sync')
  443.     end
  444.  
  445.     invokeClientFunction(Player(), 'sync', {ShipData = ShipData})
  446. end
  447.  
  448. function GetRelationColor(relation)
  449.     for _, RC in pairs(RelationColors) do
  450.         local result = RC.Relation - relation
  451.         --print(RC.Relation,relation,math.abs(result))
  452.         if math.abs(result) < 10000 then
  453.             return RC.R, RC.G, RC.B
  454.         end
  455.     end
  456. end
  457.  
  458. return ShipNotifier
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement