Drediks
Developer LUA
Wiek: 30 Na forum: 3352 dni Posty: 44
Nick w MP: Trojka
Piwa : 66
Czo?em ostatnio zacz??em bawi? si? paczk? owla. Spodoba?y mi si? syreny i chcia?bym ich doda? wi?cej pod bindami etc a za bardzo nie wiem jak to zrobi? kto? doradzi?
(kod z pd-system c_sirens.lua)
local sounds = { }
-- Bind Keys required
function bindKeys ( res )
bindKey ( "n" , "down" , toggleSirens )
for key , value in ipairs ( getElementsByType ( "vehicle" )) do
if isElementStreamedIn ( value ) then
if getElementData ( value , "lspd:siren" ) then
sounds [ value ] = playSound3D ( "siren.wav" , 0 , 0 , 0 , true )
attachElements ( sounds [ value ], value )
setSoundVolume ( sounds [ value ], 0.4 )
setSoundMaxDistance ( sounds [ value ], 180 )
setElementDimension ( sounds [ value ], getElementDimension ( value ))
setElementInterior ( sounds [ value ], getElementInterior ( value ))
end
end
end
end
addEventHandler ( "onClientResourceStart" , getResourceRootElement (), bindKeys )
function toggleSirens ()
local theVehicle = getPedOccupiedVehicle ( getLocalPlayer ())
if ( theVehicle ) then
local occupants = getVehicleOccupants ( theVehicle )
if occupants [ 0 ]== getLocalPlayer () then
triggerServerEvent ( "lspd:setSirenState" , theVehicle )
end
end
end
addCommandHandler ( "togglesirens" , toggleSirens , false )
function streamIn ()
if getElementType ( source ) == "vehicle" and getElementData ( source , "lspd:siren" ) and not sounds [ source ] then
sounds [ source ] = playSound3D ( "siren.wav" , 0 , 0 , 0 , true )
attachElements ( sounds [ source ], source )
setSoundVolume ( sounds [ source ], 0.4 )
setSoundMaxDistance ( sounds [ source ], 180 )
setElementDimension ( sounds [ source ], getElementDimension ( source ))
setElementInterior ( sounds [ source ], getElementInterior ( source ))
end
end
addEventHandler ( "onClientElementStreamIn" , getRootElement (), streamIn )
function streamOut ()
if getElementType ( source ) == "vehicle" and sounds [ source ] then
destroyElement ( sounds [ source ] )
sounds [ source ] = nil
end
end
addEventHandler ( "onClientElementStreamOut" , getRootElement (), streamOut )
function updateSirens ( name )
if name == "lspd:siren" and isElementStreamedIn ( source ) and getElementType ( source ) == "vehicle" then
local attached = getAttachedElements ( source )
if attached then
for key , value in ipairs ( attached ) do
if getElementType ( value ) == "sound" and value ~= sounds [ source ] then
destroyElement ( value )
end
end
end
if not getElementData ( source , name ) then
if sounds [ source ] then
destroyElement ( sounds [ source ] )
sounds [ source ] = nil
end
else
if not sounds [ source ] then
sounds [ source ] = playSound3D ( "siren.wav" , 0 , 0 , 0 , true )
attachElements ( sounds [ source ], source )
setSoundVolume ( sounds [ source ], 0.4 )
setSoundMaxDistance ( sounds [ source ], 180 )
setElementDimension ( sounds [ source ], getElementDimension ( source ))
setElementInterior ( sounds [ source ], getElementInterior ( source ))
end
end
end
end
addEventHandler ( "onClientElementDataChange" , getRootElement (), updateSirens )
(kod z pd-system s_sirens.lua)
function vehicleBlown ()
exports . anticheat : changeProtectedElementDataEx ( source , "lspd:siren" , false )
setVehicleSirensOn ( source , false )
end
addEventHandler ( "onVehicleRespawn" , getRootElement (), vehicleBlown )
function setSirenState ()
if exports .global: hasItem ( source , 85 ) then -- sirens
local curState = getElementData ( source , "lspd:siren" )
exports . anticheat : changeProtectedElementDataEx ( source , "lspd:siren" , not curState )
setVehicleSirensOn ( source , not curState )
end
end
addEvent ( "lspd:setSirenState" , true )
addEventHandler ( "lspd:setSirenState" , getRootElement (), setSirenState )
function isOwnedByFactionType ( vehicle , factiontypes )
local vehicleFactionID = getElementData ( vehicle , "faction" )
local vehicleFactionElement = exports . pool : getElement ( "team" , vehicleFactionID )
if vehicleFactionElement then
local vehicleFactionType = getElementData ( vehicleFactionElement , "type" )
for key , factionType in ipairs ( factiontypes ) do
if factionType == vehicleFactionType then
return true
end
end
end
return false
end
function addSirens ( player , seat )
if player and ( seat == 0 ) then
if ( getVehicleName ( source ) == 'Police LV' ) or ( getVehicleName ( source ) == 'Police SF' ) or ( getVehicleName ( source ) == 'FBI rancher' ) or ( getVehicleName ( source ) == 'Police LS' ) then
addVehicleSirens ( source , 8 , 2 , false , true , true , true )
-- vehicle , sirenPoint , x , y , z , r , g , b , alpha , minAlpha
setVehicleSirens ( source , 1 , 0.5 , - 0.3 , 1 , 0 , 0 , 255 , 255 , 255 )
setVehicleSirens ( source , 2 , 0 , - 0.3 , 1 , 255 , 255 , 255 , 255 , 255 )
setVehicleSirens ( source , 3 , - 0.5 , - 0.3 , 1 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 4 , - 0.3 , - 1.9 , 0.4 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 5 , 0.3 , - 1.9 , 0.4 , 0 , 0 , 255 , 255 , 255 )
setVehicleSirens ( source , 6 , 0.0 , - 2.95 , - 0.1 , 255 , 215 , 0 , 100 , 100 )
setVehicleSirens ( source , 7 , - 0.3 , 2.7 , 0.0 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 8 , 0.3 , 2.7 , 0.0 , 0 , 0 , 255 , 255 , 255 )
elseif( getVehicleName ( source ) == 'Ambulance' ) then
addVehicleSirens ( source , 7 , 2 , false , true , true , true )
-- vehicle , sirenPoint , x , y , z , r , g , b , alpha , minAlpha
-- lightbar
setVehicleSirens ( source , 1 , 0.5 , 0.9 , 1.3 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 2 , 0 , 0.9 , 1.3 , 255 , 255 , 255 , 255 , 255 )
setVehicleSirens ( source , 3 , - 0.5 , 0.9 , 1.3 , 255 , 0 , 0 , 255 , 255 )
-- right side
setVehicleSirens ( source , 4 , 1.3 , 0.2 , 1.5 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 5 , 1.3 , - 3.3 , 1.5 , 255 , 0 , 0 , 255 , 255 )
-- left side
setVehicleSirens ( source , 6 , - 1.3 , 0.2 , 1.5 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 7 , - 1.3 , - 3.3 , 1.5 , 255 , 0 , 0 , 255 , 255 )
elseif( getVehicleName ( source ) == 'Fire Truck' ) then
addVehicleSirens ( source , 7 , 2 , false , true , true , true )
-- lightbar
setVehicleSirens ( source , 1 , 0.6 , 3.2 , 1.4 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 2 , 0 , 3.2 , 1.4 , 255 , 255 , 255 , 255 , 255 )
setVehicleSirens ( source , 3 , - 0.6 , 3.2 , 1.4 , 255 , 0 , 0 , 255 , 255 )
-- rear
setVehicleSirens ( source , 4 , 0.4 , - 3.7 , 0.4 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 5 , - 0.4 , - 3.7 , 0.4 , 255 , 0 , 0 , 255 , 255 )
-- grill
setVehicleSirens ( source , 6 , 0.6 , 4.2 , 0.1 , 255 , 0 , 0 , 255 , 255 )
setVehicleSirens ( source , 7 , - 0.6 , 4.2 , 0.1 , 255 , 0 , 0 , 255 , 255 )
elseif( getVehicleName ( source ) == 'Fire Truck Ladder' ) then
-- not working ( vehicle is probably one of the few models that does not support sirens )
elseif( getVehicleName ( source ) == 'Towtruck' ) then
addVehicleSirens ( source , 3 , 4 , true , true , true , true )
setVehicleSirens ( source , 1 , - 0.7 , - 0.35 , 1.5250904560089 , 255 , 0 , 0 , 255 , 0 )
setVehicleSirens ( source , 2 , 0 , - 0.35 , 1.5250904560089 , 255 , 198 , 10 , 255 , 0 )
setVehicleSirens ( source , 3 , 0.7 , - 0.35 , 1.5250904560089 , 255 , 0 , 0 , 255 , 0 )
end
end
end
addEventHandler ( "onVehicleEnter" , getRootElement (), addSirens )