Okay so i got the custom sounds working but the problem is that when they dont have any custom sounds bought it dosnt play a sound can someone help
[CODE]
--- Author informations --
local explodeSounds = {
'jihad25/jihad.wav', -- Sound number 1 (default)
'jihad25/president.mp3', -- Sound number 2
'jihad25/johncena.mp3', -- Sound number 3
'jihad25/nuke.wav', -- Sound number 4
'jihad25/join3.mp3', -- Sound number 5
'jihad25/pac2.mp3', -- Sound number 6
'jihad25/saywhatagain2.mp3', -- Sound number 7
'jihad25/shutup.mp3', -- Sound number 8
'jihad25/smokeweed.mp3', -- Sound number 9
'jihad25/suprisemofo.mp3', -- Sound number 10
'jihad25/wtfboom2.mp3', -- Sound number 11
}
SWEP.Author = "Zaratusa"
SWEP.Contact = "http://steamcommunity.com/profiles/76561198032479768"
if SERVER then
AddCSLuaFile()
resource.AddWorkshop("254177214")
else
SWEP.PrintName = "Jihad Bomb"
SWEP.Slot = 8
SWEP.Icon = "vgui/ttt/icon_jihad_bomb"
-- Equipment menu information is only needed on the client
SWEP.EquipMenuData = {
type = "item_weapon",
desc = "Sacrifice yourself to Allah.\nYour 72 virgins await.\n\nNOTE: No refund after use."
}
end
-- Always derive from weapon_tttbase
SWEP.Base = "weapon_tttbase"
--- Default GMod values ---
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 5
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
--- Model settings ---
SWEP.HoldType = "slam"
SWEP.UseHands = true
SWEP.DrawAmmo = false
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 54
SWEP.ViewModel = Model("models/weapons/zaratusa/jihad_bomb/v_jb.mdl")
SWEP.WorldModel = Model("models/weapons/zaratusa/jihad_bomb/w_jb.mdl")
--- TTT config values ---
-- Kind specifies the category this weapon is in. Players can only carry one of
-- each. Can be: WEAPON_... MELEE, PISTOL, HEAVY, NADE, CARRY, EQUIP1, EQUIP2 or ROLE.
-- Matching SWEP.Slot values: 0 1 2 3 4 6 7 8
SWEP.Kind = WEAPON_ROLE
-- If AutoSpawnable is true and SWEP.Kind is not WEAPON_EQUIP1/2,
-- then this gun can be spawned as a random weapon.
SWEP.AutoSpawnable = false
-- InLoadoutFor is a table of ROLE_* entries that specifies which roles should
-- receive this weapon as soon as the round starts.
SWEP.InLoadoutFor = { ROLE_TRAITOR }
-- If AllowDrop is false, players can't manually drop the gun with Q
SWEP.AllowDrop = true
-- If IsSilent is true, victims will not scream upon death.
SWEP.IsSilent = false
-- If NoSights is true, the weapon won't have ironsights
SWEP.NoSights = true
-- Precache sounds and models
function SWEP:Precache()
util.PrecacheSound("jihad25/jihad.wav")
util.PrecacheSound("jihad25/big_explosion.wav")
util.PrecacheModel("models/humans/charple01.mdl")
util.PrecacheModel("models/humans/charple02.mdl")
util.PrecacheModel("models/humans/charple03.mdl")
util.PrecacheModel("models/humans/charple04.mdl")
end
function SWEP:Initialize()
if (CLIENT and self:Clip1() == -1) then
self:SetClip1(self.Primary.DefaultClip)
elseif SERVER then
self.fingerprints = {}
end
self:SetDeploySpeed(self.DeploySpeed)
if (self.SetHoldType) then
self:SetHoldType(self.HoldType or "pistol")
end
self:SetNWBool("Exploding", false)
end
local function ScorchUnderRagdoll(ent)
-- big scorch at center
local mid = ent:LocalToWorld(ent:OBBCenter())
mid.z = mid.z + 25
util.PaintDown(mid, "Scorch", ent)
end
-- Checks if the burn time is over, or if the body is in water
local function RunIgniteTimer(tname, body, burn_destroy)
if (IsValid(body) and body:IsOnFire()) then
if (CurTime() > burn_destroy) then
body:SetNotSolid(true)
body:Remove()
elseif (body:WaterLevel() > 0) then
body:Extinguish()
end
else
timer.Destroy(tname)
end
end
-- Burn the body of the user
local function BurnOwnersBody(model)
local body
-- Search for all ragdolls and the one with the given model
for _, ragdoll in pairs(ents.FindByClass("prop_ragdoll")) do
if (ragdoll:GetModel() == model) then
body = ragdoll
end
end
ScorchUnderRagdoll(body)
if SERVER then
local burn_time = 7.5
local burn_destroy = CurTime() + burn_time
local tname = "burn_jihad"
timer.Simple(0.01, function() if (IsValid(body)) then body:Ignite(burn_time, 100) end end)
timer.Create(tname, 0.1, math.ceil(1 + burn_time / 0.1), function () RunIgniteTimer(tname, body, burn_destroy) end)
end
end
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
--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( "jihad25/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\n" )
-- end
end
/*---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire( CurTime() + 1 )
local TauntSound = Sound( "vo/npc/male01/overhere01.wav" )
self.Weapon:EmitSound(explodeSounds[self.Owner:GetNWInt('JihadSound') or 1])
// The rest is only done on the server
if (!SERVER) then return end
-- self.Weapon:EmitSound( TauntSound ) -- why the hell 2nd time?
end
function SWEP:Deploy()
self:SetNWBool("Exploding", false)
end
function SWEP:Holster()
return !self:GetNWBool("Exploding")
end
-- Reload does nothing
function SWEP:Reload()
end
[/CODE]
Here is the pointshop item
[CODE]
ITEM.Name = 'Say What Again'
ITEM.Price = 500
ITEM.Model = "models/weapons/w_toolgun.mdl"
function ITEM:OnBuy(ply)
ply:SetNWInt('JihadSound', 7) -- number of custom sound with ID = 2
end
function ITEM:OnEquip(ply, modifications)
ply:SetNWInt('JihadSound', 7) -- number of custom sound with ID = 2
end
function ITEM:OnHolster(ply)
ply:SetNWInt('JihadSound', 1) -- number of default sound with ID = 1
end
function ITEM:OnSell(ply)
ply:SetNWInt('JihadSound', 1) -- number of default sound with ID = 1
end
[/CODE]
anyone have a idea?
i tried changing it to
[CODE]
self.Owner:EmitSound(1 or explodeSounds[self.Owner:GetNWInt('JihadSound')])
[/CODE]
but no luck
:snip:
[QUOTE='[PGN]Schuyler;50120871']
[CODE]
self.Owner:EmitSound(1 or explodeSounds[self.Owner:GetNWInt('JihadSound')])
[/CODE]
[/QUOTE]
That will never work either way. 1 will always be valid so it will try to do self.Owner:EmitSound(1), and that will just do nothing
As for your initial code, GetNWInt returns an integer, always. Even if the player doesn't have a weapon bought, it will return something. Since you didn't supply a fallback int, it automatically uses 0. Since [I]0 or 1[/I] returns 0, you are trying to access a non-existent table value (returns nil).
Simply change [lua]self.Owner:EmitSound(explodeSounds[self.Owner:GetNWInt('JihadSound') or 1])[/lua] into [lua]self.Owner:EmitSound(explodeSounds[self.Owner:GetNWInt('JihadSound',1)])[/lua]
Okay ill try it thank you so much
Sorry, you need to Log In to post a reply to this thread.