Jump to content

Siren on other cars than police, fire and EMS


dragonofdark

Recommended Posts

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

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

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

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

Ek, just a last little question and I'll leave you alone :S

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

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

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
  • 2 months later...

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

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 by Guest
Link to comment
  • 3 months later...

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