How can I add a rounded box to my HUD that is filled with some sort of bar, then when you hold shift it will decrease and once that bar hits 0 (starting from 100, of course) you cannot sprint anymore until it recharges?
[EDITLINE]3:39PM[/EDITLINE]
Well no the rounded box part, just the contents on the inside.
bump?
Drawing a bar is quite straight forward. Draw a box the size of the entire bar, then draw another box, this box's width being dependent on another variable.
For example, if you wanted to make a health bar, you could do so by drawing a box 100 units wide, and then another box after that which's width is health (1-100).
You can experiment with different colours, making the back box slightly larger to give it a border, etc.
As for stamina dependent sprinting, that's a bit more complicated. I guess it involves replacing the existing sprint command with your own. Think you can figure that out, or do you need some help with that too?
For sprinting, just create a global variable, name it sprint or something, then use [b][url=http://wiki.garrysmod.com/?title=Input.IsKeyDown]Input.IsKeyDown [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] to check if the player is in sprint, then create an infinite timer, of no more than a second delay between reps, and the function should be:
[lua]sprint = sprint - 1[/lua]
So, all together it should look like this:
[lua]sprint = 100
if ( input.IsKeyDown( IN_RUN ) ) then
timer.Create( "sprintdecrease", 0.5, 0, function()
sprint = sprint - 1
end )
else
timer.Destroy( "sprintdecrease" )
if sprint < 100 then
timer.Create( "sprintincrease", 1, 0, function()
sprint = sprint + 1
end )
elseif sprint == 100 then
timer.Destroy( "sprintincrease" )
end
end[/lua]
The above code implements the sprint increasing and decreasing, but since SprintEnable and SprintDisable functions are broken (apparantly) I don't know how to stop them from sprinting if they're stamina is 0.
In that case, my best idea would be to replace the existing sprint key binding with a new one, from which you can increase the player's velocity yourself and keep track of their stamina too.
Oh I get it you made it so the bar will go from 100-0, but after that you couldn't figure out how to make it stop them from sprinting? Maybe it's the same type of hook that stops the grav gun from using its punt?
As I said, there used to be two working functions, SprintEnable and SprintDisable, however, they were broken a couple updates ago.
The only way I can think of is setting the run speed exactly the same as the walk speed when it reaches zero, then give the client about 5 or 10 seconds before they can start sprinting again, but a problem with setting the walk speed is it only updates when you respawn.
I wonder how perp still works then?
What I did in my Stamina system, is set a variable when the player shouldn't run. Then, I checked in [b][url=wiki.garrysmod.com/?title=Gamemode.KeyPress]Gamemode.KeyPress [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] if the player had pressed the sprint key (IN_SPEED). If he had, then I return false to stop the player from sprinting.
This may not be the most efficient method, but it works.
[QUOTE=Jamie932;24498918]What I did in my Stamina system, is set a variable when the player shouldn't run. Then, I checked in [b][url=wiki.garrysmod.com/?title=Gamemode.KeyPress]Gamemode.KeyPress [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] if the player had pressed the sprint key (IN_SPEED). If he had, then I return false to stop the player from sprinting.
This may not be the most efficient method, but it works.[/QUOTE]
What do you mean? Sorry I am still a noob :p
[lua]
function KeyPressed (P, key)
if(sprint =< 1) then
if(key == IN_SPEED) then
return false --Does this really work? 0.o
end
end
end
hook.Add( "KeyPress", "KeyPressedHook", KeyPressed )
[/lua]
So I combine that, with the code he posted earlier? Makes a lot of sense actually!
[editline]06:41AM[/editline]
btw this is all client sided correct?
Nope
sv_auxpowers 1 anyone?
So then is it sv or sh?
I cant actually tell but if it is serverside everybody's spring will affect eachover.
SO if Player A runs out of stamina, then Player B can't run either?
[QUOTE=Willox;24536796]I cant actually tell but if it is serverside everybody's spring will affect eachover.[/QUOTE]
Its serverside, you just need to loop through the players and set their own stamina variable.
wow. This is a lot more complicated then I thought
[QUOTE=iRzilla;24567176]No it's not you just don't understand it.[/QUOTE]
Well, yeah. That's why it's complicated to me :|
Sorry, you need to Log In to post a reply to this thread.