PHP-Code:
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
if SERVER then
AddCSLuaFile("shared.lua")
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
end
if CLIENT then
SWEP.PrintName = "NoCollide SWEP"
SWEP.Slot = 5
SWEP.SlotPos = 10
SWEP.DrawCrosshair = true
SWEP.DrawAmmo = false
end
SWEP.Primary.Automatic = false
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.SelectedEntity = NULL
SWEP.SelectedSound = "" --When selecting an entity first
SWEP.AbortedSound = "Weapon_AR2.Special2" --When deselecting (shooting at it again)
SWEP.NocollidedSound = "ItemBattery.Touch" --When creating the nocollide
local function CheckValid(e)
if e and e:IsValid() and e:GetClass() != "worldspawn" and !e:IsPlayer() and !e:IsNPC() then
return true
end
return false
end
function SWEP:PrimaryAttack()
local tr = self.Owner:GetEyeTrace()
if tr.Hit then
if CheckValid(self.SelectedEntity) then
if tr.Entity == self.SelectedEntity then
self.Weapon:EmitSound(self.AbortedSound)
else
self.Weapon:EmitSound(self.NocollidedSound)
constraint.NoCollide(tr.Entity, self.SelectedEntity, 0, 0)
end
self.SelectedEntity = nil
elseif CheckValid(tr.Entity) then
self.SelectedEntity = tr.Entity
self.Weapon:EmitSound(self.SelectedSound)
end
end
end
function SWEP:SecondaryAttack()
local tr = self.Owner:GetEyeTrace()
if tr.Hit and CheckValid(tr.Entity) then
if (tr.Entity.CollisionGroup == COLLISION_GROUP_WORLD) then
tr.Entity:SetCollisionGroup( COLLISION_GROUP_NONE)
tr.Entity.CollisionGroup = COLLISION_GROUP_NONE
self.Weapon:EmitSound(self.NocollidedSound)
else
tr.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
tr.Entity.CollisionGroup = COLLISION_GROUP_WORLD
end
end
end
function SWEP:Reload()
if self.SelectedEntity then
self.Weapon:EmitSound(self.AbortedSound)
self.SelectedEntity = nil
end
end