ya you can now make a stamina code. Here is what I came up with.
-- Created by: Mr. Ea King, July 2017
-- Check out my Youtube channel www.youtube.com/mreaking
--You are free to use this code however you wish.
g_stamina = 20
local drain_stamina = 0
local TimePassed = 0
local Time1 = 0
local Time2 = 0
function stamina_init(e)
--loads images for stamina
imgStam20 = LoadImage("scriptbank\\stamina\\stam_20.png")
imgStam19 = LoadImage("scriptbank\\stamina\\stam_19.png")
imgStam18 = LoadImage("scriptbank\\stamina\\stam_18.png")
imgStam17 = LoadImage("scriptbank\\stamina\\stam_17.png")
imgStam16 = LoadImage("scriptbank\\stamina\\stam_16.png")
imgStam15 = LoadImage("scriptbank\\stamina\\stam_15.png")
imgStam14 = LoadImage("scriptbank\\stamina\\stam_14.png")
imgStam13 = LoadImage("scriptbank\\stamina\\stam_13.png")
imgStam12 = LoadImage("scriptbank\\stamina\\stam_12.png")
imgStam11 = LoadImage("scriptbank\\stamina\\stam_11.png")
imgStam10 = LoadImage("scriptbank\\stamina\\stam_10.png")
imgStam9 = LoadImage("scriptbank\\stamina\\stam_9.png")
imgStam8 = LoadImage("scriptbank\\stamina\\stam_8.png")
imgStam7 = LoadImage("scriptbank\\stamina\\stam_7.png")
imgStam6 = LoadImage("scriptbank\\stamina\\stam_6.png")
imgStam5 = LoadImage("scriptbank\\stamina\\stam_5.png")
imgStam4 = LoadImage("scriptbank\\stamina\\stam_4.png")
imgStam3 = LoadImage("scriptbank\\stamina\\stam_3.png")
imgStam2 = LoadImage("scriptbank\\stamina\\stam_2.png")
imgStam1 = LoadImage("scriptbank\\stamina\\stam_1.png")
imgStam0 = LoadImage("scriptbank\\stamina\\stam_0.png")
--sets image to stamina 20
Loc_StamSprite = CreateSprite ( imgStam20 )
--sets position of sprite
SetSpritePosition(Loc_StamSprite,3,93)
end
function stamina_main(e)
--sets the sprite if stamina has changed
if g_stamina == 20 then
SetSpriteImage ( Loc_StamSprite , imgStam20 )
end
if g_stamina == 19 then
SetSpriteImage ( Loc_StamSprite , imgStam19 )
end
if g_stamina == 18 then
SetSpriteImage ( Loc_StamSprite , imgStam18 )
end
if g_stamina == 17 then
SetSpriteImage ( Loc_StamSprite , imgStam17 )
end
if g_stamina == 16 then
SetSpriteImage ( Loc_StamSprite , imgStam16 )
end
if g_stamina == 15 then
SetSpriteImage ( Loc_StamSprite , imgStam15 )
end
if g_stamina == 14 then
SetSpriteImage ( Loc_StamSprite , imgStam14 )
end
if g_stamina == 13 then
SetSpriteImage ( Loc_StamSprite , imgStam13 )
end
if g_stamina == 12 then
SetSpriteImage ( Loc_StamSprite , imgStam12 )
end
if g_stamina == 11 then
SetSpriteImage ( Loc_StamSprite , imgStam11 )
end
if g_stamina == 10 then
SetSpriteImage ( Loc_StamSprite , imgStam10 )
end
if g_stamina == 9 then
SetSpriteImage ( Loc_StamSprite , imgStam9 )
end
if g_stamina == 8 then
SetSpriteImage ( Loc_StamSprite , imgStam8 )
end
if g_stamina == 7 then
SetSpriteImage ( Loc_StamSprite , imgStam7 )
end
if g_stamina == 6 then
SetSpriteImage ( Loc_StamSprite , imgStam6 )
end
if g_stamina == 5 then
SetSpriteImage ( Loc_StamSprite , imgStam5 )
end
if g_stamina == 4 then
SetSpriteImage ( Loc_StamSprite , imgStam4 )
end
if g_stamina == 3 then
SetSpriteImage ( Loc_StamSprite , imgStam3 )
end
if g_stamina == 2 then
SetSpriteImage ( Loc_StamSprite , imgStam2 )
end
if g_stamina == 1 then
SetSpriteImage ( Loc_StamSprite , imgStam1 )
end
if g_stamina == 0 then
SetSpriteImage ( Loc_StamSprite , imgStam0 )
end
--sets it to drain or replenish stamina 1 = drain 2 = replenish 0 = idle
if GetGamePlayerControlMovement() == 1 and GetGamePlayerControlIsRunning() == 1 and drain_stamina ~= 1 then
--is player running and stamina drain is not happening then start drain
drain_stamina = 1
Time1 = g_Time
elseif g_stamina < 20 and GetGamePlayerControlIsRunning() == 0 and drain_stamina ~= 2 then
--is the player walking but has less then 20 stamina then start replenish
drain_stamina = 2
Time1 = g_Time
elseif g_stamina == 20 and GetGamePlayerControlIsRunning() == 0 then
--stamina full and not running then set to idle
drain_stamina = 0
end
Time2 = g_Time
TimePassed = (Time2 - Time1) * 0.001
--drain_stamina
if TimePassed >= .5 then -- every .5s drain stamina
if drain_stamina == 1 then
g_stamina = g_stamina - 1 --drain and reset
Time1 = g_Time
end
TimePassed = 0
end
--replenish stamina
if TimePassed >= .25 then --every .25s replenish 1 stamina
if drain_stamina == 2 then
g_stamina = g_stamina + 1 --replenish and reset
Time1 = g_Time
end
TimePassed = 0
end
--makes sure stamina doesn't go over 20
if g_stamina > 20 then
g_stamina = 20
end
--if you run out of stamina stop the player from running
if g_stamina <= 0 then
g_stamina = 0
SetGamePlayerControlCanRun(0)
end
--if player has 10 stamina player can run.
if g_stamina > 10 then
SetGamePlayerControlCanRun(1)
end
end
Just paste into your scripts folder both the stamina folder with graphics and the script then attach script to barrel and make always active. I tried to comment the code as much as I could so I hope you can figure it out and alter it to your own needs.
oh and I was able to increase speed to with my adrenaline shot i made. but what i had to do was make a global variable then change the code inside the gameplayercontrol.lua and changed this SetGamePlayerControlMaxspeed to multiply by 2 if my variable was true. hope that helps
Youtube - www.Youtube.com/MrEaKing Twitch - www.Twitch.com/MrEaKing Steam - Mr EA King
ELC - Explore, Learn and Create.
Desktop - HomeBuilt- Win 7 - AMD-FX 8300 Eight Core 3.30 Ghz
12 GB RAM
GeForce GTX 1050 Ti 4GB