CheezusCrust

Untitled

Feb 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 KB | None | 0 0
  1. @name Lap Timer Multi Lap Multi Person 2
  2. @inputs EGP:wirelink
  3. @outputs [Player Lap RefTime LapTime BestLap Done]:array
  4. @persist Stage Laps FinishDist StartTime CountDown FinishCount MinTime StartPos:vector
  5. @trigger
  6.  
  7. runOnChat(1)
  8.  
  9. #[
  10. How to use:
  11. Spawn this e2 at your start/finish line (finish line if you aren't on a circuit)
  12. Wire it to an EGP HUD
  13. Refresh the E2
  14.  
  15. Chat commands:
  16. /add <name> - adds a player to the list of racers
  17. /start - starts the countdown
  18. /dq <name> - disqualifies a player currently in the race (does not work when race not started)
  19. #]
  20.  
  21. if(first()) {
  22. Laps = 3
  23. FinishDist = 400 #Distance the player has to be from the finish to be counted
  24. CountDown = 10 #What number to count down from when started
  25. MinTime = 30 #Minimum time (in seconds) before counting someone as crossing the line
  26. #This is important because there is no checkpoint system
  27. #10-30s is usually fine
  28. StartPos = entity():pos()
  29.  
  30. EGP:egpClear()
  31. EGP:egpText(1,"Waiting...",vec2(256,256))
  32. EGP:egpSize(1,64)
  33. EGP:egpAlign(1,1)
  34. }
  35.  
  36. if(Stage > 1) {
  37. interval(33)
  38. } else {
  39. interval(1000)
  40. }
  41.  
  42. if(chatClk(owner())) {
  43. if(!Stage) {
  44. C = lastSaid():explode(" ")
  45. if(C[1,string] == "/add") {
  46. hideChat(1)
  47. if(C[2,string]) {
  48. Ply = findPlayerByName(C[2,string])
  49. if(Ply) {
  50. if(Player:count()) {
  51. for(I=1,Player:count()) {
  52. if(Ply == Player[I,entity]) {
  53. Flag = 1
  54. }
  55. }
  56. }
  57. if(!Flag) {
  58. Player:pushEntity(Ply)
  59. print("[LAP TIMER] Added racer #" + Player:count() + " - " + Ply:name())
  60. EGP:entity():soundPlay(1,0,"buttons/blip2.wav")
  61. timer("stopSound",500)
  62. for(I=1,Player:count()) {
  63. EGP:egpText(Player:count(), Player[I,entity]:name(), vec2(256,64+(I*25)))
  64. EGP:egpAlign(Player:count(), 1)
  65. EGP:egpSize(Player:count(), 25)
  66. }
  67. } else {
  68. print("[LAP TIMER] Player already in list")
  69. }
  70. } else {
  71. print("[LAP TIMER] Player not found")
  72. }
  73. } else {
  74. print("[LAP TIMER] Please name a person to add")
  75. }
  76. }
  77.  
  78. if(C[1,string] == "/start") {
  79. hideChat(1)
  80. if(Player:count() >= 1) {
  81. Stage = 1
  82. } else {
  83. print("[LAP TIMER] No players added")
  84. }
  85. }
  86. }
  87. if(Stage == 2) {
  88. C = lastSaid():explode(" ")
  89. if(C[1,string] == "/dq") {
  90. hideChat(1)
  91. if(C[2,string]) {
  92. Ply = findPlayerByName(C[2,string])
  93. if(Ply) {
  94. for(I=1,Player:count()) {
  95. if(Player[I,entity] == Ply & !Done[I,number]) {
  96. BestLap[I,number] = 59999
  97. Done[I,number] = 2
  98. FinishCount++
  99. }
  100. }
  101. concmd("ulx tsay [LAP TIMER] " + Ply:name() + " has been disqualified from the race")
  102. timer("dqclk",500)
  103. } else {
  104. print("[LAP TIMER] Player not found")
  105. }
  106. } else {
  107. print("[LAP TIMER] Please type the name of the one you wish to disqualify")
  108. }
  109. }
  110. }
  111. }
  112.  
  113. if(clk("stopSound")) {
  114. soundStop(1)
  115. }
  116.  
  117. if(changed(Stage)&Stage == 1) {
  118. EGP:egpClear()
  119. EGP:egpText(1,"RACE STARTING IN: ",vec2(256,128))
  120. EGP:egpSize(1,100)
  121. EGP:egpColor(1,vec(0,255,0))
  122. EGP:egpAlign(1,1)
  123.  
  124. EGP:egpText(2,CountDown:toString(),vec2(256,192))
  125. EGP:egpSize(2,200)
  126. EGP:egpAlign(2,1)
  127.  
  128. EGP:entity():soundPlay(1,0,"buttons/blip1.wav")
  129. timer("soundStop",500)
  130. timer("cd",1000)
  131. }
  132.  
  133. if(clk("cd")) {
  134. if(CountDown > 1) {
  135. CountDown--
  136.  
  137. EGP:egpText(2,CountDown:toString(),vec2(256,192))
  138. EGP:egpSize(2,200)
  139. EGP:egpAlign(2,1)
  140.  
  141. EGP:entity():soundPlay(1,0,"buttons/blip1.wav")
  142. timer("soundStop",500)
  143. timer("cd",1000)
  144. } else {
  145. EGP:egpRemove(1)
  146. EGP:egpText(2,"GO",vec2(256,192))
  147. EGP:egpColor(2,vec(255,0,0))
  148. EGP:egpSize(2,200)
  149. EGP:egpAlign(2,1)
  150. EGP:entity():soundPlay(1,0,"buttons/bell1.wav")
  151. timer("soundStop",500)
  152. timer("inProgress",5000)
  153.  
  154. Stage = 2
  155. }
  156. }
  157.  
  158. if(clk("inProgress")) {
  159. EGP:egpClear()
  160. EGP:egpText(1,"--------Race in Progress--------",vec2(256,128))
  161. EGP:egpSize(1,100)
  162. EGP:egpAlign(1,1)
  163. }
  164.  
  165. if(Stage == 2) {
  166. if(changed(Stage)) {
  167. for(I=1,Player:count()) {
  168. StartTime = realtime()
  169. RefTime[I,number] = realtime()
  170. BestLap[I,number] = 9999
  171. Lap[I,number] = 1
  172. }
  173. }
  174. for(I=1,Player:count()) {
  175. if(!Done[I,number]) {
  176. LapTime[I,number] = realtime() - RefTime[I,number]
  177.  
  178. if((Player[I,entity]:pos() - StartPos):length() < FinishDist & LapTime[I,number] > MinTime & !Done[I,number]) {
  179. if(LapTime[I,number] < BestLap[I,number]) {
  180. BestLap[I,number] = LapTime[I,number]
  181. }
  182. RefTime[I,number] = realtime()
  183. Lap[I,number] = Lap[I,number] + 1
  184. if(BestLap[I,number]%60<10) {
  185. Time=(floor(BestLap[I,number]/60)+":0"+floor(BestLap[I,number]%60,3))
  186. } else {
  187. Time=(floor(BestLap[I,number]/60)+":"+floor(BestLap[I,number]%60,3))
  188. }
  189. if(Lap[I,number] <= Laps) {
  190. concmd("ulx tsay [LAP TIMER] " + Player[I,entity]:name() + " is on lap " + Lap[I,number] + " with a current best time of " + Time)
  191. }
  192. }
  193.  
  194. if(Lap[I,number] == Laps + 1 & !Done[I,number]) {
  195. Done[I,number] = 1
  196. }
  197. } else {
  198. if(Done[I,number] == 1) {
  199. if(BestLap[I,number]%60<10) {
  200. Time=(floor(BestLap[I,number]/60)+":0"+floor(BestLap[I,number]%60,3))
  201. } else {
  202. Time=(floor(BestLap[I,number]/60)+":"+floor(BestLap[I,number]%60,3))
  203. }
  204. concmd("ulx tsay [LAP TIMER] " + Player[I,entity]:name() + " has finished with a personal best lap time of " + Time)
  205. Done[I,number] = 2
  206. FinishCount++
  207. }
  208. }
  209. }
  210. if((realtime()-StartTime)%60<10) {
  211. Time=(floor((realtime()-StartTime)/60)+":0"+floor((realtime()-StartTime)%60,3))
  212. } else {
  213. Time=(floor((realtime()-StartTime)/60)+":"+floor((realtime()-StartTime)%60,3))
  214. }
  215. EGP:egpText(3,"Current Race Time: " + Time,vec2(256,312))
  216. EGP:egpSize(3,50)
  217. EGP:egpAlign(3,1)
  218. }
  219.  
  220. if(FinishCount > 0 & (changed(FinishCount) | clk("dqclk")) & FinishCount >= Player:count()) {
  221. timer("finalstats",1500)
  222. Stage = 3
  223. }
  224.  
  225. if(clk("finalstats")) {
  226. concmd("ulx tsay [LAP TIMER] THE RACE IS OVER! FINAL TIMES: ")
  227. for(I=1,Player:count()) {
  228. if(BestLap[I,number]%60<10) {
  229. Time=(floor(BestLap[I,number]/60)+":0"+floor(BestLap[I,number]%60,3))
  230. } else {
  231. Time=(floor(BestLap[I,number]/60)+":"+floor(BestLap[I,number]%60,3))
  232. }
  233. concmd("ulx tsay [LAP TIMER] " + Player[I,entity]:name() + " - " + Time)
  234. timer("reset",5000)
  235. }
  236. }
  237.  
  238. if(clk("reset")) {
  239. reset()
  240. }
  241.  
  242. if(dupefinished()) {
  243. reset()
  244. }
Advertisement
Add Comment
Please, Sign In to add comment