Blockland Forums > Modification Help
On Brick Hit If Projectile
DrenDran:
He wants to know how he can do it with events.
phflack:
--- Quote from: DrenDran on November 25, 2011, 07:20:00 PM ---He wants to know how he can do it with events.
--- End quote ---
you couldn't tell the brick to call the event from that?
jes00:
--- Quote from: Destiny/Zack0Wack0 on November 25, 2011, 07:06:44 PM ---
--- Code: ---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
}
--- End code ---
If your projectile is named something different, change the SkillPickaxeProjectile part.
--- End quote ---
So this should work?
--- Code: ---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.");
}
}
}
--- End code ---
EDIT: Does not work. When the pickaxe hits it nothing happens.
--- Quote from: DrenDran on November 25, 2011, 07:20:00 PM ---He wants to know how he can do it with events.
--- End quote ---
Wrong sir.
DOUBLE EDIT: Here is the projectile data for the pickaxe:
--- Code: ---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";
};
--- End code ---
computermix:
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: ---datablock fxDTSBrickData (brickRPGOredata : brick1x1data)
{
category = "RPG";
subCategory = "Ore";
uiName = "Ore";
isOre = 1;
Health = 200;
defaultHealth = 200;
regrowtime = 20;
oreAmount = 50;
oreName = "Mashed diamonds";
};
--- End 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: ---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.");
}
}
}
--- End 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.
jes00:
--- Quote from: computermix on November 26, 2011, 05:17:28 PM ---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.
--- End quote ---
Here is the result:
When I hit it with the pickaxe nothing happens (still).
EDIT: Here is one of the brick files:
--- Code: ---//=========================================================================
// 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;
};
--- End code ---
Also how could I make it so you must be an admin to place ore?