Advertisement
Urik_Kane

Untitled

Nov 14th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 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)   -- I've also tried "args, player" and "player" here
  25.     self.player = player
  26.  
  27.     -- the MapInstamce:Addplayer is supposed to be called for a player who joined the server. It initializes the object streaming for their client side
  28.     -- it looks like this:
  29.     -- function MapEditor.MapInstance:AddPlayer(player)
  30.     -- table.insert(self.players , player)
  31.     -- Network:Send(player , "InitializeMapInstance" , self.clientObjects)
  32.     -- end
  33.    
  34.     -- so I need to provide it with player, which I am trying to do
  35.     -- as you see below I've tried different ways to get players, or player ids, to no avail
  36.     -- I've referred to other scripts, they just use OnPlayerJoin(args) and then use (args.player) but it doesn't work here
  37.    
  38.     -- in console, either nothing happens, or "Player" being a nil value, or it gives "void NetworkManager:Send (...."
  39.     -- so I realize that function doesn't get what I'm supposed to provide it with
  40.     -- I don't get what MapInstance:AddPlayer wants from me in the brackets, and what I get with args.player
  41.     -- 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
  42.     -- 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.
  43.    
  44.     --local newblokeID = tostring ( args.player:GetId() )
  45.     local newplayer = args.player
  46.     --local newplayerid = newplayer:GetId()
  47. --for players in Server:GetPlayers() do
  48.     self.MapInstance:AddPlayer(newplayer)
  49. end
  50.  
  51. -- pretty much the same will have to be done for onplayerleave later on.
  52. --[[
  53. function Worldinit:OnPlayerLeave()
  54.  
  55. self.MapInstance:RemovePlayer(player)
  56.  
  57. end--]]
  58.  
  59. --function Worldinit:OnModuleLoad()
  60. -- 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
  61. -- the iteration didn't work anyway
  62. --[[
  63. for player in Server:GetPlayers(args) do
  64.     self.MapInstance:AddPlayer(player)
  65. end-]]
  66. --end
  67.  
  68.  
  69. Worldinit = Worldinit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement