Jump to content

Help again


sckatchof

Recommended Posts

Posted

hi guys i have problem when i do /radio the speaker attach to vehicle but only one player get the speaker when anther player do /radio the speaker change to his car and it removed from my vehicle this is my script

carRadio = createObject(2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, 0, 2, 30) 
  
function attachradio(thePlayer) 
   local car = getPedOccupiedVehicle(thePlayer) 
   if(car) then 
      local x, y, z = getElementRotation(car) 
      setObjectRotation(carRadio, x, y, z) 
      triggerClientEvent ( thePlayer, "playRadioCar", getRootElement(), car) 
      attachElements(carRadio, car, 0, -4, 0.45) 
      setObjectRotation(carRadio, x, y, z) 
      outputChatBox("Here is the radio!", thePlayer) 
end 
end 
addCommandHandler("radio", attachradio) 
  

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted

You need create the object every time a player types /radio and attach the created object to the vehicle.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted (edited)
addCommandHandler ( 'radio',  
    function ( player, command ) 
        if ( getPedOccupiedVehicle ( player ) ) then 
            local carRadio = createObject ( 2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, 0, 2, 30 ); 
            local x, y, z = getElementRotation ( getPedOccupiedVehicle ( player ) ); 
            triggerClientEvent ( 'playRadioCar', root, getPedOccupiedVehicle ( player ) ) 
            attachElements ( carRadio, getPedOccupiedVehicle ( player ), 0, -4, 0.45 ); 
            setObjectRotation ( carRadio, x, y, z ); 
            outputChatBox ( 'Here is the radio!', player ); 
        end 
    end 
) 
  

Edited by Guest

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted
carRadio = createObject(2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, 0, 2, 30) 
  
function attachradio() 
   local car = getPedOccupiedVehicle(source) 
   if(car) then 
      local x, y, z = getElementRotation(car) 
      setObjectRotation(carRadio, x, y, z) 
      triggerClientEvent ( source, "playRadioCar", car) 
      attachElements(carRadio, car, 0, -4, 0.45) 
      setObjectRotation(carRadio, x, y, z) 
      outputChatBox("Here is the radio!", source) 
end 
end 
addCommandHandler("radio", attachradio) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted

and how to make it defined

i see all functions in mta wiki all like this

getPlayerPing = (source)

just like me

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted

addCommandHandler has no source. You need define in function.

Example:

addCommandHandler ( 'blabla',  
   function ( player, command ) 
        -- something 
   end 
) 

Here, player is the source player.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

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... 
            destroyElement ( carRadios[ car ] ) -- Destroy it. 
        end 
        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 ( thePlayer, "playRadioCar", getRootElement(), car ) 
        outputChatBox ( "Here is the radio!", thePlayer ) 
    end 
end 
addCommandHandler ( "radio", attachradio ) 

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

The script creates the radio object, I've tested and it worked.

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
The script creates the radio object, I've tested and it worked.

sorry i edit my post it work thank yooou :D

but i have anther problem when i do /radio start music attach to my car it work but me can listen but anther players can't listen

this is my script

.. 
  
sounds = "http://www.181.fm/winamp.pls?station=181-power&style=mp3" 
function playRadioCar ( car ) 
            local x,y,z = getElementPosition( car ) 
            sound = playSound3D( sounds, x, y, z, true) 
            attachElements ( sound, car) 
 end 
addEvent( "playRadioCar", true ) 
addEventHandler("playRadioCar", getRootElement(), playRadioCar) 
  

Posted

playSound3D plays the sound only for localPlayer.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

Like:

triggerClientEvent ( 'playRadioCar', root ) 

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted
Like:
triggerClientEvent ( 'playRadioCar', root ) 

i add that look to server side it work sound when i do /radio but just on player can lesten to music i want just players near to the car can listen to music

Posted

-- client side:

sounds = "http://www.181.fm/winamp.pls?station=181-power&style=mp3" 
  
function playRadioCar ( car ) 
    local x,y,z = getElementPosition ( car ) 
    sound = playSound3D ( sounds, x, y, z, true ) 
    attachElements ( sound, car ) 
end 
addEvent ( "playRadioCar", true ) 
addEventHandler( "playRadioCar", getRootElement(), playRadioCar ) 

-- 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... 
            destroyElement ( carRadios[ car ] ) -- Destroy it. 
        end 
        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 
addCommandHandler ( "radio", attachradio ) 

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

thank you snake for help work :) i have anther question how can i make if player do /radio and get to anther car and do /radio

it radio remouve with music and create to his car or he have already the radio it show outputChatBox ( "tthe radio is already exists", thePlayer ) .

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