Trouble in Terrorist Town Custom Jihad Sound Pointshop

Hey there.

I am very newbie when it comes to LUA and coding in general, so I wouldn’t doubt it if the answers to any of my problems are easily / blatantly fixable.

I’ve been trying to make custom jihad sounds in my pointshop (to override the default lalalala when you explode if the item is equipped.) using the pointshop function ‘ply:PS_HasItemEquipped’. I looked it up and I added ‘ply’ as a value (ply = {}) which got rid of the original error message which stated something along the lines of ‘ply is a nil value’. Now I’m getting PS_HasItemEquipped is a nil value and when I try to add a value for it I still get the same error message. Here is my code so far:


// Variables that are used on both client and server

SWEP.Author			= "Stingwraith"
SWEP.Contact		= "stingwraith123@yahoo.com"
SWEP.Purpose		= "Sacrifice yourself for Allah."
SWEP.Instructions	= "Left Click to make yourself EXPLODE. Right click to taunt."
SWEP.DrawCrosshair		= false

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true		// Spawnable in singleplayer or by server admins

SWEP.ViewModel			= "models/weapons/v_jb.mdl"
SWEP.WorldModel			= "models/weapons/w_jb.mdl"
-- TTT Information Start
SWEP.Base = "weapon_tttbase"
SWEP.ViewModelFlip = false
SWEP.Kind = WEAPON_EQUIP1
SWEP.Slot = 7
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.LimitedStock = true
SWEP.AllowDrop = false
SWEP.AutoSpawnable = false
-- TTT Information End
SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "none"
SWEP.Primary.Delay			= 3

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"

/*---------------------------------------------------------
	Reload does nothing
---------------------------------------------------------*/
function SWEP:Reload()
end   

function SWEP:Initialize()
    util.PrecacheSound("siege/big_explosion.wav")
    util.PrecacheSound("siege/jihad.wav")
end


/*---------------------------------------------------------
   Think does nothing
---------------------------------------------------------*/
function SWEP:Think()	
end


/*---------------------------------------------------------
	PrimaryAttack
---------------------------------------------------------*/
PS_HasItemEquipped = {}
ply = {}
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + 3)

	
	local effectdata = EffectData()
		effectdata:SetOrigin( self.Owner:GetPos() )
		effectdata:SetNormal( self.Owner:GetPos() )
		effectdata:SetMagnitude( 8 )
		effectdata:SetScale( 1 )
		effectdata:SetRadius( 16 )
	util.Effect( "Sparks", effectdata )
	
	self.BaseClass.ShootEffects( self )

if (SERVER) then
   if ply:PS_HasItemEquipped("custom1") then
      timer.Simple(2, function() self:Asplode() end )
      self.Owner:EmitSound( "taunt/custom1.mp3" )
   end
end

end
--The asplode function
function SWEP:Asplode()
local k, v
	
	// Make an explosion at your position
	local ent = ents.Create( "env_explosion" )
		ent:SetPos( self.Owner:GetPos() )
		ent:SetOwner( self.Owner )
		ent:Spawn()
		ent:SetKeyValue( "iMagnitude", "250" )
		ent:Fire( "Explode", 0, 0 )
		ent:EmitSound( "siege/big_explosion.wav", 500, 500 )
		
		self.Owner:Kill( )
		self.Owner:AddFrags( -1 )
 
		for k, v in pairs( player.GetAll( ) ) do
		  v:ConCommand( "play siege/big_explosion.wav
" )
		end

end


/*---------------------------------------------------------
	SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()	
	
	self.Weapon:SetNextSecondaryFire( CurTime() + 1 )
	
	local TauntSound = Sound( "vo/npc/male01/overhere01.wav" )

	self.Weapon:EmitSound( TauntSound )
	
	// The rest is only done on the server
	if (!SERVER) then return end
	
	self.Weapon:EmitSound( TauntSound )


end


Thanks for atleast giving me a read!

I think, the best way here is to create a table of sounds and, in SWEP explode function write something like:


...
local sound = ply:GetNWInt('JihadSound') or 1
ply:EmitSound(soundsTable[sound])
...

So, soundsTable is the table of all your jihad sounds. On Pointshop equip function you can set this networked integer to needed table element id.
The code is server-sided ofc.

Update: oh, sorry! I didn’t help you with your problem, but i wrote the other way of doing it and i think its simplier

New update :3…
Idk if this SWEP can work as it must, but here is example:



local explodeSounds = {
    'blahblah.vaw', -- Sound number 1 (default)
    'wow/such/donater.vaw', -- Sound number 2
    'etc.vaw', -- Sound number 3
}

// Variables that are used on both client and server

SWEP.Author			= "Stingwraith"
SWEP.Contact		= "stingwraith123@yahoo.com"
SWEP.Purpose		= "Sacrifice yourself for Allah."
SWEP.Instructions	= "Left Click to make yourself EXPLODE. Right click to taunt."
SWEP.DrawCrosshair		= false

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true		// Spawnable in singleplayer or by server admins

SWEP.ViewModel			= "models/weapons/v_jb.mdl"
SWEP.WorldModel			= "models/weapons/w_jb.mdl"
-- TTT Information Start
SWEP.Base = "weapon_tttbase"
SWEP.ViewModelFlip = false
SWEP.Kind = WEAPON_EQUIP1
SWEP.Slot = 7
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.LimitedStock = true
SWEP.AllowDrop = false
SWEP.AutoSpawnable = false
-- TTT Information End
SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "none"
SWEP.Primary.Delay			= 3

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"

/*---------------------------------------------------------
	Reload does nothing
---------------------------------------------------------*/
function SWEP:Reload()
end   

function SWEP:Initialize()
    util.PrecacheSound("siege/big_explosion.wav")
    util.PrecacheSound("siege/jihad.wav")
end


/*---------------------------------------------------------
   Think does nothing
---------------------------------------------------------*/
function SWEP:Think()	
end


/*---------------------------------------------------------
	PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + 3)

	local effectdata = EffectData()
	effectdata:SetOrigin( self.Owner:GetPos() )
	effectdata:SetNormal( self.Owner:GetPos() )
	effectdata:SetMagnitude( 8 )
	effectdata:SetScale( 1 )
	effectdata:SetRadius( 16 )
	util.Effect( "Sparks", effectdata )
	
	self.BaseClass.ShootEffects( self )

	if (SERVER) then
    	timer.Simple(2, function() self:Asplode() end)
    	self.Owner:EmitSound(explodeSounds[self.Owner:GetNWInt('JihadSound') or 1])
   	end
end

end
--The asplode function
function SWEP:Asplode()
	// Make an explosion at your position
	local ent = ents.Create( "env_explosion" )
	ent:SetPos( self.Owner:GetPos() )
	ent:SetOwner( self.Owner )
	ent:Spawn()
	ent:SetKeyValue( "iMagnitude", "250" )
	ent:Fire( "Explode", 0, 0 )
	ent:EmitSound( "siege/big_explosion.wav", 500, 500 )
		
	self.Owner:Kill( )
	self.Owner:AddFrags( -1 )
 
	-- lol what? Why?!
	-- for k, v in pairs( player.GetAll( ) ) do
	--  	v:ConCommand( "play siege/big_explosion.wav
" )
	-- end
end


/*---------------------------------------------------------
	SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()	
	self.Weapon:SetNextSecondaryFire( CurTime() + 1 )
	
	local TauntSound = Sound( "vo/npc/male01/overhere01.wav" )

	self.Weapon:EmitSound( TauntSound )
	
	// The rest is only done on the server
	if (!SERVER) then return end
	
	-- self.Weapon:EmitSound( TauntSound ) -- why the hell 2nd time?
end


And the pointshop part of code should be like:



function ITEM:OnEquip(ply, modifications)
	ply:SetNWInt('JihadSound', 2) -- number of custom sound with ID = 2
end

function ITEM:OnHolster(ply)
	ply:SetNWInt('JihadSound', 1) -- number of default sound with ID = 1
end


Hey man! I really appreciate your help with this. I got a very similar error to last time. It says that ‘self’ is a nil value at line 58. I tried putting in ‘self = {}’ and after I did that I’m getting ‘Weapon’ is a nil value on the same line. I added ‘Weapon = {}’ and it’s not adding a value to it.

remove self.Weapon and replace it with just self
it’s old code and that shouldn’t be used anymore

Now it says ‘SetNextPrimaryFire’ is a nil value.