dragonofdark Posted January 18, 2011 Posted January 18, 2011 Hello all, I was wondering if it's possible to put the police siren on a normal car (so not the police, fire and EMS) with a script ? If it's not possible, do you think that that will be possible in further versions of MTA ? Thanks in advance, dragonofdark
proracer Posted January 18, 2011 Posted January 18, 2011 Try using this but I'm not really sure because I never used it. https://wiki.multitheftauto.com/wiki/GetVehicleSirensOn
dragonofdark Posted January 18, 2011 Author Posted January 18, 2011 Returns true if the sirens are turned on for the specified vehicle, false if the sirens are turned off for the specified vehicle, if the vehicle doesn't have sirens or if invalid arguments are specified. So I don't think that it works
DiSaMe Posted January 18, 2011 Posted January 18, 2011 It's easily scriptable. Scripting with runcode: Done with some other vehicles: -
dragonofdark Posted January 18, 2011 Author Posted January 18, 2011 Thanks Doomed_Space_Marine for this great tutorial But my question was to put a siren on it, not lights
Castillo Posted January 18, 2011 Posted January 18, 2011 I suposed you wanted that too you can add a 3D sound around the vehicle. https://wiki.multitheftauto.com/wiki/PlaySound3D San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
DiSaMe Posted January 18, 2011 Posted January 18, 2011 But my question was to put a siren on it, not lights Damn, I must have read it too quickly, because I don't remember myself getting drunk -
dragonofdark Posted January 18, 2011 Author Posted January 18, 2011 Ahah don't worry Doomed_Space_Marine... Your link is useful for me too Thanks Solidsnake14, so if I'm right, I need to : - Create a car ; - Make a playSound3D ; - Attach playSound3D to the car ; - Create a command to play the sound. Okay ?
Castillo Posted January 18, 2011 Posted January 18, 2011 I guess so San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
madis Posted January 18, 2011 Posted January 18, 2011 (edited) Ahah don't worry Doomed_Space_Marine... Your link is useful for me too Thanks Solidsnake14, so if I'm right, I need to : - Create a car ; - Make a playSound3D ; - Attach playSound3D to the car ; - Create a command to play the sound. Okay ? Unfortunately you can't simply use attach method to attach it (you could add a feature request for that in MTA). You need to add handler method for a render event, and update the sound3d element's position on each call of that handler method. You can get the required position from the vehicle. Update: As SDK noted, it is possible to use attachElements method. I guess I was a bit behind of time with having the deprecated attachElementToElement in mind. Edited January 24, 2011 by Guest
dragonofdark Posted January 18, 2011 Author Posted January 18, 2011 Wow, Now it's more difficult I'll request that for the next version.
SDK Posted January 19, 2011 Posted January 19, 2011 https://wiki.multitheftauto.com/wiki/AttachElements Sure it can be attached like you wrote, no render events are needed. (I've done it before) Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
dragonofdark Posted January 19, 2011 Author Posted January 19, 2011 Hmmm... If you've done it without render events so I'll follow what your said.
dragonofdark Posted January 19, 2011 Author Posted January 19, 2011 Well, I started to script that. But the vehicle isn't there and I can't hear any sound. Here is my meta.xml : <meta> <info author="dragonofdark" version="1.0" name="4X4 avec sirène et gyros" type="misc" /> <script src="sirene.lua" type="client" /> <file src="sons/sirene1.wav" /> </meta> My sirene.lua : function onClientResourceStart() local commandant = createVehicle ( 554, 1227.746, -1422.281, 13.5432, [0, 0, 0, COMM1] ) local x,y,z = getElementPosition( commandant ) local sound = playSound3D("sons/sirene1.wav", 0, 0, 0, true) attachElements ( sound, commandant, 0, 0, 0 ) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onResourceStart) In the script folder I have : - Directory "sons" with my sirene1.wav - meta.xml - sirene.lua It's just a test to see if it can create and attach the siren to it but it doesn't work
SDK Posted January 19, 2011 Posted January 19, 2011 Your code is theoretically pretty good, but you made a lot of errors. And unfortunately, using directories can be quite tricky. I corrected your meta and script and commented the errors. Meta: - The tag src's filename needs to have backslashes ( \ ) instead of slashes ( / ) <meta> <info author="dragonofdark" version="1.0" name="4X4 avec sirène et gyros" type="misc" /> <script src="sirene.lua" type="client" /> <file src="sons\sirene1.wav" /> </meta> createVehicle: - "[" and "]" are not needed for optional arguments and forbidden actually- The num plate needs to be a string playSound3D: - This is the trickiest, you need two backslashes here since Lua interpretes \ in a special way (check here)- play the sound on x, y, z attachElements: - The 0,0,0 are not needed cause they're by default 0,0,0 addEventHandler: - You attached the event to the wrong function (onResourceStart) function onClientResourceStart() local commandant = createVehicle ( 554, 1227.746, -1422.281, 13.5432, 0, 0, 0, "COMM1" ) local x,y,z = getElementPosition( commandant ) local sound = playSound3D("sons\\sirene1.wav", x, y, z, true) attachElements ( sound, commandant ) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onClientResourceStart) Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
dragonofdark Posted January 19, 2011 Author Posted January 19, 2011 The errors are due of it's my first script Hm... Your corrections work well but how can I set up for the siren is listened in more longer distances? And... I can't enter in the vehicle O_o
SDK Posted January 19, 2011 Posted January 19, 2011 You can use these for sound distances (you can click on them): setSoundVolume setSoundMinDistance setSoundMaxDistance And for not being able to enter, I don't know why, maybe cause it's created client side? Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
dragonofdark Posted January 19, 2011 Author Posted January 19, 2011 The problem is that the playSound3D is just client-side... We should ask for this function in further versions.
SDK Posted January 19, 2011 Posted January 19, 2011 That's not a problem or bug, (it's a feature ) Simply create the vehicle serverside and use triggerClientEvent to notify all clients a sound must be attached to that vehicle. Quick script: Server: function testSirene( player, cmd ) local commandant = createVehicle ( 554, 1227.746, -1422.281, 13.5432, 0, 0, 0, "COMM1" ) triggerClientEvent ( "startSirene", player, commandant ) end addCommandHandler ( "testsirene", testSirene) Client: 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", getResourceRootElement(), startSirene) Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
dragonofdark Posted January 19, 2011 Author Posted January 19, 2011 The command "startSirene" doesn't work. (Ahah, you're also Belgian )
Castillo Posted January 19, 2011 Posted January 19, 2011 the command is "testsirene" not "startsirene" o_o San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
dragonofdark Posted January 19, 2011 Author Posted January 19, 2011 Oh damn... But "testsirene" only spawn the vehicle and not the siren...
Castillo Posted January 19, 2011 Posted January 19, 2011 it's giving any error in debugscript? /debugscript 3 in game San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Castillo Posted January 19, 2011 Posted January 19, 2011 change the triggerClientEvent with this one: triggerClientEvent (player, "startSirene", getRootElement(), commandant ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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