I asked this question not even a week ago, but might as well ask it again since it's been plaguing all of my scripts. The question was "how do I stop a script from repeating before it's finished." I didn't give any details as to what it was, but I was trying to make a custom siren for police vehicles. I've been working on it for literally weeks and still can't find a solution and have remade the script several times over it trying to figure out how to stop it. This is what I have so far if you're interested.
function startMySound()
local driver = getVehicleOccupant ( source )
if ( driver ) then
sound = playSound( "sound1.mp3", true )
end
end
addEventHandler( "onClientVehicleEnter", root, startMySound )
addCommandHandler ( "siren", startMySound)
function stopMySound()
stopSound( sound )
end
addCommandHandler ( "stopsound", stopMySound )
addEventHandler( "onClientVehicleStartExit", root, stopMySound )
function bindTheKeys ()
bindKey ( "1", "up", startMySound )
bindKey ( "2", "up", stopMySound )
end
addCommandHandler ( "bindme", bindTheKeys )
addEventHandler("onClientResourceStart", resourceRoot, bindTheKeys)
function disableSirens ( theVehicle, seat )
local id = getElementModel ( theVehicle )
if id == 596 or id == 598 or id == 597 then
toggleControl ( "horn", false )
else
toggleControl ( "horn", true )
end
end
addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableSirens )
The sound just goes on top of eachother everytime it is activated and I don't know how to prevent it. This script is far from complete, but just trying to make out my question clearly this time around with video this time .
The script I'm working on and also having this problem with is my toll both script. I've spent almost a week on this as well and barely got it functioning correctly today, but I'm still having the same problem with no solution. The main command activates over and over again and I don't know how to prevent it and can't find a solution.
local gate1 = createObject(968, 1544.6999511719, -1623.9000244141, 13, 0, 89.1, 270)
local marker1 = createMarker(1544.5, -1628, 13.5, "cylinder",6,225,225,255,25)
function moveToll(player)
local player
if source == marker1 then
moveObject(gate1, 2000, 1544.6999511719, -1623.9000244141, 13, 0, -89.1, 0)
if moveObject then setTimer(gate2, 4000, 1, true)
end
end
end
addEventHandler("onClientMarkerHit", root, moveToll)
function gate2()
moveObject(gate1, 2000, 1544.6999511719, -1623.9000244141, 13, 0, 89.1, 0)
end