• What do you need help with? V3
    6,419 replies, posted
  • Avatar of Rimbas
  • [QUOTE=Jinx786;34818791]While raising the timer countdown time would lighten up the calculations it would also have a huge impact on precision on roads like this: [url]http://shrani.si/f/1p/M0/ZdaaBDn/1/example.png[/url] Hmm, based on speed, I could try to squeeze something out. [CODE] distance = distance + LocalPlayer():GetVelocity():Length() / (1 / timer) * 0.00001905 [/CODE] This is probably lighter?[/QUOTE] so we are stuck on this question :v: [lua] local distance = 0 --we need this outside the function local pos1 = LocalPlayer():GetPos() --initial pos so its not nil and we also need this to save outside func function calcDist() local pos2 = LocalPlayer():GetPos() --current position vector local lenght = pos1:Lenght(pos2) distance = distance + lenght --might want to throw in your unit conversion here pos1 = pos2 --so we get correct distance next time end timer.Create("distancecalculate interval",1,0,calcDist) -- check if interval is 1 second and times repeated = infinity[/lua] Again, no way for me to check if this works. Look which way is better for you. Damnit page king
  • Avatar of brandonj4
  • Could someone explain how I could make this camera rotate from a y axis around to move the camera slowly in front of me instead of just snapping to this view? [lua] hook.Add("CalcView", "CalcTheView", function(ply, pos, angles, fov) local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = (LocalPlayer():EyePos() - view.origin):Angle() view.fov = fov return view end) hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply) return true end [/lua]
  • Avatar of Kwaq
  • how do i get an int value of player velocity and remove Z (up down)? i just want a value that shows directional velocity (flat surface)
  • Avatar of pennerlord
  • [QUOTE=brandonj4;34828884]Could someone explain how I could make this camera rotate from a y axis around to move the camera slowly in front of me instead of just snapping to this view? [lua] hook.Add("CalcView", "CalcTheView", function(ply, pos, angles, fov) local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = (LocalPlayer():EyePos() - view.origin):Angle() view.fov = fov return view end) hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply) return true end [/lua][/QUOTE] I haven't worked with CalcView yet, but I think you need this: [B][URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index95e8.html?title=G.RealTime"]G.RealTime [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
  • [QUOTE=Kwaq;34831556]how do i get an int value of player velocity and remove Z (up down)? i just want a value that shows directional velocity (flat surface)[/QUOTE] local dir = player:GetVelocity() dir.z = 0
  • Avatar of Fantym420
  • [QUOTE=brandonj4;34828884]Could someone explain how I could make this camera rotate from a y axis around to move the camera slowly in front of me instead of just snapping to this view? [lua] hook.Add("CalcView", "CalcTheView", function(ply, pos, angles, fov) local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = (LocalPlayer():EyePos() - view.origin):Angle() view.fov = fov return view end) hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply) return true end [/lua][/QUOTE] This is what I do: Create a variable to store the last time and one for last Angle Then in CalcView make a variable to store the delta from CurTime() and lastTime Set lastTime to CurTime() LerpAngle the new angle with the last angle using the delta time for the percent Set lastAngle to the new Lerp'd Angle Repeat like this [lua] local lastCalcView = CurTime() local lastAngle = Angle(0,0,0) function MyCalcView(ply, pos, angles, fov) local deltaTime = CurTime() - lastCalcView lastCalcView = CurTime() local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = LerpAngle(deltaTime, lastAngle, (LocalPlayer():EyePos() - view.origin):Angle()) lastAngle = view.angles view.fov = fov return view end hook.Add("CalcView", "CalcTheView", MyCalcView) [/lua] not tested, but that's how it should work, if the angles aren't going fast enough multiply the deltaTime part of LerpAngle. Hope that helps.
  • Avatar of Hugabuga
  • What the hell does this error mean? [code][autorun\client\cl_test.lua:24] attempt to call local 'TestMenu' (a userdata value)[/code]
  • [lua] if ((t == TEAM_SUPERTHIEF || t == TEAM_HITMAN || t == TEAM_MERCENARY || t == TEAM_EXGOV || t == TEAM_SNIPER) and not self:IsUserGroup("vip") || self:IsUserGroup("admin") || self:IsUserGroup("superadmin")) then [/lua] I did this and it works however only being in group VIP works, if you are in admin or superadmin it still says you need to be VIP. I'm guessing it's my brackets or something.
  • Avatar of _nonSENSE
  • [QUOTE=Mrkrabz;34833631][lua] if ((t == TEAM_SUPERTHIEF || t == TEAM_HITMAN || t == TEAM_MERCENARY || t == TEAM_EXGOV || t == TEAM_SNIPER) and not self:IsUserGroup("vip") || self:IsUserGroup("admin") || self:IsUserGroup("superadmin")) then [/lua] I did this and it works however only being in group VIP works, if you are in admin or superadmin it still says you need to be VIP. I'm guessing it's my brackets or something.[/QUOTE] I can only guess if this is what you are trying to achieve: [lua] if (t == TEAM_SUPERTHIEF || t == TEAM_HITMAN || t == TEAM_MERCENARY || t == TEAM_EXGOV || t == TEAM_SNIPER) and not (self:IsUserGroup("vip") || self:IsUserGroup("admin") || self:IsUserGroup("superadmin")) then [/lua]
  • [QUOTE=_nonSENSE;34833686]I can only guess if this is what you are trying to achieve: [lua] if (t == TEAM_SUPERTHIEF || t == TEAM_HITMAN || t == TEAM_MERCENARY || t == TEAM_EXGOV || t == TEAM_SNIPER) and not (self:IsUserGroup("vip") || self:IsUserGroup("admin") || self:IsUserGroup("superadmin")) then [/lua][/QUOTE] What did you change?
  • Avatar of _nonSENSE
  • I added brackets to group the different usergroups. I assume that was your intention.
  • [QUOTE=_nonSENSE;34833732]I added brackets to group the different usergroups. I assume that was your intention.[/QUOTE] Ah right I see, yeah that works. I thought it was brackets or something. Thanks.
  • Avatar of Hugabuga
  • [QUOTE=GranPC;34833538]Thanks for giving us the code so we can see how you caused it.[/QUOTE] Well, I was actually only needing a explanation about what the error means, not how to fix it. [editline]23rd February 2012[/editline] In case, this is the line. [lua]local TestMenu = vgui.Create( "DFrame" )[/lua] [editline]23rd February 2012[/editline] Ah, finally got it working. But it seems like I can't include my sh_test.lua as it says [code]Couldn't include file 'autorun\sh_test.lua' (File not found) (@autorun\client\cl_test.lua (line 1))[/code] No clue why, as my sv_test.lua finds it? [b]After looking through my code 1000 more times I finally managed to fix it.[/b]
  • Avatar of ralle105
  • [QUOTE=Persious;34833494]What the hell does this error mean? [code][autorun\client\cl_test.lua:24] attempt to call local 'TestMenu' (a userdata value)[/code][/QUOTE] [QUOTE=Persious;34834662]Well, I was actually only needing a explanation about what the error means, not how to fix it. [editline]23rd February 2012[/editline] In case, this is the line. [lua]local TestMenu = vgui.Create( "DFrame" )[/lua] [/QUOTE] It means that somewhere in your code you're doing TestMenu() ie trying to call TestMenu as a function. But TestMenu is a vgui component (userdata) hence the error.
  • Avatar of brandonj4
  • [QUOTE=Fantym420;34832710]This is what I do: Create a variable to store the last time and one for last Angle Then in CalcView make a variable to store the delta from CurTime() and lastTime Set lastTime to CurTime() LerpAngle the new angle with the last angle using the delta time for the percent Set lastAngle to the new Lerp'd Angle Repeat like this [lua] local lastCalcView = CurTime() local lastAngle = Angle(0,0,0) function MyCalcView(ply, pos, angles, fov) local deltaTime = CurTime() - lastCalcView lastCalcView = CurTime() local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = LerpAngle(deltaTime, lastAngle, (LocalPlayer():EyePos() - view.origin):Angle()) lastAngle = view.angles view.fov = fov return view end hook.Add("CalcView", "CalcTheView", MyCalcView) [/lua] not tested, but that's how it should work, if the angles aren't going fast enough multiply the deltaTime part of LerpAngle. Hope that helps.[/QUOTE] Thank you so much it worked! How would I lock it to start at a certain angle always? ex. When I look at the ground I see all black and that's not what I want.
  • Avatar of G-Enigma
  • Is there any reason that this simple reload code : [CODE]if self.Owner:KeyPressed(IN_RELOAD) then [U]self.Busy = true[/U] self.Weapon:DefaultReload(ACT_VM_RELOAD) self.Busy = false end[/CODE] Would still be interrupted by this ironsights code: [CODE] if self.Owner:KeyPressed(IN_ATTACK2) [U]and self.Busy == false[/U] then if !self.Owner:KeyDown(IN_DUCK) and !self.Owner:KeyDown(IN_WALK) then self:SetWeaponHoldType("rpg") else self:SetWeaponHoldType("ar2") end self.Weapon:SetNextPrimaryFire(CurTime()+0.3) self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 ) self.IronSightsPos = self.SightsPos // Bring it up self.IronSightsAng = self.SightsAng // Bring it up self:SetIronsights(true, self.Owner) self:SendWeaponAnim(ACT_VM_LOWERED_TO_IDLE) self.Ironsighted = true -- Set the ironsight true if CLIENT then return end end[/CODE] except that in the ironsights code, only the animation, (ACT_VM_LOWERED_TO_IDLE) is played, while the rest of the function acts as if the self.Busy check is working. :pwn: PS: Basically what I'm trying to do is prevent the player cutting short the reload animation by ironsighting (which plays an ironsighting animation). The offending (?) code is underlined.
  • Avatar of Nerdeboy
  • It looks like you're setting the weapon to busy, playing the animation, and then immediately setting it back to not be busy. You'll need to add a timer with the duration of the animation that runs self.Busy = false, rather than what you're doing. [b]Edit:[/b] This may do the trick. [lua]if self.Owner:KeyPressed(IN_RELOAD) then self.Busy = true self.Weapon:DefaultReload(ACT_VM_RELOAD) local animationDuration = 1.5 -- set this to the duration of -- the reload animation, in seconds timer.Simple( animationDuration, function() self.Busy = false end ) end[/lua]
  • Avatar of Charrax
  • I need help with Lua itself. Arguments confuse the shit out of me. Oh and hooks. Can somebody nice please point me in the right direction?
  • Avatar of G-Enigma
  • [QUOTE=Nerdeboy;34842587]It looks like you're setting the weapon to busy, playing the animation, and then immediately setting it back to not be busy. You'll need to add a timer with the duration of the animation that runs self.Busy = false, rather than what you're doing.[/QUOTE] Well thanks, *cough*, better come clean, *cough*... I literally have no freaking coding background whatsoever, just started fiddling with gmod Swep coding a few months ago, so... How would I do that, exactly? :wink: [QUOTE]I need help with Lua itself. Arguments confuse the shit out of me. Oh and hooks. Can somebody nice please point me in the right direction?[/QUOTE] Try dis: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7a06.html?title=Lua_Tutorial_Series[/url]
  • Avatar of G-Enigma
  • [QUOTE=Nerdeboy;34842587]It looks like you're setting the weapon to busy, playing the animation, and then immediately setting it back to not be busy. You'll need to add a timer with the duration of the animation that runs self.Busy = false, rather than what you're doing. [b]Edit:[/b] This may do the trick. [lua]if self.Owner:KeyPressed(IN_RELOAD) then self.Busy = true self.Weapon:DefaultReload(ACT_VM_RELOAD) local animationDuration = 1.5 -- set this to the duration of -- the reload animation, in seconds timer.Simple( animationDuration, function() self.Busy = false end ) end[/lua][/QUOTE] Well, thanks for trying to help, but it seems that ironsighting animation is too stubborn to be defeated so easily :( Even if I remove the "Self.Busy = false" at the end of the reload, the ironsight animation still plays, even though the code above and below it doesn't. :suicide:
  • Avatar of brandonj4
  • How would I lock it to start at a certain angle always? ex. When I look at the ground I see all black and that's not what I want. [lua] local lastCalcView = CurTime() local lastAngle = Angle(0,0,0) function MyCalcView(ply, pos, angles, fov) local deltaTime = CurTime() - lastCalcView lastCalcView = CurTime() local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = LerpAngle(deltaTime, lastAngle, (LocalPlayer():EyePos() - view.origin):Angle()) lastAngle = view.angles view.fov = fov return view end hook.Add("CalcView", "CalcTheView", MyCalcView)[/lua]
  • Avatar of G-Enigma
  • [QUOTE=Nerdeboy;34842916]Try changing self.Busy == false to !self.Busy[/QUOTE] :( Maybe the check is glitchy, or if it sees an animation with no other animation to play if the check fails, then it just plays the animation anyway.
  • Avatar of Nerdeboy
  • [QUOTE=brandonj4;34842978]How would I lock it to start at a certain angle always? ex. When I look at the ground I see all black and that's not what I want. [lua] local lastCalcView = CurTime() local lastAngle = Angle(0,0,0) function MyCalcView(ply, pos, angles, fov) local deltaTime = CurTime() - lastCalcView lastCalcView = CurTime() local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = LerpAngle(deltaTime, lastAngle, (LocalPlayer():EyePos() - view.origin):Angle()) lastAngle = view.angles view.fov = fov return view end hook.Add("CalcView", "CalcTheView", MyCalcView)[/lua][/QUOTE] You could change the components of view.angles. For example, [lua]view.angles.p = 0[/lua] [QUOTE=G-Enigma;34843082]:( Maybe the check is glitchy, or if it sees an animation with no other animation to play if the check fails, then it just plays the animation anyway.[/QUOTE] That doesn't sound right. Maybe you're changing the animation somewhere else?
  • Avatar of brandonj4
  • [QUOTE=Nerdeboy;34843813]You could change the components of view.angles. For example, [lua]view.angles.p = 0[/lua] That doesn't sound right. Maybe you're changing the animation somewhere else?[/QUOTE] Well I still need to to make the animation of moving to the player but I don't want it to be underground if a player looks up.
  • Avatar of Fantym420
  • [QUOTE=brandonj4;34842978]How would I lock it to start at a certain angle always? ex. When I look at the ground I see all black and that's not what I want. [lua] local lastCalcView = CurTime() local lastAngle = Angle(0,0,0) function MyCalcView(ply, pos, angles, fov) local deltaTime = CurTime() - lastCalcView lastCalcView = CurTime() local view = {} view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50) view.angles = LerpAngle(deltaTime, lastAngle, (LocalPlayer():EyePos() - view.origin):Angle()) lastAngle = view.angles view.fov = fov return view end hook.Add("CalcView", "CalcTheView", MyCalcView)[/lua][/QUOTE] just set the line lastAngle = Angle(0,0,0) to whatever angle you want to start with like [lua] local lastAngle = Angle(90,0,45) -- Would be 90 deg. pitch, 0 deg. yaw, 45 deg. roll [/lua] and if you don't want the player to be able to look around with the mouse add [lua] ply:SetEyeAngles(lastAngle) [/lua] as the last line of the calcview function.
  • Avatar of G-Enigma
  • [QUOTE=Nerdeboy;34843813]You could change the components of view.angles. For example, [lua]view.angles.p = 0[/lua] That doesn't sound right. Maybe you're changing the animation somewhere else?[/QUOTE] No, the only time that animation is set to play is when you ironsight in. what about "If CLIENT then return end"? What does that do :~0 ?