Advertisement
Guest User

Land of Dran Speedcart

a guest
Apr 13th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.10 KB | None | 0 0
  1. if speedcartVars == nil or speedcartVars == false then
  2.     speedcartVars = true
  3.     raceStarted = false
  4.     lastSpawnUsed = 0
  5.     lastWinner = nil
  6. end
  7.  
  8. function constantCheck()
  9.     cancel(constantSch)
  10.    
  11.     numGoodOnes = 0
  12.     theGoodOne = nil
  13.    
  14.     numClients = getNumClients()
  15.     for i = 0,numClients-1,1 do
  16.         client = getClientIdx(i)
  17.         player = client:getPlayer()
  18.         if player ~= nil then
  19.             x,y,z = player:getPosition()
  20.             if y > 15 then
  21.                 theGoodOne = client
  22.                 numGoodOnes = numGoodOnes + 1
  23.             else
  24.                 playSound("Death",x,y,z,false)
  25.                 client:setPlayer(nil)
  26.                 player:remove()
  27.                 client:setCameraPosition(x,y,z)
  28.                 client:bottomPrint("You uh drowned I guess.",7000)
  29.             end
  30.         end
  31.     end
  32.    
  33.     if numGoodOnes == 0 then
  34.         bottomPrintAll("Everyone died!",2000)
  35.         schedule(2100,"endRace")
  36.     elseif numGoodOnes == 1 then
  37.         lastWinner = theGoodOne
  38.         winRace()
  39.     else
  40.         constantSch = schedule(1000,"constantCheck")
  41.     end
  42. end
  43.  
  44. function preStartRace()
  45.  
  46.     numBricks = getNumNamedBricks("stopLight")
  47.     for i = 0,numBricks-1,1 do
  48.         brick = getNamedBrickIdx("stopLight",i)
  49.         if brick ~= nil then
  50.             brick:setColor(1,1,0,1)
  51.         end
  52.     end
  53.    
  54.     playSound("NoteFs5")
  55.     schedule(1000,"preStartRaceA")
  56.     schedule(2000,"startRace")
  57. end
  58.  
  59. function preStartRaceA()
  60.     playSound("NoteFs5")
  61. end
  62.  
  63. function startRace()
  64.     numBricks = getNumNamedBricks("stopLight")
  65.     for i = 0,numBricks-1,1 do
  66.         brick = getNamedBrickIdx("stopLight",i)
  67.         if brick ~= nil then
  68.             brick:setColor(0,1,0,1)
  69.         end
  70.     end
  71.  
  72.     playSound("NoteA6")
  73.  
  74.     numClients = getNumClients()
  75.     for i = 0,numClients-1,1 do
  76.         getClientIdx(i):clearBricks()
  77.     end
  78.    
  79.     numBricks = getNumNamedBricks("garageDoor")
  80.     for i = 0,numBricks-1,1 do
  81.         brick = getNamedBrickIdx("garageDoor",i)
  82.         if brick ~= nil then
  83.             r,g,b,a = brick:getColor()
  84.             brick:setColor(r,g,b,0)
  85.             brick:setColliding(false)
  86.         end
  87.     end
  88.    
  89.     bottomPrintAll("The race has started! 5 minutes remaining!",7000)
  90.     endRaceSchedule = schedule(300000,"raceTimeout")
  91.     constantSch = schedule(1000,"constantCheck")
  92.     raceStarted = true
  93. end
  94.  
  95. function raceTimeout()
  96.     bottomPrintAll("The time limit is up!",7000)
  97.     endRace()
  98. end
  99.  
  100. function spawnPlayerSpeedcart(client,x,y,z,cancelled)
  101.    
  102.     numSpawns = getNumNamedBricks("spawn")
  103.    
  104.     x = 1000 + math.random(-5,5)
  105.     y = 70
  106.     z = 150 + math.random(-5,5)
  107.    
  108.     if numSpawns > 0 then
  109.         x,y,z = getNamedBrickIdx("spawn",lastSpawnUsed):getPosition()
  110.         y = y + 2
  111.         lastSpawnUsed = lastSpawnUsed + 1
  112.         if lastSpawnUsed >= numSpawns then
  113.             lastSpawnUsed = 0
  114.         end
  115.     end
  116.  
  117.     if raceStarted == true then
  118.         cancelled = true
  119.         client:setCameraPosition(1000,70,150)
  120.         client:bottomPrint("You will spawn after the race!",15000)
  121.     end
  122.    
  123.     if cancelled == false then
  124.         playSound("Spawn",x,y,z,false)
  125.     end
  126.    
  127.     return client,x,y,z,cancelled
  128. end
  129. registerEventListener("spawnPlayer","spawnPlayerSpeedcart")
  130.  
  131. function winRace()
  132.     bottomPrintAll(lastWinner:getName() .. " has won the race!",7000)
  133.     playSound("Win")
  134.            
  135.     numClients = getNumClients()
  136.     for i = 0,numClients-1,1 do
  137.         if lastWinner:getPlayer() == nil then
  138.             getClientIdx(i):setCameraPosition(-450,80,1200)
  139.         else
  140.             getClientIdx(i):bindCamera(lastWinner:getPlayer())
  141.         end
  142.     end
  143.            
  144.     schedule(7000,"endRace")
  145. end
  146.  
  147. function endRace()
  148.     clearAllCars()
  149.     cancel(endRaceSchedule)
  150.     cancel(constantSch)
  151.     raceStarted = false
  152.    
  153.     numBricks = getNumNamedBricks("stopLight")
  154.     for i = 0,numBricks-1,1 do
  155.         brick = getNamedBrickIdx("stopLight",i)
  156.         if brick ~= nil then
  157.             brick:setColor(1,0,0,1)
  158.         end
  159.     end
  160.    
  161.     numBricks = getNumNamedBricks("garageDoor")
  162.     for i = 0,numBricks-1,1 do
  163.         brick = getNamedBrickIdx("garageDoor",i)
  164.         if brick ~= nil then
  165.             r,g,b,a = brick:getColor()
  166.             brick:setColor(r,g,b,0.95) -- Keep a bit below 1 otherwise transparency can be messed up later
  167.             brick:setColliding(true)
  168.         end
  169.     end
  170.    
  171.     numClients = getNumClients()
  172.     for i = 0,numClients-1,1 do
  173.         getClientIdx(i):spawnPlayer(1000+math.random(-5,5),70,150+math.random(-5,5))
  174.     end
  175. end
  176.  
  177. function clientLeaveSpeedcart(client)
  178.     client:clearBricks()
  179. end
  180. registerEventListener("clientLeave","clientLeaveSpeedcart")
  181.  
  182. function clickBrick(client,brick,x,y,z)
  183.     if brick:getName() == "goob" then
  184.         player = client:getPlayer()
  185.         if player ~= nil then
  186.             x,y,z = player:getPosition()
  187.             playSound("FastImpact",x,y,z,false)
  188.             client:bottomPrint("Bwoamp",2000);
  189.         end
  190.     end
  191.    
  192.     if raceStarted == true then
  193.         if brick:getName() == "winner" then
  194.             lastWinner = client
  195.             winRace()
  196.         end
  197.     end
  198. end
  199. registerEventListener("clientClickBrick","clickBrick")
  200.  
  201. function plantBrick(client,brick)
  202.     if raceStarted == true then
  203.         client:bottomPrint("You can not build during the race!",7000)
  204.         brick:remove()
  205.     end
  206. end
  207. registerEventListener("clientPlantBrick","plantBrick")
  208.  
  209. function loadCarSpeedcart(client,car,loadCarAsCar)
  210.     if raceStarted == true then
  211.         client:bottomPrint("You can not load cars during the race!",7000)
  212.         return true
  213.     else
  214.         if client:getNumVehicles() > 1 then
  215.             client:bottomPrint("You can't have over 2 cars at a time!",7000)
  216.             return true
  217.         end
  218.     end
  219.    
  220.     return false
  221. end
  222. registerEventListener("clientTryLoadCar","loadCarSpeedcart")
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement