Author Topic: On Brick Hit If Projectile  (Read 2951 times)

How would I code a brick so that when it's hit it checks if the projectile is SkillPickaxe and if so it does stuff?

On the projectile's onCollision function, if it hits a brick, make it process the input event.

if it hits a brick, make it process the input event.
How would I make it check if it hit a brick? why would I want to process the input event?
« Last Edit: November 25, 2011, 06:55:06 PM by jes00 »

Something like yourweaponprojectile::oncollision

Code: [Select]
function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(!(%col.getType() & $TypeMasks::FxBrickObjectType))
return;

//Do brick collision stuff here, %col is the brick, %obj is the projectile
}

If your projectile is named something different, change the SkillPickaxeProjectile part.

He wants to know how he can do it with events.

He wants to know how he can do it with events.
you couldn't tell the brick to call the event from that?

Code: [Select]
function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(!(%col.getType() & $TypeMasks::FxBrickObjectType))
return;

//Do brick collision stuff here, %col is the brick, %obj is the projectile
}

If your projectile is named something different, change the SkillPickaxeProjectile part.
So this should work?
Code: [Select]
function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(!(%col.getType() & $TypeMasks::FxBrickObjectType))
return;

if(%col.isOre == 1)
{
if(%col.Health >= 1)
{
%col.Health -= getRandom(1,5);
commandToClient(%this,'centerPrint',"\c6You swing your pick at the ore.",3);
}

else if(%col.Health < 1)
{
%col.Health = %col.defaultHealth;
%col.Dissapear(%col.regrowTime);
%this.Resources +=  %col.oreAmount;
messageClient(%this,'',"\c3You have mined some \c6" @ %col.oreName @ "\c3.");
}
}
}

EDIT: Does not work. When the pickaxe hits it nothing happens.
He wants to know how he can do it with events.
Wrong sir.

DOUBLE EDIT: Here is the projectile data for the pickaxe:
Code: [Select]
datablock ProjectileData(SkillPickaxeProjectile)
{
   directDamage        = 1;
   directDamageType  = $DamageType::SkillPickaxe;
   radiusDamageType  = $DamageType::SkillPickaxe;
   explosion           = SkillPickaxeExplosion;

   muzzleVelocity      = 50;
   velInheritFactor    = 1;

   armingDelay         = 0;
   lifetime            = 100;
   fadeDelay           = 70;
   bounceElasticity    = 0;
   bounceFriction      = 0;
   isBallistic         = false;
   gravityMod = 0.0;

   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 0 0.5";

   uiName = "Skill Pickaxe Hit";
};
« Last Edit: November 26, 2011, 04:40:52 PM by jes00 »

Wait, are you using a custom brick? If you are you should include "isOre" in it's datablock along with all the other values.

Example:
Code: [Select]
datablock fxDTSBrickData (brickRPGOredata : brick1x1data)
{
category = "RPG";
subCategory = "Ore";
uiName = "Ore";

        isOre = 1;
        Health = 200;
        defaultHealth = 200;
        regrowtime = 20;
        oreAmount = 50;
        oreName = "Mashed diamonds";
};

So when you use SkillPickaxeProjectile::onCollision, make sure to use "if(%col.getDataBlock().isOre)". I don't think "== 1" is really needed.

Example:
Code: [Select]
function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(!(%col.getType() & $TypeMasks::FxBrickObjectType))
return;

if(%col.getDataBlock().isOre) ///// == 1)
{
if(%col.getDatablock().Health >= 1)
{
%col.getDataBlock().Health -= getRandom(1,5);
commandToClient(%this,'centerPrint',"\c6You swing your pick at the ore.",3);
}

else if(%col.getDatablock().Health < 1)
{
%col.getDatablock().Health = %col.getDataBlock().defaultHealth;
%col.Dissapear(%col.getDatablock().regrowTime);
%this.Resources +=  %col.getDataBlock().oreAmount;
messageClient(%this,'',"\c3You have mined some \c6" @ %col.getDataBlock().oreName @ "\c3.");
}
}
}

I haven't tested this, but I'm pretty sure it will do something. The old CityRPG uses the datablock idea to manage how much ore or lumber it had left in a brick I believe.

Wait, are you using a custom brick? If you are you should include "isOre" in it's datablock along with all the other values.

Example:
-code-

So when you use SkillPickaxeProjectile::onCollision, make sure to use "if(%col.getDataBlock().isOre)". I don't think "== 1" is really needed.

Example:
-code-

I haven't tested this, but I'm pretty sure it will do something. The old CityRPG uses the datablock idea to manage how much ore or lumber it had left in a brick I believe.
Here is the result:
When I hit it with the pickaxe nothing happens (still).

EDIT: Here is one of the brick files:
Code: [Select]
//=========================================================================
// Brick Register
//=========================================================================
datablock fxDTSBrickData(CoalOreData)
{
brickFile = "base/data/bricks/bricks/2x2.blb";
category = "Special";
subCategory = "Interactive";
uiName = "Coal";
iconName = "base/client/ui/brickicons/2x2";

oreName = "Coal";
Health = 100;
isOre = 1;
regrowTime = 60;
oreAmount = 10;
defaultHealth = 100;
};

Also how could I make it so you must be an admin to place ore?
« Last Edit: November 27, 2011, 06:53:29 AM by jes00 »

Is there any chance that the brick isn't raycasting? Try replacing the getType part with:
Code: [Select]
if(%col.getClassName() !$ = "fxDtsBrick")
        return;
If that doesn't work, then dump %col and see what it is, there might be something wrong with the args.

For the admin only brick thing, you would package fxDtsBrick::onPlant(%brick), get the brick group from the object and if the .client value of the brickgroup is an object and the client isn't admin, delete the brick (and show them a message, I guess).

Is there any chance that the brick isn't raycasting? Try replacing the getType part with:
Code: [Select]
if(%col.getClassName() !$ = "fxDtsBrick")
        return;
If that doesn't work, then dump %col and see what it is, there might be something wrong with the args.

For the admin only brick thing, you would package fxDtsBrick::onPlant(%brick), get the brick group from the object and if the .client value of the brickgroup is an object and the client isn't admin, delete the brick (and show them a message, I guess).
D:

I accidentally put a space between the equals sign and the dollar sign.

I accidentally put a space between the equals sign and the dollar sign.
Same result, nothing! I think it's the SkillPickaxeProjectile::onCollision that hates me.

Maybe a white space got behind the "return;" part. Delete everything behind it and press tab until it looks right. If that doesn't work, comment the "if(%col.getClassName() !$= "fxdtsbrick")" thing out and see if its actually causing the problem or not.