Author Topic: Getting when any player dies, and the killer of that player?  (Read 949 times)

I was planning on making a jail RP that would be moderated by a script instead of admins to enforce no freekilling.
My idea is to have a crime system, so that when you enter a zone, an event triggers, increasing your crime by 1.
So, if you can detect when a player dies, check if that player had a crime level, and if he didnt, kill the player that killed the innocent and warn him.

So after like 3 freekills, the player would be kicked, then banned, and so on.

My problem is how to get the killer and the victim?

Code: [Select]
function whoKilledWho(%killed, %killer) {
    announce((isObject(%killed) ? %killed.getPlayerName() : "A bot") SPC "was killed by" SPC (isObject(%killer) ? %killer.getPlayerName() : "a bot") @ ".");
}

package whoKilledWho {
    function armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) {
        parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
        if(%obj.getDamagePercent() >= 100) {
            whoKilledWho(%obj.client, %sourceObject.client);
        }
    }
};
activatePackage(whoKilledWho);
« Last Edit: July 28, 2013, 02:21:15 PM by $trinick »

My problem is how to get the killer and the victim?

Off Topic: Your problem is actually how to make the code detect a freekill vs an accident or a kill due to defiance.

Code: [Select]
function whoKilledWho(%killed, %killer) {
    announce((isObject(%killed) ? %killed.getPlayerName() : "A bot") SPC "was killed by" SPC (isObject(%killer) ? %killer.getPlayerName() : "a bot") @ ".");
}

package whoKilledWho {
    function armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) {
        parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
        if(%obj.getDamageLevel() >= 100) {
            whoKilledWho(%obj.client, %sourceObject.client);
        }
    }
};
activatePackage(whoKilledWho);

You know there is armor::onDeath() right?

Plus if a player is weakened already they may not need 100 damage to die.

Plus if a player is weakened already they may not need 100 damage to die.
That's not checking the damage done, that's checking the player's current damage.

Wouldn't a datablock with more than 100 maxDamage be wrongly affected by that? Maybe I'm mixing up my methods. I could've sworn there was something like .getDamagePercent().

That's not checking the damage done, that's checking the player's current damage.
Fair enough.

Code: [Select]
function whoKilledWho(%killed, %killer) {
    announce((isObject(%killed) ? %killed.getPlayerName() : "A bot") SPC "was killed by" SPC (isObject(%killer) ? %killer.getPlayerName() : "a bot") @ ".");
}

package whoKilledWho {
    function armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) {
        parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
        if(%obj.getDamageLevel() >= 100) {
            whoKilledWho(%obj.client, %sourceObject.client);
        }
    }
};
activatePackage(whoKilledWho);

Why are you spoon feeding?

You know there is armor::onDeath() right?
I don't believe armor::onDeath sends the killing object as a parameter. I could be wrong though.

Why are you spoon feeding?
I'm not, really. I gave him code to do 1/4 of what he asked for, and it would be somewhat difficult to repurpose that code into his goal. I simply explained how to do it using code instead of words.

Wouldn't a datablock with more than 100 maxDamage be wrongly affected by that? Maybe I'm mixing up my methods. I could've sworn there was something like .getDamagePercent().

You're right, I've updated my code. That was a mistake on my part, I meant to call getDamagePercent.
« Last Edit: July 28, 2013, 02:19:41 PM by $trinick »

You should use GameConnection::onDeath. I'm on mobile, so I can't look up the parameters, sorry.

GameConnection::OnDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)