Lua trails!

Can someone give me the code for making a lua trail that is hooked to PlayerSpawn? ( So as to always be there )


(User was banned for this post ("Wrong section" - mahalis))

function TrailSpawn( ply ) util.SpriteTrail(ply, 0, Color(255,255,255), false, 2, 0, 3, 15, “trails/smoke.vmt”) end hook.Add( “PlayerSpawn”, “TrailSpawn”, TrailSpawn ) I guess that is what you want.

[editline]10:04AM[/editline]

The Forum layout jumbled the code, and I can’t edit, wtf?

What made you think it was a good idea to repost the thread again in the wrong section after a moderator locked your previous?

Ah, the wave of sarcastic lua kings begin.

Agh, I fuckin’ put the hook before the function :stuck_out_tongue: I am retarded

you could still do that though Fologi.

[lua] hook.Add(“PlayerSpawn”, “TrailSpawn” function()
util.SpriteTrail(ply, 0, Color(255,255,255), false, 2, 0, 3, 15, “trails/smoke.vmt”)
end
end)[/lua]
Something like that

You mean you did something like:

[lua]
hook.Add(“MyHook”, 0, TestFunction)

local function TestFunction(…)
print"Hello" – correct syntax, don’t need brackets with 1 argument.
end
[/lua]

Any functions you define are still variables it’s the same as trying to do this:

[lua]
local a = 5

print(tostring(a)…" + “…tostring(b)…” = "…tostring(a+b))

local b = 5
[/lua]

Hmm, I think that I just don’t really know :confused:

Here:



hook.Add("PlayerSpawn", "AddTrails", function(pl)
	pl.Trail = util.SpriteTrail(pl, 0, Color(255,102,0,255), false, 15, 1, 4, 1/(15+1)*0.5, "trails/plasma.vmt")
end)

hook.Add("PlayerDisconnect", "RemoveTrails", function(pl)
	SafeRemoveEntity(pl.Trail)
end)


The first place where it says Color(255,102,0,255) is to change the color of the trails. In the end of the code you can change the trail itself.
This works 100% as im using it myself right now.

Stick in init.lua

He rated himself friendly. Lol.

Just testing here, but I believe you can also do this


 concommand.Add("GiveTrails", function() 
	hook.Add("PlayerSpawn", "AddTrails", function(pl)
		l.Trail = util.SpriteTrail(pl, 0, Color(255,102,0,255), false, 15, 1, 4, 1/(15+1)*0.5, "trails/plasma.vmt")
	end)
end)

concommand.Add("TakeTrails", function()
	hook.Add("PlayerDisconnect", "RemoveTrails", function(pl)
		SafeRemoveEntity(pl.Trail)
	end)
end)

and then make the server run the console commands when a player wants to give himself a trail or when he leaves to take his trail.

[editline]15th October 2010[/editline]

credit to crap-head for original code.

Wrong c-unit think about how that code would execute ingame.

The PlayerSpawn hook is correctish you still need it to be unique (do this by appending the users UID to the hooks unique name), but the PlayerDisconnect hook needs to always be there (Just stick it by it’s self.)

When you get the concommand from a player asking to RemoveTrails, remove the PlayerSpawn hook as well.

Thanks for correcting me, but if you remove the PlayerSpawn hook won’t it remove it for everyone in the server? Say you are going to do what Sassilization did where the player decides whether you have a trail or not.

That’s why you assign it a UNIQUE id. (Sorry for not being clearer before, typing on a 10 cm tochscreen keyboard isn’t the easiest)

Or how about have ONE hook if it’s gonna be automatic?

And if it’s only supposed to be created/removed when you run the concommands, then why not just do it in the concommand function instead of adding tons of useless hooks?:argh: