finding a items "maker" on collision

Author Topic: finding a items "maker" on collision  (Read 1351 times)

ok, well i'm pretty new to coding so basically ive been messing around with stuff and I want
to be able to (on collision) find out if a player that touches a item object is the "maker of that object"

(this current code works well)

//this is where the object is created
%obj.client.bomb = new item()
{
     position = %location;
     rotation = "1 0 0 0";
     scale = "1 1 1";
     dataBlock = "Bomb";
};

function bomb::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
    if(%col.getclassname() $= "player")
    {
        messageall('',"someone touched a bomb!");
    }
}
« Last Edit: September 14, 2007, 08:47:27 PM by Melting Plastic »

Is this going to be a weapon you fire?

If so, you need to define 3 separate bomb datablocks.

bombItem - What the player can pick up.
bombImage - What the player holds as he uses the item.
bombProjectile - What the player fires as he uses the item.

Now, the projectile has a sourceObject property that tells you the player that fired the projectile.

Code: [Select]
function bombProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
     if(%col.getclassname() $= "Player" && %obj.sourceObject == %col)
     {
          <your code goes here>
     }
}
« Last Edit: September 15, 2007, 12:52:35 PM by Trader »

well basically i'm messing around with the remote bomb, and trying to make it so if you collide with someone elses bomb it explodes, but if you collide with your own bomb it doesnt.

thanks alot, and yes i have all those datablocks (i just didnt show all of the in my post) - thanks again trader!
« Last Edit: September 15, 2007, 12:45:08 PM by Melting Plastic »

Yeah, if you're doing it like that, just have your collision method pass the sourceObject property to your new staticShape.  Also, if you're expanding on the remote bomb, I recommend a few house-cleaning changes:

Make it so that it keeps track of how many bombs you've placed (or just run a search for the bomb objects) so that when a player leaves the game, his bombs are removed.

Similar to the last one, if a player plants a bomb in a mini-game and leaves the mini-game, his bombs should be removed.

Also related to the other two, when a mini-game ends, all bombs created by the minigame players should be removed.

Thanks for the advice - i'll work on it.