• Stopwatch with start & stop area
    14 replies, posted
Hello! Like you may know im currently working on a new Bunnyhop server. One of the last things that have to be done is a stopwatch. My idea is to make a timer that starts counting when a player is in the first red area, and the timer stay on 0.00 when the player is in it. Whenever he leaves it the timer continues counting. The timer gets stopped by entering the second area (on the end of the map) and then prints in chat "$player has finished the map in $time" If he then returns to the first area it goes back to 0.00 :) Also, the timer must be visible on the Clients hud. (dont bother making it fancy, that's my job; just a simple draw.DrawText is enough) Here are some screenshots of what I define by those "areas" [B]Start area.[/B] [IMG]http://i40.tinypic.com/1zbsyrn.jpg[/IMG] [B]Stop area.[/B] [IMG]http://i41.tinypic.com/20jqyie.jpg[/IMG] [B]Just for your curiosity, this is my layout. The timer will come to the right of the VEL.[/B] [IMG]http://i42.tinypic.com/2u9kgfm.png[/IMG] This was just done with the rope tool, because I saw something familiar in other servers (parkour) Anyways, thanks for reading this far! :) Kind regards, Ho7s0
I believe per map you'd have to set a predetermined start zone, and predetermined end zone, then based on local player start that timer and end it based on the second they enter that area, and have a variable that is set when they run through it, so if the variable is 1 then the next zone they hit, it will reset the timer to 0 to start all over again.
[QUOTE=Nookyava;41918863]I believe per map you'd have to set a predetermined start zone, and predetermined end zone, then based on local player start that timer and end it based on the second they enter that area, and have a variable that is set when they run through it, so if the variable is 1 then the next zone they hit, it will reset the timer to 0 to start all over again.[/QUOTE] I have seen examples over the internet where the areas are highlighted areas with coords in a lua file PER map, like an item as a stop, but then with an area. Im sure there's someone on here who can teach/code me this :3
You can use something like this, inside of a think hook. [url]http://wiki.garrysmod.com/page/ents/FindInBox[/url] Basically when the function "catches a player", have it reset any previous timers. Once the function "loses that player", have a variable hold the os.time() and catch it once more when they finish. Then everything between those two numbers is there time. You can do simple math to create a timer object on the screen based on the first os.time() variable you saved, and the current os.time() inside a think hook.
[QUOTE=find me;41931927]You can use something like this, inside of a think hook. [url]http://wiki.garrysmod.com/page/ents/FindInBox[/url] Basically when the function "catches a player", have it reset any previous timers. Once the function "loses that player", have a variable hold the os.time() and catch it once more when they finish. Then everything between those two numbers is there time. You can do simple math to create a timer object on the screen based on the first os.time() variable you saved, and the current os.time() inside a think hook.[/QUOTE] There is a much better way to do this. You make a non solid entity with a custom collison box set to the same area that you want to cover with the stop/start watches and when a player enters them you can cause the reaction you want. EDIT: You would create your entity like this: [code]ENT.Type = "anim" if SERVER then function ENT:Initialize() self:SetModel("models/hunter/blocks/cube025x025x025.mdl") end function ENT:StartTouch(ent) if ent:IsPlayer() then ent:ChatPrint("Entered Box") end end function ENT:EndTouch(ent) if ent:IsPlayer() then ent:ChatPrint("Left Box") end function ENT:SetPhysics(vec1, vec2) self:PhysicsInitBox(vec1, vec2) self:SetCollisionBounds(vec1, vec2) self:EnableCustomCollisions( true ) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:EnableCollisions(false) phys:EnableMotion(false) end self:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER) self:SetTrigger(true) self:SetNotSolid(true) end else function ENT:Draw() end end[/code] Then I guess you call it like this: [code]local vec1, vec2 = Vector(0,0,0), Vector(500, 500, 500) local coolcube = ents.Create("my_cool_cube") coolcube:SetPos(vec1) coolcube:SetPhysics(vec1, vec2) coolcube:Spawn()[/code] I would assume this would take up less resources since you don't have to do an Ents.FindInBox all the time, and if you wanted to you could even make them visible.
Nice, but this doesn't print any times :I
Ozymandias is on the right path for generally how you would want to do this ( although you can probably do the positions in hammer if you set the fgd up for it and use keyvalues ). First, when the player starts their turn at the course, you'd want to do something like: [code] pl:SetDTFloat( 0, 0 ) pl:SetDTBool( 0, false ) pl:SetDTBool( 1, false )[/code] We're going to use the float to track their time, and the bools to see if the player should have their time incremented each frame, or if the player is in a safe zone. So, when the player enters the box, we do this: [code] function ENT:StartTouch( pl ) if self.IsStartBox then pl:SetDTBool( 0, true ) --Player should be timed once they leave the box elseif self.IsEndBox then pl:SetDTBool( 0, false ) --Player finished this segment of the course pl:SetDTBool( 1, false ) --Stop tracking time end end function ENT:EndTouch( pl ) if pl:GetDTBool( 0 ) then pl:SetDTBool( 1, true ) end end [/code] This sets the states so that we know if the player is in a safe box or not, and if they are on the course or not. Then, in the gamemode's think function, we do something like: [code] function GM:Think( ) --Any other stuff for k, v in ipairs( player.GetAll( ) ) do if v:GetDTBool( 0 ) and v:GetDTBool( 1 ) then v:SetDTFloat( 0, v:GetDTFloat( 0 ) + FrameTime( ) ) end end end [/code] You might need to track the delta yourself - I don't remember if FrameTime is still iffy or not on the server. Then, to display the time, you would do this on the client: [code] local txt = string.ToMinutsSecondsMilliseconds( pl:GetDTFloat( 0 ) ) [/code] And then you can draw that wherever you want. There's other ways to approach it, and certainly room for improvement with how I suggest doing it, but this should give you the gist of a way to do what you want.
Wow, there are a lot of codes popping up now, but I think you'll have to have a sepperate .lua file for EVERY map with the coords of the areas? something like(this one is for bhop_eazy while using a gun as the stop): [CODE]STGamemodes.Weapons:Add(Vector(-775.54632568359, -284.48303222656, 104.03125))[/CODE] This is from another bhop gamemode from 2007. I don't want a weapon I need 2 areas, this one was just as an example***
Or instead of defining the start and stop areas you could define the "play field" with a bounding box (2 set points defining the uppermost left and lowermost right points) and then with the think hook if the player is within that area it counts the time, and as soon as they are out of it the time count stops.
[QUOTE=KarmaLord;41954634]Or instead of defining the start and stop areas you could define the "play field" with a bounding box (2 set points defining the uppermost left and lowermost right points) and then with the think hook if the player is within that area it counts the time, and as soon as they are out of it the time count stops.[/QUOTE] This sounds more like it. Will it display the lines on the map like I showed in the pictures? And if anyone could give me the code for 1 map, and explain me how to add it for other maps I would be very thankfull.
[QUOTE=Ho7s0;41918503][B]Just for your curiosity, this is my layout. The timer will come to the right of the VEL.[/B] [IMG]http://i42.tinypic.com/2u9kgfm.png[/IMG] [/QUOTE] That font is really pretty, which one is it? Or did you just modify an existing one?
[QUOTE=EvacX;41960674]That font is really pretty, which one is it? Or did you just modify an existing one?[/QUOTE] It's "Ariel" with size 30 and weight 300 :)
[QUOTE=Ho7s0;41918503] [B]Just for your curiosity, this is my layout. The timer will come to the right of the VEL.[/B] [IMG]http://i42.tinypic.com/2u9kgfm.png[/IMG] [/QUOTE] You should use a surface.GetTextSize() / 2 to center your '100' and '0' in my opinion, or is it still under construction?
[QUOTE=Ho7s0;41960250]This sounds more like it. Will it display the lines on the map like I showed in the pictures? And if anyone could give me the code for 1 map, and explain me how to add it for other maps I would be very thankfull.[/QUOTE] No, lines do not show up, you would use [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexedb0.html"]this[/URL] and [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1fe0-2.html"]this[/URL].
I'm giving up guys, lua is to far for my brain for me. I'll just stay with my java. Anyways, I'll leave this open for people to react with possible codes, but that will be for people with the same question. I threw that project in my trash bin. *nuff said* Regards.
Sorry, you need to Log In to post a reply to this thread.