• Setting a trail in lua
    12 replies, posted
Here's my code: [CODE]util.SpriteTrail( player, 0, Color(245, 245, 245), False, 35, 0, 3, 0.14, "trails/tube" )[/CODE] I got this error: [CODE]lua:88: Tried to use a NULL entity![/CODE] It's on client in the shared area for client and server. I want to add it to the Primary Attack of a gun. When clicked, it will add the tube trail to the player. Thanks!
player is undefined and your [b]False[/b] should be [b]false[/b].
[QUOTE=Robotboy655;50812211]player is undefined and your [b]False[/b] should be [b]false[/b].[/QUOTE] Thank you, I just worked it out myself. It's self.Owner. Interestingly, it worked even without the false. What does a additive do anyways? Also, now I have one, how do I remove the trail? Thanks!
[QUOTE=tcmaxwell2;50812285]Thank you, I just worked it out myself. It's self.Owner. Interestingly, it worked even without the false. What does a additive do anyways? Also, now I have one, how do I remove the trail? Thanks![/QUOTE] util.SpriteTrail returns an entity. You can store it to a variable and run :Remove() on it when you want to gone. Also, it works with False because that essentially sends in "nil" to the function. I believe additive has something to do with how it displays the trail, but I could be wrong.
[QUOTE=code_gs;50812310]util.SpriteTrail returns an entity. You can store it to a variable and run :Remove() on it when you want to gone. Also, it works with False because that essentially sends in "nil" to the function. I believe additive has something to do with how it displays the trail, but I could be wrong.[/QUOTE] So, what's the name of the output entity? I'm use to coding in visual C# so all this entity stuff is new to me :P Thanks
-snip- wrong post. Sorry.
I gave it a shot, I ended up with this: [CODE]local jeff = util.SpriteTrail( self.Owner, 0, Color(245, 245, 245), false, 200, 0, 0.1, 0.14, "trails/tube.vmt" )[/CODE] But It doesnt work and gives me this: [CODE]attempt to index global 'jeff' (a nil value) [/CODE] That happens when I try to remove it using [CODE]jeff:Remove()[/CODE] Any help would be great. Thank you!
jeff is local to that function it's in only. You have to store it to the player or weapon if you want to access it from the outside.
[QUOTE=code_gs;50812792]jeff is local to that function it's in only. You have to store it to the player or weapon if you want to access it from the outside.[/QUOTE] Right, ok. Can you give me an example please?
[CODE] local ply = self.Owner ply.Jeff = util.SpriteTrail( ply, 0, Color(245, 245, 245), false, 200, 0, 0.1, 0.14, "trails/tube.vmt" ) [/CODE]
[QUOTE=MPan1;50838892][CODE] local ply = self.Owner ply.Jeff = util.SpriteTrail( ply, 0, Color(245, 245, 245), false, 200, 0, 0.1, 0.14, "trails/tube.vmt" ) [/CODE][/QUOTE] And then to remove it, I do Jeff:Remove() ? Edit: Nope, Jeff:Remove() didn't work.
ply.Jeff:Remove() [editline]13th August 2016[/editline] And make sure ply is an actual player, so [CODE] local ply = self.Owner ply.Jeff:Remove() [/CODE] Something like that
Use SafeRemoveEntity. [url]https://wiki.garrysmod.com/page/Global/SafeRemoveEntity[/url]
Sorry, you need to Log In to post a reply to this thread.