Advertisement
GoodManUsernameGood

Untitled

Feb 20th, 2022
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. local jobs = {"assistant", "engineer", "mechanic"} -- add or remove jobs
  2. local spawnTime = 4 -- how many seconds the client has to wait until he gets spawned
  3. local waitingClients = {}
  4.  
  5. local respawnClients = {}
  6.  
  7. LuaUserData.AddCallMetaMember(LuaUserData.RegisterType("Barotrauma.Job"))
  8. local localJob = LuaUserData.CreateStatic("Barotrauma.Job")
  9.  
  10. local function SpawnCharacter(client)
  11.     if #WayPoint.WayPointList == 0 then
  12.         print("Waypoint list is zero, aborting spawn!")
  13.         return
  14.     end
  15.  
  16.     local info = CharacterInfo("human", client.Name)
  17.     client.CharacterInfo = info
  18.  
  19.     info.Job = localJob(JobPrefab.Get(jobs[Random.Range(1, #jobs + 1)]))
  20.     local waypoint = WayPoint.SelectCrewSpawnPoints({info}, Submarine.MainSub)
  21.  
  22.     local character
  23.  
  24.     if waypoint == nil or #waypoint == 0 then
  25.         character = Character.Create(info, Submarine.MainSub.WorldPosition, info.Name, 0, true, false)
  26.         character.TeamID = CharacterTeamType.Team1
  27.         character.GiveJobItems()
  28.     else
  29.         character = Character.Create(info, waypoint[1].WorldPosition, info.Name, 0, true, false)
  30.         character.TeamID = CharacterTeamType.Team1
  31.         character.GiveJobItems(waypoint[1])
  32.     end
  33.  
  34.     if Traitormod ~= nil then
  35.         local amount = Traitormod.Config.AmountExperienceWithPoints(Traitormod.GetData(client, "Points") or 0)
  36.         character.Info.GiveExperience(amount)
  37.     end
  38.  
  39.     client.SetClientCharacter(character)
  40. end
  41.  
  42. Hook.Add("roundStart", "populateRespawnClients", function ()
  43.     respawnClients = {}
  44.     for key, value in pairs(Client.ClientList) do
  45.         respawnClients[value.SteamID] = true
  46.     end
  47. end)
  48.  
  49. Hook.Add("think", "checkforclients", function ()
  50.     for key, value in pairs(waitingClients) do
  51.         if Timer.GetTime() > value then
  52.             SpawnCharacter(key)
  53.             Game.Log(key.Name .. " Got Spawned in the sub", ServerLogMessageType.ServerMessage) -- log text
  54.             waitingClients[key] = nil
  55.         end
  56.     end
  57.  
  58.     for key, value in pairs(Client.ClientList) do
  59.         if respawnClients[value.SteamID] == nil and waitingClients[value] == nil and value.Character == nil and value.InGame and Game.RoundStarted then
  60.             waitingClients[value] = Timer.GetTime() + spawnTime
  61. --            Game.SendDirectChatMessage("", "You will be spawned in " .. spawnTime .. " seconds!", nil, ChatMessageType.ServerMessageBoxInGame, value) -- client text when he is spectating
  62.             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
  63.             respawnClients[value.SteamID] = true
  64.         end
  65.     end
  66. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement