Xwad Posted August 17, 2016 Posted August 17, 2016 why is the sound not random? client sounds = {"files/sounds/g_grenade1.mp3", "files/sounds/g_grenade2.mp3", "files/sounds/g_grenade3.mp3", "files/sounds/g_grenade4.mp3", "files/sounds/g_grenade5.mp3", "files/sounds/g_grenade6.mp3"} sound = sounds [ math.random ( #sounds ) ] function onClientPlayerWeaponFireFunc(weapon) if (weapon == 16) then outputChatBox("g",1,55,32) local x,y,z = getElementPosition(localPlayer) local sound_grenade = playSound3D(sound, x,y,z, false) setSoundVolume(sound_grenade, 1) setSoundMaxDistance(sound_grenade, 100) end end addEventHandler("onClientPlayerWeaponFire", root, onClientPlayerWeaponFireFunc)
roaddog Posted August 17, 2016 Posted August 17, 2016 Because.... U declare 'sound' outside function so first time the script load it will be random BUT everytime the onClientPlayerWeaponFireFunc called and execute playSound the 'sound' variable from the firts time it set. Solution would be placing line 2 inside function
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now