I am making a laser shoot from the front of the car and the explosion works fine and hits where I want it to but the tool tracer is not showing, I am getting no errors and not sure why it wont work. I did make it as a sent and it worked but it was cleaner having it in the init.lua. Any help will be greatly appreciated. Thanks
This is what i have in the init.lua
[Lua]
local function ShootLaser(ply)
local jeep = ply:GetVehicle()
if not ValidEntity(jeep) then return end
local tracedata = {}
tracedata.start = jeep:GetPos()
tracedata.endpos = (jeep:GetPos() + jeep:GetForward() * 1000000)
tracedata.filter = jeep
local trace = util.TraceLine(tracedata)
if( trace.Hit ) then
HitPos = trace.HitPos
else
HitPos = false
end
local effectdata = EffectData()
effectdata:SetOrigin(HitPos)
effectdata:SetStart(jeep:GetPos())
effectdata:SetAttachment( 1 )
util.Effect( "ToolTracer", effectdata )
local explosion = ents.Create( "env_explosion" ) // Creating our explosion
explosion:SetKeyValue( "spawnflags", 144 ) //Setting the key values of the explosion
explosion:SetKeyValue( "iMagnitude", 15 ) // Setting the damage done by the explosion
explosion:SetKeyValue( "iRadiusOverride", 128 ) // Setting the radius of the explosion
explosion:SetPos(HitPos) // Placing the explosion where we are
explosion:Spawn() // Spawning it
explosion:Fire("explode","",0)
end
function GM:KeyPress(ply,key) – You can easilly do the rest of your key detection here
if key == IN_ATTACK2 then
SpawnBomb(ply) – If right click was pressed then we can call our SpawnBomb function for that player
end
if key == IN_ATTACK then
ShootLaser(ply)
end
end[/Lua]