Jump to content

Help again


sckatchof

Recommended Posts

Posted
local carRadios = { } -- Create a table. 
  
function attachradio ( thePlayer ) 
    local car = getPedOccupiedVehicle ( thePlayer ) 
    if ( car ) then 
        if ( isElement ( carRadios[ car ] ) ) then -- If the vehicle already has a radio... 
            outputChatBox ( "This vehicle already has a radio.", thePlayer, 255, 0, 0 ) 
        else 
            local x, y, z = getElementRotation ( car ) 
            carRadios[ car ] = createObject ( 2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, x, y, z ) -- Create radio object for the vehicle. 
            attachElements ( carRadios[ car ], car, 0, -4, 0.45 ) -- Attach the radio to the vehicle. 
            triggerClientEvent ( "playRadioCar", root, car ) 
            outputChatBox ( "Here is the radio!", thePlayer ) 
        end 
    end 
end 
addCommandHandler ( "radio", attachradio ) 

This will check if the vehicle already has a radio, if so, output a message to the player.

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.

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted

thank you again snake work :D:D

and who can i make a command to destroy attachElement from vehicle and destroy sound like /destoryradio ?

and sorry for inconvenience again :oops:

Posted

-- client side:

sounds = "http://www.181.fm/winamp.pls?station=181-power&style=mp3" 
carSounds = { } 
  
function playRadioCar ( car ) 
    local x,y,z = getElementPosition ( car ) 
    if ( isElement ( carSounds[ car ] ) ) then 
        destroyElement ( carSounds[ car ] ) 
    end 
    carSounds[ car ] = playSound3D ( sounds, x, y, z, true ) 
    attachElements ( carSounds[ car ], car ) 
end 
addEvent ( "playRadioCar", true ) 
addEventHandler( "playRadioCar", getRootElement(), playRadioCar ) 
  
addEvent ( "stopCarRadio", true ) 
addEventHandler ( "stopCarRadio", root, 
    function ( car ) 
        if ( isElement ( carSounds[ car ] ) ) then 
            destroyElement ( carSounds[ car ] ) 
        end 
    end 
) 

-- server side:

local carRadios = { } -- Create a table. 
  
function attachradio ( thePlayer ) 
    local car = getPedOccupiedVehicle ( thePlayer ) 
    if ( car ) then 
        if ( isElement ( carRadios[ car ] ) ) then -- If the vehicle already has a radio... 
            outputChatBox ( "This vehicle already has a radio.", thePlayer, 255, 0, 0 ) 
        else 
            local x, y, z = getElementRotation ( car ) 
            carRadios[ car ] = createObject ( 2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, x, y, z ) -- Create radio object for the vehicle. 
            attachElements ( carRadios[ car ], car, 0, -4, 0.45 ) -- Attach the radio to the vehicle. 
            triggerClientEvent ( "playRadioCar", root, car ) 
            outputChatBox ( "Here is the radio!", thePlayer ) 
        end 
    end 
end 
addCommandHandler ( "radio", attachradio ) 
  
addCommandHandler ( "stopradio", 
    function ( thePlayer ) 
        local car = getPedOccupiedVehicle ( thePlayer ) 
        if ( car ) then 
            if ( not isElement ( carRadios[ car ] ) ) then -- If the vehicle has no radio... 
                outputChatBox ( "This vehicle has no radio.", thePlayer, 255, 0, 0 ) 
            else 
                triggerClientEvent ( "stopCarRadio", root, car ) 
                destroyElement ( carRadios[ car ] ) 
            end 
        end 
    end 
) 

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

try using this

  
addEvent ( "stopCarRadio", true ) 
addEventHandler ( "stopCarRadio", root, 
    function ( car ) 
        if ( isElement ( carSounds[ car ] ) ) then 
            stopSound ( carSounds[ car ] ) 
        end 
    end 
) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted
thannnnnnnnk you snake but sound dont stop when i do /stopradio just speacker destory but music dont stop

The sound is destroyed, it works fine here.

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
try using this
  
addEvent ( "stopCarRadio", true ) 
addEventHandler ( "stopCarRadio", root, 
    function ( car ) 
        if ( isElement ( carSounds[ car ] ) ) then 
            stopSound ( carSounds[ car ] ) 
        end 
    end 
) 

it still work the sound

The sound is destroyed, it works fine here.

idk why dont work for me i tested it i do /radio and the sound start and when i do /stopradio the music still work just speaker destroy

Posted
addEvent ( "stopCarRadio", true ) 
addEventHandler ( "stopCarRadio", root, 
    function ( car ) 
        if ( isElement ( carSounds[ car ] ) ) then 
            stopSound ( Sounds) 
        end 
    end 
) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted

@X-SHADOW: Stop posting the same thing, that'll just stop the sound, it'll stay there still.

@sckatchof: I've tested it with two vehicles, both times is destroyed.

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

Random codes won't help him.

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
thanks all for help but i will try to fix it idk why it dont work for me :(

Are you sure you've copied my last code?

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

Try copying my last code again.

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

hope this work

local s = false 
addCommandHandler ( "stopradio", 
function () 
if s then stopSound(carSounds[ car ]) s = false return end 
end) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted

How could it ever work if you forgot to add this:

addEvent ( "stopCarRadio", true ) 
addEventHandler ( "stopCarRadio", root, 
    function ( car ) 
        if ( isElement ( carSounds[ car ] ) ) then 
            destroyElement ( carSounds[ car ] ) 
        end 
    end 
) 

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