Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class 'Worldinit'
- function Worldinit:__init()
- -- self.player = player
- -- self.playerId = player:GetId()
- -- self.name = player:GetName()
- -- self.steamId = player:GetSteamId().id
- -- This part works. They define a map file, and initialize a mapinstance (serverside)
- local path = "LAbase6.map"
- --local path = ..name..".map"
- self.map = MapEditor.LoadFromFile(path)
- self.MapInstance = MapEditor.MapInstance(self.map)
- -- The next part, initializing clientside part for players, is where I'm hitting the wall
- 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
- 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)
- Events:Subscribe("PlayerJoin", self, self.OnPlayerJoin)
- --Events:Subscribe("PlayerQuit", self, self.OnPlayerLeave)
- end
- function Worldinit:OnPlayerJoin(args) -- I've also tried "args, player" and "player" here
- self.player = player
- -- the MapInstamce:Addplayer is supposed to be called for a player who joined the server. It initializes the object streaming for their client side
- -- it looks like this:
- -- function MapEditor.MapInstance:AddPlayer(player)
- -- table.insert(self.players , player)
- -- Network:Send(player , "InitializeMapInstance" , self.clientObjects)
- -- end
- -- so I need to provide it with player, which I am trying to do
- -- as you see below I've tried different ways to get players, or player ids, to no avail
- -- I've referred to other scripts, they just use OnPlayerJoin(args) and then use (args.player) but it doesn't work here
- -- in console, either nothing happens, or "Player" being a nil value, or it gives "void NetworkManager:Send (...."
- -- so I realize that function doesn't get what I'm supposed to provide it with
- -- I don't get what MapInstance:AddPlayer wants from me in the brackets, and what I get with args.player
- -- 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
- -- 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.
- --local newblokeID = tostring ( args.player:GetId() )
- local newplayer = args.player
- --local newplayerid = newplayer:GetId()
- --for players in Server:GetPlayers() do
- self.MapInstance:AddPlayer(newplayer)
- end
- -- pretty much the same will have to be done for onplayerleave later on.
- --[[
- function Worldinit:OnPlayerLeave()
- self.MapInstance:RemovePlayer(player)
- end--]]
- --function Worldinit:OnModuleLoad()
- -- 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
- -- the iteration didn't work anyway
- --[[
- for player in Server:GetPlayers(args) do
- self.MapInstance:AddPlayer(player)
- end-]]
- --end
- Worldinit = Worldinit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement