• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=-Raven-;52571089]I know that. I meant, like, the math behind it, and what it is actually doing when you call it. I probably should have phrased that question better. Sorry. :/[/QUOTE] Transforming a 3D point into 2D coordinates is, funnily enough, a 4D problem. Source does it by treating the first row of the world-projection matrix as the x projection and the second as the y projection. The non-local x and y coordinates are calculated by taking the dot product of the 3D point and the respective matrix row. Similarly, the 4th dimensional point analogue of the 2D view is calculated with the dot product of the 3D point and fourth row of the projection matrix. This is used to tell if the point is actually on the screen or not. Finally, if the point is in the view fulcrum, the non-local x and y coordinates are multiplied by the reciprocal of the 4th dimensional point, making the point local to a {x: [0, width] y: [0, height]} coordinate system. You can see the method source code here: [url]https://github.com/LestaD/SourceEngine2007/blob/master/se2007/game/client/view_scene.cpp#L55-L85[/url] The calculation of the world-projection matrix can be found here, but is way above my mathematical knowledge for a solid explanation: [url]https://github.com/LestaD/SourceEngine2007/blob/master/src_main/engine/gl_rmain.cpp#L543-L595[/url]
[QUOTE=code_gs;52571204]Transforming a 3D point into 2D coordinates is, funnily enough, a 4D problem. Source does it by treating the first row of the world-projection matrix as the x projection and the second as the y projection. The non-local x and y coordinates are calculated by taking the dot product of the 3D point and the respective matrix row. Similarly, the 4th dimensional point analogue of the 2D view is calculated with the dot product of the 3D point and fourth row of the projection matrix. This is used to tell if the point is actually on the screen or not. Finally, if the point is in the view fulcrum, the non-local x and y coordinates are multiplied by the reciprocal of the 4th dimensional point, making the point local to a {x: [0, width] y: [0, height]} coordinate system. You can see the method source code here: [url]https://github.com/LestaD/SourceEngine2007/blob/master/se2007/game/client/view_scene.cpp#L55-L85[/url] The calculation of the world-projection matrix can be found here, but is way above my mathematical knowledge for a solid explanation: [url]https://github.com/LestaD/SourceEngine2007/blob/master/src_main/engine/gl_rmain.cpp#L543-L595[/url][/QUOTE] I appreciate the answer, but I gotta be honest. Half the shit you just said flew way over my head. Gimme a moment to decipher this lol.
[QUOTE=-Raven-;52571239]I appreciate the answer, but I gotta be honest. Half the shit you just said flew way over my head. Gimme a moment to decipher this lol.[/QUOTE] The algorithm I described requires a bit of linear algebra knowledge to fully comprehend and visualise -- I would start with some reading up on dimensionality and matrix multiplication. As always, [URL="https://www.khanacademy.org/math/precalculus/precalc-matrices/multiplying-matrices-by-matrices/a/multiplying-matrices"]Khan Academy[/URL] is a great, free resource if you don't have a formal environment available for the specific topic. For more mathematical, discrete proofs and definitions, [URL="https://math.feld.cvut.cz/ftp/krajnik/vyuka/ua/linalgeb.pdf"]this textbook[/URL] is also a good start, though the language is a bit thick to trudge through at times.
This should be simple, but I can't figure it out. I'm practicing nextbot creation. I am trying to make it so my nextbot cannot take any damage. I tried EntityTakeDamage and OnInjured, SetDamage(0) ScaleDamage(0) yet my NPC is still taking damage and dying. [code]function ENT:OnInjured(info) info:ScaleDamage(0) info:SetDamage(0) end[/code] I am obviously missing something pretty simple. Anybody know?
--snip nvm--
When trying to create a gameserver account using [URL]http://steamcommunity.com/dev/managegameservers[/URL] it says I don't own appid 4020 (gmod dedicated server id). Would using appid 4000 work just fine? Also, what is this vgui element? [IMG]https://i.gyazo.com/b0f0b7dce2e058dec13003be7f84293c.png[/IMG]
[QUOTE=Lil_Roach;52577611] what is this vgui element? [IMG]https://i.gyazo.com/b0f0b7dce2e058dec13003be7f84293c.png[/IMG][/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/DermaMenu]DermaMenu[/url]
[QUOTE=Lil_Roach;52577611]When trying to create a gameserver account using [URL]http://steamcommunity.com/dev/managegameservers[/URL] it says I don't own appid 4020 (gmod dedicated server id). Would using appid 4000 work just fine?[/QUOTE] Yes. For Gmod servers you've gotta use 4000.
How would I go about changing the order of items in a DComboBox? By default it's alphabetical EDIT: Nevermind, I just found out about DComboBox:SetSortItems( false )
Hey Im working on a script that stuns or slow down players if their near an other Player who dies. [CODE]local GM = GM or GAMEMODE -- Frighten Function local function PlayerDeathFrighten(victim, inflictor, attacker) if victim:Team() == TEAM_SURVIVORS then for a,b in pairs( ents.FindInSphere( victim:GetPos(), 1000 )) do if b:IsPlayer() and b:IsValid() and b:Team() == TEAM_SURVIVORS and !b.stunfrighten then local randomfreeze = math.random(1,10) randomfreeze = math.Round(randomfreeze) if randomfreeze == 1 then --IN THIS FUNCTION HE HAVE TO PICK ONE RANDOM PLAYETR FROM THE A,B IN PAIRS FUNCTION local randomply = table.Random(b) --DONT WORK timer.Create("stun_frighten" .. randomply:UniqueID(), math.random(4, 6), 1, function() if !IsValid(randomply) then return end if randomply:Alive() then randomply:SetMoveType(MOVETYPE_WALK) randomply:SetRunSpeed(randomply.stungun_runspeed) randomply:SetWalkSpeed(randomply.stungun_walkspeed) end randomply:SetMoveType(MOVETYPE_WALK) randomply.stunfrighten = false end) randomply:SetMoveType(MOVETYPE_NONE) randomply.stunfrighten = true randomply.stungun_runspeed = randomply:GetRunSpeed() randomply.stungun_walkspeed = randomply:GetWalkSpeed() randomply:SetRunSpeed(50) randomply:SetWalkSpeed(50) else timer.Create("stun_frighten" .. b:UniqueID(), math.random(4, 6), 1, function() if !IsValid(b) then return end if b:Alive() then b:SetRunSpeed(b.stungun_runspeed) b:SetWalkSpeed(b.stungun_walkspeed) end b.stunfrighten = false end) b.stunfrighten = true b.stungun_runspeed = b:GetRunSpeed() b.stungun_walkspeed = b:GetWalkSpeed() b:SetRunSpeed(50) b:SetWalkSpeed(50) end end end end end hook.Add("PlayerDeath", "shl_frightten_PlayerDeath", PlayerDeathFrighten)[/CODE] Now i want that from the Entities in Range one Random get stunned U can see im working with table.Random but it dont work. How is it possible so just one player gets on the first timer get stunned and other would nothing happen. thanks alot
[QUOTE=Sodak;52583545]Hey Im working on a script that stuns or slow down players if their near an other Player who dies. Now i want that from the Entities in Range one Random get stunned U can see im working with table.Random but it dont work. How is it possible so just one player gets on the first timer get stunned and other would nothing happen. thanks alot[/QUOTE] First, loop through the entities in range and add any candidates to a new table: [lua] local survivors = {} for a, b in pairs(ents.FindInSphere(victim:GetPos(), 1000)) do if b:IsPlayer() and b:Team() == TEAM_SURVIVORS and not b.stunfrighten then table.insert(survivors, b) end end [/lua] [i]Then[/i] you can use table.Random: [lua]local ply = table.Random(survivors)[/lua]
[QUOTE=Luni;52584261]First, loop through the entities in range and add any candidates to a new table: [lua] local survivors = {} for a, b in pairs(ents.FindInSphere(victim:GetPos(), 1000)) do if b:IsPlayer() and b:Team() == TEAM_SURVIVORS and not b.stunfrighten then table.insert(survivors, b) end end [/lua] [i]Then[/i] you can use table.Random: [lua]local ply = table.Random(survivors)[/lua][/QUOTE] Thank u Luni this works
How would one be able to change the chance a certain person has of becoming a traitor on TTT? I don't want to force them to be a traitor, just give them a very slightly higher chance.
[QUOTE=WitheredPyre;52585899]How would one be able to change the chance a certain person has of becoming a traitor on TTT? I don't want to force them to be a traitor, just give them a very slightly higher chance.[/QUOTE] [lua] -- first select traitors local ts = 0 while ts < traitor_count do -- select random index in choices table local pick = math.random(1, #choices) -- the player we consider local pply = choices[pick] -- make this guy traitor if he was not a traitor last time, or if he makes -- a roll if IsValid(pply) and ((not table.HasValue(prev_roles[ROLE_TRAITOR], pply)) or (math.random(1, 3) == 2)) then pply:SetRole(ROLE_TRAITOR) table.remove(choices, pick) ts = ts + 1 end end[/lua] init.lua line 873 you'll need to mess around with the random, or add another statement e.g. or (pply:IsVIP() and math.random(1, 3) == 1) or whatever you want it to be.
Anyone knows how to spawn a brush entity as trigger? I'm spawning my brush with the following code [lua] function createBrush() if MAINBRUSH then MAINBRUSH:Remove() end MAINBRUSH = ents.Create("func_cleanser_wall") MAINBRUSH:SetPos(Vector(-10, 51, 64)) MAINBRUSH:SetBounds(Vector(0,0,0), Vector(24, 47, 236)-Vector(-23, -179, 64)) MAINBRUSH:Spawn() MsgN(MAINBRUSH) end [/lua] Mainbrush gets printed after spawned, but still not getting output when i touch it [lua] ENT.Type = "brush" ENT.Base = "base_brush" function ENT:SetBounds(min, max) self:SetSolid(SOLID_BBOX) self:SetCollisionBounds(min, max) self:SetTrigger(true) end function ENT:StarTouch( ent ) MsgN("INSIDE") if (ent:IsPlayer()) then ent:ApplyForceCenter(Vector(500 * (ent:Team() == 1 and -10 or 10), 0, 500)) end end [/lua]
[QUOTE=gonzalolog;52587621]Anyone knows how to spawn a brush entity as trigger? I'm spawning my brush with the following code code [/QUOTE] missing t in ENT:StarTouch Also try setting the collision bounds after MAINBRUSH:Spawn()
[QUOTE=zoox;52587766]missing t in ENT:StarTouch Also try setting the collision bounds after MAINBRUSH:Spawn()[/QUOTE] He is in Initialize.
Actually tried to set before and after, no differences :/ Nevermind! Actually i forgot to write it correctly! Damn...Thank you so much
how can I make show a line between things that are constrained with weld tool? like showing which ones welded to each other. do I need to override default weld tool? how would you guys do it? because "constraint.FindConstraints( Entity ent, string type )" is being serverside, I can't see constrained things in client.
[QUOTE=gmoddertr;52588684]how can I make show a line between things that are constrained with weld tool? like showing which ones welded to each other. do I need to override default weld tool? how would you guys do it? because "constraint.FindConstraints( Entity ent, string type )" is being serverside, I can't see constrained things in client.[/QUOTE] Strangely, as far as I can see everything constraint-related is serverside only, with the sole exception of the boolean [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsConstrained]Entity:IsConstrained[/url]. Even the constraint entities themselves are serverside only. I think you're out of luck. Your best bet would be to request such a list from the server using the [url=http://wiki.garrysmod.com/page/Net_Library_Usage]net library[/url]. It would have a short delay while waiting to get the response back from the server, but it's better than nothing! 12
That's because the constraint physics only has to be done serverside. I believe the rope tool networks its constraint positions internally, but I'd have to verify.
Thank you both for your trys. There is also another problem. How can I get player's active tool name? (weld/hydraulic etc.) [code]if ply:GetActiveWeapon():GetClass()=="gmod_tool" then ... end[/code]
I am working on creating on a motd for my server, but i've run into a problem where I don't know how to change the html panel to a different website using buttons on the side of the page. I was just wondering generally how you would make a button that changed the current webpage being shown. I tried to create a variable called "curWebsite" and when the player clicked the "Rules" button it would change the link the rules page, but this failed miserably because the page wouldn't change. I used chtml:OpenUrl(curWebsite)
[QUOTE=gmoddertr;52589017]Thank you both for your trys. There is also another problem. How can I get player's active tool name? (weld/hydraulic etc.) [code]if ply:GetActiveWeapon():GetClass()=="gmod_tool" then ... end[/code][/QUOTE] Check the gmod_toolmode console command value.
[QUOTE=gmoddertr;52589017]Thank you both for your trys. There is also another problem. How can I get player's active tool name? (weld/hydraulic etc.) [code]if ply:GetActiveWeapon():GetClass()=="gmod_tool" then ... end[/code][/QUOTE] [b]ToolGun:GetMode()[/b] - [url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua#L136-L141[/url] where ToolGun is the weapon with the class gmod_tool - in your example this is [b]ply:GetActiveWeapon()[/b]:GetMode() Edit: if you want the whole tool table/object, use [b]ToolGun:GetToolObject()[/b] - [url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua#L302-L310[/url] You can also use [b]ToolGun:GetToolObject("weld")[/b], for example, to get a specific tool even if it's not the active one. Either way, the object returned by this function has these functions: [url]http://wiki.garrysmod.com/page/Category:Tool[/url] as well as any functions specifically made by the individual tool. Technically, you can also call its [url=http://wiki.garrysmod.com/page/Category:TOOL_Hooks]hooks[/url] but you generally shouldn't. 11
[QUOTE=NeatNit;52590211][b]ToolGun:GetMode()[/b] - [url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua#L136-L141[/url] where ToolGun is the weapon with the class gmod_tool - in your example this is [b]ply:GetActiveWeapon()[/b]:GetMode() Edit: if you want the whole tool table/object, use [b]ToolGun:GetToolObject()[/b] - [url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua#L302-L310[/url] You can also use [b]ToolGun:GetToolObject("weld")[/b], for example, to get a specific tool even if it's not the active one. Either way, the object returned by this function has these functions: [url]http://wiki.garrysmod.com/page/Category:Tool[/url] as well as any functions specifically made by the individual tool. Technically, you can also call its [url=http://wiki.garrysmod.com/page/Category:TOOL_Hooks]hooks[/url] but you generally shouldn't. 11[/QUOTE] Thanks [editline]19th August 2017[/editline] Are there any way in lua to set render distance of players? I've set up fog but it doesnt block rendering.
How should I set a server cvar such as 'sv_friction' quietly, such that no message like 'Server cvar 'sv_friction' changed to 6' shows up for everyone? Right now the only thing I can think of is [code]if SERVER then RunConsoleCommand("sv_friction", 4.75) end[/code] which feels shitty af
[QUOTE=VIoxtar;52591413]How should I set a server cvar such as 'sv_friction' quietly, such that no message like 'Server cvar 'sv_friction' changed to 6' shows up for everyone? Right now the only thing I can think of is [code]if SERVER then RunConsoleCommand("sv_friction", 4.75) end[/code] which feels shitty af[/QUOTE] You can hook [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ChatText]GM:ChatText[/url] and stifle the message.
anyone know how to create clientside physics objects, if that's even possible?
A simple google search should land you here [url]https://facepunch.com/showthread.php?t=1372766&p=44149143&viewfull=1#post44149143[/url]
Sorry, you need to Log In to post a reply to this thread.