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

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.
Tabbing doesn't really ever matter for anything but readability.

Tabbing doesn't really ever matter for anything but readability.
I understand your logic there...
but doesn't
Code: [Select]
        if(!%client.isAdmin)
                   return;
having a difference between
Code: [Select]
        if(!%client.isAdmin)
return;
break it? (I actually never knew if it matters on the next line or the tab)
« Last Edit: November 28, 2011, 06:02:08 PM by computermix »

not really, it just doesn't look as good

not really, it just doesn't look as good
Oh.

Well it looks like somebody learned something today.

Oh.

Well it looks like somebody learned something today.
Either way, it looks a lot better and is a lot easier to read when you don't do that. To most people, I mean.

Post your new code. (all of it)

Post your new code. (all of it)
Server.cs
Code: [Select]
exec("./Mining.cs");

Mining.cs
Code: [Select]
//=========================================================================
// 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.");
}
}
}

Copper.cs
Code: [Select]
//=========================================================================
// 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;
};
There are more ore bricks but they are all similar to copper.cs.

Tool_Pickaxe.cs
Code: [Select]
//=========================================================================
// 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);
}

%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.

%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)
How do I fix this?
%col.Dissapear(%col.getDatablock().regrowTime);
Should be "disappear" - this will just cause a console error and not make the brick actually disappear.
Thanks.
%col.getDataBlock().Health -= getRandom(1,5);
What messages/particle effects do you see in-game when you hit a block?
One that looks like the sword's.
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.
Do I need to call the parent?

How do I fix this?

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

Also

Code: [Select]
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.");
}
}
}

Notice how the parent is called, also notice the code i fixed in the asterisks.
« Last Edit: December 05, 2011, 07:13:03 AM by Superb »

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

Also

-code-

Notice how the parent is called, also notice the code i fixed in the asterisks.
There is still something wrong because when I hit it nothing happens(still).

You need to replace all the the %col.getDatablock().Health checks with %col.health as well.

You need to replace all the the %col.getDatablock().Health checks with %col.health as well.
Still does not work ):
Code: [Select]
function SkillPickaxeProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(%col.getClassName() !$= "fxDtsBrick")
{
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);

if(%col.getDataBlock().isOre)
{
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.getDataBlock().defaultHealth;
%col.Disappear(%col.getDatablock().regrowTime);
%this.Resources +=  %col.getDataBlock().oreAmount;

messageClient(%this,'',"\c3You have mined some \c6" @ %col.getDataBlock().oreName @ "\c3.");
}
}
}

else
{
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
}
}
« Last Edit: December 06, 2011, 06:27:12 AM by jes00 »

You might also want to package

function FxDtsBrick::onPlant(%this,%stuff...)

and inside somewhere call

%this.health = %this.getDataBlock().defaultHealth;

You still have the %col.getDatablock().Health things inside the if checks.