Author Topic: Checking if an object is a vehicle  (Read 2309 times)

How do I check if an object is a vehicle? I want to check if the object a projectile has hit is a vehicle but I'm not sure how.

if(%obj.getClassName() $= "WheeledVehicle")

Thanks! One more thing - how would I check if a variable exists within the WheeledVehicleData block and if it does, retrieve it? It wouldn't just be col.<variablename>, would it?

Thanks! One more thing - how would I check if a variable exists within the WheeledVehicleData block and if it does, retrieve it? It wouldn't just be col.<variablename>, would it?

Should be %variable = %col.getDatablock().somevariable;

if(%obj.getClassName() $= "WheeledVehicle")
If you wanted to check if it was any vehicle - not just a wheeled one - you would use if(%col.getType() & $Typemasks::VehicleObjectType)

Actually, neither of the .getClassName() solutions seem to be working. It doesn't seem to recognize that it's hit a car.

Actually, neither of the .getClassName() solutions seem to be working. It doesn't seem to recognize that it's hit a car.
post the code

Code: [Select]
function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
{
if(%col.getClassName() == "WheeledVehicle")//it's a vehicle
//TODO Make this apply to units with armor too
{
%vehicleArmor = %col.getDatablock().armorValue;
%weaponPiercing = %obj.sourceObject.getDatablock().armorPiercing;
messageClient(%obj.sourceObject.client,' ',"Hit a vehicle.");
if(%vehicleArmor > 0)//if it is armored
{
messageClient(%obj.sourceObject.client,' ',"Hit an armored vehicle.");
if(%weaponPiercing >= %vehicleArmor)//can penetrate, continue normally.
{
%damApply = %this.directDamage;
}
else
{
%damApply = (%this.directDamage) * 0.5;
}
}
else
{
%damApply = %this.directDamage;//no armor, apply normally
}
}
s%points = %damApply;
//Check if that would be more than the target's health, and if so, set points to max health.
if((%col.getDamageLevel() + %damApply) > %col.getDatablock().maxDamage)
{
%points = %col.getDatablock().maxDamage - %col.getDamageLevel();
}
messageClient(%obj.sourceObject.client,' ',"Points Earned:" @ %points);
Parent::damage(%this,%obj,%col,%fade,%pos,%normal);
}
When I shoot a jeep with the gun, I get no "hit a vehicle" message.


Typed from memory, actual code has that. Still doesn't work, though.

post the actual code then

I just checked. Replace the == with $= and you have the actual code.

Code: [Select]
s%points = %damApply;

Is that s in the actual code?
Anyhow, I suggest you use if(%col.getType() & $TypeMasks::VehicleObjectType) instead of if(%col.getClassName() $= "WheeledVehicle").
« Last Edit: December 07, 2011, 08:16:45 AM by Port »

Try Projectile::damage instead.

Is that s in the actual code?
Anyhow, I suggest you use if(%col.getType() & $TypeMasks::VehicleObjectType) instead of if(%col.getClassName() $= "WheeledVehicle").
Yes, turns out it is. Here's the code as it stands, right now, after changes:
Code: [Select]
//exec("./Weapon_AntiArmor.cs");//test weapon, testing entry 1
//exec("./armorjeep.cs");//test vehicle, set with armor 1
//REMINDER: Added lines to jeep and rocket launcher scripts, must remove

//Main
package testPackage2
{

function ProjectileData::radiusDamage(%this, %obj, %col, %distanceFactor, %pos, %damageAmt)
{

if(%distanceFactor <= 0)
return;
else if(%distanceFactor > 1)
%distanceFactor = 1;

if(%col.getType() & $Typemasks::VehicleObjectType)//it's a vehicle
{
%vehicleArmor = %col.getDatablock().armorValue;
%weaponPiercing = %obj.sourceObject.getDatablock().armorPiercing;
messageClient(%obj.sourceObject.client,' ',"Hit a vehicle.");
if(%vehicleArmor > 0)//if it is armored
{
messageClient(%obj.sourceObject.client,' ',"Hit an armored vehicle.");
if(%weaponPiercing >= %vehicleArmor)//can penetrate, continue normally.
{
%damApply = %damageAmt * %distanceFactor;
}
else
{
%damApply = (%damageAmt * %distanceFactor) * 0.5;//TODO: Make this loop for armor values above 1.
//Would be ((%damageAmt * &distanceFactor) * 0.5)^(armorValue - armorPiercing) but how2power in C#?
}
}
}
else
{
%damApply = %damageAmt * %distanceFactor;//no armor, apply normally
}
%points = %damApply;
//Check if that would be more than the target's health, and if so, set points to max health.
if((%col.getDamageLevel() + %damApply) > %col.getDatablock().maxDamage)
{
%points = %col.getDatablock().maxDamage - %col.getDamageLevel();
}

messageClient(%obj.sourceObject.client,' ',"Points Earned:" @ %points);//display points earned
Parent::radiusDamage(%this,%obj,%col,%distanceFactor,%pos,%damApply);
//Parent::radiusDamage(%this,%obj,%col,%distanceFactor,%pos,%damageAmt);

}

function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
{
if(%col.getType() & $TypeMasks::VehicleObjectType)//it's a vehicle
{
%vehicleArmor = %col.getDatablock().armorValue;
%weaponPiercing = %obj.sourceObject.getDatablock().armorPiercing;
messageClient(%obj.sourceObject.client,' ',"Hit a vehicle.");
if(%vehicleArmor > 0)//if it is armored
{
messageClient(%obj.sourceObject.client,' ',"Hit an armored vehicle.");
if(%weaponPiercing >= %vehicleArmor)//can penetrate, continue normally.
{
%damApply = %this.directDamage;
}
else
{
%damApply = (%this.directDamage) * 0.5;//TODO: Make this loop for armor values above 1.
//Would be ((%damageAmt * &distanceFactor) * 0.5)^(armorValue - armorPiercing) but how2power in C#?
}
}
else
{
%damApply = %this.directDamage;//no armor, apply normally
}
}
%points = %damApply;
//Check if that would be more than the target's health, and if so, set points to max health.
if((%col.getDamageLevel() + %damApply) > %col.getDatablock().maxDamage)
{
%points = %col.getDatablock().maxDamage - %col.getDamageLevel();
}
messageClient(%obj.sourceObject.client,' ',"Points Earned:" @ %points);
Parent::damage(%this,%obj,%col,%fade,%pos,%normal);
}
};
activatePackage(testPackage2);

As you can see, I used Projectile::damage and the Typemask suggestions, but neither works. Does Projectile::damage have the same arguments as ProjectileData::damage?
« Last Edit: December 08, 2011, 09:50:41 PM by Unicide »