Swep Help Involving Decals

How can I make a swep select a decal randomly from a list when it shoots?

Make a table of decals and use table.random to select one.

function ENT:PhysicsCollide(data,phy)
local trace = {}
trace.filter = {self.Entity}
data.HitNormal = data.HitNormal * -1
local start = data.HitPos + data.HitNormal
local endpos = data.HitPos - data.HitNormal

util.Decal("splat"..math.random(1,12),start,endpos)
self.Entity:EmitSound(Sound( "marker/pbhit.wav" ))

util.BlastDamage(self.Entity:GetOwner(),self.Entity:GetOwner(),data.HitPos,1,paintballdamage)
// if 
	// ( data.HitEntity:IsValid() && data.HitEntity:IsPlayer() ) then data.HitEntity:TakeDamage( 1, self.Owner ) 
// end
self.Entity:Fire("kill", "", 0)

end

This is the original code, it does NOT work. I am trying to fix it up so that there is a decal.

Then look it up.

[editline]24th December 2013[/editline]

Oh god typing code on my phone. Here goes:



function SWEP:PaintRandomDecal()
        local decals = { "Scorch", "SmallScorch", "OtherDecals" }
        local tr = self.Owner:GetEyeTrace()
		local Pos1 = tr.HitPos + tr.HitNormal
		local Pos2 = tr.HitPos - tr.HitNormal
	util.Decal( table.random( decals ), Pos1, Pos2 )
end


Put this code in your SWEP files.

Call this function inside the primary fire function.

Should I remove


function ENT:PhysicsCollide(data,phy)
	local trace = {}
	trace.filter = {self.Entity}
	data.HitNormal = data.HitNormal * -1
	local start = data.HitPos + data.HitNormal
	local endpos = data.HitPos - data.HitNormal
  
	util.Decal("splat"..math.random(1,12),start,endpos)
	self.Entity:EmitSound(Sound( "marker/pbhit.wav" ))
 
	util.BlastDamage(self.Entity:GetOwner(),self.Entity:GetOwner(),data.HitPos,1,paintballdamage)
	// if 
		// ( data.HitEntity:IsValid() && data.HitEntity:IsPlayer() ) then data.HitEntity:TakeDamage( 1, self.Owner ) 
	// end
	self.Entity:Fire("kill", "", 0)
end

from init.lua?

[editline]24th December 2013[/editline]

@CallMePyro Garry’s mod did not like that code, lua errored right when I shot.