## Closed Thread Subscribe

1. While raising the timer countdown time would lighten up the calculations it would also have a huge impact on precision on roads like this: http://shrani.si/f/1p/M0/ZdaaBDn/1/example.png

Hmm, based on speed, I could try to squeeze something out.
Code:
`distance = distance + LocalPlayer():GetVelocity():Length() / (1 / timer) * 0.00001905`
This is probably lighter?
so we are stuck on this question
```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```

Again, no way for me to check if this works. Look which way is better for you.
Damnit page king

2. 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?
```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
```

3. 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)

4. 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?
```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
```

I haven't worked with CalcView yet, but I think you need this:
G.RealTime

5. 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)
local dir = player:GetVelocity()
dir.z = 0
Lua Helper x 1 (list)

6. 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?
```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
```
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

```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)

```

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.

7. What the hell does this error mean?

Code:
`[autorun\client\cl_test.lua:24] attempt to call local 'TestMenu' (a userdata value)`

8. Thanks for giving us the code so we can see how you caused it.
Funny x 2 (list)

9. ```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
```

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.

10. ```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
```

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.
I can only guess if this is what you are trying to achieve:

```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 Helper x 1 (list)

11. I can only guess if this is what you are trying to achieve:

```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
```
What did you change?

12. I added brackets to group the different usergroups. I assume that was your intention.
Agree x 1 (list)

13. I added brackets to group the different usergroups. I assume that was your intention.
Ah right I see, yeah that works. I thought it was brackets or something. Thanks.
Friendly x 1 (list)

14. Thanks for giving us the code so we can see how you caused it.
Well, I was actually only needing a explanation about what the error means, not how to fix it.

Edited:

In case, this is the line.

`local TestMenu = vgui.Create( "DFrame" )`

Edited:

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))`
No clue why, as my sv_test.lua finds it?

After looking through my code 1000 more times I finally managed to fix it.

15. What the hell does this error mean?

Code:
`[autorun\client\cl_test.lua:24] attempt to call local 'TestMenu' (a userdata value)`
Well, I was actually only needing a explanation about what the error means, not how to fix it.

Edited:

In case, this is the line.

`local TestMenu = vgui.Create( "DFrame" )`
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.
Friendly x 1 (list)

16. does file.Size work properly in retail GMod? Specifically for files NOT in the data folder.
Disagree x 2 (list)

17. 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

```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)

```

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.
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.

18. Is there any reason that this simple reload code :
Code:
```if self.Owner:KeyPressed(IN_RELOAD) then
self.Busy = true
self.Weapon:DefaultReload(ACT_VM_RELOAD)
self.Busy = false
end```
Would still be interrupted by this ironsights code:
Code:
```         if self.Owner:KeyPressed(IN_ATTACK2) and self.Busy == false 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```
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.

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.

19. 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.

Edit:

This may do the trick.

```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 Helper x 1 (list)

20. 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?

21. 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.
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?

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?
Try dis: http://maurits.tv/data/garrysmod/wik...utorial_Series

22. Thank you :)
Friendly x 1 (list)

23. 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.

Edit:

This may do the trick.

```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```
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.

24. Try changing self.Busy == false to !self.Busy

25. 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.

```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)```

26. Try changing self.Busy == false to !self.Busy
:(
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.

27. 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.

```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)```
You could change the components of view.angles. For example,
`view.angles.p = 0`

:(
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.
That doesn't sound right. Maybe you're changing the animation somewhere else?

28. You could change the components of view.angles. For example,
`view.angles.p = 0`

That doesn't sound right. Maybe you're changing the animation somewhere else?
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.

29. 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.

```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)```
just set the line lastAngle = Angle(0,0,0) to whatever angle you want to start with like
```local lastAngle = Angle(90,0,45)  -- Would be 90 deg. pitch, 0 deg. yaw, 45 deg. roll
```

and if you don't want the player to be able to look around with the mouse add
```ply:SetEyeAngles(lastAngle)
```

as the last line of the calcview function.

30. You could change the components of view.angles. For example,
`view.angles.p = 0`

That doesn't sound right. Maybe you're changing the animation somewhere else?
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 ?

31. 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 ?
Checks if the script is being ran by the client, if so end the function or w/e.

32. Checks if the script is being ran by the client, if so end the function or w/e.
Well, I don't think thats causing it. :(

33. 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 ?
LMFAO I just realised he answered my question and then your question in his post hahaha,,,

34. 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! :'(

35. 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".

36. 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".
http://www.facepunch.com/threads/1165921

Not like I've already told you so. Comeon..

37. I'm currently doing

```function MyCalcView(ply, pos, angles, fov)
gui.EnableScreenClicker(true)
local view = {}
view.origin = pos+(angles:Up()*300)
view.angles = Angle(90,0,0)
view.fov = fov
return view
end```

To set my camera up and facing down onto the player, however my player faces the wrong way (everything is opposite like WASD is reversed). I'm needing it to aim where my mouse is or w/e. How would I go about doing this?

38. I'm currently doing

```function MyCalcView(ply, pos, angles, fov)
gui.EnableScreenClicker(true)
local view = {}
view.origin = pos+(angles:Up()*300)
view.angles = Angle(90,0,0)
view.fov = fov
return view
end```

To set my camera up and facing down onto the player, however my player faces the wrong way (everything is opposite like WASD is reversed). I'm needing it to aim where my mouse is or w/e. How would I go about doing this?
Try this

```function MyCalcView(ply, pos, angles, fov)
gui.EnableScreenClicker(true)
local view = {}
view.origin = pos+(angles:Up()*300)

local myAng = angles
myAng.p = 90

view.angles = myAng
view.fov = fov
return view
end```

It's using the player's rotation to determine the angles, but setting the pitch to 90. It should turn with the player.

39. Try this

```function MyCalcView(ply, pos, angles, fov)
gui.EnableScreenClicker(true)
local view = {}
view.origin = pos+(angles:Up()*300)

local myAng = angles
myAng.p = 90

view.angles = myAng
view.fov = fov
return view
end```

It's using the player's rotation to determine the angles, but setting the pitch to 90. It should turn with the player.
The player faces the correct direction now, however moving the mouse doesn't rotate the player :( The hook is hook.Add("CalcView", "MyCalcView", MyCalcView)

Aha, you are the one who made the top-down shooter right? It's made me want to develop my old gamemode again but getting stuck with this. I'm pretty much trying to get what you made in that video.

40. Ah. Well for one, I don't have the screen clicker enabled. That's probably why you can't rotate with the mouse. I'd remove the "gui.EnableScreenClicker(true)" line and limit the player's range some other way.