Hello everyone!
Im currently trying to add a toggle button which controls wheter a running effect is enabled or disabled. Im really not very good at convars, and despite my best attempts, all i get is errors or no actual function. This is my current code:
[CODE]
for k,v in ipairs{
{"jb_cl_option_toggleaim","toggle","Toggle aim (default: Right Mouse)"},
{"jb_cl_option_togglecrouch","toggle","Toggle crouch (default: CTRL)"},
{"jb_cl_option_togglewalk","toggle","Toggle walk (default: ALT)"},
{"jb_cl_option_sprintanimation","toggle","Disable the sprint animation"}, -- This is what i added into the current script.
{"jb_cl_option_always_spectate","toggle","Always spawn as spectator after joining"}
} do
local fragment=container:Add("Panel");
fragment:SetSize(container:GetWide(),32);
fragment:SetPos(0,(k-1)*32);
local lbl=Label(v[3],fragment);
lbl:SetFont("JBSmall");
lbl:SizeToContents();
lbl:SetPos(32,fragment:GetTall()/2-lbl:GetTall()/2);
lbl:SetColor(color_text);
local DermaCheckbox = vgui.Create( "DCheckBox",fragment )
DermaCheckbox:SetPos( fragment:GetTall()/2 - DermaCheckbox:GetWide()/2, fragment:GetTall()/2 - DermaCheckbox:GetTall()/2)// Set the position
DermaCheckbox:SetConVar( v[1] )
end
end[/CODE]
Now, in a seperate lua file, there is the code for the running animation. I need it so that if the box is checked, it runs the second part of the script:
[CODE] local cvarRunAnimation = CreateClientConVar( "jb_cl_option_sprintanimation", "0", true, false )
if cvarRunAnimation:GetBool() then
if ply:KeyDown(IN_SPEED) then --Running animation
count=count+(FrameTime()*8)*mulSpeed;
fovSmooth= Lerp(FrameTime()*5,fovSmooth,(fov + mulSpeed * 10 ));
angRightSmooth= -math.abs(math.sin(count)*1);
angUpSmooth= math.sin(count)*1.5;
else --no running animation
fovSmooth= Lerp(FrameTime()*20,fovSmooth,fov);
angRightSmooth= Lerp(FrameTime()*10,angRightSmooth,0);
angUpSmooth= Lerp(FrameTime()*10,angUpSmooth,0);
mulSpeed=0;
count=0;
end
else
if ply:KeyDown(IN_SPEED) then --no running animation
fovSmooth= Lerp(FrameTime()*20,fovSmooth,fov);
angRightSmooth= Lerp(FrameTime()*10,angRightSmooth,0);
angUpSmooth= Lerp(FrameTime()*10,angUpSmooth,0);
mulSpeed=0;
count=0;
else --no running animation
fovSmooth= Lerp(FrameTime()*20,fovSmooth,fov);
angRightSmooth= Lerp(FrameTime()*10,angRightSmooth,0);
angUpSmooth= Lerp(FrameTime()*10,angUpSmooth,0);
mulSpeed=0;
count=0;
end
end[/CODE]
Id really appreciate it if one of you guys could go over this and show me the bits that you edited to make this work. As mentioned in my previous post, im a novice at lua and coding in general :)
[QUOTE=joealdred;49448110]all i get is errors or no actual function[/QUOTE]
Can I ask what the errors are?
Also, in the second part of your script, is that the whole thing or are you calling it in a hook, cause if it IS the whole thing, ply is undefined, and if it's in a hook or something, you may be calling 'CreateClientConVar' multiple times, meaning the value might be getting reset
ply is defined. I have simply modified what is already there in the gamemode. the usual errors i have been getting are nil values on calling cvarRunAnimation:GetBool(). i have tried changing it to if cvarRunAnimation:GetBool() = true then, but i get an error about then expected near '='
[editline]3rd January 2016[/editline]
if it helps, the whole second part by deafult in the gamemode is this:
[CODE] if ply:KeyDown(IN_SPEED) then --If the player is sprinting, then use this camera shake animation
count=count+(FrameTime()*8)*mulSpeed;
fovSmooth= Lerp(FrameTime()*5,fovSmooth,(fov + mulSpeed * 10 ));
angRightSmooth= -math.abs(math.sin(count)*1);
angUpSmooth= math.sin(count)*1.5;
else --otherwise, keep the camera still
fovSmooth= Lerp(FrameTime()*20,fovSmooth,fov);
angRightSmooth= Lerp(FrameTime()*10,angRightSmooth,0);
angUpSmooth= Lerp(FrameTime()*10,angUpSmooth,0);
mulSpeed=0;
count=0;
end[/CODE]
Im basically trying to create a tick box which allows the player to select whether they want the animation when running, or whether they want to have no animation (which is the else part of the code)
[QUOTE=joealdred;49449328]ply is defined. I have simply modified what is already there in the gamemode. the usual errors i have been getting are nil values on calling cvarRunAnimation:GetBool(). i have tried changing it to if cvarRunAnimation:GetBool() = true then, but i get an error about then expected near '='[/QUOTE]
Perhaps try
[CODE]
CreateClientConVar( "jb_cl_option_sprintanimation", "0", true, false )
local cvarRunAnimation = GetConVar( "jb_cl_option_sprintanimation" )
if cvarRunAnimation:GetBool() then
[/CODE]
Instead? Perhaps CreateClientConVar doesn't return the convar if it already exists
Ok, ill let you know what happens
[editline]3rd January 2016[/editline]
Well well well, you sir are a genius :)
It works a treat! I just have to swap it around now so that by default it is enabled, not disabled.
Thanks for your help! Also, please let me know how i kudos you
Sorry, you need to Log In to post a reply to this thread.