1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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

Custom TDM ruins.as

Discussion in 'Modding [KAG]' started by Rayne, Jun 6, 2013.

  1. Rayne

    Rayne ༼ つ ◕_◕ ༽つ Administrator Global Moderator Forum Moderator Tester

    Messages:
    1,916
    this is for when you want create teams that have different classes, but dont want the other team accessing the different classes.

    part of a series of small edits to help modders.

    Code:
    // TDM Ruins logic
     
    #include "ClassSelectMenu.as"
    #include "StandardRespawnCommand.as"
    #include "Help.as";
     
    void onInit( CBlob@ this )
    {
        this.CreateRespawnPoint( "ruins", Vec2f(0.0f, 16.0f) );
        AddIconToken( "$knight_class_icon$", "GUI/MenuItems.png", Vec2f(32,32), 12 );
        AddIconToken( "$archer_class_icon$", "GUI/MenuItems.png", Vec2f(32,32), 16 );
        //TDM classes
        if ( this.getTeamNum() == 0 ) //blue team classes
            {
                addPlayerClass( this, "Knight", "$knight_class_icon$", "knight", "Hack and Slash." );
                addPlayerClass( this, "Archer", "$archer_class_icon$", "archer", "The Ranged Advantage." );
            }
       
        else if ( this.getTeamNum() == 1 ) // red team classes
            {
                addPlayerClass( this, "Zombie", "$knight_class_icon$", "zombie", "Rotting Flesh." );
                addPlayerClass( this, "Skeleton", "$archer_class_icon$", "skeleton", "Bare Bones." );
            }
        this.getShape().SetStatic(true);
        this.getShape().getConsts().mapCollisions = false;
        this.addCommandID("class menu");
     
        this.Tag("change class drop inventory");
     
        SetHelp( this, "help use", "", "Change class.\n\n      $KEY_E$" );
     
        this.getSprite().SetZ( -50.0f ); // push to background
    }
     
    bool canChangeClass( CBlob@ this, CBlob @caller )
    {
        return ((this.getPosition() - caller.getPosition()).Length() < this.getRadius() + caller.getRadius());
    }
     
    void onCommand( CBlob@ this, u8 cmd, CBitStream @params )
    {
        if (cmd == this.getCommandID("class menu"))
        {
            u16 callerID = params.read_u16();
            CBlob@ caller = getBlobByNetworkID( callerID );
     
            if (caller !is null && caller.isMyPlayer())    {
                BuildRespawnMenuFor( this, caller );
            }
        }
        else {
            onRespawnCommand( this, cmd, params );
        }
    }
     
    void GetButtonsFor( CBlob@ this, CBlob@ caller )
    {
        if (canChangeClass( this, caller ) && this.getTeamNum() == caller.getTeamNum()) //only let the caller access the menu if it's his team's spawner
        {                                                                                //prevents other team from accessing team specific classes.
            Vec2f pos = this.getPosition();
            if ((pos - caller.getPosition()).Length() < this.getRadius()) {
                BuildRespawnMenuFor( this, caller );
            }
            else
            {
                CBitStream params;
                params.write_u16( caller.getNetworkID() );
                caller.CreateGenericButton( "$change_class$", Vec2f(0, 12), this, this.getCommandID("class menu"), "Change class", params );
            }
        }
     
        // warning: if we don't have this button just spawn menu here we run into that infinite menus game freeze bug
    }
    

    to enforce the classes upon changing team, you must edit DoSpawnPlayer in TDM.as

    line 107:

    Code:
                if ( player.getTeamNum() == 0 && p_info.blob_name == "archer" )
                {
                    p_info.blob_name = "archer";
                }
                else if ( player.getTeamNum() == 0 )
                {
                    p_info.blob_name = "knight";
                }
                else if ( player.getTeamNum() == 1 && p_info.blob_name == "skeleton" )
                {
                    p_info.blob_name = "skeleton";
                }
                else if ( player.getTeamNum() == 1 )
                {
                    p_info.blob_name = "zombie";
                }
    
     
    VanHuek, Varion and jerloch like this.
  2. Inferdy

    Inferdy Arsonist

    Messages:
    246
    sprites, pls :(
     
  3. Rayne

    Rayne ༼ つ ◕_◕ ༽つ Administrator Global Moderator Forum Moderator Tester

    Messages:
    1,916
    sprites for what?

    it uses the tdm_ruins already in game, it only changes how it works, you'd replace tdm_ruins.as if you wanted to use this.
     
  4. Inferdy

    Inferdy Arsonist

    Messages:
    246
    Oops, I mean screenshots xD
    </br>--- merged: Jun 14, 2013 5:50 PM ---</br>
    Oops, I understood :( I thinked it is generator with ruins :S