Jump to content

Siren on other cars than police, fire and EMS


dragonofdark

Recommended Posts

Posted

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

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

Posted
But my question was to put a siren on it, not lights :S

Damn, I must have read it too quickly, because I don't remember myself getting drunk :oops:

-

Posted

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 ?

Posted (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 by Guest
Posted

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

Posted

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!

Posted

The errors are due of it's my first script :P

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

Posted

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) 

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!

Posted

the command is "testsirene" not "startsirene" o_o

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

it's giving any error in debugscript? /debugscript 3 in game

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

change the triggerClientEvent with this one:

triggerClientEvent (player, "startSirene", getRootElement(), commandant ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...