Hello, I have a custom swep that replaces the default crowbar for our server. It’s a lightsaber. I was wondering what I would have to put in to make it so when i right click it pushes people just like the crowbar. Here’s the shared.lua code for the lightsaber.
edit I noticed a push force in the code. I guess it just doesn’t work? Anyone can help? Thank you very much for taking your time!
if SERVER then
AddCSLuaFile( "shared.lua" )
resource.AddFile("materials/vgui/ttt/lightsaber_green.png")
end
SWEP.HoldType = "melee"
if CLIENT then
SWEP.PrintName = "Lightsaber"
SWEP.Slot = 0
SWEP.Icon = "vgui/ttt/lightsaber_green.png"
SWEP.ViewModelFOV = 54
end
SWEP.Base = "weapon_tttbase"
SWEP.ViewModel = "models/weapons/v_growbar.mdl"
SWEP.WorldModel = "models/weapons/v_growbar.mdl"
SWEP.Weight = 5
SWEP.DrawCrosshair = false
SWEP.ViewModelFlip = false
SWEP.Primary.Damage = 20
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.5
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 5
SWEP.Kind = WEAPON_MELEE
SWEP.WeaponID = AMMO_CROWBAR
SWEP.NoSights = true
SWEP.IsSilent = true
SWEP.AutoSpawnable = false
SWEP.AllowDelete = false -- never removed for weapon reduction
SWEP.AllowDrop = false
local sound_single = Sound("phantom/sword/saberhup1.wav")
local sound_open = Sound("DoorHandles.Unlocked3")
if SERVER then
CreateConVar("ttt_crowbar_unlocks", "1", FCVAR_ARCHIVE)
CreateConVar("ttt_crowbar_pushforce", "395", FCVAR_NOTIFY)
end
-- only open things that have a name (and are therefore likely to be meant to
-- open) and are the right class. Opening behaviour also differs per class, so
-- return one of the OPEN_ values
local function OpenableEnt(ent)
local cls = ent:GetClass()
if ent:GetName() == "" then
return OPEN_NO
elseif cls == "prop_door_rotating" then
return OPEN_ROT
elseif cls == "func_door" or cls == "func_door_rotating" then
return OPEN_DOOR
elseif cls == "func_button" then
return OPEN_BUT
elseif cls == "func_movelinear" then
return OPEN_NOTOGGLE
else
return OPEN_NO
end
end
local function CrowbarCanUnlock(t)
return not GAMEMODE.crowbar_unlocks or GAMEMODE.crowbar_unlocks[t]
end
-- will open door AND return what it did
function SWEP:OpenEnt(hitEnt)
-- Get ready for some prototype-quality code, all ye who read this
if SERVER and GetConVar("ttt_crowbar_unlocks"):GetBool() then
local openable = OpenableEnt(hitEnt)
if openable == OPEN_DOOR or openable == OPEN_ROT then
local unlock = CrowbarCanUnlock(openable)
if unlock then
hitEnt:Fire("Unlock", nil, 0)
end
if unlock or hitEnt:HasSpawnFlags(256) then
if openable == OPEN_ROT then
hitEnt:Fire("OpenAwayFrom", self.Owner, 0)
end
hitEnt:Fire("Toggle", nil, 0)
else
return OPEN_NO
end
elseif openable == OPEN_BUT then
if CrowbarCanUnlock(openable) then
hitEnt:Fire("Unlock", nil, 0)
hitEnt:Fire("Press", nil, 0)
else
return OPEN_NO
end
elseif openable == OPEN_NOTOGGLE then
if CrowbarCanUnlock(openable) then
hitEnt:Fire("Open", nil, 0)
else
return OPEN_NO
end
end
return openable
else
return OPEN_NO
end
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
if not IsValid(self.Owner) then return end
if self.Owner.LagCompensation then -- for some reason not always true
self.Owner:LagCompensation(true)
end
local spos = self.Owner:GetShootPos()
local sdest = spos + (self.Owner:GetAimVector() * 70)
local tr_main = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL})
local hitEnt = tr_main.Entity
self.Weapon:EmitSound(sound_single)
if IsValid(hitEnt) or tr_main.HitWorld then
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
if not (CLIENT and (not IsFirstTimePredicted())) then
local edata = EffectData()
edata:SetStart(spos)
edata:SetOrigin(tr_main.HitPos)
edata:SetNormal(tr_main.Normal)
--edata:SetSurfaceProp(tr_main.MatType)
--edata:SetDamageType(DMG_CLUB)
edata:SetEntity(hitEnt)
if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then
util.Effect("BloodImpact", edata)
-- does not work on players rah
--util.Decal("Blood", tr_main.HitPos + tr_main.HitNormal, tr_main.HitPos - tr_main.HitNormal)
-- do a bullet just to make blood decals work sanely
-- need to disable lagcomp because firebullets does its own
self.Owner:LagCompensation(false)
self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=0})
else
util.Effect("Impact", edata)
end
end
else
self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
end
if CLIENT then
-- used to be some shit here
else -- SERVER
-- Do another trace that sees nodraw stuff like func_button
local tr_all = nil
tr_all = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner})
self.Owner:SetAnimation( PLAYER_ATTACK1 )
if hitEnt and hitEnt:IsValid() then
if self:OpenEnt(hitEnt) == OPEN_NO and tr_all.Entity and tr_all.Entity:IsValid() then
-- See if there's a nodraw thing we should open
self:OpenEnt(tr_all.Entity)
end
local dmg = DamageInfo()
dmg:SetDamage(self.Primary.Damage)
dmg:SetAttacker(self.Owner)
dmg:SetInflictor(self.Weapon)
dmg:SetDamageForce(self.Owner:GetAimVector() * 1500)
dmg:SetDamagePosition(self.Owner:GetPos())
dmg:SetDamageType(DMG_CLUB)
hitEnt:DispatchTraceAttack(dmg, spos + (self.Owner:GetAimVector() * 3), sdest)
-- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
-- self.Owner:TraceHullAttack(spos, sdest, Vector(-16,-16,-16), Vector(16,16,16), 30, DMG_CLUB, 11, true)
-- self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=20})
else
-- if tr_main.HitWorld then
-- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
-- else
-- self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
-- end
-- See if our nodraw trace got the goods
if tr_all.Entity and tr_all.Entity:IsValid() then
self:OpenEnt(tr_all.Entity)
end
end
end
if self.Owner.LagCompensation then
self.Owner:LagCompensation(false)
end
end
function SWEP:GetClass()
return "weapon_zm_improvised"
end
function SWEP:OnDrop()
self:Remove()
end
function SWEP:Deploy()
self:SetIronsights(false)
if CLIENT then
surface.PlaySound("sound/phantom/sword/saberon.wav")
end
return true
end
--// File Generated By Fox-Warrior's Resources Generator Version 2.05 \\--
if (SERVER) then
resource.AddFile( "sound/phantom/sword/saberhup1.wav" )
resource.AddFile( "sound/phantom/sword/saberhup2.wav" )
resource.AddFile( "sound/phantom/sword/saberhup3.wav" )
resource.AddFile( "sound/phantom/sword/saberhup4.wav" )
resource.AddFile( "sound/phantom/sword/saberhup5.wav" )
resource.AddFile( "sound/phantom/sword/saberoff.wav" )
resource.AddFile( "sound/phantom/sword/saberon.wav" )
resource.AddFile( "sound/phantom/force/heal.wav" )
resource.AddFile( "sound/phantom/force/jump.wav" )
resource.AddFile( "sound/phantom/force/pull.wav" )
resource.AddFile( "sound/phantom/force/push.wav" )
resource.AddFile( "sound/phantom/force/see.wav" )
resource.AddFile( "sound/phantom/force/speed.wav" )
resource.AddFile( "models/weapons/v_blowbar.mdl" )
resource.AddFile( "models/weapons/v_browbar.mdl" )
resource.AddFile( "models/weapons/v_growbar.mdl" )
resource.AddFile( "models/weapons/v_lrowbar.mdl" )
resource.AddFile( "models/weapons/v_rrowbar.mdl" )
resource.AddFile( "models/weapons/v_yrowbar.mdl" )
resource.AddFile( "materials/weapons/lightsaber.vmt" )
resource.AddFile( "materials/weapons/lightsaber.vtf" )
resource.AddFile( "materials/weapons/lightsaber_black.vmt" )
resource.AddFile( "materials/weapons/lightsaber_black.vtf" )
resource.AddFile( "materials/weapons/lightsaber_blue.vmt" )
resource.AddFile( "materials/weapons/lightsaber_blue.vtf" )
resource.AddFile( "materials/weapons/lightsaber_green.vmt" )
resource.AddFile( "materials/weapons/lightsaber_green.vtf" )
resource.AddFile( "materials/weapons/lightsaber_lila.vmt" )
resource.AddFile( "materials/weapons/lightsaber_lila.vtf" )
resource.AddFile( "materials/weapons/lightsaber_red.vmt" )
resource.AddFile( "materials/weapons/lightsaber_red.vtf" )
resource.AddFile( "materials/weapons/lightsaber_yellow.vmt" )
resource.AddFile( "materials/weapons/lightsaber_yellow.vtf" )
resource.AddFile( "materials/VGUI/entities/lightsaber_black.vmt" )
resource.AddFile( "materials/VGUI/entities/lightsaber_black.vtf" )
resource.AddFile( "materials/VGUI/entities/lightsaber_blue.vmt" )
resource.AddFile( "materials/VGUI/entities/lightsaber_blue.vtf" )
resource.AddFile( "materials/VGUI/entities/lightsaber_green.vmt" )
resource.AddFile( "materials/VGUI/entities/lightsaber_green.vtf" )
resource.AddFile( "materials/VGUI/entities/lightsaber_lila.vmt" )
resource.AddFile( "materials/VGUI/entities/lightsaber_lila.vtf" )
resource.AddFile( "materials/VGUI/entities/lightsaber_red.vmt" )
resource.AddFile( "materials/VGUI/entities/lightsaber_red.vtf" )
resource.AddFile( "materials/VGUI/entities/lightsaber_yellow.vmt" )
resource.AddFile( "materials/VGUI/entities/lightsaber_yellow.vtf" )
resource.AddFile( "materials/pac/lightsaber_black_killicon.vmt" )
resource.AddFile( "materials/pac/lightsaber_black_killicon.vtf" )
resource.AddFile( "materials/pac/lightsaber_blue_killicon.vmt" )
resource.AddFile( "materials/pac/lightsaber_blue_killicon.vtf" )
resource.AddFile( "materials/pac/lightsaber_green_killicon.vmt" )
resource.AddFile( "materials/pac/lightsaber_green_killicon.vtf" )
resource.AddFile( "materials/pac/lightsaber_lila_killicon.vmt" )
resource.AddFile( "materials/pac/lightsaber_lila_killicon.vtf" )
resource.AddFile( "materials/pac/lightsaber_red_killicon.vmt" )
resource.AddFile( "materials/pac/lightsaber_red_killicon.vtf" )
resource.AddFile( "materials/pac/lightsaber_yellow_killicon.vmt" )
resource.AddFile( "materials/pac/lightsaber_yellow_killicon.vtf" )
resource.AddFile( "materials/models/oggyel/fx2ogg.vmt" )
resource.AddFile( "materials/models/oggyel/fx2ogg.vtf" )
resource.AddFile( "materials/models/oggyel/fxogg.vmt" )
resource.AddFile( "materials/models/oggyel/fxogg.vtf" )
resource.AddFile( "materials/models/oggyel/masogg.vmt" )
resource.AddFile( "materials/models/oggyel/masogg.vtf" )
resource.AddFile( "materials/models/oggyel/masogg_f.vtf" )
resource.AddFile( "materials/models/oggyel/masogg_n.vtf" )
resource.AddFile( "materials/models/oggmix/fx2ogg.vmt" )
resource.AddFile( "materials/models/oggmix/fx2ogg.vtf" )
resource.AddFile( "materials/models/oggmix/fxogg.vmt" )
resource.AddFile( "materials/models/oggmix/fxogg.vtf" )
resource.AddFile( "materials/models/oggmix/masogg.vmt" )
resource.AddFile( "materials/models/oggmix/masogg.vtf" )
resource.AddFile( "materials/models/oggmix/masogg_f.vtf" )
resource.AddFile( "materials/models/oggmix/masogg_n.vtf" )
resource.AddFile( "materials/models/oggmip/fx2ogg.vmt" )
resource.AddFile( "materials/models/oggmip/fx2ogg.vtf" )
resource.AddFile( "materials/models/oggmip/fxogg.vmt" )
resource.AddFile( "materials/models/oggmip/fxogg.vtf" )
resource.AddFile( "materials/models/oggmip/masogg.vmt" )
resource.AddFile( "materials/models/oggmip/masogg.vtf" )
resource.AddFile( "materials/models/oggmip/masogg_f.vtf" )
resource.AddFile( "materials/models/oggmip/masogg_n.vtf" )
resource.AddFile( "materials/models/oggmil/fx2ogg.vmt" )
resource.AddFile( "materials/models/oggmil/fx2ogg.vtf" )
resource.AddFile( "materials/models/oggmil/fxogg.vmt" )
resource.AddFile( "materials/models/oggmil/fxogg.vtf" )
resource.AddFile( "materials/models/oggmil/masogg.vmt" )
resource.AddFile( "materials/models/oggmil/masogg.vtf" )
resource.AddFile( "materials/models/oggmil/masogg_f.vtf" )
resource.AddFile( "materials/models/oggmil/masogg_n.vtf" )
resource.AddFile( "materials/models/oggmic/fx2ogg.vmt" )
resource.AddFile( "materials/models/oggmic/fx2ogg.vtf" )
resource.AddFile( "materials/models/oggmic/fxogg.vmt" )
resource.AddFile( "materials/models/oggmic/fxogg.vtf" )
resource.AddFile( "materials/models/oggmic/masogg.vmt" )
resource.AddFile( "materials/models/oggmic/masogg.vtf" )
resource.AddFile( "materials/models/oggmic/masogg_f.vtf" )
resource.AddFile( "materials/models/oggmic/masogg_n.vtf" )
resource.AddFile( "materials/models/oggbla/fx2ogg.vmt" )
resource.AddFile( "materials/models/oggbla/fx2ogg.vtf" )
resource.AddFile( "materials/models/oggbla/fxogg.vmt" )
resource.AddFile( "materials/models/oggbla/fxogg.vtf" )
resource.AddFile( "materials/models/oggbla/masogg.vmt" )
resource.AddFile( "materials/models/oggbla/masogg.vtf" )
resource.AddFile( "materials/models/oggbla/masogg_f.vtf" )
resource.AddFile( "materials/models/oggbla/masogg_n.vtf" )
end