Jump to content

Attaching sound to player


sacr1ficez

Recommended Posts

Posted

Hey. I have question, if i attach sound to player i need destroy it?

By using attachElements or

attachElementToBone(aSound, source, 3, 0.19, -0.31, -0.1, 0, 270, -90)

 

Thanks for help anyway.

  • Moderators
Posted

You can also make the sound a child of a player.

setElementParent(sound, player)

 

This will auto destroy the sound when the player leaves the server.

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted (edited)
1 hour ago, Peti said:

You want to destroy an attached sound?

No, i want to know if i need to destroy sound. Attached sound have normal behaviour like sound which isn't attached to player? (loop = false)

Edited by majqq
  • Moderators
Posted
1 hour ago, majqq said:

No, i want to know if i need to destroy sound. Attached sound have normal behaviour like sound which isn't attached to player? (loop = false)

If it is not looped or streamed, then it will destroy itself when it ends.

  • Like 1
  • Thanks 1

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

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
On 01/02/2019 at 17:23, IIYAMA said:

You can also make the sound a child of a player.


setElementParent(sound, player)

 

This will auto destroy the sound when the player leaves the server.

You sure about that?
On the wiki it says:

Quote

This function does not change when an element will be destroyed - Elements are always destroyed when the resource that created them is stopped.

 

  • Thanks 1
  • Moderators
Posted
39 minutes ago, Pirulax said:

You sure about that?
On the wiki it says:

 

Quote

This function does not change when an element will be destroyed - Elements are always destroyed when the resource that created them is stopped.

That is about this:

 

1.

Resource 1

<resourceRoot></resourceRoot>

 

Resource 2

<resourceRoot></resourceRoot>

 

------------------------------

 

2.

 

Resource 1

example = createElement("example", "example")
<resourceRoot>
	<example id="example"></example>
</resourceRoot>

 

Resource 2

<resourceRoot></resourceRoot>

 

------------------------------

 

3.

Resource 1

<resourceRoot>
	<example id="example"></example>
</resourceRoot>

 

example = getElementByID("example")
setElementParent(example, resourceRoot)

New structure:

<resourceRoot></resourceRoot>

 

Resource 2

<resourceRoot>
	<example id="example"></example>
</resourceRoot>

 

------------------------------

 

It looks now as if the element <example> has been transferred to another resource. But it didn't.
It is still part of resource 1. If you stop resource 1, then the <example> element will still be destroyed. < that comment it about his.
And the funny thing is, that <example>  will ALSO be destroyed when you stop resource 2

That poor example does not stand a chance! :microwave:

 

And this comment for some reason doesn't make sense, because I have never seen this happen.

Quote

Note: When an element is destroyed, its parent becomes the new parent of its children.

 

 

 

 

 

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

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

@majqq@Pirulax

I am terrible sorry. It seems like my information is partly incorrect.

 

I tested it:

  • It seems that it only will destroy children when you manually destroy an element. (It will only destroy it's children with destroyElement + propagation is enabled)
    Quote

    And the funny thing is, that <example>  will ALSO be destroyed when you stop resource 2

     

  • And changing the parent to player doesn't work.
     

    Quote

    setElementParent(sound, player)

     

 

 

Information that is still correct:

  • Sound elements do destroy them self after ending.

 

 

  • Thanks 1

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
6 hours ago, IIYAMA said:

@majqq@Pirulax

I am terrible sorry. It seems like my information is partly incorrect.

 

I tested it:

  • It seems that it only will destroy children when you manually destroy an element. (It will only destroy it's children with destroyElement + propagation is enabled)

     

  • And changing the parent to player doesn't work.
     

     

 

 

Information that is still correct:

  • Sound elements do destroy them self after ending.

 

 

 

What about your solution for this? 

 

Because i didn't test it/create it yet. Everything should be okay?

 

 

  • Like 1
  • Moderators
Posted
13 minutes ago, majqq said:

 

What about your solution for this? 

 

Because i didn't test it/create it yet. Everything should be okay?

 

 

That should be fine, as long as the sound stays the child and not the parent.

 

  • Like 1

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

 

  Useful functions  3x 

  Tutorials  4x 

 

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