Blockland Forums > Modification Help
On Brick Hit If Projectile
<< < (5/7) > >>
Destiny/Zack0Wack0:
Post your new code. (all of it)
jes00:

--- Quote from: Destiny/Zack0Wack0 on November 28, 2011, 06:53:02 PM ---Post your new code. (all of it)

--- End quote ---
Server.cs

--- Code: ---exec("./Mining.cs");

--- End code ---

Mining.cs

--- Code: ---//=========================================================================
// Skill_Mining Confirm
//=========================================================================
//This confirms to Skill_Core that you have Skill_Mining enabled.
$Skill::Mining = 1;
//=========================================================================
// Executions
//=========================================================================
// Misc
exec("./Tool_Pickaxe.cs");
// Ore
exec("./Ore/Copper.cs");
exec("./Ore/Tin.cs");
exec("./Ore/Iron.cs");
exec("./Ore/Coal.cs");
exec("./Ore/Gold.cs");
//=========================================================================
// Ore functions
//=========================================================================
function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(%col.getClassName() !$= "fxDtsBrick")
        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 ---

Copper.cs

--- Code: ---//=========================================================================
// Brick Register
//=========================================================================
datablock fxDTSBrickData(CopperOreData)
{
brickFile = "base/data/bricks/bricks/2x2.blb";
category = "Special";
subCategory = "Interactive";
uiName = "Copper";
iconName = "base/client/ui/brickicons/2x2";

oreName = "Copper";
Health = 50;
isOre = 1;
regrowTime = 10;
oreAmount = 2;
defaultHealth = 50;
};

--- End code ---
There are more ore bricks but they are all similar to copper.cs.

Tool_Pickaxe.cs

--- Code: ---//=========================================================================
// Pickaxe
//=========================================================================
datablock ExplosionData(SkillPickaxeExplosion)
{
   lifeTimeMS = 400;

   soundProfile = swordHitSound;

   particleEmitter = swordExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "0.5 0.5 0.5";
   camShakeDuration = 0.25;
   camShakeRadius = 5.0;

   lightStartRadius = 1.5;
   lightEndRadius = 0;
   lightStartColor = "00.0 0.2 0.6";
   lightEndColor = "0 0 0";
};


datablock ItemData(SkillPickaxeItem : swordItem)
{
shapeFile = "./Skill_Pickaxe.dts";
uiName = "Pickaxe";
doColorShift = true;
colorShiftColor = "0.471 0.471 0.471 1.000";

image = SkillPickaxeImage;
canDrop = true;
iconName = "./Skill_Pickaxe_Icon";
};

AddDamageType("SkillPickaxe",   '<bitmap:add-ons/Skill_Mining/Skill_Pickaxe_CI> %1',    '%2 <bitmap:add-ons/Skill_Mining/Skill_Pickaxe_CI> %1',0.75,1);

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";
};



datablock ShapeBaseImageData(SkillPickaxeImage)
{
   shapeFile = "./Skill_Pickaxe.dts";
   emap = true;

   mountPoint = 0;
   offset = "0 0 0";

   correctMuzzleVector = false;

   className = "WeaponImage";

   item = SkillPickaxeItem;
   ammo = " ";
   projectile = SkillPickaxeProjectile;
   projectileType = Projectile;


   melee = true;
   doRetraction = false;

   armReady = true;


   doColorShift = true;
   colorShiftColor = "0.471 0.471 0.471 1.000";

stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.5;
stateTransitionOnTimeout[0]      = "Ready";
stateSound[0]                    = swordDrawSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "PreFire";
stateAllowImageChange[1]         = true;

stateName[2] = "PreFire";
stateScript[2]                  = "onPreFire";
stateAllowImageChange[2]        = false;
stateTimeoutValue[2]            = 0.1;
stateTransitionOnTimeout[2]     = "Fire";

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "CheckFire";
stateTimeoutValue[3]            = 0.2;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;

stateName[4] = "CheckFire";
stateTransitionOnTriggerUp[4] = "StopFire";
stateTransitionOnTriggerDown[4] = "Fire";


stateName[5]                    = "StopFire";
stateTransitionOnTimeout[5]     = "Ready";
stateTimeoutValue[5]            = 0.2;
stateAllowImageChange[5]        = false;
stateWaitForTimeout[5] = true;
stateSequence[5]                = "StopFire";
stateScript[5]                  = "onStopFire";


};

function SkillPickaxeImage::onPreFire(%this, %obj, %slot)
{
%obj.playthread(2, armattack);
}

function SkillPickaxeImage::onStopFire(%this, %obj, %slot)
{
%obj.playthread(2, root);
}

--- End code ---
Space Guy:
%col.getDataBlock().Health -= getRandom(1,5);
This and various other statements mean you're checking/subtracting from the Health variable of the shared data of all blocks of that ore, not the specific brick you're hitting. (e.g. hit a copper ore, all copper ore loses 3 health)

%col.Dissapear(%col.getDatablock().regrowTime);
Should be "disappear" - this will just cause a console error and not make the brick actually disappear.

What messages/particle effects do you see in-game when you hit a block?

You're not calling Parent::onCollision somewhere in your modified one (the default projectile collision function) so the pickaxe e.g. won't deal damage or possibly do other neede things.
jes00:

--- Quote from: Space Guy on December 04, 2011, 04:51:42 PM ---%col.getDataBlock().Health -= getRandom(1,5);
This and various other statements mean you're checking/subtracting from the Health variable of the shared data of all blocks of that ore, not the specific brick you're hitting. (e.g. hit a copper ore, all copper ore loses 3 health)

--- End quote ---
How do I fix this?

--- Quote from: Space Guy on December 04, 2011, 04:51:42 PM ---%col.Dissapear(%col.getDatablock().regrowTime);
Should be "disappear" - this will just cause a console error and not make the brick actually disappear.

--- End quote ---
Thanks.

--- Quote from: Space Guy on December 04, 2011, 04:51:42 PM ---%col.getDataBlock().Health -= getRandom(1,5);
What messages/particle effects do you see in-game when you hit a block?

--- End quote ---
One that looks like the sword's.

--- Quote from: Space Guy on December 04, 2011, 04:51:42 PM ---You're not calling Parent::onCollision somewhere in your modified one (the default projectile collision function) so the pickaxe e.g. won't deal damage or possibly do other neede things.

--- End quote ---
Do I need to call the parent?
Superb:

--- Quote from: jes00 on December 05, 2011, 06:03:22 AM ---How do I fix this?

--- End quote ---

Use %col.health -= getRandom(1,5);

Also


--- Code: ---function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
//*Need to call the parent*
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);

if(%col.getClassName() !$= "fxDtsBrick")
{
return;
}

if(%col.getDataBlock().isOre) ///// == 1)
{
if(%col.getDatablock().Health >= 1)
{
//**********
//%col.getDataBlock().Health -= getRandom(1,5);
%col.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.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 ---

Notice how the parent is called, also notice the code i fixed in the asterisks.
Navigation
Message Index
Next page
Previous page

Go to full version