• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
I would like to put a halo around an SENT. I have code that's using 'self'. I had it working in the think function, but it's not good to do that. This is the code I was using: [lua] if !self then return end local Fluxor = math.tan(CurTime()*8) if Fluxor > 2 then Fluxor = 0 end local Flux = .5*Fluxor Flux = math.max(0.1, math.Clamp((Flux*.9)+.1, 0, 1)) halo.Add( {self}, Color( 0, 0, 0, 255 ), 10, 10, 1, false, false ) halo.Add( {self}, Color( 255, 128, 0, 255 ), 10*Flux, 10*Flux, 1, true, false )[/lua] I'm trying to use hook "PreDrawHalos" to run this code. Of course, that doesn't work, so how can I fix this problem?
You could do something like this on the client for your SENT. [code]function ENT:Initialize( ) hook.Add( "PreDrawHalos", self, self.PreDrawHalos ) end function ENT:PreDrawHalos( ) local tr = { } local pl = LocalPlayer( ) tr.start = pl:GetShootPos( ) tr.endpos = tr.start + pl:GetAimVector( ) * 100 tr.filter = pl tr = util.TraceLine( tr ) if tr.Entity == self then halo.Add( { self }, Color( 160, 0, 192 ), 1, 1, 10 ) end end[/code]
I don't want it to apply the same for every one, I will want to make it disappear when one of the ENT's variables runs down to 0. This variable, however, has a different value for every player. I will script it so when the table var is 0 for the LocalPlayer() the halo will not draw. Because of this it needs to be the self, and not every instance.
[QUOTE=WalkingZombie;46449731]I don't want it to apply the same for every one, I will want to make it disappear when one of the ENT's variables runs down to 0. This variable, however, has a different value for every player. I will script it so when the table var is 0 for the LocalPlayer() the halo will not draw. Because of this it needs to be the self, and not every instance.[/QUOTE] Instead of using a trace, you can always just check the conditions [code]if < some set of conditions > then halo.Add( < relevant data > ) end[/code] You'd have access to the player via LocalPlayer and everything.
Oh... ok well you've answered one of the questions I had in the back of my mind. That code isn't exactly what I planned on doing, but I should be able to make it work now! Thank you for the help! [editline]9th November 2014[/editline] The table is set server side, so I believe I'll need to network it. [editline]9th November 2014[/editline] [QUOTE=Kogitsune;46449711]You could do something like this on the client for your SENT. [code] hook.Add( "PreDrawHalos", self, self.PreDrawHalos )[/QUOTE] Wouldn't it be self:PreDrawHalos and not self.PreDrawHalos ? Colon, not period?
Anyone know how to make it so props act like fences (ie bullets go straight through props) with lua [editline]49[/editline] SetNotSolid isn't want I want, I still want to be able to make it so I can detect it with a trace
[QUOTE=WalkingZombie;46449751]Oh... ok well you've answered one of the questions I had in the back of my mind. That code isn't exactly what I planned on doing, but I should be able to make it work now! Thank you for the help! [editline]9th November 2014[/editline] The table is set server side, so I believe I'll need to network it. [editline]9th November 2014[/editline] Wouldn't it be self:PreDrawHalos and not self.PreDrawHalos ? Colon, not period?[/QUOTE] The colon is used for calls and declarations where the OOP aspect is needed. The actual function is accessed with the period. Call [lua]ENT:Function()[/lua] Declaration [lua]function ENT:Function() end[/lua] Access [lua]local func = ENT.Function[/lua] Trying to access it using a colon won't work.
[QUOTE=ROFLBURGER;46450622]Anyone know how to make it so props act like fences (ie bullets go straight through props) with lua [editline]49[/editline] SetNotSolid isn't want I want, I still want to be able to make it so I can detect it with a trace[/QUOTE] It has been a bit since I messed with it, but it used to be ( and may still be ) that if you created the physics with PhysicsInitBox/Sphere without setting the model first, it'd be solid for movement but wouldn't block traces / bullets - which isn't desirable because we want to be able to trace to it. Other than that, there isn't a way that isn't terribly hacky - like checking for bullets being shot and having your entities fake being not solid for a frame or two, but that would cause all kinds of problems. The best way would be to ask whoever adds engine methods to define Entity:SetSolidMask( int mask ) since it is hard coded for CBaseEntity to return SOLID_MASK in physics_main_shared.cpp: [code]unsigned int CBaseEntity::PhysicsSolidMaskForEntity( void ) const { return MASK_SOLID; }[/code]
If i open url in dhtml or html and that url has video auto playing how can i disable audio in panel or mute video sound?
[QUOTE=ROFLBURGER;46450622]Anyone know how to make it so props act like fences (ie bullets go straight through props) with lua [editline]49[/editline] SetNotSolid isn't want I want, I still want to be able to make it so I can detect it with a trace[/QUOTE] You could use [URL="http://wiki.garrysmod.com/page/GM/EntityFireBullets"]GM:EntityFireBullets( Entity ent, table data ) [/URL] When something fires a bullet, do a trace to see if your fence prop is the only thing in the way and fire a new bullet from the other side of the fence along the same normal. or make a custom entity (i.e. "prop_fence"), the entity when shot fires a new bullet along the hit normal from the other side. just a few thoughts, hope it helps.
Oh well. Now I have another question, is there a way to check if prop is in a player? ent:GetPhysicsObject():IsPenetrating() only checks if another prop is in it [QUOTE=Fantym420;46451087]You could use [URL="http://wiki.garrysmod.com/page/GM/EntityFireBullets"]GM:EntityFireBullets( Entity ent, table data ) [/URL] When something fires a bullet, do a trace to see if your fence prop is the only thing in the way and fire a new bullet from the other side of the fence along the same normal. or make a custom entity (i.e. "prop_fence"), the entity when shot fires a new bullet along the hit normal from the other side. just a few thoughts, hope it helps.[/QUOTE] unfortunately I can't do this because it needs to be a prop_physics in order for all this to work
Create an entity that is 30 x 30 x 70, make it a non-solid trigger parented to the player and centered so it is just inside the player object and define StartTouch and EndTouch. Have a table on the entity that is updated with each touching entity as the key in the Start/End events. Something like: [code] function ENT:Initialize( ) self.Touchers = { } --set bounds self:SetSolid( SOLID_NONE ) self:SetTrigger( true ) end function ENT:StartTouch( e ) if e ~= self:GetParent( ) then self.Touchers[ e ] = true end end function ENT:EndTouch( e ) self.Touchers[ e ] = nil end [/code] Then, you would do this: [code] SafeRemoveEntity( pl.Checker ) pl.Checker = ents.Create( "collision thing name here" ) pl.Checker:SetPos( pl:GetPos( ) + vector_up ) pl.Checker:SetParent( pl ) pl.IsIntersecting = function( me, that ) if not IsValid( me.Checker ) then return false end return me.Checker.Touchers[ that ] end[/code] There's probably a better way, but I don't think there's a way other than looping through all entities and doing manually doing a box within box collision check.
[QUOTE=sacred1337;46420703]I'm trying to make an entity do a 2D orbit. at a set height (Z) Circle math isn't my thing, but this is what I've got :P This is what im doing, the movement works, alothough it's pretty rubberbandy until it gets into a nice circle (rubber bands as it hits the path). If you've got better ideas for the movement, i'd appreciate it. The Angle is more my issue, this seemed to work but then just goes random, it seems to sometimes try and align itself but is pretty horrible at it. [/QUOTE] An easy way is to simply use an _ang = Angle( 0, 0 , 0 ) ( modify yaw ) then _ang.y = math.NormalizeAngle( _ang.y ); Then use the forward normal: _ang:Forward( ), then use a start position plus the normal plus the distance away. _p:GetPos( ) + angle:Forward( ) * 50; Now, it will orbit around the player if you simply keep incrementing yaw on the angle. It is an easy way to have a 2d orbit. If you want to stick a camera on the orbit, and have the orbit face the center simply invert the angle ( add 180 to yaw and it'll face the center ). Here's my over-the-shoulder thirdperson free camera: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/camera/cl_thirdperson_freecam.lua.html[/url] Orbits using Forward( ) * -1 to start behind, also instead of orbiting by just incrementing by 1 I simply use the direction the player is looking in ( which also means I don't need to reverse the angle to get it to look at the player ).
I'm drawing a laser with render.DrawBeam() from everyones eyes to see where they aim, it all works however the laser is going on forever until it hits something, how can i add limit in there, so instead of waiting until the laser hits something its always at lets say 300 units? [lua] local tracer = Material( "sprites/physbeam" ) function test() for k,v in pairs(player.GetAll() ) do if ( v:Alive() && v != LocalPlayer() ) then local trace = v:GetEyeTrace() local start = trace.StartPos local hit = trace.HitPos cam.Start3D( EyePos(), EyeAngles() ) render.SetMaterial( tracer ) render.DrawBeam( start, hit, 3, 0, 0, Color( 50, 255, 50, 255 ) ) cam.End3D() end end end hook.Add("HUDPaint", "test", test) [/lua] Any help is appreciated.
[QUOTE=Kogitsune;46449711]You could do something like this on the client for your SENT. [code]function ENT:Initialize( ) hook.Add( "PreDrawHalos", self, self.PreDrawHalos ) end function ENT:PreDrawHalos( ) [...] halo.Add( { self }, Color( 160, 0, 192 ), 1, 1, 10 ) end end[/code][/QUOTE] this won't work since the hook isn't called with the entity as the first variable (or any variable for that matter) edit: apparently I am wrong, you learn something new everyday!
You need a different trace, where you define the startpos and endpos. [code]local _p = LocalPlayer( ); local _trdata = { start = _p:GetShootPos( ); endpos = _p:GetShootPos( ) + _p:GetShootPos( ) + _p:GetAimVector( ) * 300; }; local _tr = util.TraceLine( _trdata ); [/code] Setup mask / filter, or whatever else.... Take a look at the structure: [url]http://wiki.garrysmod.com/page/Structures/Trace[/url]
Okay another problem that I don't even understand [code][ERROR] expected near ')' 1. unknown - addons/prophealth/lua/weapons/weapon_prophealth_base.lua:0 [/code] any reason as to why I would be getting this error? Here's SWEP structure that I'm using [lua]if CLIENT then SWEP.PrintName = "Base Prop Repair Wrench" SWEP.Slot = 0 SWEP.SlotPos = 0 SWEP.ViewModelFlip = false end SWEP.HoldType = "melee2" SWEP.Base = "weapon_base" SWEP.Spawnable = false --SWEP.AdminOnly = false SWEP.Category = "Prop Health" SWEP.Primary.Ammo = "none" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.UseHands = true SWEP.ViewModel = "models/weapons/c_stunstick.mdl" SWEP.WorldModel = "models/weapons/w_stunbaton.mdl"[/lua]
[QUOTE=MeepDarknessM;46451580]this won't work since the hook isn't called with the entity as the first variable (or any variable for that matter)[/QUOTE] Actually, it is almost being set up correctly; it would almost be correct if it was hook.Call instead of hook.Add, but for hook.Call instead of using self as the table ( because the function self.PreDrawHalos is already being defined as the 3rd arg ) you'd need to use GAMEMODE as it is a GM hook. For it to work, it'd need to be hook.Add( "PreDrawHalos", "NameOfHookPlusUniqueAddition" .. self:EntIndex( ), self.PreDrawHalos ); and then it'd work using function ENT:PreDrawHalos, for each entity that is added... [editline]10th November 2014[/editline] [QUOTE=ROFLBURGER;46451644]Okay another problem that I don't even understand [code][ERROR] expected near ')' 1. unknown - addons/prophealth/lua/weapons/weapon_prophealth_base.lua:0 [/code] any reason as to why I would be getting this error? Here's SWEP structure that I'm using [lua]if CLIENT then SWEP.PrintName = "Base Prop Repair Wrench" SWEP.Slot = 0 SWEP.SlotPos = 0 SWEP.ViewModelFlip = false end SWEP.HoldType = "melee2" SWEP.Base = "weapon_base" SWEP.Spawnable = false --SWEP.AdminOnly = false SWEP.Category = "Prop Health" SWEP.Primary.Ammo = "none" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.UseHands = true SWEP.ViewModel = "models/weapons/c_stunstick.mdl" SWEP.WorldModel = "models/weapons/w_stunbaton.mdl"[/lua][/QUOTE] That's gotta be the wrong file; there is no ) in that file.
edit: revised script. Why won't it work? [code] function GM:PlayerSetModel(ply) ModelMaps = {} ModelMaps["gm_construct"] = "models/player/phoenix.mdl" for k, v in pairs(ModelMaps) do if k == string.lower(game.GetMap()) then local mdl = (v) else local mdl = "models/player/phoenix.mdl" end end util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code] [code] [ERROR] gamemodes/terrortown/gamemode/player.lua:263: bad argument #1 to 'PrecacheModel' (string expected, got nil) 1. PrecacheModel - [C]:-1 2. Call - gamemodes/terrortown/gamemode/player.lua:263 3. SpawnForRound - gamemodes/terrortown/gamemode/player_ext.lua:272 4. SpawnWillingPlayers - gamemodes/terrortown/gamemode/init.lua:567 5. unknown - gamemodes/terrortown/gamemode/init.lua:414 [/code]
[QUOTE=Acecool;46451686]Actually, it is almost being set up correctly; it would almost be correct if it was hook.Call instead of hook.Add, but for hook.Call instead of using self as the table ( because the function self.PreDrawHalos is already being defined as the 3rd arg ) you'd need to use GAMEMODE as it is a GM hook. For it to work, it'd need to be hook.Add( "PreDrawHalos", "NameOfHookPlusUniqueAddition" .. self:EntIndex( ), self.PreDrawHalos ); and then it'd work using function ENT:PreDrawHalos, for each entity that is added...[/QUOTE] you completely ignored what he said [lua]hook.Add("PreDrawHalos", "halo"..self:EntIndex(), function() self.PreDrawHalos(self) end)[/lua]
[QUOTE=Acecool;46451686]That's gotta be the wrong file; there is no ) in that file.[/QUOTE] it's the right file [code][ERROR] expected near ')' 1. unknown - addons/prophealth/lua/weapons/weapon_prophealth_base.lua:0 [/code] [img]http://i.imgur.com/DmI8Bza.png[/img]
[QUOTE=BlaBlaAccount;46451727]Still new to lua. What I am trying to do here is set the local mdl to breen.mdl when the current map is gm_construct. However I don't know how to properly use the table indexes or do math with them. Also is there a way to use a range of indexes for each map? [code] function GM:PlayerSetModel(ply) playermodelmaps = { "gm_construct", "gm_flatgrass" } if string.lower(game.GetMap()) = playermodelmaps(1) then local mdl = "models/player/breen.mdl" else local mdl = "models/player/phoenix.mdl" end -- ignore anything under this. It's unrelated to my problem. util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code][/QUOTE] [code] function GM:PlayerSetModel(ply) local playermodelmaps = { ["gm_flatgrass"] = true, ["gm_construct"] = true } if (playermodelmaps[game.GetMap()]) then local mdl = "models/player/breen.mdl" else local mdl = "models/player/phoenix.mdl" end -- ignore anything under this. It's unrelated to my problem. util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code]
[QUOTE=ROFLBURGER;46451900]it's the right file [code][ERROR] expected near ')' 1. unknown - addons/prophealth/lua/weapons/weapon_prophealth_base.lua:0 [/code] [img]http://i.imgur.com/DmI8Bza.png[/img][/QUOTE] you didnt show us the the full code, if you dont supply us atleast a little more, we cant help you
[QUOTE=Sm63;46451923]you didnt show us the the full code, if you dont supply us atleast a little more, we cant help you[/QUOTE] Fair enough. I just thought if it was an actual problem with functions or whatever, it would tell me. [url]http://pastebin.com/VC5X4zkm[/url]
[QUOTE=Lolcats;46451910][code] function GM:PlayerSetModel(ply) local playermodelmaps = { ["gm_flatgrass"] = true, ["gm_construct"] = true } if (playermodelmaps[game.GetMap()]) then local mdl = "models/player/breen.mdl" else local mdl = "models/player/phoenix.mdl" end -- ignore anything under this. It's unrelated to my problem. util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code][/QUOTE] [code] function GM:PlayerSetModel(ply) local playermodelmaps = { ["gm_flatgrass"] = "models/player/breen.mdl", ["gm_construct"] = "models/player/barney.mdl" -- Made these have strings instead of the bool because its more configurable } local mdl = "models/player/phoenix.mdl" -- Need a default, just in case theres no map config if (playermodelmaps[game.GetMap()]) then mdl = playermodelmaps[game.GetMap()] end -- I didnt re-localise the variable because imo its just ugly -- ignore anything under this. It's unrelated to my problem. util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code] It isnt that much different, but, atleast you can choose which map will have which models. [editline]10th November 2014[/editline] [QUOTE=ROFLBURGER;46451937]Fair enough. I just thought if it was an actual problem with functions or whatever, it would tell me. [url]http://pastebin.com/VC5X4zkm[/url][/QUOTE] First problem: [img]http://puu.sh/cKz65/c4661ef236.png[/img] Seems to be missing the ], its the same with line 170, and 177
[QUOTE=Lolcats;46451910][code] function GM:PlayerSetModel(ply) local playermodelmaps = { ["gm_flatgrass"] = true, ["gm_construct"] = true } if (playermodelmaps[game.GetMap()]) then local mdl = "models/player/breen.mdl" else local mdl = "models/player/phoenix.mdl" end -- ignore anything under this. It's unrelated to my problem. util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code][/QUOTE] Thanks, but this isn't exactly how I wanted it to work. I've revised my script using a for loop in my last post. Maybe it will be more clear. Here it is [code] function GM:PlayerSetModel(ply) ModelMaps = {} ModelMaps["gm_construct"] = "models/player/phoenix.mdl" for k, v in pairs(ModelMaps) do if k == string.lower(game.GetMap()) then local mdl = (v) else local mdl = "models/player/phoenix.mdl" end end util.PrecacheModel(mdl) ply:SetModel(mdl) -- Always clear color state, may later be changed in TTTPlayerSetColor ply:SetColor(COLOR_WHITE) end [/code] What am I doing wrong?
[QUOTE=Acecool;46451637]You need a different trace, where you define the startpos and endpos. [code]local _p = LocalPlayer( ); local _trdata = { start = _p:GetShootPos( ); endpos = _p:GetShootPos( ) + _p:GetShootPos( ) + _p:GetAimVector( ) * 300; }; local _tr = util.TraceLine( _trdata ); [/code] Setup mask / filter, or whatever else.... Take a look at the structure: [url]http://wiki.garrysmod.com/page/Structures/Trace[/url][/QUOTE] Never done this before, i tried doing something like this: [lua] local tracer = Material( "sprites/physbeam" ) function test() for k,v in pairs(player.GetAll() ) do if ( v:Alive() && v != LocalPlayer() ) then local tracedata = { start = v:GetShootPos(), endpos = v:GetShootPos() + v:GetAimVector() * 150 } local td = util.TraceLine( tracedata ) cam.Start3D( EyePos(), EyeAngles() ) render.SetMaterial( tracer ) render.DrawBeam( td.start, td.endpos, 3, 0, 0, Color( 50, 255, 50, 255 ) ) cam.End3D() end end end hook.Add("HUDPaint", "test", test) [/lua] But i got an error saying: bad argument #1 to 'DrawBeam' (Vector expected, got nil) Thanks for the help so far Acecool.
[QUOTE=Sm63;46451953] First problem: [img]http://puu.sh/cKz65/c4661ef236.png[/img] Seems to be missing the ], its the same with line 170, and 177[/QUOTE] Oh thanks. I never ran into problems like this, I automatically assumed it had something to do with the SWEP Structure since that pretty much starts on line 0
[QUOTE=Invule;46451983]Never done this before, i tried doing something like this: [lua] local tracer = Material( "sprites/physbeam" ) function test() for k,v in pairs(player.GetAll() ) do if ( v:Alive() && v != LocalPlayer() ) then local tracedata = { start = v:GetShootPos(), endpos = v:GetShootPos() + v:GetAimVector() * 150 } local td = util.TraceLine( tracedata ) cam.Start3D( EyePos(), EyeAngles() ) render.SetMaterial( tracer ) render.DrawBeam( td.start, td.endpos, 3, 0, 0, Color( 50, 255, 50, 255 ) ) cam.End3D() end end end hook.Add("HUDPaint", "test", test) [/lua] But i got an error saying: bad argument #1 to 'DrawBeam' (Vector expected, got nil) Thanks for the help so far Acecool.[/QUOTE] start isnt part of the table that traces return, read [url="http://wiki.garrysmod.com/page/Structures/TraceResult"]here[/url]
[QUOTE=Sm63;46451991]start isnt part of the table that traces return, read [url="http://wiki.garrysmod.com/page/Structures/TraceResult"]here[/url][/QUOTE] Ok, thanks for helping me Sm63, StartPos is the start, what should be for the end? EndPos was not listed in the trace result link you gave me, so HitPos would work? or [lua] local tracedata = { StartPos = v:GetShootPos(), HitPos = v:GetShootPos() + v:GetAimVector() * 150 } local td = util.TraceLine( tracedata ) cam.Start3D( EyePos(), EyeAngles() ) render.SetMaterial( tracer ) render.DrawBeam( td.StartPos, td.HitPos, 3, 0, 0, Color( 50, 255, 50, 255 ) ) cam.End3D() [/lua] Still getting the error 'DrawBeam' (Vector expected, got nil)
Sorry, you need to Log In to post a reply to this thread.