Okay, here’s my Lua Script I have, and it’s not working, which doesn’t make any sense.
local isCreated = false
hook.Add("PlayerSpawn", "FixSpawners", function(ply)
timer.Simple(0.1,function()
ply.Energy = 100
end)
end)
hook.Add("KeyPress", "Healer", function(ply)
if ply:KeyDown(IN_USE) then
if ply.Mode == 0 then
local ent = ply:GetEyeTrace().Entity
if ent:IsValid() and (ent:Health() < 100) and (ply:GetPos():Distance(ent:GetPos()) < 75) and (ply.Energy > 40) then
ent:SetHealth(ent:Health() + 20)
ply.Energy = ply.Energy - 40
if ent:Health() >= 100 then
ent:SetHealth(100)
ply:SetHealth(ply:Health() + 10)
end
end
end
if ply.Mode == 1 then
end
if ply.Mode == 2 then
if ply.Energy >= 20 then
ply:SetVelocity(Vector(0,0,500))
ply.Energy = ply.Energy - 20
end
end
end
end)
hook.Add("HUDPaint", "HealPaint", function()
local ply = LocalPlayer()
if isCreated == false then
surface.CreateFont("ScoreboardText", 65, 400, true, false, "testercd")
isCreated = true
end
if not ply.Energy then
ply.Energy = 100
end
if not ply.Retime then
ply.Retime = CurTime()
end
if not ply.IsPressing then
ply.IsPressing = false
end
if not ply.Mode then
ply.Mode = 0
end
if ply:KeyDown(IN_SPEED) and ply:KeyDown(IN_ZOOM) then
if ply.IsPressing == false then
ply.Mode = ply.Mode + 1
if ply.Mode >= 3 then
ply.Mode = 0
end
end
ply.IsPressing = true
else
ply.IsPressing = false
end
if ply:KeyDown(IN_USE) then
if ply.Energy <= 0 then
ply.Energy = 0
end
ply.Retime = CurTime() + 5
else
if CurTime() > ply.Retime then
ply.Energy = ply.Energy + 0.05
if ply.Energy >= 100 then
ply.Energy = 100
end
end
end
if ply.Mode == 0 then
draw.SimpleText("Mode: Healing", "testercd", 0, ScrH() - 210, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
elseif ply.Mode == 1 then
draw.SimpleText("Mode: Running", "testercd", 0, ScrH() - 210, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
elseif ply.Mode == 2 then
draw.SimpleText("Mode: Jumping", "testercd", 0, ScrH() - 210, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
end
draw.RoundedBox( 6, 30, ScrH() - 170, 190, 70, Color( 0, 0, 0, 75 ) )
draw.SimpleText("Energy", "ScoreboardText", 70, ScrH() - 120, Color(235,200,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(tostring(math.Round(ply.Energy)), "testercd", 150, ScrH() - 140, Color(235,200,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.RoundedBox( 6, 30, ScrH() - 90, 190, 70, Color( 0, 0, 0, 75 ) )
if ply:Health() <= 0 then
draw.SimpleText("Health", "ScoreboardText", 70, ScrH() - 40, Color(255,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(ply:Health(), "testercd", 150, ScrH() - 60, Color(255,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
else
draw.SimpleText("Health", "ScoreboardText", 70, ScrH() - 40, Color(235,200,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(ply:Health(), "testercd", 150, ScrH() - 60, Color(235,200,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
end)
//{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}
function hidehud(name)
for k, v in pairs{"CHudHealth"} do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "hidehud", hidehud)
So my problem lies within the KeyPress hook. When the mode is set to “2” (Jumping), it will then check if the player has enough energy (20 or more) if they do, Set the Velocity of the player to the Vector of (0,0,500) and decrease their energy by 20. Now, this is being executed, the player is losing energy, however, the player’s velocity is not being modified. They just stay still. If I move the “ply:SetVelocity(Vector(0,0,500))” above the whole if statement, then it works, oddly enough (With the exception that every single key makes you fly upwards). This lua file is just placed into the: “lua/autorun/” directory and runs perfectly fine if you were to test it out. The only thing is, the player does not fly up into the air when they are supposed to. If you have a solution, I’d be glad to hear it. Thanks!