Slam Problem

shared.lua

if SERVER then
   AddCSLuaFile( "shared.lua" )
end

SWEP.HoldType			= "slam"

if CLIENT then
   SWEP.PrintName			= "SLAM"
   SWEP.Slot				= 6
   SWEP.EquipMenuData = {

      type  = "item_weapon",
      name  = "S.L.A.M",
      desc  = "A IED Explosive that can also be planted on walls."
   };

   SWEP.Icon = "VGUI/ttt/icon_c4"
end

SWEP.Base = "weapon_tttbase"

SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
SWEP.WeaponID = AMMO_C4

SWEP.ViewModel  = Model("models/weapons/v_slam.mdl")
SWEP.WorldModel = Model("models/weapons/w_slam.mdl")

SWEP.DrawCrosshair      = false
SWEP.ViewModelFlip      = false
SWEP.Primary.ClipSize       = -1
SWEP.Primary.DefaultClip    = -1
SWEP.Primary.Automatic      = true
SWEP.Primary.Ammo       = "none"
SWEP.Primary.Delay = 5.0

SWEP.Secondary.ClipSize     = -1
SWEP.Secondary.DefaultClip  = -1
SWEP.Secondary.Automatic    = true
SWEP.Secondary.Ammo     = "none"
SWEP.Secondary.Delay = 1.0

SWEP.NoSights = true

local throwsound = Sound( "Weapon_SLAM.SatchelThrow" )
	   
function SWEP:PrimaryAttack()
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
   self:BombStick()
end

function SWEP:BombStick()
   if SERVER then
      local ply = self.Owner
      if not ValidEntity(ply) then return end

      if self.Planted then return end

      local ignore = {ply, self.Weapon}
      local spos = ply:GetShootPos()
      local epos = spos + ply:GetAimVector() * 80
      local tr = util.TraceLine({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID})

      if tr.HitWorld then
         local turret = ents.Create("npc_tripmine")
         if ValidEntity(turret) then
            turret:PointAtEntity(ply)

            local tr_ent = util.TraceEntity({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID}, turret)

            if tr_ent.HitWorld then

				   local ang = tr_ent.HitNormal:Angle()
				   ang:RotateAroundAxis(ang:Right(), -90)
				   ang:RotateAroundAxis(ang:Up(), 180)

				   turret:SetPos(tr_ent.HitPos)
				   turret:SetAngles(ang)
				   turret:SetOwner(ply)
				   turret:SetCollisionGroup(COLLISION_GROUP_NONE)
				   turret:Spawn()
				   

				   turret.fingerprints = self.fingerprints
				   
				   local phys = turret:GetPhysicsObject()
				   if ValidEntity(phys) then
					  phys:EnableMotion(false)
				   end

				   

				   self:Remove()

				   self.Planted = true

            end
         end

         ply:SetAnimation( PLAYER_ATTACK1 )         
      end
   end
end

function SWEP:Touch(ent)
	if ent:IsPlayer() or ent:IsNPC() then
		self.Explode = true
	end
end
	
function SWEP:OnRemove()
   if CLIENT and ValidEntity(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then
      RunConsoleCommand("lastinv")
   end
end

function SWEP:Reload()
   return false
end
		
function SWEP:SecondaryAttack()
		return false end

Help? It says this in console:

[ERROR] …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:112: attempt to call global ‘ValidEntity’ (a nil value)

  1. unknown - …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:112

[ERROR] …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:112: attempt to call global ‘ValidEntity’ (a nil value)

  1. unknown - …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:112

init.lua

 AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')

function SWEP:Holster( )
	if timer.IsTimer("anim_timer"..tostring(self.Weapon)) then
		timer.Remove("anim_timer"..tostring(self.Weapon))
	end

	return true
end

function SWEP:Reload()
end

function SWEP:Think()
end

function SWEP:PrimaryAttack()

	util.PrecacheSound( "buttons/button3.wav" )
	self.Weapon:EmitSound( "buttons/button3.wav", 100, 100 )

	if (!SERVER) then return end

	local ent = ents.Create( "slam" )
	ent:SetNetworkedBool( "Active", false )
	ent:SetPos( self.Owner:GetShootPos() )
	ent:SetAngles( self.Owner:GetAimVector() )
	ent:Spawn()
	ent:Activate()
	//ent:SetOwner(self.Owner)
	ent:GetPhysicsObject():ApplyForceCenter( self.Owner:GetAimVector() * 3000 )

	//self.Weapon:SendWeaponAnim( ACT_VM_PULLBACK_HIGH )

	//self.Weapon:SendWeaponAnim( ACT_VM_PULLBACK_LOW )

	self.Weapon:SendWeaponAnim( ACT_VM_THROW )

	//self.Weapon:SetNextPrimaryFire( CurTime() + 1.2 )

	undo.Create("Slam")
	undo.AddEntity( ent )
	undo.SetPlayer( self.Owner )
	undo.Finish()

	timer.Create( "anim_timer"..tostring(self.Weapon), 0.1, 1, self.ResetAnim, self )

end

function SWEP:ResetAnim( )

	self.Weapon:SendWeaponAnim( ACT_VM_DRAW )

end

function SWEP:SecondaryAttack()

	util.PrecacheSound( "buttons/button3.wav" )
	self.Weapon:EmitSound( "buttons/button3.wav", 100, 100 )

	if (!SERVER) then return end

	local ent = ents.Create( "hopwire_trap" )
	ent:SetNetworkedBool( "Active", false )
	ent:SetPos( self.Owner:GetShootPos() )
	ent:SetAngles( self.Owner:GetAimVector() )
	ent:Spawn()
	ent:Activate()
	//ent:SetOwner(self.Owner)
	ent:SetVar( "Owner", self.Owner )
	ent:GetPhysicsObject():ApplyForceCenter( self.Owner:GetAimVector() * 2000 )

	//self.Weapon:SendWeaponAnim( ACT_VM_PULLBACK_HIGH )

	//self.Weapon:SendWeaponAnim( ACT_VM_PULLBACK_LOW )

	self.Weapon:SendWeaponAnim( ACT_VM_THROW )

	//self.Weapon:SetNextSecondaryFire( CurTime() + 1.2 )

	undo.Create("Hopwire")
	undo.AddEntity( ent )
	undo.SetPlayer( self.Owner )
	undo.Finish()

	timer.Create( "anim_timer"..tostring(self.Weapon), 0.1, 1, self.ResetAnim, self )

end

cl_init.lua


include('shared.lua')

ValidEntity was removed, it was just an alias of IsValid.

I removed it and changed ValidEntity to IsValid
Still doesn’t work… Help?

What errors do you get now?

It wont plant at all. I can see the model and stuff but It wont plant it or place it or anything. It doesn’t create script errors or anything…

Edit:

[ERROR] …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:112: attempt to call method ‘Alive’ (a nil value)

  1. unknown - …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:112

[ERROR] …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:55: attempt to call global ‘ValidEntity’ (a nil value)

  1. BombStick - …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:55
  2. unknown - …s/terrortown/entities/weapons/weapon_ttt_slam/shared.lua:49

Is what comes up I guess I will go edit the ValidEntity part at line 55 but I did at 112

BUMP Help please? It is really messing my up and it use to place before when I tested it on bots and now it doesn’t… D:

PLEASE HELP :frowning:

[ERROR] …des/terrortown/entities/weapons/weapon_ttt_slam/init.lua:28: Tried to use a NULL entity!

  1. SetPos - [C]:-1
  2. unknown - …des/terrortown/entities/weapons/weapon_ttt_slam/init.lua:28

What is wrong?

Edit: got it fixed, requesting lock and also, if you want the lua code pm me on here.