Function to Change a Person's Team
Moderator: Core Staff
-
- CJ Wannabe
- Posts: 4
- Joined: November 20th, 2011, 6:18 pm
Function to Change a Person's Team
Hey everyone. I was making a mod and I couldn't figure out a function to change a person's team. I'm wondering if there is one at all. Could anyone help?
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: Function to Change a Person's Team
For Black Ops it is this:
The .gsc path may be slightly different in CoD4 though (or whatever game you're modding), but it will either be that or something very similar.
Code: Select all
self thread maps\mp\gametypes\_teams::changeTeam( "axis" );
-
-
- CJ Wannabe
- Posts: 4
- Joined: November 20th, 2011, 6:18 pm
Re: Function to Change a Person's Team
Thanks. Should work.
Also, is there a way to detect who killed someone?
Also, is there a way to detect who killed someone?
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: Function to Change a Person's Team
Yeah, using the killed callback. See below.
Pretty simple, the first if statement just checks that the attacker exists and is a player (rather than something like world geometry/killtrigger), and isn't yourself. Then it checks if the killer (eAttacker) was the "special person".
Code: Select all
killed(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
if(isdefined(eAttacker)&&isplayer(eAttacker)&&eAttacker!=self)
{
if(eAttacker == special_person)
self iprintlnbold("You were killed by "+special_person.name);
}
[[level.oldcallbackplayerkilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
}
-
-
- CJ Wannabe
- Posts: 4
- Joined: November 20th, 2011, 6:18 pm
Re: Function to Change a Person's Team
Isn't there supposed to be one more set of brackets for the if statement for the: if(eAttacker == special_person)?
And how would you reference the team the attacker was on?
EDIT: I took a guess.. Is this the right way to reference an attacker and his team?
And how would you reference the team the attacker was on?
EDIT: I took a guess.. Is this the right way to reference an attacker and his team?
Code: Select all
Â
SwapTeam()
{
    self endon("disconnect");
    self endon("spawned_player");
    self waittill("death");
    killed(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
    {
        if(isdefined(eAttacker)&&isplayer(eAttacker)&&eAttacker!=self)
        {
            if(eAttacker == special_person) && (eAttacker.team == ("allies"))
            {
                self iprintlnbold("You were killed by "+special_person.name);
                self thread maps\mp\gametypes\_teams::changeTeam("axis");
            }
            elseif(eAttacker == special_person) && (eAttacker.team == ("axis"))
            {
                self iprintlnbold("You were killed by "+special_person.name);
                self thread maps\mp\gametypes\_teams::changeTeam("allies");      Â
            }
        }
        [[level.oldcallbackplayerkilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
    }
}
Â
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: Function to Change a Person's Team
I didn't need the brackets after the if statement because there was only one line after it, however yes you should use the pair of brackets as it also makes it clearer to read. You kind of got the idea right but made a few mistakes.
The whole killed() callback shouldn't be inside another function (the one called swap team). The killed() callback should be somewhere after the init() function. The killed() callback will be read everytime a player is killed, so you needn't put it inside another function.
You made a few mistakes, eg your if statement
should be
A simpler version is this which I made below.
This means when somebody dies, it will check if they were killed by special person, if they wern't, the rest of the killed() callback is ignored and nothing happens. If they were killed by special person, it checks their team and moves them to other team.
Edit: Also feel free to add me on xfire if you want to ask any questions for help etc.
The whole killed() callback shouldn't be inside another function (the one called swap team). The killed() callback should be somewhere after the init() function. The killed() callback will be read everytime a player is killed, so you needn't put it inside another function.
You made a few mistakes, eg your if statement
Code: Select all
if(eAttacker == special_person) && (eAttacker.team == ("allies"))
Code: Select all
if(eAttacker == special_person && eAttacker.team == "allies")
Code: Select all
killed(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
    if(isdefined(eAttacker) && isplayer(eAttacker) && eAttacker!=self && eAttacker==special_person && isDefined(self.team))
    {
        if(self.team == "axis")
        {
            self thread maps\mp\gametypes\_teams::changeTeam("allies");
        }
        else
        {
            self thread maps\mp\gametypes\_teams::changeTeam("axis");
        }
    }
    [[level.oldcallbackplayerkilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
}
Edit: Also feel free to add me on xfire if you want to ask any questions for help etc.
-
-
- CJ Wannabe
- Posts: 4
- Joined: November 20th, 2011, 6:18 pm
Re: Function to Change a Person's Team
Thanks so much!
I'll be adding you to my X-Fire very soon!
EDIT: Request sent
I'll be adding you to my X-Fire very soon!
EDIT: Request sent
Who is online
Users browsing this forum: No registered users and 2 guests