1. GetUserGroup was never a method that was default, you always had to add it yourself.

```function _R.Player:GetUserGroup()
return self:GetNWString( "UserGroup" )
end```
Thanks, really useful!

2. How do you find the position of the center of the map? A lot of maps don't center on 0,0,0 unfortunately.

3. How do you find the position of the center of the map? A lot of maps don't center on 0,0,0 unfortunately.
Ah well, impossible as the center of the map is really relative. BUUUT, if you REALLY need it, get the position where the left most brush is, get the position where the right most brush is, divide by 2, do the same thing with the other 2 sides and bham, you got the relative x and y of the center of the map.

4. Ah well, impossible as the center of the map is really relative. BUUUT, if you REALLY need it, get the position where the left most brush is, get the position where the right most brush is, divide by 2, do the same thing with the other 2 sides and bham, you got the relative x and y of the center of the map.
Are you saying there's a way to detect brushes in lua? Or are you saying scan around with traces? I was already considering using a tracing algorithm to attempt to get the dimensions of the map, but with underground areas it will require a lot of checking. I was hoping there was some sort of function I could use to find the map center easier.

5. Just iterate through func_brushes
Dumb x 1 (list)

6. Replace self with v, sorry.
I didn't have time to test it until today, and it doesn't work.

I added the Categories doing this:

```table.insert(Collaps, Cat1)
table.insert(Collaps, Cat2)
table.insert(Collaps, Cat3)
table.insert(Collaps, Cat4)
```

I printed the table after, and it returned:

1 = Panel: [name:Panel][class:Panel][5,5,480,50]
2 = Panel: [name:Panel][class:Panel][5,5,480,50]
3 = Panel: [name:Panel][class:Panel][5,5,480,50]
4 = Panel: [name:Panel][class:Panel][5,5,480,50]

When I press a header, it says:
Code:
```[@messingaround\gamemode\base\client\main_menu.lua:61] bad argument #1 to 'pairs' (table expected, got nil)	pairs	[C]:-1

7. What's on line 56?

8. I'm sure you guys get this all the time, but should I learn Java or C++ before jumping into LUA? I have no experience with programming so I'm looking to start somewhere. I want to use it for more practical applications than just Gmod, so I would appreciate a starter guide for someone who's literally never coded before.

So far I've been looking through this guide: http://lua.gts-stolberg.de/en/Programmieren.php

However, I doubt it'll get me far. It seems to be really simplified and probably won't help me in the long run. I just haven't had much luck finding a book or an internet source which starts from square one without assuming you know ANYTHING like what a syntax is, what a runtime environment is, etc. To get a feel for LUA I've been sifting through various addon LUA codes to see how the process is done, yet, it obviously makes little sense to me. I think doing this would be more resourceful when I actually have a grasp on the terminology of LUA and coding in general.

I appreciate any responses I can get!

9. I'm sure you guys get this all the time, but should I learn Java or C++ before jumping into LUA? I have no experience with programming so I'm looking to start somewhere. I want to use it for more practical applications than just Gmod, so I would appreciate a starter guide for someone who's literally never coded before.

So far I've been looking through this guide: http://lua.gts-stolberg.de/en/Programmieren.php

However, I doubt it'll get me far. It seems to be really simplified and probably won't help me in the long run. I just haven't had much luck finding a book or an internet source which starts from square one without assuming you know ANYTHING like what a syntax is, what a runtime environment is, etc. To get a feel for LUA I've been sifting through various addon LUA codes to see how the process is done, yet, it obviously makes little sense to me. I think doing this would be more resourceful when I actually have a grasp on the terminology of LUA and coding in general.

I appreciate any responses I can get!
First of all, it's called "Lua" not "LUA" (it's a name and not an acronym or something like that).

A good start to learn Lua should be this site: http://www.lua.org/pil/
Disagree x 1 (list)

10. First of all, it's called "Lua" not "LUA" (it's a name and not an acronym or something like that).

A good start to learn Lua should be this site: http://www.lua.org/pil/
Yeah I have that open actually, but it seems to be aimed at people who have experience with programming.

11. Yeah I have that open actually, but it seems to be aimed at people who have experience with programming.
Yeah I never really used it, I started out in a similar way, no previous programming experience at all (infact, learning Lua was what led me into learning C++/PHP/Java), and I always found the `official` Lua documentation long winded & over-complicated.

The tutorials on the old GMod wiki were pretty good, there are quite a few on the new one too.

I learned from a combination of those, trial & error, the old Questions subforum (rip in peace) and other peoples stuff.
Agree x 1 (list)

12. Hi, I'm having issues with scripted entities. When I set the model of a model with a ragdoll like say, http://www.garrysmod.org/downloads/?a=view&id=115389 the physics model is rotated 90 degrees on all axis away. This means I need to fiddle about with bone matrices, which are annoying and time consuming. Is there some kind of physics type I need to use aside from the usual SOLID_VPHYSICS?

http://steamcommunity.com/id/ylsid/s...24819578009375
http://steamcommunity.com/id/ylsid/s...24819578007546

13. Having issues with derma. Whenever I click on something other than the panel list, the panel list goes behind the derma frame.

Pic related.

```function DrawAssassinGunMenu()
function Categoryitemgetname()
if categoryitemselected == nil then
return "Pick A Weapon"
else
return categoryitemselected
end
end

local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetSize( 600, 325 )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( false )
DermaPanel:ShowCloseButton( true )
DermaPanel:Center()
DermaPanel:MakePopup()
DermaPanel:SetBackgroundBlur( true )

local TestingPanel = vgui.Create( "DPanel", DermaPanel )
local x,y = DermaPanel:GetPos()
TestingPanel:SetPos( 5, 25 )
TestingPanel:SetSize( 590, 132  )
TestingPanel.Paint = function() -- Paint function
--Set our rect color below us; we do this so you can see items added to this panel
surface.SetDrawColor( 50, 50, 50, 255 )
surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) -- Draw the rect
end

local Panel2 = vgui.Create( "DPanel", DermaPanel )
local x,y = DermaPanel:GetPos()
Panel2:SetPos( 5, 163 )
Panel2:SetSize( 590, 150 )
Panel2.Paint = function() -- Paint function
--Set our rect color below us; we do this so you can see items added to this panel
surface.SetDrawColor( 50, 50, 50, 255 )
surface.DrawRect( 0, 0, Panel2:GetWide(), Panel2:GetTall() ) -- Draw the rect
end

local PrimaryLabel = vgui.Create("Label", DermaPanel )
local x,y = DermaPanel:GetPos()
PrimaryLabel:SetText("Primary Weapon")
PrimaryLabel:SetFont("defaultbold")
PrimaryLabel:SetPos(9, 28)
PrimaryLabel:SizeToContents()

local DescLabel = vgui.Create( "Label", Panel2 )
DescLabel:SetText("Pick A Weapon")
DescLabel:SetFont("defaultbold")
DescLabel:SetPos(5, 5)
DescLabel:SizeToContents()

local DescLabel2 = vgui.Create( "Label", Panel2 )
DescLabel2:SetText("Description text here you fucking clownshoe")
DescLabel2:SetPos(5, 20)
DescLabel2:SizeToContents()

local DermaList = vgui.Create( "DPanelList", TestingPanel )
local x,y = DermaPanel:GetPos()
DermaList:SetPos( x + 12, y + 45 )
DermaList:SetSize( DermaPanel:GetWide() - 25, 100 )
DermaList:SetSpacing( 5 ) -- Spacing between items
DermaList:EnableHorizontal( true ) -- Only vertical items
DermaList:EnableVerticalScrollbar( false ) -- Allow scrollbar if you exceed the Y axis
DermaList:MakePopup()

local CreditLabel = vgui.Create( "DLabel", Panel2 )
CreditLabel:SetFont("defaultbold")
CreditLabel:SetPos( 5, 82 )
CreditLabel:SetText("Credits to Unlock")
CreditLabel:SizeToContents()

local Credits = vgui.Create( "DProgressBar", Panel2)
Credits:SetSize( 300, 40 )
Credits:SetPos( 3, 100 )
Credits:SetMin( 0 )
Credits:SetMax(1000)
Credits:SetValue(10)

local CategoryItem1Panel = vgui.Create( "DPanel", DermaList )
CategoryItem1Panel:SetSize(100,100)
CategoryItem1Panel.Paint = function() -- Paint function
surface.SetDrawColor( 100, 100, 100, 255 )
surface.DrawOutlinedRect( 0, 0, 100, 100)
end

local CategoryItem1Gun = vgui.Create( "DModelPanel", CategoryItem1Panel )
CategoryItem1GunCost = 30
CategoryItem1Gun:SetPos(1,1)
CategoryItem1Gun:SetSize(98,98)
CategoryItem1Gun:SetModel( "models/weapons/w_rif_ak47.mdl" )
CategoryItem1Gun:SetToolTip("AK-47")
CategoryItem1Gun:SetCamPos( Vector( 40, 40, 0 ) )
CategoryItem1Gun:SetLookAt( Vector( 0, 7, 0 ) )
CategoryItem1Gun.OnMousePressed = function()
DescLabel:SetText("AK-47")
DescLabel2:SetText("It costs \$200,000 to fire this weapon for twelve seconds.".."\n".."Pew Pew")
DescLabel2:SizeToContents()
Credits:SetMin( 0 )
Credits:SetMax(CategoryItem1GunCost)
end

local CategoryItem2Panel = vgui.Create( "DPanel", DemaList )
CategoryItem2Panel:SetSize(100,100)
CategoryItem2Panel.Paint = function()
surface.SetDrawColor( 100, 100, 100, 255 )
surface.DrawOutlinedRect( 0, 0, 100, 100)
end

local CategoryItem2Gun = vgui.Create( "DModelPanel", CategoryItem2Panel )
CategoryItem2GunCost = 50
CategoryItem2Gun:SetPos(1,1)
CategoryItem2Gun:SetSize(98,98)
CategoryItem2Gun:SetModel( "models/weapons/w_rif_m4a1.mdl" )
CategoryItem2Gun:SetToolTip("M4A1")
CategoryItem2Gun:SetCamPos( Vector( 40, 40, 0 ) )
CategoryItem2Gun:SetLookAt( Vector( 0, 7, 0 ) )
CategoryItem2Gun.OnMousePressed = function()
DescLabel:SetText("M4A1")
DescLabel2:SizeToContents()
DescLabel2:SetText("Standard issue army stuff.")
Credits:SetMin( 0 )
Credits:SetMax(CategoryItem2GunCost)
end
end
```

14. I really need help with 3d2d, the text is flat on the ground, how do I make it flat on a wall to face me?
```Ang:RotateAroundAxis(Ang:Up(), 90)
cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)```

15. Can someone tell me what I'm doing wrong here? I'm using WorldToLocal to get the position of one vector-angle pair (V1, A1) relative to another vector-angle pair. (V2, A2)

With V1 = [0, 0, -20], A1 = [315, 0, 0], V2 = [0, 0, -20], A2 = [0,0,0], I expected the resulting local vector to be [0,0,0] because V1 and V2 are equal. Instead, WorldToLocal(V1, A1, V2, A2) returns a vector [0, 6.8, -18.7].

EDIT: Solved. The compiler was reading my code better than I was; local entang, entpos = ent:getPos(), ent:getAng()

How do you find the position of the center of the map? A lot of maps don't center on 0,0,0 unfortunately.
AFAIK there's no way of detecting map boundaries, but util.IsInWorld can tell you what positions are within the map. You can iterate using that function over the whole map space (-16384 to 16384 xyz, obviously NOT one unit at a time D:) to gain a rough idea of where the boundaries are. This approach isn't cheap, and guessing how expensive that function is I'd recommend only doing that upon map loading

16. Agh, right now I have a hud with text alignments on each side accordingly, like text that's on the right side of my screen is aligned to the right, but i'm confused on how i would make icons/textures appear the same way it's dynamically moving with the length of the text, can anyone give some tips?

17. Friendly x 1 (list)

18. So, I wanted to create a set of HL2 Sweps with drastically different damage and rate of fire.

Jvs kindly pointed me to the SWEP base in garrysmod's .gcf, but I can't wrap my head around it. Can someone please help me out?

Sorry if this isn't the right place but I don't browse this section often

19. So, I wanted to create a set of HL2 Sweps with drastically different damage and rate of fire.

Jvs kindly pointed me to the SWEP base in garrysmod's .gcf, but I can't wrap my head around it. Can someone please help me out?

Sorry if this isn't the right place but I don't browse this section often
You wouldn't need a them to be created again you can easily do this(If this applies to the HL2 weapons):
Weapon = ents.Create("weapon_357") --replace
Weapon.Primary.Damage = 999
Weapon.Primary.Delay = 0.1
Weapon.Primary.ClipSize = 100
Disagree x 3 Informative x 1 (list)

20. Can you guys help me. I keep getting Error: !IsValidGamemode. When I try to load my gamemode.. Help!?

21. Thank you!

22. If a networked variable is set before the client loads into the server, does that networked variable get sent to the player on load? My code returns the empty string from running GetNWString() on the client. SetNWString() was run before I load my client onto the server. I tried running SetNWString() after the client was loaded and it succeeded.

I would like the variables to be global for all players, but it should only be synced to all players if it changes. How could the NW variable be set without resending to everyone in the server again? Please let me know if you have any links to helpful information, and thank you!

23. How can I get a point relative to another point and angle? I want to know the relative x and y positions to an angled square, from a point on the square found with an eye trace.

I feel I can do this using the angle from the center of the square to the eye trace point, but I cannot find the angle. Dotp, maga, and magb all print fine to the console, but ang prints #IND (indefinite?), and the game crashes if I try to use it.

```local dotp = ent:GetPos():DotProduct(tr.HitPos)
local maga = math.sqrt(ent:GetPos().x+ent:GetPos().y+ent:GetPos().z)
local magb = math.sqrt(tr.HitPos.x+tr.HitPos.y+tr.HitPos.z)
local ang = math.acos(dotp/(maga*magb))
print("dotp "..dotp)
print("maga "..maga)
print("magb "..magb)
print("ang "..ang)
testselectorent:SetPos(Angle(0,ang,0):Forward()*75)```

24. As cos can never be greater than 1 or less than -1, arccos is only defined for -1 <= x <= 1, check what dotp/(maga*magb) is, I'll bet it isn't in that range.

Can you re-word exactly what you're trying to do? I don't quite understand.

Also assuming maga means magnitude, shouldn't it be root(x^2 + y^2 + z^2) not root( x + y + z )? That could explain the invalid value being thrown to arccos.

Edited:

OH you're trying to find the angle between two vectors, yeah that should work when you fix the magnitude calculation.
Lua Helper x 1 (list)

25. Thanks, that solved it not working. I do not understand the values I'm getting back, though.

While I'm not getting #IND or anything, the formula's output angle really must not be correct at all for some reason. For instance, it varies strongly depending on where the square is in the world, and which part of a straight line from the center I am looking at.

Maybe I am misunderstanding what this formula does. What I need is a way to find the angle from the center of a plane to a point on the plane determined by the player's eyetrace. I want to use this angle to later find the x and y position of the point, using the length of the line (I plan to put this angle and its length around the world center, then read the X and Y of the point).

I am hoping to find that angle without having to worry about the angle of the plane as a whole in world space.

26. Of course it's going to vary greatly depending on the position in the world, the vectors you're finding the angle between are position vectors (i.e. from 0, 0, 0, through the center of the object)?

Imagine drawing a line from 0, 0, 0 to ent:GetPos(), then drawing a line from 0, 0, 0, to tr.HitPos, then finding the angle between those lines, that's what the formula you're using does.

[img]http://puu.sh/OAm3[/img]

Is that what you're ultimately trying to find? The x, y co-ordinates the player is looking at relative to the planes origin + x/y axes?

Edited:

Yeah my paint skills are awful

27. Yes. If I could replace that 0,0,0 with a coordinate relative to the plane's angle, would that formula work for this? If so, how, and how would it know the x and y (I imagine it would have trouble knowing if you mean 181 degrees from the right, or 179 degrees from the left)?

Edited:

With the angle, I think I can just apply this as a yaw to the world center, get the forward vector, and multiply it by the distance between the entpos and the tracepos, to get the x and y.

Edited:

Oh durr, I can just use coordinates relative to the square.

Edited:

That solved the angle value changing due to entity position, but the values are affected for some reason by the plane entity's angle.

Additionally, the angle value changes if I change the 140 at the end of this first line to another value. Why would the length of either vector matter when determining the angle?

```local entloc = Angle(ent:GetAngles().p,ent:GetAngles().y,ent:GetAngles().r):Right()*140 //room for modifications on the angle
local traceloc = tr.HitPos-ent:GetPos()
local dotp = entloc:DotProduct(traceloc)
local maga = math.sqrt((entloc.x^2)+(entloc.y^2)+(entloc.z^2))
local magb = math.sqrt((traceloc.x^2)+(traceloc.y^2)+(traceloc.z^2))
local ang = math.acos(dotp/(maga*magb))*(180/math.pi)
```

28. I'm trying to figure out how scrolling works with panels. My custom scroll buttons aren't doing anything. Also, despite being parented properly, those bottom panels still show their model panels for some reason.

29. You need to clip them.

30. You'll need to use a scissor rect to clip the models properly, alternatively (and probably more easy) you can just size the DPanelList to a multiple of the size of the DModelPanels, then override the DPanelLists OnVScroll hook so it'll only move the canvas to a multiple of the size of the DModelPanels.
Useful x 3 Late x 1 Lua Helper x 1 (list)

31. Or you could use this, not sure who made it, but its really useful and a simple solution.

```local PANEL = {}
function PANEL:Paint()
local x, y = self:LocalToScreen( 0, 0 )
local w, h = self:GetSize()

local sl, st, sr, sb = x, y, x + w, y + h

local p = self
while p:GetParent() do
p = p:GetParent()
local pl, pt = p:LocalToScreen( 0, 0 )
local pr, pb = pl + p:GetWide(), pt + p:GetTall()
sl = sl < pl and pl or sl
st = st < pt and pt or st
sr = sr > pr and pr or sr
sb = sb > pb and pb or sb
end

render.SetScissorRect( sl, st, sr, sb, true )
self.BaseClass.Paint( self )
render.SetScissorRect( 0, 0, 0, 0, false )
end
vgui.Register( "DModelPanel2", PANEL, "DModelPanel" )
```
Useful x 3 Winner x 2 (list)

32. Is it possible to change an entity's origin? ie Offset it by a local vector
Funny x 1 (list)

33. `ent:SetPos(ent:GetPos()+Vector(offsetx,offsety,offsetz))`

Though when you say local vector, maybe you mean relative to the ent's angle?

`ent:SetPos(ent:GetPos()+(ent:GetAngles():Forward()*Length))`

You can also try Up and Right, instead of forward. Negative length number for down, left, and backward.

If you want the entity's position plus angle relative vector offset with angular offset,

`ent:SetPos(ent:GetPos()+(Angle(ent:GetAngles().p+poffset,ent:GetAngles().y+yoffset,ent:GetAngles().r+roffset):Forward()*Length)))`
Artistic x 1 (list)

34. I don't mean move it, I mean change the origin of where its model renders from.

Edited:

Never mind, found it by trawling Maurits's wiki backup, Entity.SetRenderOrigin

Edited:

Using a ClientsideModel and parenting it works much much better

35. Quick question:

How do I make Ignite() do no damage to players other than the recipient? I tried setting the radius to zero ( ply:Ingite( 10, 0 ) player:Ignite( time, radius ) ) but it didn't work... The players do not collide with the other players of the same team by the way... And it's meant to be that way.

36. Does it still damage other players if you don't pass it a radius at all?

37. Yep.

38. As a last resort you could use an EntityTakeDamage hook

39. I didn't have time to test it until today, and it doesn't work.

I added the Categories doing this:

```table.insert(Collaps, Cat1)
table.insert(Collaps, Cat2)
table.insert(Collaps, Cat3)
table.insert(Collaps, Cat4)
```

I printed the table after, and it returned:

1 = Panel: [name:Panel][class:Panel][5,5,480,50]
2 = Panel: [name:Panel][class:Panel][5,5,480,50]
3 = Panel: [name:Panel][class:Panel][5,5,480,50]
4 = Panel: [name:Panel][class:Panel][5,5,480,50]

When I press a header, it says:
Code:
```[@messingaround\gamemode\base\client\main_menu.lua:61] bad argument #1 to 'pairs' (table expected, got nil)	pairs	[C]:-1
Can I see the code in a PM or something?

40. Hello guys, I'm new to Lua and I've hacked together a Gamemode.

This function is called on round restart:

```function reset_round()

for k,v in pairs(swaplist_to_1) do
local t1 = team.NumPlayers(1)
local t2 = team.NumPlayers(2)

if t1 < (t2/3) then
--if guards are lacking, source a player from the swap list
if v:IsValid() then
v:SetTeam(1)
end
local thisKey = table.KeyFromValue( swaplist_to_1, v )
table.remove(swaplist_to_1, thisKey)
end
end

for k,v in pairs(swaplist_to_2) do
local t1 = team.NumPlayers(1)
local t2 = team.NumPlayers(2)

if t2 < (3*t1) then
if t1 != 1 then
--if prisoners are lacking, source a player from the swap list
if v:IsValid() then
--make sure this player is still valid and didnt disconnect
v:SetTeam(2)
end
local thisKey = table.KeyFromValue( swaplist_to_2, v )
table.remove(swaplist_to_2, thisKey)
end
end
end

game.CleanUpMap()
for k, v in pairs(player.GetAll()) do
v:RemoveAllAmmo()--remove ammo so they can pick up weapons again
if v:Team() == 1 then
--alive guards, just respawn them
v:Spawn()
elseif v:Team() == 2 then
--alive prisoners, just respawn them
v:Spawn()
elseif v:Team() == 3 then
--dead guards, set to 1 then respawn them
v:SetTeam(1)
v:Spawn()
elseif v:Team() == 4 then
--dead prisoners, set to 2 then respawn
v:SetTeam(2)
v:Spawn()
end
end
game_over = false

local alive_guards = team.GetPlayers(1)--this is a problem because what if the guards are dead? So, get the table of dead players (3) and live players and merge them, THEN pick a random value
--RunConsoleCommand("say", table.ToString(alive_guards))
if table.Count(alive_guards) > 0 then
warden = table.Random(alive_guards)--gets a random value from the table of players
else
warden = NullEntity()--if for some reason there are no guards, send a null entity
end
for k, v in pairs(player.GetAll()) do
v:SetNetworkedString("warden", warden:UniqueID())--update players with new warden
end

timer.Destroy("update_time")
timer.Create("update_time", 1, 0, update_time)
time_remaining = 300 -- 5 minutes
end
```

Can anyone see why I get horrible lag on round restart? I'm willing to accept the fact it might just be the CPU getting overloaded. When the server reaches around 20 players, everyone will lag horrendously for the first 10 seconds or so. After that, everything is fine.

Any ideas?

Thanks