Author Topic: On projectileCollision function  (Read 786 times)

When a projectile Collides
Do some search in a small radius for a player
If a player is detected, have that player play a sound

How would i do this?

Let's say you have a projectile datablock called MyProjectile. Start with the following code block, and add code to alter what happens when it collides with things.

Code: [Select]
function MyProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
}

You can search for things in a radius with InitContainerRadiusSearch. A simple example that finds all players in a radius about an arbitrary point:
Code: [Select]
InitContainerRadiusSearch(%center, %radius, $Typemasks::PlayerObjectType);
while(%detected = containerSearchNext())
{
echo("Found " @ %detected @ " at position (" @ %detected.getPosition() @ ")");
}

Finally, the following function will play a sound at a given position.
Code: [Select]
serverPlay3d(MySound, %pos);

Yep, last Function is easy, i use it alot

Thanks for the help

I already use the Function:
OnProjectile::Collide

To play a sound