Advertisement
Urik_Kane

Untitled

Nov 14th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. class 'Worldinit'
  2.  
  3. function Worldinit:__init()
  4. --  self.player = player
  5. --  self.playerId = player:GetId()
  6. --  self.name = player:GetName()
  7. --  self.steamId = player:GetSteamId().id
  8.  
  9. -- This part works. They define a map file, and initialize a mapinstance (serverside)
  10. local path = "LAbase6.map"
  11. --local path = ..name..".map"
  12. self.map = MapEditor.LoadFromFile(path)
  13. self.MapInstance = MapEditor.MapInstance(self.map)
  14.  
  15. -- The next part, initializing clientside part for players, is where I'm hitting the wall
  16.  
  17. --local Urikplayer = Player.GetById(0)  -- I know this is wrong but it's THE ONLY WAY I got it to work so far. I was just desperate to find out if I'm doing the right thing afterall
  18. --self.MapInstance:AddPlayer(Urikplayer)    -- So it works when I reload it while being on the server (because my id is always 0 when I'm alone)
  19.  
  20. Events:Subscribe("PlayerJoin", self, self.OnPlayerJoin)
  21. --Events:Subscribe("PlayerQuit", self, self.OnPlayerLeave)
  22. end
  23.  
  24. function Worldinit:OnPlayerJoin(args)
  25.     self.MapInstance:AddPlayer(args.player)
  26. end
  27.  
  28. --[[
  29. function Worldinit:OnPlayerJoin(args)   -- I've also tried "args, player" and "player" here
  30.     --self.player = player
  31.  
  32.     -- the MapInstamce:Addplayer is supposed to be called for a player who joined the server. It initializes the object streaming for their client side
  33.     -- it looks like this:
  34.     -- function MapEditor.MapInstance:AddPlayer(player)
  35.     -- table.insert(self.players , player)
  36.     -- Network:Send(player , "InitializeMapInstance" , self.clientObjects)
  37.     -- end
  38.    
  39.     -- so I need to provide it with player, which I am trying to do
  40.     -- as you see below I've tried different ways to get players, or player ids, to no avail
  41.     -- I've referred to other scripts, they just use OnPlayerJoin(args) and then use (args.player) but it doesn't work here
  42.    
  43.     -- in console, either nothing happens, or "Player" being a nil value, or it gives "void NetworkManager:Send (...."
  44.     -- so I realize that function doesn't get what I'm supposed to provide it with
  45.     -- I don't get what MapInstance:AddPlayer wants from me in the brackets, and what I get with args.player
  46.     -- my success with Player.GetById only lead me to assumption it wants an Id, but extracting Id of newlyjoined player and feeding that to the function via local variable did nothing
  47.     -- if I'm just using args.player, I'm not even sure what kind of data it is providing to the function. I thought Id must be there too.
  48.    
  49.     --local newblokeID = tostring ( args.player:GetId() )
  50.     --local newplayer = args.player:GetId()
  51.     --local newplayerid = newplayer:GetId()
  52. --for players in Server:GetPlayers() do
  53.     print(args.player)
  54.     self.MapInstance:AddPlayer(args.player)
  55.  
  56. end--]]
  57.  
  58. -- pretty much the same will have to be done for onplayerleave later on.
  59. --[[
  60. function Worldinit:OnPlayerLeave()
  61.  
  62. self.MapInstance:RemovePlayer(player)
  63.  
  64. end--]]
  65.  
  66. --function Worldinit:OnModuleLoad()
  67. -- I assume I will need something this for the event of module loading on occupied server, but I didn't get to it yet hence didn't add subsription
  68. -- the iteration didn't work anyway
  69. --[[
  70. for player in Server:GetPlayers(args) do
  71.     self.MapInstance:AddPlayer(player)
  72. end-]]
  73. --end
  74.  
  75.  
  76. Worldinit = Worldinit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement