// this function ripped from contest of champions
void ApplyFlagEffect( object oPlayer )
{
    int nTeam, nVisEffect;
    effect eFlagEffect;

//    nTeam = GetPlayerTeam(oPlayer);


//    if ( nTeam == TEAM_BLUE )
//    {
//        nVisEffect = VFX_DUR_FLAG_BLUE;
//    }
//    else if ( nTeam == TEAM_RED )
//    {
        nVisEffect = VFX_DUR_FLAG_RED;
//    }
//    else if ( nTeam == TEAM_GOLD )
//    {
//        nVisEffect = VFX_DUR_FLAG_PURPLE;
//    }
//    else if ( nTeam == TEAM_PURPLE )
//    {
//        nVisEffect = VFX_DUR_FLAG_GOLD;
//    }

    eFlagEffect = EffectVisualEffect(nVisEffect);
    eFlagEffect = SupernaturalEffect(eFlagEffect);

    ApplyEffectToObject(DURATION_TYPE_PERMANENT,eFlagEffect,oPlayer);
    PlaySound("as_mg_telepout1");
}

// good = 1, evil = 2

void AddPlayerToTeam( int nTeam, object oPlayer )
{
//    int nNumPlayers, nCount;
//    string sAreaTag;
//    object oArea;
//
//    nNumPlayers = GetTeamData(nTeam,TEAM_NUM_PLAYERS);
//
    SetLocalInt(oPlayer,"m_nTeam",nTeam);
//
//    SetTeamData(nTeam,TEAM_NUM_PLAYERS,nNumPlayers + 1);
//
//    // Signal an event to each team's HQ to add a counter
//    // for the number of players on a team.
//    for ( nCount = 0; nCount < GetMaxTeams(); nCount++ )
//    {
//        sAreaTag = "Team_" + IntToString(nCount) + "_HQ";
//        oArea = GetObjectByTag(sAreaTag);
//
//        if ( GetIsObjectValid(oArea) == TRUE )
//        {
//            SignalEvent(oArea,EventUserDefined(EVENT_ADD_PLAYER_TO_TEAM + nTeam));
//        }
//    }
//
    // Loop through all other players in the game
    // and set up the likes/dislikes appropriately.
    object oPC;
    int nPTeam;

    oPC = GetFirstPC();
    while ( GetIsObjectValid(oPC) == TRUE )
    {
        if ( oPC != oPlayer )
        {
            nPTeam = GetLocalInt(oPC,"m_nTeam");
            if ( nPTeam == nTeam )
            {
                SetPCLike(oPlayer,oPC);
                SetPCLike(oPC,oPlayer);
            }
           else
            {
                SetPCDislike(oPlayer,oPC);
                SetPCDislike(oPC,oPlayer);
           }
        }

        oPC = GetNextPC();
    }
}


void main()
{
// Move individual to new location
        location lNewLocation = GetLocation(GetObjectByTag("EvilSpawn"));
        object oTarget;


        //Since the script is called from a conversation
        //determine who is moved by calling the GetPCSpeaker function
        oTarget = GetPCSpeaker();

        if (GetIsObjectValid(oTarget) == TRUE){
          AssignCommand(oTarget,ActionJumpToLocation(lNewLocation));
//          ApplyFlagEffect(oTarget);

          AddPlayerToTeam( 2, oTarget );

          object oGuard = GetObjectByTag("EvilGuard");
          if (oGuard != OBJECT_INVALID) {
            AdjustReputation(oTarget, oGuard, 100);
          }

          object oMerchant = GetObjectByTag("BlottotheReluctantHealer");
          if (oMerchant != OBJECT_INVALID) {
            AdjustReputation(oTarget, oMerchant, 100);
          }

          object oCommon = GetObjectByTag("GadnartheMime");
          if (oCommon != OBJECT_INVALID) {
            AdjustReputation(oTarget, oCommon, 100);

        }
        else if (GetIsObjectValid(oTarget) == FALSE) {
          SpeakString("Problem here");
        }


} }
