Advertisement
MaDDoX_br

Untitled

May 9th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1.  
  2. ----==== [gadget] game_team_com_ends.lua
  3.  
  4. if (gadgetHandler:IsSyncedCode()) then
  5.  
  6. ----  SYNCED
  7.  
  8. function gadget:UnitCreated(u, ud, team)
  9.     isAlive[u] = true
  10.     if UnitDefs[ud].customParams.iscommander then
  11.         local allyTeam = GetUnitAllyTeam(u)
  12.         aliveCount[allyTeam] = aliveCount[allyTeam] + 1
  13.         SendToUnsynced("CommCountEvent", allyTeam, aliveCount[allyTeam])
  14.     end
  15. end
  16.  
  17. else
  18.  
  19. ------------------------------------------
  20. --UNSYNCED
  21. ------------------------------------------
  22.  
  23. --Makes an unsynced gadget call a function that is in one or more widgets.
  24. local function HandleCommCountEvent(cmd, allyTeam, aliveCount)
  25.     if Script.LuaUI('CommCountUIEvent') then
  26.         Script.LuaUI.CommCountUIEvent(allyTeam, aliveCount)
  27.     end
  28. end
  29.  
  30. -- In unsynced/init, we need to wire up a function to fire any time the comm count changes (event)
  31. function gadget:Initialize()
  32.     gadgetHandler:AddSyncAction("CommCountEvent", HandleCommCountEvent)
  33. end
  34.  
  35. function gadget:Shutdown()
  36.     gadgetHandler:RemoveSyncAction("CommCountEvent")
  37. end
  38.  
  39. ------------------------------------------
  40. ------------------------------------------
  41.  
  42.  
  43. -----===== [gadget] gui_comcounter.lua:
  44.  
  45. local function CommCountChanged(allyTeam, aliveCount)
  46.     -- Sets up local variables, does what it has to do
  47. end
  48.  
  49. --Sets up to receive CommCountChanged event from game_team_comm_ends
  50. function widget:Initialize()
  51.     widgetHandler:RegisterGlobal('CommCountUIEvent', CommCountChanged)
  52. end
  53.  
  54. function widget:Shutdown()
  55.     widgetHandler:DeregisterGlobal('CommCountUIEvent')
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement