• Lua Coding problem with GMOD server
    6 replies, posted
HI , I'm trying to create a SWEP for lua. I got the sound to come through in the game where i can hear it, but in console it says SV_StartSound: youprovokemyrage.wav not precached (0) *** I am new to programming with Lua, so i don't know a lot of of things when it comes to it. I don't understand why it says this. The entire code is listed below: if SERVER then resource.AddFile( "sound/getoverhere.wav" ) resource.AddFile( "sound/youprovokemyrage.wav" ) resource.AddFile( "sound/yourfamilyendsnow.wav" ) AddCSLuaFile () end if CLIENT then SWEP.PrintName = "Scorpion" SWEP.Author = "Assassin" SWEP.Slot = 2 SWEP.SlotPos = 1 end SWEP.Category = "Scorpion Sound SWEP" SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 60 SWEP.Spawnable = true SWEP.AdminOnly = false SWEP.UseHands = false SWEP.ViewModel = "models/weapons/v_crowbar.mdl" SWEP.WorldModel = "models/weapons/w_crowbar.mdl" SWEP.Weight = 1 SWEP.AutoSwitchFrom = true SWEP.Primary.Recoil = 0 SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" function SWEP:Initialize() timer.Simple(0, function() self:SetHoldType("idle") end) self:SetHoldType("idle") end local sound = {"getoverhere.wav", "youprovokemyrage.wav", "yourfamilyendsnow.wav"} function SWEP.PrimaryAttack() EmitSound( Sound( sound[math.random( 1, #sound )] ) , Entity( 1 ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 ) end function SWEP.Secondary() return end
Use the Lua code wrap for you Lua, it makes it easier to read but I'd imagine you'd need to precache the sound: util.PrecacheSound
It says that util.PreacheSound is a nil value
you spelled it wrong.
what folder is this in? and how are you using PrecacheSound?
dang it lol, thanks. I feel stupid now
Weird, Sound is supposed to pre-cache the sound for you, but I guess since you are calling it right away it doesn't actually have enough time to pre-cache it. You could alternatively try storing your paths like this local sound = { Sound( "getoverhere.wav" ), Sound( "youprovokemyrage.wav" ), Sound( "yourfamilyendsnow.wav" ) } Then you could just do as you were: EmitSound( table.Random( sound ), Entity( 1 ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
Sorry, you need to Log In to post a reply to this thread.