I have a laser which fires foward when touched. The laser is an entity but I want it to fire when the left mouse button has been pushed, at the moment with the other weapons I have such as the missile i have used [B][URL="http://wiki.garrysmod.com/?title=Gamemode.KeyPress"]Gamemode.KeyPress [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B] . I am unsure how to impliment this with the laser
the init.lua of the laser
[Lua]AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self.Entity:SetModel("models/props_junk/wood_crate001a.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
phys:SetMass(100)
end
end
function ENT:Touch()
local pos = self.Entity:GetPos()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = (pos+ self.Entity:GetForward() * 1000000)
tracedata.filter = self.Entity
local trace = util.TraceLine(tracedata)
if( trace.Hit ) then
HitPos = trace.HitPos
else
HitPos = false
end
local effectdata = EffectData()
effectdata:SetOrigin(HitPos)
effectdata:SetStart(pos)
effectdata:SetAttachment( 1 )
effectdata:SetEntity( self.Entity )
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[/Lua]
I would like to know how to do this also. I searched for help and couldn't find any but i came across this thread.
Sorry, you need to Log In to post a reply to this thread.