Msypon Posted January 27, 2013 Posted January 27, 2013 Hi guys, i want to attach a sound box on my car but what is wrong? server box = { } addCommandHandler ( "caf", function ( source, commandName ) local veh = getPedOccupiedVehicle ( source ) local x, y, z = getElementPosition ( veh ) box [ source ] = createObject ( 2229, x, y, z ) local ax, ay, az = getElementPosition ( box [ source ] ) attachElements ( box [ source ], veh, 0.3, -2.3, 0 ) triggerClientEvent ( 'boxattach', root, box, ax, ay, az ) end ) client addEvent ( 'boxattach', true ) addEventHandler ( 'boxattach', root, function ( box, ax, ay, az, url ) sound = playSound3D(url, ax, ay, az, true) setSoundMaxDistance ( sound, 100 ) attachElements ( sound, box [ localPlayer ] ) end )
Ab-47 Posted January 27, 2013 Posted January 27, 2013 box = { } addCommandHandler ( "caf", function ( source, commandName ) local veh = getPedOccupiedVehicle ( source ) local x, y, z = getElementPosition ( veh ) box[source] = createObject ( 2229, x, y, z ) local ax, ay, az = getElementPosition ( box[source] ) attachElements ( box[source], veh, 0.3, -2.3, 0 ) triggerClientEvent ( 'boxattach', root, box, ax, ay, az ) end ) addEvent ( 'boxattach', true ) addEventHandler ( 'boxattach', root, function ( box, ax, ay, az, url ) sound = playSound3D(url, ax, ay, az, true) setSoundMaxDistance ( sound, 100 ) attachElements ( sound, box[localPlayer] ) end ) Try use 'box [ source ]' & 'box [ localPlayer ]' without spaces, like; 'box[source]' & 'box[localPlayer]'. That was my problem with another script.
iPrestege Posted January 27, 2013 Posted January 27, 2013 Server : box = { } addCommandHandler ( "caf", function ( plr, commandName ) if isPedInVehicle(plr) then local veh = getPedOccupiedVehicle ( plr ) local x, y, z = getElementPosition ( plr ) if isElement(box[plr]) then destroyElement(box[plr]) box[plr] = nil end box[plr] = createObject ( 2229, x, y, z ) local ax, ay, az = getElementPosition ( box[plr] ) attachElements ( box[plr], veh, 0.3, -2.3, 0 ) triggerClientEvent ( plr, 'boxattach', root, box[plr], ax, ay, az) end end ) addEventHandler("onPlayerQuit",root, function () if isElement(box[source]) then destroyElement(box[source]) box[source] = nil end end ) Client : local sound = nil addEvent ( 'boxattach', true ) addEventHandler ( 'boxattach', root, function ( box, ax, ay, az) local url = "" --here link sound if isElement(sound) then destroyElement(sound) sound = nil end sound = playSound3D(url, ax, ay, az, true) setSoundMaxDistance ( sound, 100 ) attachElements ( sound, box) end )
Msypon Posted January 27, 2013 Author Posted January 27, 2013 It worked prestagi, but only me can listen the music, I want everyone
iPrestege Posted January 27, 2013 Posted January 27, 2013 It worked prestagi, but only me can listen the music, I want everyone Server : box = { } addCommandHandler ( "caf", function ( plr, commandName ) if isPedInVehicle(plr) then local veh = getPedOccupiedVehicle ( plr ) local x, y, z = getElementPosition ( plr ) if isElement(box[plr]) then destroyElement(box[plr]) box[plr] = nil end box[plr] = createObject ( 2229, x, y, z ) local ax, ay, az = getElementPosition ( box[plr] ) attachElements ( box[plr], veh, 0.3, -2.3, 0 ) triggerClientEvent ( root, 'boxattach', root, box[plr], plr, ax, ay, az) end end ) addEventHandler("onPlayerQuit",root, function () if isElement(box[source]) then destroyElement(box[source]) box[source] = nil end end ) Client : local sound = {} addEvent ( 'boxattach', true ) addEventHandler ( 'boxattach', root, function ( box, plr, ax, ay, az) local url = "" --here link sound if isElement(sound[plr]) then destroyElement(sound[plr]) sound[plr] = nil end sound[plr] = playSound3D(url, ax, ay, az, true) setSoundMaxDistance ( sound[plr], 100 ) attachElements ( sound[plr], box) end ) addEventHandler("onClientPlayerQuit",root, function () if isElement(sound[source]) then destroyElement(sound[source]) sound[source] = nil end end ) My bad i change it to player "only" .
Msypon Posted January 27, 2013 Author Posted January 27, 2013 Thx worked, i need another help with this addEvent ( 'pRemove', true ) addEventHandler ( 'pRemove', root, function ( ) if isElement(sound[source]) then stopSound ( sound[source] ) destroyElement(sound[source]) sound[source] = nil end end ) The sound is not stopping
Msypon Posted January 27, 2013 Author Posted January 27, 2013 addCommandHandler ( 'remspe', function ( source, cmd ) if ( isElement ( box[source] ) ) then destroyElement ( box[source] ) triggerClientEvent ( root, 'pRemove', root ) end end )
TAPL Posted January 27, 2013 Posted January 27, 2013 -- Server Side -- addCommandHandler('remspe', function(source) if isElement(box[source]) then destroyElement(box[source]) triggerClientEvent(root, 'pRemove', root, source) end end) -- Client Side -- addEvent('pRemove', true) addEventHandler('pRemove', root, function(player) if isElement(sound[player]) then stopSound(sound[player]) destroyElement(sound[player]) sound[player] = nil end end)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now