Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Lap Timer Multi Lap Multi Person 2
- @inputs EGP:wirelink
- @outputs [Player Lap RefTime LapTime BestLap Done]:array
- @persist Stage Laps FinishDist StartTime CountDown FinishCount MinTime StartPos:vector
- @trigger
- runOnChat(1)
- #[
- How to use:
- Spawn this e2 at your start/finish line (finish line if you aren't on a circuit)
- Wire it to an EGP HUD
- Refresh the E2
- Chat commands:
- /add <name> - adds a player to the list of racers
- /start - starts the countdown
- /dq <name> - disqualifies a player currently in the race (does not work when race not started)
- #]
- if(first()) {
- Laps = 3
- FinishDist = 400 #Distance the player has to be from the finish to be counted
- CountDown = 10 #What number to count down from when started
- MinTime = 30 #Minimum time (in seconds) before counting someone as crossing the line
- #This is important because there is no checkpoint system
- #10-30s is usually fine
- StartPos = entity():pos()
- EGP:egpClear()
- EGP:egpText(1,"Waiting...",vec2(256,256))
- EGP:egpSize(1,64)
- EGP:egpAlign(1,1)
- }
- if(Stage > 1) {
- interval(33)
- } else {
- interval(1000)
- }
- if(chatClk(owner())) {
- if(!Stage) {
- C = lastSaid():explode(" ")
- if(C[1,string] == "/add") {
- hideChat(1)
- if(C[2,string]) {
- Ply = findPlayerByName(C[2,string])
- if(Ply) {
- if(Player:count()) {
- for(I=1,Player:count()) {
- if(Ply == Player[I,entity]) {
- Flag = 1
- }
- }
- }
- if(!Flag) {
- Player:pushEntity(Ply)
- print("[LAP TIMER] Added racer #" + Player:count() + " - " + Ply:name())
- EGP:entity():soundPlay(1,0,"buttons/blip2.wav")
- timer("stopSound",500)
- for(I=1,Player:count()) {
- EGP:egpText(Player:count(), Player[I,entity]:name(), vec2(256,64+(I*25)))
- EGP:egpAlign(Player:count(), 1)
- EGP:egpSize(Player:count(), 25)
- }
- } else {
- print("[LAP TIMER] Player already in list")
- }
- } else {
- print("[LAP TIMER] Player not found")
- }
- } else {
- print("[LAP TIMER] Please name a person to add")
- }
- }
- if(C[1,string] == "/start") {
- hideChat(1)
- if(Player:count() >= 1) {
- Stage = 1
- } else {
- print("[LAP TIMER] No players added")
- }
- }
- }
- if(Stage == 2) {
- C = lastSaid():explode(" ")
- if(C[1,string] == "/dq") {
- hideChat(1)
- if(C[2,string]) {
- Ply = findPlayerByName(C[2,string])
- if(Ply) {
- for(I=1,Player:count()) {
- if(Player[I,entity] == Ply & !Done[I,number]) {
- BestLap[I,number] = 59999
- Done[I,number] = 2
- FinishCount++
- }
- }
- concmd("ulx tsay [LAP TIMER] " + Ply:name() + " has been disqualified from the race")
- timer("dqclk",500)
- } else {
- print("[LAP TIMER] Player not found")
- }
- } else {
- print("[LAP TIMER] Please type the name of the one you wish to disqualify")
- }
- }
- }
- }
- if(clk("stopSound")) {
- soundStop(1)
- }
- if(changed(Stage)&Stage == 1) {
- EGP:egpClear()
- EGP:egpText(1,"RACE STARTING IN: ",vec2(256,128))
- EGP:egpSize(1,100)
- EGP:egpColor(1,vec(0,255,0))
- EGP:egpAlign(1,1)
- EGP:egpText(2,CountDown:toString(),vec2(256,192))
- EGP:egpSize(2,200)
- EGP:egpAlign(2,1)
- EGP:entity():soundPlay(1,0,"buttons/blip1.wav")
- timer("soundStop",500)
- timer("cd",1000)
- }
- if(clk("cd")) {
- if(CountDown > 1) {
- CountDown--
- EGP:egpText(2,CountDown:toString(),vec2(256,192))
- EGP:egpSize(2,200)
- EGP:egpAlign(2,1)
- EGP:entity():soundPlay(1,0,"buttons/blip1.wav")
- timer("soundStop",500)
- timer("cd",1000)
- } else {
- EGP:egpRemove(1)
- EGP:egpText(2,"GO",vec2(256,192))
- EGP:egpColor(2,vec(255,0,0))
- EGP:egpSize(2,200)
- EGP:egpAlign(2,1)
- EGP:entity():soundPlay(1,0,"buttons/bell1.wav")
- timer("soundStop",500)
- timer("inProgress",5000)
- Stage = 2
- }
- }
- if(clk("inProgress")) {
- EGP:egpClear()
- EGP:egpText(1,"--------Race in Progress--------",vec2(256,128))
- EGP:egpSize(1,100)
- EGP:egpAlign(1,1)
- }
- if(Stage == 2) {
- if(changed(Stage)) {
- for(I=1,Player:count()) {
- StartTime = realtime()
- RefTime[I,number] = realtime()
- BestLap[I,number] = 9999
- Lap[I,number] = 1
- }
- }
- for(I=1,Player:count()) {
- if(!Done[I,number]) {
- LapTime[I,number] = realtime() - RefTime[I,number]
- if((Player[I,entity]:pos() - StartPos):length() < FinishDist & LapTime[I,number] > MinTime & !Done[I,number]) {
- if(LapTime[I,number] < BestLap[I,number]) {
- BestLap[I,number] = LapTime[I,number]
- }
- RefTime[I,number] = realtime()
- Lap[I,number] = Lap[I,number] + 1
- if(BestLap[I,number]%60<10) {
- Time=(floor(BestLap[I,number]/60)+":0"+floor(BestLap[I,number]%60,3))
- } else {
- Time=(floor(BestLap[I,number]/60)+":"+floor(BestLap[I,number]%60,3))
- }
- if(Lap[I,number] <= Laps) {
- concmd("ulx tsay [LAP TIMER] " + Player[I,entity]:name() + " is on lap " + Lap[I,number] + " with a current best time of " + Time)
- }
- }
- if(Lap[I,number] == Laps + 1 & !Done[I,number]) {
- Done[I,number] = 1
- }
- } else {
- if(Done[I,number] == 1) {
- if(BestLap[I,number]%60<10) {
- Time=(floor(BestLap[I,number]/60)+":0"+floor(BestLap[I,number]%60,3))
- } else {
- Time=(floor(BestLap[I,number]/60)+":"+floor(BestLap[I,number]%60,3))
- }
- concmd("ulx tsay [LAP TIMER] " + Player[I,entity]:name() + " has finished with a personal best lap time of " + Time)
- Done[I,number] = 2
- FinishCount++
- }
- }
- }
- if((realtime()-StartTime)%60<10) {
- Time=(floor((realtime()-StartTime)/60)+":0"+floor((realtime()-StartTime)%60,3))
- } else {
- Time=(floor((realtime()-StartTime)/60)+":"+floor((realtime()-StartTime)%60,3))
- }
- EGP:egpText(3,"Current Race Time: " + Time,vec2(256,312))
- EGP:egpSize(3,50)
- EGP:egpAlign(3,1)
- }
- if(FinishCount > 0 & (changed(FinishCount) | clk("dqclk")) & FinishCount >= Player:count()) {
- timer("finalstats",1500)
- Stage = 3
- }
- if(clk("finalstats")) {
- concmd("ulx tsay [LAP TIMER] THE RACE IS OVER! FINAL TIMES: ")
- for(I=1,Player:count()) {
- if(BestLap[I,number]%60<10) {
- Time=(floor(BestLap[I,number]/60)+":0"+floor(BestLap[I,number]%60,3))
- } else {
- Time=(floor(BestLap[I,number]/60)+":"+floor(BestLap[I,number]%60,3))
- }
- concmd("ulx tsay [LAP TIMER] " + Player[I,entity]:name() + " - " + Time)
- timer("reset",5000)
- }
- }
- if(clk("reset")) {
- reset()
- }
- if(dupefinished()) {
- reset()
- }
Advertisement
Add Comment
Please, Sign In to add comment