Jump to content

Siren on other cars than police, fire and EMS


dragonofdark

Recommended Posts

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 by Guest
Link to comment

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 :S

Link to comment

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) 

Link to comment

That's not a problem or bug, (it's a feature 8))

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) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...