Game Development Community

Nothing major, but clears out an error with vehicles.. (Script part)

by John "Mythic" Henry · in Torque 3D Professional · 06/04/2011 (1:10 pm) · 8 replies

My destruction code reminded me to check for this
and the Vehicle::onRemove() call has the same code
and would cause this same issue :

(Ive got some added code for damage/destruction)

scripts/server/vehicle.cs

function VehicleData::onRemove(%this, %obj)
{
   //echo("\c4VehicleData::onRemove("@ %this.getName() @", "@ %obj.getClassName() @")");

   // if there are passengers/driver, kick them out
   for(%i = 0; %i < %obj.getDatablock().numMountPoints; %i++)
   {
      if (%obj.getMountNodeObject(%i))
      {
         %passenger = %obj.getMountNodeObject(%i);
         %passenger.getDataBlock().doDismount(%passenger, true);
      }
   }
}

(results in)
----------------
VehicleData::damage() ... WheeledVehicle
VehicleData::onDamage() ... WheeledVehicle
VehicleData::onDestroyed() ... Cheetah
scripts/server/vehicle.cs (247): Unknown command getDataBlock.
  Object (4155) PointLight -> LightBase -> SceneObject -> NetObject -> SimObject
scripts/server/vehicle.cs (247): Unable to find object: '' attempting to call function 'doDismount'
scripts/server/vehicle.cs (247): Unknown command getDataBlock.

With the additional Mounted Items you have on the Cheetah that are not players
do a check for wether or not its a player...

updated version

function VehicleData::onRemove(%this, %obj)
{
   //echo("\c4VehicleData::onRemove("@ %this.getName() @", "@ %obj.getClassName() @")");

   // if there are passengers/driver, kick them out
   for(%i = 0; %i < %obj.getDataBlock().numMountPoints; %i++)
   {
      if (%obj.getMountNodeObject(%i))
      {
         %passenger = %obj.getMountNodeObject(%i);
         if( isObject(%passenger) && %passenger.isMemberOfClass("Player") )
            %passenger.getDataBlock().doDismount(%passenger, true);
      }
   }
}

Any place you go through the mounted objects for an Object,
if it can have more then one type of Object mounted to it,
it is a good idea to make sure you got the right type :)

#1
06/04/2011 (4:20 pm)
good catch,
thats been a bother for ages.
#2
06/04/2011 (4:28 pm)
Oops, doulbed up on a call uneccessarily...

if (%obj.getMountNodeObject(%i))  
      {  
         %passenger = %obj.getMountNodeObject(%i); 
         if( isObject(%passenger) && %passenger.isMemberOfClass("Player") )

change to:
%passenger = %obj.getMountNodeObject(%i);  
      if( isObject(%passenger) && passenger.isMemberOfClass("Player") )
#3
06/05/2011 (3:31 am)
Jup, good find! Thnx for posting the fix too!
#4
06/05/2011 (7:14 am)
Heres an Updated version to deal with Removing Mounted Items
and deleting them...

Requires a script (Dynamic) var added to vehicletype datablock

// This will deal with AI controlled Vehicles as well
   // It doesn't mishandle a player

   // if there are passengers/driver/weapons/whatever, 
   // kick them out or destroy them
   for(%i = 0; %i < %obj.getDataBlock().totalMountPoints; %i++)
   {
      %mntObj = %obj.getMountNodeObject(%i);
      if( isObject(%mntObj) )
      {
         if( %mntObj.isMemberOfClass("Player") )
            %mntObj.getDataBlock().doDismount(%mntObj, true);
         else
            %mntObj.delete();
      }
   }

as I use seperate [C++] exposed vars in datablock for dealing
with the mounted objects, all you need is the [ totalMountPoints ]
in your vehicle datablock. This count includes All mount points
on vehicle. Thus cleaning up your vehicles on removal.
#5
12/09/2011 (7:19 am)
still not fixed in t3d v1.2


Quote:
Requires a script (Dynamic) var added to vehicletype datablock
all you need is the [ totalMountPoints ]
in your vehicle datablock

why need it,when there is a standard var made by gg "numMountPoints"?

for(%i = 0; %i < %obj.getDatablock().numMountPoints; %i++)// if there are passengers/driver, kick them out
   {
     %passenger = %obj.getMountNodeObject(%i);
         
	 //fix:---do a check for wether or not its a player...
	 if( isObject(%passenger))
	{
	   if(%passenger.isMemberOfClass("Player"))
	   {
	     echo("!!!!!!!!!!!!!!!!%passenger="@%passenger);
	     %passenger.getDataBlock().doDismount(%passenger, true);
	   }
	   else
	   {
	      %passenger.delete();
	   }
	}
	
   }

is not it similar to last fix?



one question:
why i need to dismount mounted player or those point light?
are not those automatically deleted by engine?



can not understand why this comment needed:
"// This will deal with AI controlled Vehicles as well
// It doesn't mishandle a player"

was there any old facts about diMounting of " AI controlled Vehicles" or "player"?

#6
12/09/2011 (10:40 am)
This all was part of a Combination of my own changes and those originally
from two other Addons (Tank/APC). They came up with some other vars needed
which combined with my own changes added the Need for three types of mountpoints.
[Weapon/Image/Player] that couldnt be handled with the existing system.
Some of my comments dealt with those, sorry, should have been clearer.

I just provided the final bit of Object Type checking to skip the script error
report. It doesn't cause a crash or anything, just an annoying script error
report without it. The default c++ code will scan through All mounted objects
and try to dismount them, (mounted lights). Which do not have a dismount() call
linked to them. The [delete()] call got in there from the AddOns and is not
necessary..

All the basic use needs is this:
%passenger = %obj.getMountNodeObject(%i);    
          if( isObject(%passenger) && passenger.isMemberOfClass("Player") )

*edit*
If the Vehicle is Destroyed, but the player survives, then yes you need to
dismount the player. This is also a cleaner way of handling player death
by dismounting them and then applying any damage After the vehicle is destroyed.
This also allows adding a player corpse easier along with a vehicle corpse.
#7
12/09/2011 (11:18 am)
Quote:
This also allows adding a player corpse easier along with a vehicle corpse.
it clears me why dismount necessary.like player's death in flatout.thanks for that.

Quote:
The [delete()] call got in there from the AddOns
which addOn?

Quote:
is not
necessary..
is that mean engine automatically delete other mounted objects after vehicle removed?

annoying questions from a novice like me.but i am curious about every bit of code/things/+ + + of torque.
thanks
#8
12/10/2011 (5:01 am)
The other addons were the Tanks and Apcs, (Apcs has been removed I believe).
And I had more mount points added in then the basic code looks for so they
are deleted when vehicle is deleted rather then wait for the engine to remove
the additional objects.

As far as all items getting deleted, yes it should. Does it do quickly,
its a bit more complex then just yes or no. Even if you dig through the code,
it can get pretty confusing. I myself like to be clear in what I do so If
I am removing a vehicle I always remove/delete any addons I put on it as well.