[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.
What the hell does this error mean?
[code][autorun\client\cl_test.lua:24] attempt to call local 'TestMenu' (a userdata value)[/code]
Thanks for giving us the code so we can see how you caused it.
[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=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?
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.
[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]
[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.
does file.Size work properly in retail GMod? Specifically for files NOT in the data folder.
[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.
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.
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]
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=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]
Thank you :)
[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:
Try changing self.Busy == false to !self.Busy
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=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.
[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?
[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.
[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.
[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 ?
[QUOTE=G-Enigma;34846283]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 ?[/QUOTE]
Checks if the script is being ran by the client, if so end the function or w/e.
[QUOTE=Mrkrabz;34846437]Checks if the script is being ran by the client, if so end the function or w/e.[/QUOTE]
Well, I don't think thats causing it. :(
[QUOTE=G-Enigma;34846283]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 ?[/QUOTE]
LMFAO I just realised he answered my question and then your question in his post hahaha,,,
I need help! I just got into LUA, and i started out making NPCs, this code like wont work, it doesnt detect my NPC in the spawn list, like its not in there, and I am coding it right! Here is three codes, my code, my original startng code, and a metropolice code showing mine isnt incorrect.
Metro Police-
local Category = "Other Civil Protection"
local NPC = { Name = "Elite Shock Unit",
Class = "npc_combine_s",
Model = "models/leet_police2.mdl",
Health = "200",
Category = Category }
list.Set( "NPC", "npc_elitecop", NPC )
Mine-
local NPC = { Name = "SAS NPC",
Class = "npc_combine_s",
Model = "models/player/ct_sas.mdl",
Health = "25000",
Category = Animals}
list.Set( "NPC", "SAS", NPC
My starting code-
local NPC = { Name = "Name here",
Class = "npc_citizen",
Model = "models/name_here.mdl",
Health = "250",
Category = Category }
list.Set( "NPC", "npc_name_here", NPC )
see? there is no prob;lem! :'(
Use [lua] tags and tell us the error. I can see two - you're missing a ) after list.Set and category should be Category = "Animals".
Sorry, you need to Log In to post a reply to this thread.