Xwad Posted March 15, 2016 Share Posted March 15, 2016 hi im trying to make a script that will play a random sound when i type "test". the script is not working pls help. sound = {"files/shoot.wav"}, {"files/shoot2.wav"} sounds = sound [ math.random ( #sound ) ] function random_sound() local shoot = playSound(sound) setSoundVolume(shoot, 10) end addCommandHandler ( "test", random_sound ) Link to comment
Moderators Citizen Posted March 15, 2016 Moderators Share Posted March 15, 2016 Make sure both files are in your meta.xml and as far as I remember, the "test" command name is kinda internally protected, try this instead just to see if it works: addCommandHandler ( "lol", random_sound ) Link to comment
MIKI785 Posted March 15, 2016 Share Posted March 15, 2016 sound = {"files/shoot.wav"}, {"files/shoot2.wav"} That won't work, it is correct but it won't work in the way you want it to. Should be like this: sound = {"files/shoot.wav", "files/shoot2.wav"} Also, function random_sound() local shoot = playSound(sound) setSoundVolume(shoot, 10) end You are trying to play a table, should be sounds as you defined above. And setSoundVolume takes a volume in the range 0 - 1. Link to comment
Xwad Posted March 15, 2016 Author Share Posted March 15, 2016 fixing argumentum problems was always difficult for me..pls help! Bad 'sound/player' pointer @ setSoundVolume'(1) Bad Argumentum @ 'playSound' [Expected string at argument 1,got table] sound = {"files/shoot.wav", "files/shoot2.wav"} sounds = sound [ math.random ( #sound ) ] function random_sound() local shoot = playSound(sound) setSoundVolume(shoot, 1) end addCommandHandler ( "go", random_sound ) Link to comment
MIKI785 Posted March 15, 2016 Share Posted March 15, 2016 Bad Argument @ 'playSound' [Expected string at argument 1,got table] That's exactly what i've told you, why didn't you fix it? Just change sound for sounds as you defined yourself above. Link to comment
Xwad Posted March 15, 2016 Author Share Posted March 15, 2016 zeah now its working 100% thanks:D Link to comment
Xwad Posted August 12, 2016 Author Share Posted August 12, 2016 and why is this one not working? sounds = {"files/fire1.wav", "files/fire2.wav", "files/fire3.wav"} sound = sounds [ math.random ( #sounds ) ] fired = false function projectile_sound(veh) local x,y,z = getElementPosition (veh) local sound_shoot = playSound3D(sound,x,y,z, false) setSoundMaxDistance( sound_shoot, 400 ) setSoundVolume(sound_shoot, 1) attachElements ( sound_shoot, veh, 0,0,0 ) local sound_reload = playSound3D("files/reload.wav",x,y,z, false) setSoundMaxDistance( sound_reload, 100 ) setSoundVolume(sound_reload, 1) attachElements ( sound_reload, veh, 0,0,0 ) end addEvent( "projectile_sound", true ) addEventHandler( "projectile_sound", localPlayer, projectile_sound ) Link to comment
Gravestone Posted August 13, 2016 Share Posted August 13, 2016 Make sure while triggering this event you defined the vehicle element. Link to comment
Xwad Posted August 14, 2016 Author Share Posted August 14, 2016 I am sure its defined Link to comment
Gravestone Posted August 14, 2016 Share Posted August 14, 2016 What's the error with this code? Post your serverside code which triggers this function. Link to comment
Xwad Posted August 14, 2016 Author Share Posted August 14, 2016 client sounds = {"files/fire1.wav", "files/fire2.wav", "files/fire3.wav"} sound = sounds [ math.random ( #sounds ) ] fired = false function projectile_sound(veh) local x,y,z = getElementPosition (veh) local sound_shoot = playSound3D(sound,x,y,z, false) setSoundMaxDistance( sound_shoot, 400 ) setSoundVolume(sound_shoot, 1) attachElements ( sound_shoot, veh, 0,0,0 ) setTimer ( function() local sound_reload = playSound3D("files/reload.wav",x,y,z, false) setSoundMaxDistance( sound_reload, 100 ) setSoundVolume(sound_reload, 1) attachElements ( sound_reload, veh, 0,0,0 ) end, 1000, 1 ) end addEvent( "projectile_sound", true ) addEventHandler( "projectile_sound", localPlayer, projectile_sound ) function projectile_client() if fired == false then local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 457 then triggerServerEvent ( "projectile_server", resourceRoot, veh ) fired = true setTimer ( function() fired = false end, 5000, 1 ) end end end bindKey("mouse1", "down", projectile_client) server function projectile_server(veh) triggerClientEvent ("projectile_sound", getRootElement(), veh) end addEvent( "projectile_server", true ) addEventHandler( "projectile_server", getRootElement(), projectile_server ) Link to comment
Gravestone Posted August 15, 2016 Share Posted August 15, 2016 So you want to trigger the function from client to server and from server back to client, Lol. Remove the server side code and simply use this: fired = false function projectile_sound(veh) local x,y,z = getElementPosition (veh) local sound_shoot = playSound3D("files/fire"..math.random(1 ,3)..".wav", x, y, z, false) setSoundMaxDistance( sound_shoot, 400 ) setSoundVolume(sound_shoot, 1) attachElements ( sound_shoot, veh, 0,0,0 ) setTimer ( function() local sound_reload = playSound3D("files/reload.wav",x,y,z, false) setSoundMaxDistance( sound_reload, 100 ) setSoundVolume(sound_reload, 1) attachElements ( sound_reload, veh, 0,0,0 ) end, 1000, 1 ) end function fire() if fired == false then local vehicle = getPedOccupiedVehicle(localPlayer) if getElementModel(vehicle) == 457 then projectile_sound(vehicle) fired = true setTimer ( function() fired = false end, 5000, 1 ) end end end bindKey("mouse1", "down", fire) Link to comment
Xwad Posted August 15, 2016 Author Share Posted August 15, 2016 i want to sync it lol thats why i used server side Link to comment
Moderators Citizen Posted August 16, 2016 Moderators Share Posted August 16, 2016 You should also send the sound variable with the triggers so they (the clients) will all play the exact same sound. Link to comment
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