• Print

Author Topic: Lua Halo Glow Help  (Read 26917 times)

0 Members and 1 Guest are viewing this topic.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Lua Halo Glow Help
« on: August 29, 2014, 04:01:10 am »
So what im wanting is to make a code so that the client will highlight the target he/she is currently marking, say I am trying to select a small object surrounded by many other objects, it is to help with accuracy in selecting items. here's what I have so far.

Code: Lua
  1. hook.Add( "PreDrawHalos", "AddHalos", function()
  2.         halo.Add( ents.FindByClass( "prop_physics*" ), Color( 255, 0, 0 ), 5, 5, 2 )
  3. end )

but this makes all props glow, I just need something to say if ply:TEAM_PROP then do
but im not sure how to get it to work properly and in such a way that only targeted props are highlighted.

I'm still new to lua and am learning as I go. so I could use the help. anyone care to help me revise it?

EDIT:

OK here is the completed script for anyone who stumbled across this halo glow prop thingy.

« Last Edit: September 10, 2014, 01:10:32 pm by ChaosWolf »
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua Halo Glow Help
« Reply #1 on: August 29, 2014, 07:41:17 am »
Get the player's UniqueID and find props with that.
Props spawned by the player will have their UniqueID.
Out of the Garry's Mod business.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #2 on: August 29, 2014, 10:23:24 am »
You misunderstood what I'm asking. As in prop hunt when finding a prop to change into, the prop you are currently targeting should glow. As in all players on team prop. Not just 1 person. It works fine.. I just need to restrict the halo to target only.
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua Halo Glow Help
« Reply #3 on: August 29, 2014, 02:56:47 pm »
By targeting, do you mean looking at the prop before becoming it?
Out of the Garry's Mod business.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #4 on: August 29, 2014, 03:14:53 pm »
Yes exactly.

When looking at it, it should glow is its a valid prop to assist selection accuracy before becoming the prop.
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua Halo Glow Help
« Reply #5 on: August 29, 2014, 05:49:34 pm »
Code: Lua
  1. function GetTraceProp() -- This is a clientside function, please do not run it serverside.
  2.         local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )
  3.         for k,v in pairs( ents.FindByClass( "prop_physics" ) ) do
  4.                 if v == trace.Entity then
  5.                         return v
  6.                 end
  7.         end
  8. end

Here's a function to get the prop the player is looking at.

Replace ents.FindByClass( "prop_physics*" ) with GetTraceProp()
Out of the Garry's Mod business.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #6 on: August 29, 2014, 08:35:24 pm »
OH... OKAY I see what you did.... yea that makes perfect sense now, I appreciate it.

so I just combine the two in a single string or a separate function and continue to call the halo as a hook, while calling the GetProp as the primary function?
« Last Edit: August 29, 2014, 08:37:12 pm by ChaosWolf »
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua Halo Glow Help
« Reply #7 on: August 29, 2014, 10:00:04 pm »
halo.Add()'s first parameter takes either an entity or a table of entities.
ents.FindByClass() returns a table of prop_physics entities.
GetTraceProp() returns a single entity, which is the one the player is looking at.

You'd need to add the code I posted into the same lua file as the one using halo.Add().

Then you would do:
Code: Lua
  1. hook.Add( "PreDrawHalos", "AddHalos", function()
  2.         halo.Add( GetTraceProp(), Color( 255, 0, 0 ), 5, 5, 2 )
  3. end )
Out of the Garry's Mod business.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #8 on: August 29, 2014, 11:33:07 pm »
[ERROR] stack overflow
  1. __mul - [C]:-1
   2. GetPlayerTrace - lua/includes/extensions/util.lua:43
    3. GetTraceProp - lua/autorun/sh_halo.lua:8
     4. GetTraceProp - lua/autorun/sh_halo.lua:9
      5. GetTraceProp - lua/autorun/sh_halo.lua:9
       6. GetTraceProp - lua/autorun/sh_halo.lua:9
        7. GetTraceProp - lua/autorun/sh_halo.lua:9
         8. GetTraceProp - lua/autorun/sh_halo.lua:9
          9. GetTraceProp - lua/autorun/sh_halo.lua:9
           10. GetTraceProp - lua/autorun/sh_halo.lua:9
            11. GetTraceProp - lua/autorun/sh_halo.lua:9
             12. GetTraceProp - lua/autorun/sh_halo.lua:9
              13. GetTraceProp - lua/autorun/sh_halo.lua:9
               14. GetTraceProp - lua/autorun/sh_halo.lua:9
                15. GetTraceProp - lua/autorun/sh_halo.lua:9
                 16. GetTraceProp - lua/autorun/sh_halo.lua:9


That Doesn't look healthy

it also mega-spams TEST [Addon Example Directory>Directory>blah>blah>blah]
which also runs through all my pointshop inventory as well.
Sever Meltdown = Immenent.
« Last Edit: August 29, 2014, 11:36:19 pm by ChaosWolf »
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua Halo Glow Help
« Reply #9 on: August 29, 2014, 11:50:41 pm »
Hm, it seems to be running much harder than it should be.

Try getting a trace, then adding the halo, instead of using a halo that is constantly looking for a prop.
Out of the Garry's Mod business.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #10 on: August 30, 2014, 11:59:45 am »
this have it set up now, I don't see what the problem is, it all looks fine.

Code: Lua
  1. function GetTraceProp() -- This is a clientside function, please do not run it serverside.
  2.         local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )
  3.         for k,v in pairs( GetTraceProp() ) do
  4.                 if v == trace.Entity then
  5.                         return v
  6.                 end
  7.         end
  8. end
  9. -- What Kind Of Glow?
  10. hook.Add( "PreDrawHalos", "AddHalos", function()
  11.         halo.Add( GetTraceProp(), Color( 140, 0, 255 ), 5, 5, 2 )
  12. end )
  13.  

are you asking me to flip the two?
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua Halo Glow Help
« Reply #11 on: August 30, 2014, 01:40:35 pm »
The issue is my part of the code, it's running too many times.
Out of the Garry's Mod business.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #12 on: August 30, 2014, 02:04:27 pm »
I think I've got it...  my partner and I took a second look at it. this is what we came up with


you had
Code: Lua
  1. local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )


we have
Code: Lua
  1. local trace = util.TraceLine( util.GetPlayerTrace( ply, dir ) )

see the difference? im running it now I will let you know my results.
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Lua Halo Glow Help
« Reply #13 on: August 30, 2014, 03:08:18 pm »
this have it set up now, I don't see what the problem is, it all looks fine.

Code: Lua
  1. function GetTraceProp() -- This is a clientside function, please do not run it serverside.
  2.         local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )
  3.         for k,v in pairs( GetTraceProp() ) do
  4.                 if v == trace.Entity then
  5.                         return v
  6.                 end
  7.         end
  8. end
  9. -- What Kind Of Glow?
  10. hook.Add( "PreDrawHalos", "AddHalos", function()
  11.         halo.Add( GetTraceProp(), Color( 140, 0, 255 ), 5, 5, 2 )
  12. end )
  13.  

are you asking me to flip the two?

You weren't supposed to replace "ents.FindByClass( "prop_physics" )" in Neku's code with GetTraceProp(), you were supposed to replace it in your halo.Add code. Right now, the function is trying to loop through itself in the for loop, causing the stack overflow.

I think I've got it...  my partner and I took a second look at it. this is what we came up with


you had
Code: Lua
  1. local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )


we have
Code: Lua
  1. local trace = util.TraceLine( util.GetPlayerTrace( ply, dir ) )

see the difference? im running it now I will let you know my results.

This wouldn't even work due to "ply" not being specified, which is what "LocalPlayer()" is supposed to be.

The problem here wasn't Neku's original code, it was just a misunderstanding on your part (it can happen to everyone, I'm not trying to say anything bad about you).

Replace line 3 in this code (taken from one of Wolf's replies):
Code: Lua
  1. function GetTraceProp() -- This is a clientside function, please do not run it serverside.
  2.         local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )
  3.         for k,v in pairs( GetTraceProp() ) do
  4.                 if v == trace.Entity then
  5.                         return v
  6.                 end
  7.         end
  8. end
  9. -- What Kind Of Glow?
  10. hook.Add( "PreDrawHalos", "AddHalos", function()
  11.         halo.Add( GetTraceProp(), Color( 140, 0, 255 ), 5, 5, 2 )
  12. end )

With this:
Code: Lua
  1. for k,v in pairs( ents.FindByClass( "prop_physics" ) ) do

So the finished code looks like this:
Code: Lua
  1. function GetTraceProp() -- This is a clientside function, please do not run it serverside.
  2.         local trace = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )
  3.         for k,v in pairs( ents.FindByClass( "prop_physics" ) ) do
  4.                 if v == trace.Entity then
  5.                         return v
  6.                 end
  7.         end
  8. end
  9. -- What Kind Of Glow?
  10. hook.Add( "PreDrawHalos", "AddHalos", function()
  11.         halo.Add( GetTraceProp(), Color( 140, 0, 255 ), 5, 5, 2 )
  12. end )

Which is what Neku originally meant by
Replace ents.FindByClass( "prop_physics*" ) with GetTraceProp()
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: Lua Halo Glow Help
« Reply #14 on: August 30, 2014, 03:20:19 pm »
alright thanks for the input, I appreciate it. I will remember that next time, it looks like I was trying to call trace props too soon. I will try this.
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

  • Print