• Bhop help
    10 replies, posted
Okay so my first problem is im trying to make a velocity counter on the hud, but for some reason it only displays 0 whether im moving eg bunny hopping/pre-speeding or if im standing still. [CODE]local client = LocalPlayer() local t1 = CurTime() local text = string.format( "Velocity: %i", client:GetVelocity():Length( ) ); function HUD() draw.SimpleText(text, "HUDFONT1", 700, 700, Color(255, 255, 255, 255)) draw.SimpleText((math.floor(((CurTime() - t1) / 60) % 60))..":"..math.floor(CurTime() - t1) % 60, "HUDFONT1", 500, 500, Color(255, 255, 255, 255)) end hook.Add( "HUDPaint", "HUD", HUD );[/CODE] Second problem is I've disabled the movement of the doors(bhop platforms) but now people can just stand on them, how do I make it so people fall through (as in they go no-collide for the player) after a certain amount of time. Thanks.
Bump, still need help
First off why are you using string.format on your velocity? O.o You can just math.floor/ceil LocalPlayer():GetVelocity():Length2D(). You should also use length 2d because it returns your velocity horizontally. Not having a check to see if the player is valid may cause some errors. Then for the platforms. Keep track of when the player touches a func_door then after a specified amount of time if the player is still on that platform kill them or have them no colide with it or set their position to the corresponding info teleport to the closest trigger teleport.
[QUOTE=Ilyaaa;41770222]First off why are you using string.format on your velocity? O.o You can just math.floor/ceil LocalPlayer():GetVelocity():Length2D(). You should also use length 2d because it returns your velocity horizontally. Not having a check to see if the player is valid may cause some errors.[/QUOTE] Wrong. The problem is that you're setting the variable "text" only [I]once[/I] (before the function is called). [lua] local client = LocalPlayer() local time = CurTime() local function HUD() -- Always use local functions local vel = "Velocity: " .. math.floor( client:GetVelocity():Length() ) -- string.format works here, but this is easier to read. draw.SimpleText( vel, "HUDFONT1", 700, 700, Color( 255, 255, 255 ) ) local seconds = math.floor( CurTime() - time ) local minutes = math.floor( seconds / 60 ) local counter = minutes .. ":" .. ( seconds % 60 ) -- No need for ( minutes % 60 ) because it doesn't show hours anyway so it would just reset when >= 60 which is silly draw.SimpleText( counter, "HUDFONT1", 500, 500, Color( 255, 255, 255 ) end hook.Add( "HUDPaint", "HUD", HUD ) [/lua]
[QUOTE=EvacX;41770532]Wrong. The problem is that you're setting the variable "text" only [I]once[/I] (before the function is called). [lua] local client = LocalPlayer() local time = CurTime() local function HUD() -- Always use local functions local vel = "Velocity: " .. math.floor( client:GetVelocity():Length() ) -- string.format works here, but this is easier to read. draw.SimpleText( vel, "HUDFONT1", 700, 700, Color( 255, 255, 255 ) ) local seconds = math.floor( CurTime() - time ) local minutes = math.floor( seconds / 60 ) local counter = minutes .. ":" .. ( seconds % 60 ) -- No need for ( minutes % 60 ) because it doesn't show hours anyway so it would just reset when >= 60 which is silly draw.SimpleText( counter, "HUDFONT1", 500, 500, Color( 255, 255, 255 ) end hook.Add( "HUDPaint", "HUD", HUD ) [/lua][/QUOTE] Not seeing how what i said was wrong. But why not just use [CODE]string.ToMinutesSeconds(CurTime()-time) or string.ToMinutesSecondsMilliseconds(CurTime()-time)[/CODE] Also setting the players start time on client isn't the best way of doing it, because the client can easily change it.
It's perfectly fine to use string.format for something like what OP did, and LocalPlayer() doesn't need an IsValid check in a HUDPaint hook. AFAIK, it's only ever [I]nil[/I] in the first second or so after joining a server (during the authentication sequence, in which HUDPaint isn't even called).
[QUOTE=Ilyaaa;41770222]Then for the platforms. Keep track of when the player touches a func_door then after a specified amount of time if the player is still on that platform kill them or have them no colide with it or set their position to the corresponding info teleport to the closest trigger teleport.[/QUOTE] So could I have an example, sorry I'm still learning lua. I don't know how to make it no-collide after a certain amount of time.
Bump, need help with the platforms
Still need help with platforms
[lua]function GM:OnPlayerHitGround(ply) local groundEnt = ply:GetGroundEntity() if groundEnt:GetClass() == "func_door" then timer.Simple(0.03, function() groundEnt:SetOwner(ply) -- Setting owner makes you no-collide with it if CLIENT then -- Clientside things like platform color end end) timer.Simple(0.7, function() -- 0.7 seconds later you can collide with it again. groundEnt:SetOwner(nil) if CLIENT then end end) end end[/lua]
Thanks!
Sorry, you need to Log In to post a reply to this thread.