Author Topic: Detect when an Object (.DTS model) lands near player  (Read 4050 times)

When Object.DTS (or something) lands next to a player with in a 5 TU radius. Have that player play a 3d sound.
How would we do this?

Okay so pretty much what im gunning for here is this: i have a grenade, when it lands next to a player i want the player that the grenade landed by to play a 3D sound. so the .DTS model would be the grenade?

« Last Edit: November 19, 2014, 07:40:53 PM by Ctrooper »

Not enough information. What datablock will the dts be? How will the item appear? Give us some code.

What datablock will the dts be?
This isn't really important as far as giving him help, we can just give a placeholder name
But we do need what type of object it is; what class, because that affects:
How will it appear?
You say "a dts model" so I'm thinking you mean a staticshape, so handle that in the code that creating a staticshape
But then you say "lands near" so now I'm thinking a projectile (package ::onCollision) or a vehicle (I think I remember OnCollision not doing much for vehicles, you might have you write a ticking function that scans for players near it?)


What, specifically, are you trying to do

This isn't really important as far as giving him help, we can just give a placeholder name
Datablock !$= name. I'm talking about what kind of datablock. itemData, staticShape, etc.

Datablock !$= name. I'm talking about what kind of datablock. itemData, staticShape, etc.
The word is class, and that's what I said

This isn't really important as far as giving him help, we can just give a placeholder name

What, specifically, are you trying to do
That right there was an oxymoron.

That right there was an oxymoron.
No it's not
I'm addressing two different things, which the previous two posts explain

You said that Jes's specification isn't important but at the end of the post said that in order for you to help him he needs to be more specific. I won't post on this subject anymore as to not derail the topic though.

You said that Jes's specification isn't important but at the end of the post said that in order for you to help him he needs to be more specific. I won't post on this subject anymore as to not derail the topic though.
Which datablock name isn't important. That's what jess (or at least the way he worded it) was asking.
Which datablock class is. That's what I'm asking

This is the fourth time stating this. If you don't understand the difference, don't tell people who do that they're taking oxymorons

Datablock !$= name.
I hate myself for this.

Anyways, me arguing over pointless semantics aside, what is the answer?

It's not "pointless semantics"
There's a very real, and very important, difference between an object's name and an object's class.

What question? The op's question? That can't be answer with the information given

And Jes wasn't asking for the Object's name. And the last part was directed at OP.


Wtf guys, stop arguing in help threads lol. It's just gonna be confusing when the OP comes back and is trying to figure out what we're saying.

Really the only way to do this, regardless of what kind of object it is, is to write a function on that object to for players within 5 TU to hear a sound. You said that the object "lands," so I assume that means it moves. The question is, do you only need to search the moment it lands, or does it stay behind and keep playing sounds? Since it lands, I'm assuming it flies, do you want players that get near it while it's flying to hear anything?

Anyway, a function to play sounds should be written like this:

function YourDatablock::playSoundRadius(%datablock, %object) {
    %position = %object.getPosition();
    %radius = 5;
    initContainerRadiusSearch(%position, %radius, $TypeMasks::PlayerObjectType);
    while(%player = containerSearchNext()) {
        if(isObject(%player.client))
            %player.client.play3d(YourSoundDatablock, %position);
    }
}


Bolded is what needs to be changed to fit your specific needs.

Then you need to figure out when to call that function. You could call it when it hits something and has mostly downward velocity (lands), you can call it periodically, you could play it periodically until it lands, etc. Static Shapes, afaik, are, well, static. They don't move, so they don't collide. Probably the best way to have a moving object (.dts) is to make it a vehicle much like the Ball vehicle. You can copy that script and change stuff to fine-tune it to your needs.

Assuming you wanted to do it when it lands (correct me if I'm wrong here) the code should look something like this:

function YourDatablock::onImpact(%datablock, %vehicle, %collidingObject, %position, %speed) {
    %retVal = parent::onImpact(%datablock, %vehicle, %collidingObject, %position, %speed);
    %datablock.playSoundRadius(%vehicle);
    return %retVal;
}


Yeah you kinda did lol
I mean now I know what you meant, but all you said then was "datablock"


Wtf guys, stop arguing in help threads lol. It's just gonna be confusing when the OP comes back and is trying to figure out what we're saying.
Well its been almost two days since thread creation and no word from op so it's not like we're really derailing anything

To clear up any confusion, the only thing he really needs to worry about is what you posted, which is a good start (the ::onImpact function might not apply, depending on what he's trying to do), and
What, specifically, are you trying to do