Author Topic: [SOLVED] Damaging a brick  (Read 601 times)

I can't seem to get this working, can anyone see where I'm going wrong?
Code: [Select]
function loggingAxeProjectile::onCollision(%data, %player, %col, %fade, %pos, %normal)
{
if(%col.getdatablock().uiName$="Pine_Tree")
{
  messageClient(%player.client,'ClientMsg',"\c6Chop successfully registered!");
  if(%col.health$=""){%col.health=5;}
  switch$(%player.getMountedImage(0).getName())
  {
case "BronzeAxeImage":
   %damage = 1;
case "IronAxeImage":
   %damage = 2;
case "SteelAxeImage":
   %damage = 3;
case "GoldAxeImage":
   %damage = 5;
   }
   %col.health -= %damage;
   messageClient(%player.client,'ClientMsg',"\c6"@ %col.health);
   if(%col.health<1)
   {
       %col.killBrick();
       %plantlocation = %col.getTransform();
       schedule(3000,0,PlantNewTree,%plantlocation); //3000 for testing, raise to 60000
   }
}
}
What happens is it messages 5 as the bricks health, every time the projectile hits. So the damage isn't being subtracted? But I have no idea why.

Also, is scheduling the planting of new bricks an okay way to do this? Or should I store all the position datas and plant them all at once in a tick to save processing lots of schedules?
« Last Edit: February 13, 2016, 09:23:11 AM by Jervan »

You've got the args wrong:

function ProjectileData::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)

%obj is the projectile, not the player. Maybe you could use something like %obj.sourceObject?



Also, fix your formatting. Put spaces after , and around operators. Don't put if(%col.health $= "") and %col.health = 5; on the same line.

Weird, the messageClient part actually works so I guess projectiles must have a client. It's the %col.health and %damage parts that aren't working as intended but yeah I'll fix the formatting!

Here is the updated code, same problem:

Code: [Select]
function loggingAxeProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)
{
if(%col.getdatablock().uiName$="Pine_Tree")
{
  messageClient(%obj.client,'ClientMsg',"\c6Chop successfully registered!");
  switch$(%player.getMountedImage(0).getName())
  {
case "BronzeAxeImage":
   %damage = 1;
case "IronAxeImage":
   %damage = 2;
case "SteelAxeImage":
   %damage = 3;
case "GoldAxeImage":
   %damage = 5;
  }
  if(%col.health$="")
  {
%col.health=5;
%col.health-=%damage;
  }
  else
  {
%col.health -= %damage;
messageClient(%obj.client,'ClientMsg',"\c6"@ %col.health);
if(%col.health<1)
{
          %col.killBrick();
          %plantlocation = %col.getTransform();
          schedule(3000,0,PlantNewTree,%plantlocation); //6000 for testing, raise to 60000
}
  }
}
}

The outcome:

I'm a total doofus, didn't even realise the arg you mentioned wasn't only used for the messages. Thanks, it works :)

%client.chatMessage("message");