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][URL]http://puu.sh/OAm3[/URL][/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?
[editline]4th August 2012[/editline]
Yeah my paint skills are awful :v:
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)?
[editline]4th August 2012[/editline]
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.
[editline]4th August 2012[/editline]
Oh durr, I can just use coordinates relative to the square.
[editline]4th August 2012[/editline]
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?
[lua]
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)
[/lua]
[img]http://i47.tinypic.com/2ngx7og.png[/img]
[img]http://i.imgur.com/2jElF.jpg[/img]
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.
You need to clip them.
You'll need to use a [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index54c2.html]scissor rect[/url] 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.
Or you could use this, not sure who made it, but its really useful and a simple solution.
[lua]
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" )
[/lua]
Is it possible to change an entity's origin? ie Offset it by a local vector
[lua]ent:SetPos(ent:GetPos()+Vector(offsetx,offsety,offsetz))[/lua]
Though when you say local vector, maybe you mean relative to the ent's angle?
[lua]ent:SetPos(ent:GetPos()+(ent:GetAngles():Forward()*Length))[/lua]
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,
[lua]ent:SetPos(ent:GetPos()+(Angle(ent:GetAngles().p+poffset,ent:GetAngles().y+yoffset,ent:GetAngles().r+roffset):Forward()*Length)))[/lua]
I don't mean move it, I mean change the origin of where its model renders from.
[editline]5th August 2012[/editline]
Never mind, found it by trawling Maurits's wiki backup, [B][URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0930.html"]Entity.SetRenderOrigin [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL]
[/B][editline]5th August 2012[/editline]
Using a ClientsideModel and parenting it works much much better
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.
Does it still damage other players if you don't pass it a radius at all?
Yep.
[QUOTE=InfernalCookie;37096211]Yep.[/QUOTE]
As a [I]last[/I] resort you could use an EntityTakeDamage hook
[QUOTE=Persious;37051558]I didn't have time to test it until today, and it doesn't work.
I added the Categories doing this:
[lua]
table.insert(Collaps, Cat1)
table.insert(Collaps, Cat2)
table.insert(Collaps, Cat3)
table.insert(Collaps, Cat4)
[/lua]
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
unknown messingaround\gamemode\base\client\main_menu.lua:61
[/code][/QUOTE]
Can I see the code in a PM or something?
Hello guys, I'm new to Lua and I've hacked together a Gamemode.
This function is called on round restart:
[lua]
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
local dead_guards = team.GetPlayers(3)
table.Merge(alive_guards, dead_guards)
--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
[/lua]
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
I believe the problem might be game.CleanUpMap(), I've noticed it to lock up the game like that before, though it was a long time ago - it may have been fixed.
I have absolutely no clue how to add cars to a PERP server. Can someone tell me where I have to add / make the files?
[QUOTE=Trumple;37097678]
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[/QUOTE]
I'm a superadmin on community with a few jailbreak servers. I know our gamemode does this too. I don't do any of the coding so I can't really help identify the issue.
-snip- -_- browser for some reason didn't want to load the last page
[QUOTE=skullorz;37097603]Can I see the code in a PM or something?[/QUOTE]
Sure deal.
Is there any way I can get the trace of a [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2e8a.html]ent:FireBullets[/url] [b]before[/b] the bullet is actually shot?
The callback appears to be called [u]after[/u] the shot. The information I need is mostly the HitPos, HitEntity and stuff like that.
I would use a normal tracer and shoot the bullet based on that tracer, but if you want any kind of randomized bullet spread, you'd be fucked because the client would generate a different trace than the server. The nice thing about :FireBullets is that the spread is in sync between server and client, and that the bullets actually impact where the clients see them impact.
So how would I find out the HitPos of a bullet before it is actually fired (and decide whether the bullet should be fired at all)?
Some example code on the Player Classes page of the new wiki states;
[code]See gamemodes/base/player_class/player_default.lua for all overridable variables[/code]
I'm guessing this file is hidden in a .gcf?
[QUOTE=jaooe;37102922]Some example code on the Player Classes page of the new wiki states;
[code]See gamemodes/base/player_class/player_default.lua for all overridable variables[/code]
I'm guessing this file is hidden in a .gcf?[/QUOTE]
yes
[lua]PLAYER.DisplayName = "Default Class"
PLAYER.WalkSpeed = 400 -- How fast to move when not running
PLAYER.RunSpeed = 600 -- How fast to move when running
PLAYER.CrouchedWalkSpeed = 0.2 -- Multiply move speed by this when crouching
PLAYER.DuckSpeed = 0.3 -- How fast to go from not ducking, to ducking
PLAYER.UnDuckSpeed = 0.3 -- How fast to go from ducking, to not ducking
PLAYER.JumpPower = 200 -- How powerful our jump should be
PLAYER.DrawViewModel = true -- Should we draw the viewmodel
PLAYER.CanUseFlashlight = true -- Can we use the flashlight
PLAYER.MaxHealth = 100 -- Max health we can have
PLAYER.StartHealth = 100 -- How much health we start with
PLAYER.StartArmor = 0 -- How much armour we start with
PLAYER.DropWeaponOnDie = false -- Do we drop our weapon when we die
PLAYER.TeammateNoCollide = true -- Do we collide with teammates or run straight through them
PLAYER.AvoidPlayers = true -- Automatically swerves around other players[/lua]
These are the variables.
-snip nevermind-
[QUOTE=thomasfn;37097739]I believe the problem might be game.CleanUpMap(), I've noticed it to lock up the game like that before, though it was a long time ago - it may have been fixed.[/QUOTE]
How does TTT manage to reset the map without everyone lagging out like that?
Is there an alternative?
In GMod 13 how do I push a class in a binary module?
PushLightUserData & GetLightUserData are now obsolete.
Spawnmenu won't show up in my Gmod13 gamemode, why? I'm deriving from sandbox.
EDIT: Why am I late?
I have code roughly equivalent to this:
[code]local rad = vgui.Create( "HTML" )
rad:SetHTML("")
rad:SetSize( 0, 0 )
rad:SetPos( 10, 10 )
rad:OpenURL( "http://www.fragradio.co.uk/ingame/player.php?vol=10" )[/code]
I'm trying to use it for streaming sounds, and it worked perfectly in gmod12
However, in gmod13, HTML panels don't seem to run flash under any circumstances
I'm looking for an alternative function, gui.OpenURL() is the only one I can find
That might have been possible to use as a temporary work-around, if not for the fact it opens the page both in the steam browser and invisibly in the background, resulting in an echo until you close the steam browser window.
Does anyone know of any other alternatives?
Since garry closed my thread about this issue, it's safe to assume he's not going to solve it.
I think garry needs to enable plugins for awesomium (which gmod13's HTML runs in):
[url]http://support.awesomium.com/kb/plugins/why-doesnt-flash-work[/url]
[QUOTE=jaooe;37104172]Spawnmenu won't show up in my Gmod13 gamemode, why? I'm deriving from sandbox.
EDIT: Why am I late?[/QUOTE]
GMod 13 is broken at the moment wait for a patch.
Sorry, you need to Log In to post a reply to this thread.