Author Topic: WaterDamage Modification  (Read 1300 times)

Okay so I got a code from someone and altered it:
   
Code: [Select]
function Armor::damage(%data, %this, %proj, %hitPos, %damage, %type)
{
        if(%type == $DamageType::Lava)
{
            %damage = 1;
            $keep = 1;
        }
        Parent::damage(%data, %this, %proj, %hitPos, %damage, %type);
}

The script works perfectly. My only issue is that it kills vehicles. I was wondering how I change the if statement around to check if the object is a vehicle.

Code: [Select]
function Armor::damage(%data, %this, %proj, %hitPos, %damage, %type)
{
        if((%type == $DamageType::Lava) && !(//check if is vehicle))
{
            %damage = 1;
            $keep = 1;
        }
        Parent::damage(%data, %this, %proj, %hitPos, %damage, %type);
}

What? No, look at the code really closely. I'm trying to kill players if they are in water without vehicles.
« Last Edit: December 06, 2012, 10:48:26 PM by tyler0 »

Why wouldn't you want it to kill vehicles?

Why wouldn't you want it to kill vehicles?

Nope, it's water that hurts you.

So why not use lava...?

So why not use lava...?

What? No, look at the code really closely. I'm trying to kill players if they are in water without vehicles.

I know that, but why not just use the default lava?

use %obj.getClassName() $= "Player" || %obj.getClassName() $= "aiPlayer". I'll let you find out which one is the correct object as you'll need to define it first.

use %obj.getClassName() $= "Player" || %obj.getClassName() $= "aiPlayer". I'll let you find out which one is the correct object as you'll need to define it first.

Very useful, thank you!

There is also %obj.getClassName() $= "vehicle"

Don't use string comparison with class names, especially not in functions used all the time and especially not in scheduled tick functions.

if(%obj.getType() & $TypeMasks::PlayerObjectType)

This will work with both AI and human player objects..

If you only want a human, add the check isObject(%obj.client) (or vice versa)

Even with 2 checks it should be faster than two string comparisons.
« Last Edit: December 09, 2012, 02:44:01 PM by Frontier Psychiatrist »

Don't use string comparison with class names, especially not in functions used all the time and especially not in scheduled tick functions.
If you're referring to the OP, == is not a string comparison function.
« Last Edit: December 09, 2012, 02:49:16 PM by Trinick. »

If you're referring to the OP, == is not a string comparison function and it should work just fine.
I'm obviously referring to the posts directly above my own.

I've quoted the person I'm replying to this time so you don't think I'm talking to OP again.

I'm obviously referring to the posts directly above my own.

I've quoted the person I'm replying to this time so you don't think I'm talking to OP again.
That person isn't checking their type, he's checking their classname. While it wouldn't work because there are WheeledVehicles and FlyingVehicles, the string comparison there is not the issue, hence why I assumed you were talking about the OP.

Yes, he is checking class name. That is bad, which is why I corrected him. I was not addressing OP's problem. If you had read the posts above mine there would be no confusion.

Checking class name to see if it's the correct type of object is like checking race to see if something is a human being. Although no human is a "Cadillac" and no car is a "Caucasian", it's a pointless middleman. You just want to get the type of the object.

You're wrong and you're justifying your wrongness very poorly.
« Last Edit: December 09, 2012, 03:15:44 PM by Frontier Psychiatrist »

Yes, he is checking class name. That is bad, which is why I corrected him.
How exactly is this "bad"?

I was not addressing OP's problem. If you had read the posts above mine there would be no confusion.
I did read the posts above yours, why would I read the bottom of the page first and comment about something I have no sense of context for? For someone named "Frontier Psychiatrist," you seem to have a very poor understanding of how the human brain works. As I stated before,
the string comparison there is not the issue, hence why I assumed you were talking about the OP.

Checking class name to see if it's the correct type of object is like checking race to see if something is a human being. Although no human is a "Cadillac" and no car is a "Caucasian", it's a pointless middleman. You just want to get the type of the object.
What? That brown townogy made no sense whatsoever. If you needed to check if something was a player and you called ::getClassName() on it it would return "Player" if it was a player and something else if it was something else. This method of checking is 100% valid. I suspect you have absolutely no idea what you are talking about.

You're wrong and you're justifying your wrongness very poorly.
What would I even be wrong about? That you were referring to the OP? I crossed out my post, what more of an "oops" do you need?