Advertisement
NSKuber

Separate spawning script for MarkoJ

Feb 15th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. --PLACE THIS ONLY ON A SPECIAL VERSION OF THE MAP WHICH NEEDS IT
  2. --THE FIRST VARIABLE SPECIFIES HOW MANY SECONDS PASSES
  3. --FROM THE START OF A LEVEL BEFORE NEW PLAYERS GET SPAWNED
  4. --NEAR OTHER PLAYERS. BEFORE THAT TIME PASSES, NEW PLAYERS
  5. --ARE SPAWNED AT ONE OF THE TACTIC MARKERS
  6. --YOU SHOULD SELECT AND ASSIGN ALL YOUR TACTIC MARKERS TO THE VARIABLE
  7. --"SpawnMarkers", AND ASSIGN THE CHAPTER AFTER WHICH PLAYERS ARE TOGETHER
  8. --TO THE "JointChapter"
  9.  
  10. local fTimeBeforePlayerSpawnedNearAnotherPlayer = 10
  11. local ArrayOfStuffYouHaveToAssign = {
  12.   SpawnMarkers,
  13.   JointChapter,
  14. }
  15.  
  16. while not worldInfo:IsWarmupFinished() do
  17.   Wait(CustomEvent("OnStep"))
  18. end
  19.  
  20. local time = GetDateTimeLocal()
  21. local seed = 3600*tonumber(string.sub(time,-8,-7))+60*tonumber(string.sub(time,-5,-4))+tonumber(string.sub(time,-2,-1))
  22. local RNG = CreateRandomNumberGenerator(seed + mthTruncF(mthRndF() * 1000))
  23. local RndL = function(a,b)
  24.   return (mthFloorF(RNG:RndF()*(b-a+1))%(b-a+1)+a)
  25. end
  26.  
  27. local RealDeal = {}
  28. for i=1,#SpawnMarkers,1 do
  29.   RealDeal[i] = SpawnMarkers[i]
  30. end
  31.  
  32. local MixedMarkers = {}
  33. for i=1,#RealDeal,1 do
  34.   local num = RndL(1,#SpawnMarkers-i+1)
  35.   print(num)
  36.   MixedMarkers[#MixedMarkers+1] = RealDeal[num]
  37.   for j=num,#RealDeal,1 do
  38.     RealDeal[j] = RealDeal[j+1]
  39.   end
  40. end
  41.  
  42. local IsPlayerHandled = {}
  43. local currMarker = 1
  44. local PlayerDyingSpot = {}
  45.  
  46. local HandlePlayer = function(player)
  47.   RunAsync(function()
  48.     while not IsDeleted(player) do
  49.      
  50.       if not player:IsAlive() and (PlayerDyingSpot[player] == nil) then
  51.         PlayerDyingSpot[player] = player:GetPlacement()
  52.       end
  53.      
  54.       if player:IsAlive() and (PlayerDyingSpot[player] ~= nil) then
  55.         player:SetPlacement(PlayerDyingSpot[player])
  56.         PlayerDyingSpot[player] = nil
  57.       end
  58.      
  59.       Wait(CustomEvent("OnStep"))
  60.     end
  61.   end)
  62. end
  63.  
  64. local Players = worldInfo:GetAllPlayersInRange(worldInfo,10000)
  65. for i=1,#Players,1 do
  66.   IsPlayerHandled[Players[i]] = true
  67.   Players[i]:SetPlacement(MixedMarkers[currMarker]:GetPlacement())
  68.   currMarker = currMarker % #MixedMarkers + 1
  69.   HandlePlayer(Players[i])
  70. end
  71.  
  72. local bSpawnOnMarkers = true
  73.  
  74. RunHandled(function()
  75.   Wait(Event(JointChapter.Started))
  76. end,
  77.  
  78. On(Delay(fTimeBeforePlayerSpawnedNearAnotherPlayer)),
  79. function()
  80.   bSpawnOnMarkers = false
  81. end,
  82.  
  83. OnEvery(Event(worldInfo.PlayerBorn)),
  84. function(pay)
  85.   local player = pay:GetBornPlayer()
  86.   if not IsPlayerHandled[player] then
  87.     if bSpawnOnMarkers then
  88.       player:SetPlacement(MixedMarkers[currMarker]:GetPlacement())
  89.       currMarker = currMarker % #MixedMarkers + 1
  90.     else
  91.       local bTeleported = false
  92.       for pl,_ in pairs(IsPlayerHandled) do
  93.         if (mthRndF() > 0.7) then
  94.           player:SetPlacement(pl:GetPlacement())
  95.           bTeleported = true
  96.         end
  97.       end
  98.      
  99.       if not bTeleported then
  100.         for pl,_ in pairs(IsPlayerHandled) do
  101.           player:SetPlacement(pl:GetPlacement())
  102.           break
  103.         end      
  104.       end
  105.     end
  106.     IsPlayerHandled[player] = true
  107.     HandlePlayer(Players[i])
  108.   end
  109. end
  110. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement