dragonofdark Posted January 19, 2011 Author Share Posted January 19, 2011 It works ! Now I'll make the commands for the siren Link to comment
SDK Posted January 19, 2011 Share Posted January 19, 2011 Ah yes, my eventhandler was wrong. But if you use Solidsnake14's fix, it will only work for you (only your client will get the event) Change it to this: function startSirene ( vehicle ) local x,y,z = getElementPosition( vehicle ) local sound = playSound3D( "sons\\sirene1.wav", x, y, z, true) attachElements ( sound, vehicle) end addEvent( "startSirene", true ) addEventHandler("startSirene", getRootElement(), startSirene) Link to comment
dragonofdark Posted January 19, 2011 Author Share Posted January 19, 2011 I've make the commands to start/stop siren, but I have some errors in the debugscript : WARNING: sirencomm1\siren_client.lua:2: Bad argument @ 'getElementPosition' WARNING: sirencomm1\siren_client.lua:5: Bad argument @ 'attachElements' The siren_client.lua is : function startsiren (vehicle) local x,y,z = getElementPosition( vehicle ) local sound = playSound3D( "sons\\sirene1.wav", x, y, z, true) setSoundMaxDistance(sound, 70) attachElements ( sound, vehicle) end addCommandHandler("sirenon", startsiren ) function stopsiren (vehicle) local x,y,z = getElementPosition( vehicle ) local sound = playSound3D( "sons\\sirene1.wav", x, y, z, false) setSoundMaxDistance(sound, 70) attachElements ( sound, vehicle) end addEvent( "stopsiren", true ) addCommandHandler("sirenoff", startsiren ) Link to comment
Castillo Posted January 19, 2011 Share Posted January 19, 2011 this makes no sense O_o Link to comment
dragonofdark Posted January 19, 2011 Author Share Posted January 19, 2011 lol, it's my first script Link to comment
SDK Posted January 19, 2011 Share Posted January 19, 2011 This is pretty complicated for a first script already. The point of my previous script was to put the commandhandlers serverside And if you want to stop the siren, you'll first need to either store the sound element somewhere or get it using getAttachedElements and find it in the table. After that use stopSound on it. Link to comment
Castillo Posted January 19, 2011 Share Posted January 19, 2011 (edited) try this (not sure if it will work) --client function startSirene ( vehicle ) local x,y,z = getElementPosition( vehicle ) sound = playSound3D( "sons\\sirene1.wav", x, y, z, true) attachElements ( sound, vehicle) end addEvent( "startSirene", true ) addEventHandler("startSirene", getRootElement(), startSirene) function stopSirene() destroyElement(sound) end addEvent( "stopSirene", true ) addEventHandler("stopSirene", getRootElement(), stopSirene) --server function startSirene( player, cmd ) local commandant = createVehicle ( 554, 1227.746, -1422.281, 13.5432, 0, 0, 0, "COMM1" ) triggerClientEvent ( player, "startSirene", getRootElement(), commandant ) end addCommandHandler ( "sireneon", startSirene) function stopSirene( player, cmd ) triggerClientEvent ( player, "stopSirene", getRootElement() ) end addCommandHandler ( "sireneoff", stopSirene) Edited January 19, 2011 by Guest Link to comment
dragonofdark Posted January 19, 2011 Author Share Posted January 19, 2011 Doesn't work Nothing come, I haven't got any error or warning. Link to comment
Castillo Posted January 19, 2011 Share Posted January 19, 2011 You could easily fixed it yourself , i put a wrong function name in client part. Link to comment
dragonofdark Posted January 19, 2011 Author Share Posted January 19, 2011 It's okay, I fixed the function name and now the command "sireneon" works but the "sireneoff" has a problem... WARNING: sirencomm1\siren_client.lua:2: Bad argument @ 'getElementPosition' WARNING: sirencomm1\siren_client.lua:4: Bad argument @ 'attachElements' Link to comment
Castillo Posted January 19, 2011 Share Posted January 19, 2011 what are you talking about?? just copy my code (i've fixed function name) Link to comment
dragonofdark Posted January 19, 2011 Author Share Posted January 19, 2011 Hm.. Sorry... It works well (I need to sleep ) Link to comment
dragonofdark Posted January 20, 2011 Author Share Posted January 20, 2011 Ek, just a last little question and I'll leave you alone I've tried to change the script to let the vehicle created onResourceStart and to make the commands to start/stop siren but I have the bad argument warning (and the siren cannot be started/stopped)... EDIT : Damn.. I can't find the code I made > Link to comment
Jumper_Mych Posted January 20, 2011 Share Posted January 20, 2011 with me same can't start and stop syren Link to comment
SDK Posted January 21, 2011 Share Posted January 21, 2011 Why do you create a vehicle onResourceStart? Use getPedOccupiedVehicle and create a vehicle yourself using the admin panel or freeroam resource. There's still a problem with that code anyway. I guess you'll be using it on multiple vehicles but the sound variable is shared for them all. That will cause trouble when players will use the sirens at the same time. And if you want to stop the siren, you'll first need to either store the sound element somewhere or get it using getAttachedElements and find it in the table. After that use stopSound on it. Oh well, try this: --client local sounds = {} function startSirene ( vehicle ) local x,y,z = getElementPosition( vehicle ) local sirene = playSound3D( "sons\\sirene1.wav", x, y, z, true) attachElements ( sirene, vehicle) sounds [ vehicle ] = sirene end addEvent( "startSirene", true ) addEventHandler("startSirene", getRootElement(), startSirene) function stopSirene( vehicle ) local sirene = sounds [ vehicle ] stopSound ( sirene ) end addEvent( "stopSirene", true ) addEventHandler("stopSirene", getRootElement(), stopSirene) --server function startSirene( player, cmd ) local commandant = getPedOccupiedVehicle(player) triggerClientEvent ( "startSirene", getRootElement(), commandant ) end addCommandHandler ( "sireneon", startSirene) function stopSirene( player, cmd ) local commandant = getPedOccupiedVehicle(player) triggerClientEvent ( "stopSirene", getRootElement() ) end addCommandHandler ( "sireneoff", stopSirene) Link to comment
xUltimate Posted January 21, 2011 Share Posted January 21, 2011 Just tested that, it plays it really quietly and you cant turn it off. Link to comment
SDK Posted January 21, 2011 Share Posted January 21, 2011 You can use these for sound volume/distances (you can click on them): setSoundVolume setSoundMinDistance setSoundMaxDistance Serverside was wrong --server function stopSirene( player, cmd ) local commandant = getPedOccupiedVehicle(player) triggerClientEvent ( "stopSirene", getRootElement(), commandant ) end addCommandHandler ( "sireneoff", stopSirene) Link to comment
dragonofdark Posted January 21, 2011 Author Share Posted January 21, 2011 SDK... You're my god ! There's still a problem with that code anyway. I guess you'll be using it on multiple vehicles but the sound variable is shared for them all. That will cause trouble when players will use the sirens at the same time. And if I create some sirens (wail,Hi-lo,...) with differents commands, that will not cause any problem ? EDIT : We have no problem when some players start the siren ! Link to comment
SDK Posted January 22, 2011 Share Posted January 22, 2011 That sentence was about the previous code, where one sound variable was created and used Link to comment
dragonofdark Posted March 25, 2011 Author Share Posted March 25, 2011 Hey, Sorry if I restart the topic but I have changed some things in the script to make the sirens turnables with binds and I have an error. So, my server script is : ambulances = { [416]=true } perso = { urgences=true } -- sirenes ambu function sirenAmbu1 ( player ) local commandant = getPedOccupiedVehicle(player) if ( ambulances[getVehicleID ( source )] ) and ( perso[getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( player )] ) then triggerClientEvent ( "sirenAmbu1", getRootElement(), commandant ) end end bindKey ( "num_1", "down", function () sirenAmbu1 end, false ) But when I start the resource, I have this error : WARNING: Loading script failed: siernes/sirene_server.lua:11: "=" expected near 'end' Can someone help me to make it work ? Thanks EDIT : Hum... The code bugs on this forum O_o Link to comment
Castillo Posted March 26, 2011 Share Posted March 26, 2011 (edited) Well, bindKey in server side is different than client side. ambulances = { [416]=true } perso = { ["urgences"]=true } addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function () for i,v in pairs(getElementsByType("player")) do bindKey(v,"num_1","down",sirenAmu1) end end) -- sirenes ambu function sirenAmbu1 ( player ) local commandant = getPedOccupiedVehicle(player) if ( ambulances[getElementModel(commandant)] ) and ( perso[getTeamName(getPlayerTeam( player ))] ) then triggerClientEvent ( "sirenAmbu1", getRootElement(), commandant ) end end Try it (not tested) Edited March 26, 2011 by Guest Link to comment
dragonofdark Posted March 26, 2011 Author Share Posted March 26, 2011 Thanks I just added a forget "b" at line 7. Well, now I have the error ERRROR: sirenes/sirene_server.lua:6: bad argument #1 to 'pairs' (table expected, got nil) I never worked with the tables so it's a bit difficult for me to find the problem Link to comment
Castillo Posted March 26, 2011 Share Posted March 26, 2011 lol, sorry, i forgot to edit something, copy again the code. Link to comment
dragonofdark Posted March 26, 2011 Author Share Posted March 26, 2011 Thanks a lot Solidsnake14 Link to comment
dragonofdark Posted June 26, 2011 Author Share Posted June 26, 2011 Hey, I restart this topic because I have a sort of problem. I have 2 function : 1 to start the siren, 1 to stop the siren. How can I make a toogle function with one keybind ? function 1 = siren1 function 2 = siren10 Thanks 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