Advertisement
NSKuber

Exercise 7 Bonus 3

Apr 1st, 2021
1,403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. local worldInfo = worldGlobals.worldInfo
  2.  
  3. local importantValue = 0
  4.  
  5. worldGlobals.CreateRPC("server", "reliable", "SetImportantVariable",
  6.     function(newValue)
  7.         importantVariable = newValue
  8.     end
  9. )
  10.  
  11. worldGlobals.CreateRPC("client", "reliable", "RequestImportantVariable",
  12.     function()
  13.         -- Checking and sending the server-sided RPC only in a Multiplayer game
  14.         if not worldInfo:IsSinglePlayer() and worldInfo:NetIsHost() then
  15.             worldGlobals.SetImportantVariable(importantVariable)
  16.         end
  17.     end
  18. )
  19.  
  20. -- Each player requests the important variable upon joining
  21. worldGlobals.RequestImportantVariable()
  22.  
  23. -- Only the host increases the important value, and he sends it to everyone
  24. if worldInfo:NetIsHost() then
  25.     while true do
  26.         Wait(Delay(5))
  27.         importantValue = importantValue + 1
  28.         -- Checking and sending the server-sided RPC only in a Multiplayer game
  29.         if not worldInfo:IsSinglePlayer() then
  30.             worldGlobals.SetImportantVariable(importantVariable)
  31.         end
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement