ItsMods

Full Version: Event to happen when Player kills someone
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, I just recently started modding (actually yesterday), and I've been searching around for a while to find a method that lets me for instance give the player full ammo on his weapon whenever he/she kills someone. I read something about "onPlayerKilled()", tried searching in _rank.gsc and couldn't find it, so I wrote it myself as a seperate method inside _rank.gsc:

onPlayerKilled()
{
self giveMaxAmmo("crossbow_explosive_mp", 0, false);
}

This didn't help at all, so I was wondering if any of you hardcore modders out there could help me with it. (And yes, I had already given the player the weapon indicated) I'd also appreciate if you'd help me nail the basic classes that I need to know about other than _rank.gsc
Thank you in advance!
In maps/mp/gameptypes/_callbacksetup.gsc

Code:
CodeCallback_PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
    self endon("disconnect");

        if(eAttacker.team == "allies" && self.team == "axis" && eAttacker.lasthunter == 0)
    {
        self.bounty += 75;

    }

Use it like that.
(03-20-2012, 18:36)Lemon Wrote: [ -> ]In maps/mp/gameptypes/_callbacksetup.gsc

Code:
CodeCallback_PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
    self endon("disconnect");

        if(eAttacker.team == "allies" && self.team == "axis" && eAttacker.lasthunter == 0)
    {
        self.bounty += 75;

    }

Use it like that.

What exactly is self.bounty? And why do we add 75 to it? And do I have to call this method within _rank.gsc or how does it come together?
My programming knowledge is limited to basic java, and I'm trying to understand how this language connects.
he means add the file maps/mp/gameptypes/_callbacksetup.gsc to your mod and find this line

Code:
CodeCallback_PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
    self endon("disconnect");

//do stuff here

}

then all u have to do is add want you want done then add the file to your mod.csv like
Code:
rawfile,maps/mp/gameptypes/_callbacksetup.gsc

I had the same problem, you have to call the CallbackOnPlayerDeath.
This is the original Callback
Code:
/*================
Called when a player has been killed.
self is the player that was killed.
================*/
CodeCallback_PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
    self endon("disconnect");
    [[level.callbackPlayerKilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
}

But i had to rewrite it because it was giving me loads of problems, first of all you need to write this new fuction on _rank.gsc
Code:
onserverstart()
{
        wait 1; //to ensure the callbacks are already written
        //store the old callbacks
        level.oldcallbackplayerkilled=level.callbackplayerkilled;
        //now, create new callbacks
        level.callbackplayerkilled=::killed;
}

After doing this, you have to write the following
Code:
killed(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{


         if(isdefined(eAttacker)&&isplayer(eAttacker)&&eAttacker!=self)
        {
                eAttacker iPrintlnBold("^2You killed "+self.name);
        }
                
[[level.oldcallbackplayerkilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);

}

You just have to play around with eAttacker(the attacker) in the code up here, you get a message when you killed someone, but if you change it around it will show a message when they kill you.

Im also adding the original file where i found the function, i have to upload it lika a .txt, but is a gsc file.

Take care.