Jump to content

Problem with the 3D Musicspeaker


Shuvit

Recommended Posts

Posted

Hey,

I've tried to add the function of moveObject. When i use the command "/placespeaker" while sitting in the car, it will bug. So i tried to move it to the back of the car, but it seems that it does'nt work. It does'nt give any errors or warnings in the debugscript. Could anyone help me?

Best regards,

Shuvit.

-- Server Side

function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    speakerObject = createObject(2232, x, y, z-0.
    outputChatBox("You have Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    if (isPedInVehicle(thePlayer)) then 
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        local origX, origY, origZ = getElementPosition ( speakerObject ) 
        local newY = origY + 3 
        moveObject ( speakerObject, 0, origX, newY, origZ ) 
        attachElements(speakerObject, vehicle) 
        triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle) 
    else 
        triggerClientEvent(root, "playTheSound", root, x, y, z) 
    end 
end 
addCommandHandler("placespeaker", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("You have Succesfully destroyed the Speaker!", thePlayer, 0, 0, 255) 
                triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Speaker is not created!", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("destroyspeaker", deleteSpeaker) 

Posted

What do you mean by "it'll bug"?

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.

  • Moderators
Posted

try:

local x, y, z = getElementPosition(getPedOccupiedVehicle (thePlayer) or thePlayer) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
What do you mean by "it'll bug"?

By placing the speaker, it will bug into the player that is driving. By slowing down the car, your cam will be bugged into the speaker.

  • Moderators
Posted

You can also create offset.

  
--syntax 
attachElements ( element theElement, element theAttachToElement, [ float xPosOffset, float yPosOffset,  
float zPosOffset, float xRotOffset, float yRotOffset, float zRotOffset ] ) 
  
-- try 
attachElements(speakerObject, vehicle,2,0,0) 
  

and no, moveObject doesn't work when the object is attached.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
You can also create offset.
  
--syntax 
attachElements ( element theElement, element theAttachToElement, [ float xPosOffset, float yPosOffset,  
float zPosOffset, float xRotOffset, float yRotOffset, float zRotOffset ] ) 
  
-- try 
attachElements(speakerObject, vehicle,2,0,0) 
  

and no, moveObject doesn't work when the object is attached.

WARNING: 3d_musicspeakers\server.lua:6: Bad argument @'attachElements' [Expected element at argument 2, got nil]

Any suggestions to fix that?

Posted
Try to disable its collisions with
setElementCollisionsEnabled 

That should work.

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
full code?

I accidently pressed spacebar once, the function was correct,

setElementCollisionsEnabled 

worked. Thanks a lot!

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