Author Topic: Ondestroyed  (Read 1943 times)

Alright I need a block of code to run when any vehicle is destroyed. this is all i can come up with and it doesnt print the echo statement. :(

Quote
function WheeledVehicle::onDestroyed(%this,%obj,%lastState)
        {
            echo("a Vehicle just got destroyed!");
        }

this seemes to work though
Quote
function WheeledVehicle::ondamage(%this,%obj)
        {
            echo("a Vehicle just got damaged");
        }

Try this:
Code: [Select]
package DestroyVehicles
{
  function Vehicle::damage(%vehicle, %source, %pos, %dmg, %type);
  {
    Parent::damage(%vehicle, %source, %pos, %dmg, %type);
    if(%vehicle.getDamagePercent() >= 1 && !%vehicle.destroyed)
    {
      %vehicle.destroyed = 1; //To stop this being called twice if the vehicle is shot at while 'on fire'.
      if(isObject(%source.client)){%str = " by " @ %source.client.name @ ".";}else{%str = ".";}
      echo(%vehicle @ " (" @ %vehicle.getDatablock.getName() @ ") was destroyed" @ %str);
    }
  }
};activatepackage(DestroyVehicles);

It should say something like:
Code: [Select]
5928 (JeepVehicle) was destroyed by Space Guy.in the console when a vehicle is damaged up to the point where it sets on fire. (Not when it explodes)

Quote
function WheeledVehicleData::onDestroyed(%this,%obj,%lastState)
        {
            echo("a Vehicle just got destroyed!");
        }



Try that...maybe use onRemove or something.

Alo, onDestroyed doesn't exist...

Code: [Select]
      ...
      echo(%vehicle @ " (" @ %vehicle.getDatablock.getName() @ ") was destroyed" @ %str;
      ...

Should be:

echo(%vehicle @ " (" @ %vehicle.getDataBlock().getName() @ ") was destroyed" @ %str);



What I would do is just take the datablock name of whatever vehicle I wanted and use the onRemove() callback.

EX:
Code: [Select]
package Something
{
   function JeepVehicle::onRemove(%data, %car)
   {
      error("Removing Jeep:" SPC %car);
      Parent::onRemove(%data, %car);
   }
};
activatePackage(Something);
« Last Edit: May 03, 2008, 02:58:46 PM by exidyne »

That was just for the echo, anyway.

Melting Plastic, do you want the message to come up when the jeep is set on fire (when you shoot it enough times, the wheels come off and it starts emitting fire) or when the jeep explodes? (A second or two after it is on fire, it explodes in a cloud of smoke and then respawns)