Advertisement
ddson888

Untitled

Apr 16th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.87 KB | None | 0 0
  1. function onSave()
  2. local data_to_save = {
  3.  
  4. ["SarweenToolsState"]=SarweenTools,
  5. ["MuaatWarSunState"]=MuaatWarSun,
  6. ["RegulatedConscriptionState"]=RegulatedConscription
  7.  
  8. }
  9.  
  10. saved_data = JSON.encode(data_to_save)
  11. --print(tostring(saved_data).." is saved data.")
  12. return saved_data
  13. end
  14.  
  15. function onload(saved_data)
  16. setupParams = {}
  17. setupParams["Saar"] = {Infantry=4,Fighter=2,Cruiser=1,Carrier=2,["Space Dock"]=1}
  18. setupParams["Jol-nar"] = {Infantry=2,Fighter=1,Carrier=2,Dreadnought=1,["Space Dock"]=1,PDS=2}
  19. setupParams["Sardakk"] = {Infantry=5,Cruiser=1,Carrier=2,["Space Dock"]=1,PDS=1}
  20. setupParams["Hacan"] = {Infantry=4,Fighter=2,Cruiser=1,Carrier=2,["Space Dock"]=1}
  21. setupParams["Muaat"] = {Infantry=4,Fighter=2,["War Sun"]=1,["Space Dock"]=1}
  22. setupParams["Arborec"] = {Infantry=4,Fighter=2,Cruiser=1,Carrier=1,["Space Dock"]=1,PDS=1}
  23. setupParams["Creuss"] = {Infantry=4,Fighter=2,Destroyer=2,Carrier=1,["Space Dock"]=1}
  24. setupParams["Nekro"] = {Infantry=2,Fighter=2,Cruiser=1,Carrier=1,Dreadnought=1,["Space Dock"]=1}
  25. setupParams["Barony"] = {Infantry=3,Fighter=1,Destroyer=1,Carrier=1,Dreadnought=1,["Space Dock"]=1}
  26. setupParams["Sol"] = {Infantry=5,Fighter=3,Destroyer=1,Carrier=2,["Space Dock"]=1}
  27. setupParams["Naalu"] = {Infantry=4,Fighter=3,Destroyer=1,Cruiser=1,Carrier=1,["Space Dock"]=1,PDS=1}
  28. setupParams["Mentak"] = {Infantry=4,Fighter=3,Cruiser=2,Carrier=1,["Space Dock"]=1,PDS=1}
  29. setupParams["Yin"] = {Infantry=4,Fighter=4,Destroyer=1,Carrier=2,["Space Dock"]=1}
  30. setupParams["Xxcha"] = {Infantry=4,Fighter=3,Cruiser=2,Carrier=1,["Space Dock"]=1,PDS=1}
  31. setupParams["L1z1x"] = {Infantry=5,Fighter=3,Carrier=1,Dreadnought=1,["Space Dock"]=1,PDS=1}
  32. setupParams["Yssaril"] = {Infantry=5,Fighter=2,Cruiser=1,Carrier=2,["Space Dock"]=1,PDS=1}
  33. setupParams["Winnu"] = {Infantry=2,Fighter=2,Cruiser=1,Carrier=1,["Space Dock"]=1,PDS=1}
  34. ButtonsBeforeShipButtons = 9
  35. ConstructionIterator = 0
  36. ShipTable = {}
  37. OrderedShips = {}
  38. SpawnButtons()
  39. CreateShipObjects()
  40. SarweenTools = false
  41. RegulatedConscription = false
  42. MuaatWarSun = false
  43. if saved_data ~= nil and saved_data ~= "" then
  44.  
  45. loaded_data = JSON.decode(saved_data)
  46. --print(tostring(loaded_data.MuaatWarSunState).." is MuaatWarSunState.")
  47. if loaded_data.MuaatWarSunState then
  48. ToggleMuaatWarSun()
  49. end
  50.  
  51. if loaded_data.RegulatedConscriptionState then
  52. ToggleRegulatedConscription()
  53. end
  54.  
  55. if loaded_data.SarweenToolsState then
  56. ToggleSarween()
  57. end
  58.  
  59. end
  60.  
  61.  
  62. RecountAll()
  63. RecolorButtons()
  64. WipeButtonTooltips()
  65. --print(destroyer.Cost.." is the cost of a destroyer.")
  66. end
  67.  
  68.  
  69. function NewShip(N, C, L)
  70. local Ship = {}
  71. Ship.Name = N
  72. Ship.Cost = C
  73. Ship.Limit = L
  74. table.insert(ShipTable, Ship)
  75. return Ship
  76. end
  77.  
  78. function CreateShipObjects()
  79. -- eventually expand this to include model file references etc
  80. destroyer = NewShip("Destroyer", 1, 8)
  81. cruiser = NewShip("Cruiser", 2, 8)
  82. carrier = NewShip("Carrier", 3, 4)
  83. dreadnought = NewShip("Dreadnought", 4, 5)
  84. infantry = NewShip("Infantry", 0.5, 12)
  85. fighter = NewShip("Fighter", 0.5, 10)
  86. warsun = NewShip("War Sun", 12, 2)
  87. flagship = NewShip("Flagship", 8, 1)
  88. spacedock = NewShip("Space Dock", 999, 3)
  89. pds = NewShip("PDS", 999, 6)
  90. end
  91.  
  92. function ShipCost(ShipName)
  93. for v = 1, 8, 1 do
  94. if string.find(ShipName, ShipTable[v].Name) then
  95. return ShipTable[v].Cost
  96. end
  97. end
  98. end
  99.  
  100. function ShipNumber(ShipName)
  101. for v = 1, 10, 1 do
  102. if string.find(ShipName, ShipTable[v].Name) then
  103. return v
  104. end
  105. end
  106. end
  107.  
  108. function ShipLimit(ShipName)
  109. for v = 1, 10, 1 do
  110. if string.find(ShipName, ShipTable[v].Name) then
  111. return ShipTable[v].Limit
  112. end
  113. end
  114. end
  115.  
  116.  
  117. function GetShipFromBag(ShipName)
  118. for i, j in pairs(self.getObjects()) do
  119. --print(j.name)
  120. if j.name == ShipName then
  121. return j
  122. else
  123. end
  124. end
  125. return nil
  126. end
  127.  
  128.  
  129. function NewShipPosition(bConstruction)
  130. local length = #OrderedShips
  131. local SpawnOffset = {-5, 1, -4}
  132. if bConstruction then
  133. ConstructionIterator = ConstructionIterator + 1
  134. length = ConstructionIterator%14
  135. end
  136. if bConstruction then
  137. SpawnOffset = {-5, 1, -7}
  138. end
  139.  
  140. local x = self.getPosition()[1] + SpawnOffset[1] + 2*((length-2)%2)
  141. local y = self.getPosition()[2] + SpawnOffset[2]
  142. local z = self.getPosition()[3] + SpawnOffset[3] + 1.3*math.floor(length/2)
  143. return {x, y, z}
  144. end
  145.  
  146. function AddShipToOrder(ShipName, bConstruction)
  147. if GetShipFromBag(ShipName) ~= nil then
  148. local addingship = GetShipFromBag(ShipName)
  149.  
  150. params = {}
  151. params.guid = addingship.guid
  152. params.position = NewShipPosition(bConstruction)
  153.  
  154. if bConstruction ~= true then
  155. table.insert(OrderedShips, self.takeObject(params))
  156. else
  157. self.takeObject(params).setColorTint(self.getColorTint())
  158. end
  159. --print(ShipCost(ShipName).." is the cost of the "..ShipName.." added to the order.")
  160. UpdateOrderCost()
  161. FreezeShips()
  162. else
  163. print("You are out of "..ShipName.."!")
  164. end
  165. end
  166.  
  167. function FreezeShips()
  168. for i, j in pairs(OrderedShips) do
  169. j.setColorTint(self.getColorTint())
  170. j.interactable = false
  171. j.highlightOn({0.9,0.7,0.7})
  172. end
  173. end
  174.  
  175. function ClearShips()
  176. for i, j in pairs(OrderedShips) do
  177. Wait.time(function() RemoveShipFromOrder(j.getName()) end, i*0.1)
  178. end
  179. end
  180.  
  181. function RemoveShipFromOrder(ShipName)
  182. for i, j in pairs(OrderedShips) do
  183. if j.getName() == ShipName then
  184. table.remove(OrderedShips, i)
  185. j.setPositionSmooth({self.getPosition()[1], self.getPosition()[2]+2, self.getPosition()[3]})
  186. j.interactable = true
  187. UpdateOrderCost()
  188. return true
  189. end
  190. end
  191.  
  192.  
  193. end
  194.  
  195. function UpdateOrderCost()
  196. local TotalOrderCost = 0
  197. if SarweenTools == true then
  198. TotalOrderCost = -1
  199. end
  200. for i, j in pairs (OrderedShips) do
  201. TotalOrderCost = TotalOrderCost + ShipCost(j.getName())
  202. end
  203. --function to update display
  204. self.editButton({
  205. index = 0,
  206. label = TotalOrderCost
  207. })
  208. self.editButton({
  209. index = 1,
  210. label = #OrderedShips
  211. })
  212. return TotalOrderCost
  213. end
  214.  
  215. function PurchaseShips(o, color, a)
  216. Purchaser = Player[color].steam_name
  217. PurchaserColorRGB = stringColorToRGB(color)
  218. PurchaserColorHex = HexColor(color)
  219.  
  220. for i, j in pairs(OrderedShips) do
  221. j.interactable = true
  222. j.highlightOff()
  223. end
  224.  
  225. PurchasedShips = ""
  226.  
  227. for v = 1, 10, 1 do
  228. local countship = 0
  229. for i, j in pairs(OrderedShips) do
  230. if ShipTable[v].Name == j.getName() then
  231. countship = countship + 1
  232. end
  233. end
  234. if countship > 0 then
  235. PurchasedShips = PurchasedShips..countship.."x "..ShipTable[v].Name.."; "
  236. end
  237. end
  238.  
  239. broadcastToAll ("["..PurchaserColorHex.."]"..Purchaser.."[ffffff] is buying: "..PurchasedShips.."costing "..UpdateOrderCost().." Resources and requiring Production "..#OrderedShips..".")
  240.  
  241. OrderedShips = {}
  242. UpdateOrderCost()
  243. end
  244.  
  245.  
  246.  
  247. function SpawnButtons()
  248. --========================================
  249. -- MAIN BUTTONS
  250. --========================================
  251. local bcolor = {0,0,0}
  252. local bfontcolour = self.getColorTint()
  253. local by = 0
  254. local bz = 2
  255. local bx = 1
  256. --========================================
  257. --This one is the Cost number:
  258. self.createButton({
  259. label="0",
  260. click_function="Nada",
  261. function_owner = self,
  262. position={bx-0.5,by,bz},
  263. height=500,
  264. width=500,
  265. font_size=200,
  266. color = bcolor,
  267. font_color = bfontcolour
  268. })
  269. --This one is the Production number:
  270. self.createButton({
  271. label="0",
  272. click_function="Nada",
  273. function_owner = self,
  274. position={bx-0.5,by,bz+1},
  275. height=500,
  276. width=500,
  277. font_size=200,
  278. color = bcolor,
  279. font_color = bfontcolour
  280. })
  281. self.createButton({
  282. label="Purchase Order",
  283. click_function="PurchaseShips",
  284. function_owner = self,
  285. position={bx-2,by,bz+2},
  286. height=500,
  287. width=1000,
  288. font_size=120,
  289. color = bcolor,
  290. font_color = bfontcolour
  291. })
  292. self.createButton({
  293. label="Clear Order",
  294. click_function="ClearShips",
  295. function_owner = self,
  296. position={bx-2,by,bz+3},
  297. height=500,
  298. width=1000,
  299. font_size=150,
  300. color = bcolor,
  301. font_color = bfontcolour
  302. })
  303. self.createButton({
  304. label="Production: ",
  305. click_function="Nada",
  306. function_owner = self,
  307. position={bx-2,by,bz+1},
  308. height=500,
  309. width=1000,
  310. font_size=150,
  311. color = bcolor,
  312. font_color = bfontcolour
  313. })
  314. self.createButton({
  315. label="Resources: ",
  316. click_function="Nada",
  317. function_owner = self,
  318. position={bx-2,by,bz},
  319. height=500,
  320. width=1000,
  321. font_size=150,
  322. color = bcolor,
  323. font_color = bfontcolour
  324. })
  325. self.createButton({
  326. label="Sarween Tools Off",
  327. click_function="ToggleSarween",
  328. function_owner = self,
  329. position={bx-0.5,by,bz+1.75},
  330. height=250,
  331. width=500,
  332. font_size=30,
  333. color = bcolor,
  334. font_color = bfontcolour
  335. })
  336. self.createButton({
  337. label="Reg. Conscription Off",
  338. click_function="ToggleRegulatedConscription",
  339. function_owner = self,
  340. position={bx-0.5,by,bz+2.75},
  341. height=250,
  342. width=500,
  343. font_size=30,
  344. color = bcolor,
  345. font_color = bfontcolour
  346. })
  347. self.createButton({
  348. label="Muaat Upgraded War Sun Off",
  349. click_function="ToggleMuaatWarSun",
  350. function_owner = self,
  351. position={bx-0.5,by,bz+3.25},
  352. height=250,
  353. width=500,
  354. font_size=30,
  355. color = bcolor,
  356. font_color = bfontcolour
  357. })
  358.  
  359.  
  360. SarweenButtonIndex = 6
  361. RegulatedConscriptionButtonIndex = 7
  362. MuaatButtonIndex = 8
  363.  
  364. --========================================
  365. -- SHIP BUTTONS
  366. --========================================
  367. local bwidth = 800
  368. local bheight = 250
  369. local boffset = {-2.8,0,1.75}
  370. local bgap = 0.5
  371. local bi = 0
  372. local fontsize = 100
  373.  
  374. --========================================
  375. self.createButton({
  376. label="Destroyer",
  377. click_function='Destroyer',
  378. function_owner = self,
  379. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  380. height=bheight,
  381. width=bwidth,
  382. font_size=fontsize,
  383. color = bcolor,
  384. font_color = self.getColorTint()
  385. })
  386. bi = bi + 1
  387. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  388. self.createButton({
  389. label="Cruiser",
  390. click_function='Cruiser',
  391. function_owner = self,
  392. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  393. height=bheight,
  394. width=bwidth,
  395. font_size=fontsize,
  396. color = bcolor,
  397. font_color = bfontcolour
  398. })
  399. bi = bi + 1
  400. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  401. self.createButton({
  402. label="Carrier",
  403. click_function='Carrier',
  404. function_owner = self,
  405. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  406. height=bheight,
  407. width=bwidth,
  408. font_size=fontsize,
  409. color = bcolor,
  410. font_color = bfontcolour
  411. })
  412. bi = bi + 1
  413. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  414. self.createButton({
  415. label="Dreadnought",
  416. click_function='Dreadnought',
  417. function_owner = self,
  418. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  419. height=bheight,
  420. width=bwidth,
  421. font_size=fontsize-30,
  422. color = bcolor,
  423. font_color = bfontcolour
  424. })
  425. bi = bi + 1
  426. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  427. self.createButton({
  428. label="Infantry",
  429. click_function='Infantry',
  430. function_owner = self,
  431. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  432. height=bheight,
  433. width=bwidth,
  434. font_size=fontsize,
  435. color = bcolor,
  436. font_color = bfontcolour
  437. })
  438. bi = bi + 1
  439. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  440. self.createButton({
  441. label="Fighter",
  442. click_function='Fighter',
  443. function_owner = self,
  444. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  445. height=bheight,
  446. width=bwidth,
  447. font_size=fontsize,
  448. color = bcolor,
  449. font_color = bfontcolour
  450. })
  451. bi = bi + 1
  452. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  453. self.createButton({
  454. label="War Sun",
  455. click_function='WarSun',
  456. function_owner = self,
  457. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  458. height=bheight,
  459. width=bwidth,
  460. font_size=fontsize,
  461. color = bcolor,
  462. font_color = bfontcolour
  463. })
  464. bi = bi + 1
  465. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  466. self.createButton({
  467. label="Flagship",
  468. click_function='Flagship',
  469. function_owner = self,
  470. position={boffset[1],boffset[2],boffset[3]+bgap*bi},
  471. height=bheight,
  472. width=bwidth,
  473. font_size=fontsize,
  474. color = bcolor,
  475. font_color = bfontcolour
  476. })
  477. bi = bi + 1
  478. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  479. self.createButton({
  480. label="Space Dock",
  481. click_function='SpaceDock',
  482. function_owner = self,
  483. position={bx+2,by,bz},
  484. height=500,
  485. width=1000,
  486. font_size=150,
  487. color = bcolor,
  488. font_color = bfontcolour
  489. })
  490. self.createButton({
  491. label="PDS",
  492. click_function='PDS',
  493. function_owner = self,
  494. position={bx+2,by,bz+1},
  495. height=500,
  496. width=1000,
  497. font_size=150,
  498. color = bcolor,
  499. font_color = bfontcolour
  500. })
  501.  
  502. end
  503. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  504. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  505. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  506. function SpaceDock(o, c, a)
  507. local name = "Space Dock"
  508. if a then
  509. RemoveShipFromOrder(name, true)
  510. else
  511. AddShipToOrder(name, true)
  512. end
  513. Recount(name)
  514. Wait.time(function() Recount(name) end, 2)
  515. end
  516. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  517. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  518. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  519. function PDS(o, c, a)
  520. local name = "PDS"
  521. if a then
  522. RemoveShipFromOrder(name, true)
  523. else
  524. AddShipToOrder(name, true)
  525. end
  526. Recount(name)
  527. Wait.time(function() Recount(name) end, 2)
  528. end
  529. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  530. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  531. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O--O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  532. function Destroyer(o, c, a)
  533. local name = "Destroyer"
  534. if a then
  535. RemoveShipFromOrder(name, false)
  536. else
  537. AddShipToOrder(name, false)
  538. end
  539. Recount(name)
  540. Wait.time(function() Recount(name) end, 2)
  541. end
  542. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  543. function Cruiser(o, c, a)
  544. local name = "Cruiser"
  545. if a then
  546. RemoveShipFromOrder(name, false)
  547. else
  548. AddShipToOrder(name, false)
  549. end
  550. Recount(name)
  551. Wait.time(function() Recount(name) end, 2)
  552. end
  553. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  554. function Carrier(o, c, a)
  555. local name = "Carrier"
  556. if a then
  557. RemoveShipFromOrder(name, false)
  558. else
  559. AddShipToOrder(name, false)
  560. end
  561. Recount(name)
  562. Wait.time(function() Recount(name) end, 2)
  563. end
  564. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  565. function Dreadnought(o, c, a)
  566. local name = "Dreadnought"
  567. if a then
  568. RemoveShipFromOrder(name, false)
  569. else
  570. AddShipToOrder(name, false)
  571. end
  572. Recount(name)
  573. Wait.time(function() Recount(name) end, 2)
  574. end
  575. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  576. function Infantry(o, c, a)
  577. local name = "Infantry"
  578. if a then
  579. RemoveShipFromOrder(name, false)
  580. else
  581. AddShipToOrder(name, false)
  582. end
  583. Recount(name)
  584. Wait.time(function() Recount(name) end, 2)
  585. end
  586. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  587. function Fighter(o, c, a)
  588. local name = "Fighter"
  589. if a then
  590. RemoveShipFromOrder(name, false)
  591. else
  592. AddShipToOrder(name, false)
  593. end
  594. Recount(name)
  595. Wait.time(function() Recount(name) end, 2)
  596. end
  597. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  598. function WarSun(o, c, a)
  599. local name = "War Sun"
  600. if a then
  601. RemoveShipFromOrder(name, false)
  602. else
  603. AddShipToOrder(name, false)
  604. end
  605. Recount(name)
  606. Wait.time(function() Recount(name) end, 2)
  607. end
  608. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  609. function Flagship(o, c, a)
  610. local name = "Flagship"
  611. if a then
  612. RemoveShipFromOrder(name, false)
  613. else
  614. AddShipToOrder(name, false)
  615. end
  616. Recount(name)
  617. Wait.time(function() Recount(name) end, 2)
  618. end
  619. --O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O=O
  620.  
  621. function Recount(name)
  622. local count = 0
  623. for i, j in pairs(self.getObjects()) do
  624. if j.name == name then
  625. count = count + 1
  626. end
  627. end
  628.  
  629. if count == ShipLimit(name) then
  630. self.editButton({
  631. index = ButtonsBeforeShipButtons + ShipNumber(name) -1,
  632. label = name
  633. })
  634. else
  635. self.editButton({
  636. index = ButtonsBeforeShipButtons + ShipNumber(name) -1,
  637. label = name.." ("..count.."/"..ShipLimit(name)..")"
  638. })
  639. end
  640.  
  641. end
  642.  
  643.  
  644.  
  645. function onObjectEnterContainer(bag, obj)
  646. if bag == self then
  647. RecountAll()
  648. RecolorButtons()
  649. if string.find(obj.getName(), "Command Token") then
  650. FactionName = string.sub(obj.getName(), 0, string.len(obj.getName())-14)
  651. --print(FactionName)
  652. FactionSpawn(ReturnFactionShips(FactionName))
  653. EjectCommandTokens()
  654. end
  655. end
  656. end
  657.  
  658.  
  659. function onObjectLeaveContainer(bag, obj)
  660. if bag == self then
  661. RecountAll()
  662. RecolorButtons()
  663. --obj.setScale({1,1,1})
  664. end
  665. end
  666.  
  667. function Nada()
  668. end
  669.  
  670. function RecountAll()
  671. for i, j in pairs(ShipTable) do
  672. Recount(j.Name)
  673. end
  674. UpdateOrderCost()
  675. end
  676.  
  677. function HexColor(colorString)
  678. local colorTable = stringColorToRGB(colorString)
  679. colorTable = {colorTable[1]*255,colorTable[2]*255,colorTable[3]*255}
  680. local colorHex = string.format('%02x%02x%02x', unpack(colorTable))
  681. return colorHex
  682. end
  683.  
  684.  
  685.  
  686. function ToggleRegulatedConscription()
  687. RegulatedConscription = not RegulatedConscription
  688. if RegulatedConscription == true then
  689. self.editButton({index = RegulatedConscriptionButtonIndex, label = "Regulated Conscription On", color = {0.2,0.8,0.2}})
  690. fighter.Cost = 1
  691. infantry.Cost = 1
  692. else
  693. self.editButton({index = RegulatedConscriptionButtonIndex, label = "Regulated Conscription Off", color = {0,0,0}})
  694. fighter.Cost = 0.5
  695. infantry.Cost = 0.5
  696. end
  697. RecountAll()
  698. end
  699.  
  700. function ToggleMuaatWarSun()
  701. MuaatWarSun = not MuaatWarSun
  702. if MuaatWarSun == true then
  703. self.editButton({index = MuaatButtonIndex, label = "Muaat Upgraded War Sun On", color = {0.2,0.8,0.2}})
  704. warsun.Cost = 10
  705. else
  706. self.editButton({index = MuaatButtonIndex, label = "Muaat Upgraded War Sun Off", color = {0,0,0}})
  707. warsun.Cost = 12
  708. end
  709. RecountAll()
  710. end
  711.  
  712.  
  713.  
  714. function ToggleSarween()
  715. SarweenTools = not SarweenTools
  716. if SarweenTools == true then
  717. self.editButton({index = SarweenButtonIndex, label = "Sarween Tools On", color = {0.2,0.8,0.2}})
  718. else
  719. self.editButton({index = SarweenButtonIndex, label = "Sarween Tools Off", color = {0, 0, 0}})
  720. end
  721. UpdateOrderCost()
  722. RecountAll()
  723. end
  724.  
  725. function RecolorButtons()
  726. for i, j in pairs(self.getButtons()) do
  727. self.editButton({
  728. index = j.index,
  729. font_color = self.getColorTint()
  730. })
  731. end
  732. end
  733.  
  734. function WipeButtonTooltips()
  735. for i, j in pairs(self.getButtons()) do
  736.  
  737. self.editButton({
  738. index = j.index,
  739. tooltip = ""
  740. })
  741. end
  742. end
  743.  
  744. function FactionSpawn(FactionShips)
  745. for i, j in pairs(FactionShips) do
  746. AddShipToOrder(j, true)
  747. end
  748. end
  749.  
  750. function ReturnFactionShips(Faction)
  751. local FactionShips = {}
  752. for i, j in pairs(ShipTable) do
  753. if setupParams[Faction][j.Name] ~= nil then
  754. for v = 1, setupParams[Faction][j.Name], 1 do
  755. table.insert(FactionShips, j.Name)
  756. end
  757. end
  758. end
  759. return FactionShips
  760. end
  761.  
  762. function EjectCommandTokens()
  763. for i, j in pairs(self.getObjects()) do
  764. if string.find(j.name, "Command Token") then
  765.  
  766. params = {}
  767. params.guid = j.guid
  768. params.position = {self.getPosition()[1], self.getPosition()[2], self.getPosition()[3]+3}
  769. self.takeObject(params).setColorTint(self.getColorTint())
  770.  
  771. end
  772. end
  773. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement