Function to Change a Person's Team

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
LolCakeLazors
CJ Wannabe
CJ Wannabe
Posts: 4
Joined: November 20th, 2011, 6:18 pm

Function to Change a Person's Team

Post by LolCakeLazors » November 20th, 2011, 6:19 pm

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?

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: Function to Change a Person's Team

Post by F |Madness| U » November 20th, 2011, 6:47 pm

For Black Ops it is this:

Code: Select all

self thread maps\mp\gametypes\_teams::changeTeam( "axis" );
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.
-

LolCakeLazors
CJ Wannabe
CJ Wannabe
Posts: 4
Joined: November 20th, 2011, 6:18 pm

Re: Function to Change a Person's Team

Post by LolCakeLazors » November 20th, 2011, 7:16 pm

Thanks. Should work.

Also, is there a way to detect who killed someone?

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: Function to Change a Person's Team

Post by F |Madness| U » November 20th, 2011, 7:55 pm

Yeah, using the killed callback. See below.

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);
}       
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".
-

LolCakeLazors
CJ Wannabe
CJ Wannabe
Posts: 4
Joined: November 20th, 2011, 6:18 pm

Re: Function to Change a Person's Team

Post by LolCakeLazors » November 20th, 2011, 8:04 pm

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?

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);
        }
}
 

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: Function to Change a Person's Team

Post by F |Madness| U » November 20th, 2011, 11:18 pm

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

Code: Select all

if(eAttacker == special_person) && (eAttacker.team == ("allies"))
should be

Code: Select all

if(eAttacker == special_person && eAttacker.team == "allies")
A simpler version is this which I made below.

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);
}
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.
-

LolCakeLazors
CJ Wannabe
CJ Wannabe
Posts: 4
Joined: November 20th, 2011, 6:18 pm

Re: Function to Change a Person's Team

Post by LolCakeLazors » November 21st, 2011, 12:36 am

Thanks so much!

I'll be adding you to my X-Fire very soon!

EDIT: Request sent

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests