I’m working on adding a trip mine to a TTT server, and it works really well, except for most of the time the explosion causes the victims Garry’s mod to crash to desktop.
Any Help, and its not a computer specs problem, since i have tested it with other people.
-- Trip Mine ENT.
local config = ttt_perky_config
ENT.Type = "anim"
ENT.Model = Model( "models/weapons/w_slam.mdl" )
ENT.Health = config.tripmine_health
ENT.BlastRadius = 350
ENT.BlastDamage = 10000
ENT.Health = 50
ENT.CanUseKey = true
ENT.CanHavePrints = true
local explodeSound = Sound( 'weapons/explode3.wav' )
local calibrateSound = Sound( 'weapons/slam/mine_mode.wav' )
if SERVER then
AddCSLuaFile("shared.lua")
end
if CLIENT then
-- this entity can be DNA-sampled so we need some display info
ENT.Icon = "VGUI/ttt/icon_tripmine"
ENT.PrintName = "Trip Mine"
end
function ENT:Initialize()
self.Entity:SetModel( self.Model )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_NONE )
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Entity:SetHealth( self.Health )
if SERVER then
self.Entity:SetMaxHealth( self.Health )
self.Entity:SetUseType( SIMPLE_USE )
end
self.fingerprints = {}
timer.Simple( 2, self.Calibrate, self )
end
function ENT:Calibrate()
local pos = self:GetPos()
local tr = util.QuickTrace( pos, self:GetUp()*10000, self.Entity )
self.LaserLength = tr.Fraction
self.LaserEndPos = tr.HitPos
self.Calibrated = true
--self:CreateBeam( pos, tr.HitPos )
self:EmitSound( calibrateSound )
end
function ENT:CreateBeam( startPos, endPos )
if CLIENT then return end
local beamEnd = ents.Create("info_target")
beamEnd:SetKeyValue("targetname", "NULL" .. beamEnd:EntIndex() )
beamEnd:SetPos( startPos + self:GetUp()*2 )
beamEnd:Spawn()
local beam = ents.Create("env_laser")
beam:SetPos( endPos )
beam:SetKeyValue( "renderamt", "75" )
beam:SetKeyValue( "rendercolor", "255 0 0" )
beam:SetKeyValue( "texture", "sprites/laserbeam.spr" )
beam:SetKeyValue( "TextureScroll", "35")
beam:SetKeyValue( "parentname", "")
beam:SetKeyValue( "damage", "0")
beam:SetKeyValue( "spawnflags", "1")
beam:SetKeyValue( "width", "0.5")
beam:SetKeyValue( "dissolvetype", "None")
beam:SetKeyValue( "EndSprite", "")
beam:SetKeyValue( "LaserTarget", "NULL" .. beamEnd:EntIndex() )
beam:SetKeyValue( "TouchType", "0")
beam:Spawn()
self.beam = beam
self.beamEnd = beamEnd
end
function ENT:Think()
if self.Calibrated then
local tr = util.QuickTrace( self:GetPos(), self:GetUp()*10000, self )
if tr.Fraction < self.LaserLength then
self:Explode()
end
end
end
function ENT:Explode()
local pos = self:GetPos()
local radius = self.BlastRadius
local damage = self.BlastDamage
self.exploded = true
util.BlastDamage( self, self:GetOwner(), pos, radius, damage )
local effect = EffectData()
effect:SetStart(pos)
effect:SetOrigin(pos)
effect:SetScale(radius)
effect:SetRadius(radius)
effect:SetMagnitude(damage)
util.Effect("Explosion", effect, true, true)
self:Remove()
end
function ENT:Explode2()
local effect = EffectData()
effect:SetOrigin( self:GetPos() )
util.Effect("cball_explode", effect)
WorldSound( explodeSound, self:GetPos() )
end
function ENT:OnTakeDamage( dmginfo )
self:SetHealth(self:Health() - dmginfo:GetDamage())
if not self.exploded and self:Health() <= 0 then
self:Explode2()
self:Remove()
end
end
function ENT:UseOverride( pl )
local wep = pl:Give( 'weapon_ttt_tripmine' )
if IsValid( wep ) then
wep.fingerprints = wep.fingerprints or {}
table.Add( wep.fingerprints, self.fingerprints )
end
self:Remove()
end
if CLIENT then
local Laser = Material( "cable/redlaser" )
function ENT:Draw()
self.Entity:DrawModel()
if self.Calibrated then
local pos = self:GetPos()
render.SetMaterial( Laser )
render.DrawBeam( pos, self.LaserEndPos, 0.2, 0, 0, Color( 255, 255, 255, 5 ) )
self:SetRenderBoundsWS( pos, self.LaserEndPos )
end
end