Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local jobs = {"assistant", "engineer", "mechanic"} -- add or remove jobs
- local spawnTime = 4 -- how many seconds the client has to wait until he gets spawned
- local waitingClients = {}
- local respawnClients = {}
- LuaUserData.AddCallMetaMember(LuaUserData.RegisterType("Barotrauma.Job"))
- local localJob = LuaUserData.CreateStatic("Barotrauma.Job")
- local function SpawnCharacter(client)
- if #WayPoint.WayPointList == 0 then
- print("Waypoint list is zero, aborting spawn!")
- return
- end
- local info = CharacterInfo("human", client.Name)
- client.CharacterInfo = info
- info.Job = localJob(JobPrefab.Get(jobs[Random.Range(1, #jobs + 1)]))
- local waypoint = WayPoint.SelectCrewSpawnPoints({info}, Submarine.MainSub)
- local character
- if waypoint == nil or #waypoint == 0 then
- character = Character.Create(info, Submarine.MainSub.WorldPosition, info.Name, 0, true, false)
- character.TeamID = CharacterTeamType.Team1
- character.GiveJobItems()
- else
- character = Character.Create(info, waypoint[1].WorldPosition, info.Name, 0, true, false)
- character.TeamID = CharacterTeamType.Team1
- character.GiveJobItems(waypoint[1])
- end
- if Traitormod ~= nil then
- local amount = Traitormod.Config.AmountExperienceWithPoints(Traitormod.GetData(client, "Points") or 0)
- character.Info.GiveExperience(amount)
- end
- client.SetClientCharacter(character)
- end
- Hook.Add("roundStart", "populateRespawnClients", function ()
- respawnClients = {}
- for key, value in pairs(Client.ClientList) do
- respawnClients[value.SteamID] = true
- end
- end)
- Hook.Add("think", "checkforclients", function ()
- for key, value in pairs(waitingClients) do
- if Timer.GetTime() > value then
- SpawnCharacter(key)
- Game.Log(key.Name .. " Got Spawned in the sub", ServerLogMessageType.ServerMessage) -- log text
- waitingClients[key] = nil
- end
- end
- for key, value in pairs(Client.ClientList) do
- if respawnClients[value.SteamID] == nil and waitingClients[value] == nil and value.Character == nil and value.InGame and Game.RoundStarted then
- waitingClients[value] = Timer.GetTime() + spawnTime
- -- Game.SendDirectChatMessage("", "You will be spawned in " .. spawnTime .. " seconds!", nil, ChatMessageType.ServerMessageBoxInGame, value) -- client text when he is spectating
- Game.SendDirectChatMessage("", "You have 1 live and as mid game joiner your character is random.", nil, ChatMessageType.ServerMessageBoxInGame, value) -- client text when he is spectating
- respawnClients[value.SteamID] = true
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement