1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Teams Icons in Change Team Menu

Discussion in 'Modding Help' started by Tsilliev, Oct 9, 2013.

  1. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    Hi, I made 5 teams, and I assign 5 different team icons, in the teamMenu.as, for the menu when you push escape and push change team, there you see those icons.

    The problems is, that 5th icon is the same as 4th icon, and I think this is because of:

    Code:
    for (int i = 0; i < this.getTeamsCount(); i++)
    There is team 1,2,3,4,5 and i = 0,1,2,3,4

    My intuition says that this.getTeamsCount gets up to i = 3 but not higher, and this is why i = 4 icon is the same as i = 3, i tried to start from:

    int i = -1; or i have tried i <5 or i<this.getTeamsCount()+1;i++ but still it doesnt work, so my question would be how to increase the getTeamsCount by 1 in order for the 5th picture to be displayed as it should be not to copy 4th picture.

    Or maybe I can create 6th team but not use it or add it, will try that.
    lol it added the team there with the same picture, so there are 6 teams atm but I havent added anything in teamMenu,as,interesting.
     
    Last edited: Oct 9, 2013
  2. nirvanajm

    nirvanajm Builder Stabber

    Messages:
    8
    i had the same bug, ont change this:
    for (int i = 0; i < this.getTeamsCount(); i++)

    This is a synthax issue, What i did i moving the spectator place...
    --- Double Post Merged, Oct 10, 2013, Original Post Date: Oct 10, 2013 ---
    Code:
    // show menu that only allows to join spectator
    
    const int BUTTON_SIZE = 4;
    
    void onInit( CRules@ this )
    {
        this.addCommandID("pick teams");
        this.addCommandID("pick spectator");
        this.addCommandID("pick none");
    
        AddIconToken( "$BLUE_TEAM$", "GUI/TeamIcons.png", Vec2f(96, 96), 0 );
        AddIconToken( "$RED_TEAM$", "GUI/TeamIcons.png", Vec2f(96, 96), 2 );
        AddIconToken( "$GREEN_TEAM$", "GUI/TeamIcons.png", Vec2f(96, 96), 3 );
    }
    
    void ShowTeamMenu( CRules@ this )
    {
        if (getLocalPlayer() is null) {
            return;
        }
       
        getHUD().ClearMenus(true);
    
        CGridMenu@ menu = CreateGridMenu( getDriver().getScreenCenterPos(), null, Vec2f((this.getTeamsCount() + 0.5f) * BUTTON_SIZE, BUTTON_SIZE), "Change team" );
    
        if (menu !is null)
        {
            CBitStream exitParams;
            menu.AddKeyCommand( KEY_ESCAPE, this.getCommandID("pick none"), exitParams );
            menu.SetDefaultCommand( this.getCommandID("pick none"), exitParams );
    
            string icon, name;
    
            for (int i = 0; i < this.getTeamsCount(); i++)
            {
                CBitStream params;
                params.write_u16( getLocalPlayer().getNetworkID() );
                params.write_u8(i);
    
                if (i == 0)
                {
                    icon = "$BLUE_TEAM$";
                    name = "Human";
                }
                else if (i == 1)
                {
                    icon = "$RED_TEAM$";
                    name = "Dwarves";
                }
                else if (i == 2)
                {
                    // spectator
                    {
                        CBitStream params;
                        params.write_u16( getLocalPlayer().getNetworkID() );
                        params.write_u8( this.getSpectatorTeamNum() );
                        CGridButton@ button2 = menu.AddButton( "$SPECTATOR$", "Spectator", this.getCommandID("pick spectator"), Vec2f(BUTTON_SIZE/2, BUTTON_SIZE), params );
                    }
                    icon = "$GREEN_TEAM$";
                    name = "Elves";
                }
                else
                {
                    icon = "$TEAMGENERIC$";
                    name = "Generic";
                }
    
                CGridButton@ button =  menu.AddButton( icon, name, this.getCommandID("pick teams"), Vec2f(BUTTON_SIZE, BUTTON_SIZE), params );
            }
        }
    }
    
    // the actual team changing is done in the player management script -> onPlayerRequestTeamChange()
    
    void ReadChangeTeam( CRules@ this, CBitStream @params )
    {
        CPlayer@ player = getPlayerByNetworkId( params.read_u16() );
        u8 team = params.read_u8();
    
        if (player is getLocalPlayer())
        {
            player.client_ChangeTeam( team );
          // player.client_RequestSpawn(0);
            getHUD().ClearMenus();
        }
    }
    
    void onCommand( CRules@ this, u8 cmd, CBitStream @params )
    {
        if (cmd == this.getCommandID("pick teams"))
        {
            ReadChangeTeam( this, params );
        }
        else if (cmd == this.getCommandID("pick spectator"))
        {
            ReadChangeTeam( this, params );
        }
        else if (cmd == this.getCommandID("pick none"))
        {
            getHUD().ClearMenus();
        }
    }
    
     
  3. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    But you have only 3 teams :D With 4 teams, icons are fine, but with 5, anyway, did you get rid of the empty space at the end?
     
  4. nirvanajm

    nirvanajm Builder Stabber

    Messages:
    8
    I suced to make 6 team withut bug and with spectator in the middle, without space at the end (or just little )
    --- Double Post Merged, Oct 10, 2013 ---
    let me see the entire file
     
  5. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    Code:
    // show menu that only allows to join spectator
    
    const int BUTTON_SIZE = 5;
    
    void onInit( CRules@ this )
    {
        this.addCommandID("pick teams");
        this.addCommandID("pick spectator");
        this.addCommandID("pick none");
    
        AddIconToken( "$BLUE_TEAM$", "GUI/rsz_crusader.png", Vec2f(96, 96), 0 );
        AddIconToken( "$RED_TEAM$", "GUI/rsz_demon.png", Vec2f(96, 96), 1 );
        AddIconToken( "$GREEN_TEAM$", "GUI/rsz_elf.png", Vec2f(96, 96), 2 );
        AddIconToken( "$PURPLE_TEAM$", "GUI/rsz_undead.png", Vec2f(96, 96), 3 );
      // AddIconToken( "$TEAMGENERIC$", "GUI/TeamIcons.png", Vec2f(96, 96), 2 );
    }
    
    void ShowTeamMenu( CRules@ this )
    {
        if (getLocalPlayer() is null) {
            return;
        }
      
        getHUD().ClearMenus(true);
    
        CGridMenu@ menu = CreateGridMenu( getDriver().getScreenCenterPos(), null, Vec2f((this.getTeamsCount() + 0.5f) * BUTTON_SIZE, BUTTON_SIZE), "Change team" );
    
        if (menu !is null)
        {
            CBitStream exitParams;
            menu.AddKeyCommand( KEY_ESCAPE, this.getCommandID("pick none"), exitParams );
            menu.SetDefaultCommand( this.getCommandID("pick none"), exitParams );
    
            string icon, name;
    
            for (int i = 0; i < this.getTeamsCount(); i++)
            {
                CBitStream params;
                params.write_u16( getLocalPlayer().getNetworkID() );
                params.write_u8(i);
    
                if (i == 0)
                {
                    icon = "$BLUE_TEAM$";
                    name = "Human Empire";
                }
                else if (i == 1)
                {
                    // spectator
                    // {
                        // CBitStream params;
                        // params.write_u16( getLocalPlayer().getNetworkID() );
                        // params.write_u8( this.getSpectatorTeamNum() );
                        // CGridButton@ button2 = menu.AddButton( "$SPECTATOR$", "Spectator", this.getCommandID("pick spectator"), Vec2f(BUTTON_SIZE/2, BUTTON_SIZE), params );
                    // }
                    icon = "$RED_TEAM$";
                    name = "Demonic Legions of the Damned";
                }
              
                else if (i == 2)
                {
                    icon = "$GREEN_TEAM$";
                    name = "Elven Tribes";
                }
                else if (i == 3)
                {
                    icon = "$PURPLE_TEAM$";
                    name = "Undead Hordes";
                }
    
                // else
                // {
                    // icon = "$TEAMGENERIC$";
                    // name = "Generic";
                // }
    
                CGridButton@ button =  menu.AddButton( icon, name, this.getCommandID("pick teams"), Vec2f(BUTTON_SIZE, BUTTON_SIZE), params );
            }
        }
    }
    
    // the actual team changing is done in the player management script -> onPlayerRequestTeamChange()
    
    void ReadChangeTeam( CRules@ this, CBitStream @params )
    {
        CPlayer@ player = getPlayerByNetworkId( params.read_u16() );
        u8 team = params.read_u8();
    
        if (player is getLocalPlayer())
        {
            player.client_ChangeTeam( team );
          // player.client_RequestSpawn(0);
            getHUD().ClearMenus();
        }
    }
    
    void onCommand( CRules@ this, u8 cmd, CBitStream @params )
    {
        if (cmd == this.getCommandID("pick teams"))
        {
            ReadChangeTeam( this, params );
        }
        else if (cmd == this.getCommandID("pick spectator"))
        {
            ReadChangeTeam( this, params );
        }
        else if (cmd == this.getCommandID("pick none"))
        {
            getHUD().ClearMenus();
        }
    }
    
    I will try moving the spectator at the last team.
     
  6. nirvanajm

    nirvanajm Builder Stabber

    Messages:
    8
    AddIconToken( "$BLUE_TEAM$", "GUI/rsz_crusader.png", Vec2f(96, 96), 0 );

    the 0 at the end is gthe frame of the png, not the team number

    You should put zero for all
     
  7. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    I thought so, thanks.