Results 1 to 9 of 9

Thread: Automatically set killstreak in order in a menu

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    Automatically set killstreak in order in a menu

    Hi all.

    Im working on killstreak. You can pick 3 from a list. killstreak1 =1/0, killstreak2 = 1/0 etc. Now I made a small menu with 3 boxes and I want to show the image of the killstreak in each box. I can do this with endless "if statements" but i was wondering if there is a much faster way that it will check the values, assign them to the box and remove them from a list and check the next one. I have no idea how to do this and have no clue if this is even possible. Who can help me

  2. #2
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Ni3ls View Post
    Hi all.

    Im working on killstreak. You can pick 3 from a list. killstreak1 =1/0, killstreak2 = 1/0 etc. Now I made a small menu with 3 boxes and I want to show the image of the killstreak in each box. I can do this with endless "if statements" but i was wondering if there is a much faster way that it will check the values, assign them to the box and remove them from a list and check the next one. I have no idea how to do this and have no clue if this is even possible. Who can help me
    There is probably a thousand different ways you could do it, but they all involve setting a cvar on the client in order to show the right killstreak in the right box. So, as such, there is no "automatic" way to do it - you have to write code which makes a different case for each killstreak.

    In order to eliminate lots of "if .. else" statements, use the switch function, with the case being the right amount for each killstreak. If you post the code you already have, I can convert it to a switch function for you.

  3. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by Tally View Post
    There is probably a thousand different ways you could do it, but they all involve setting a cvar on the client in order to show the right killstreak in the right box. So, as such, there is no "automatic" way to do it - you have to write code which makes a different case for each killstreak.

    In order to eliminate lots of "if .. else" statements, use the switch function, with the case being the right amount for each killstreak. If you post the code you already have, I can convert it to a switch function for you.
    I'm not entirely clear on what the OP wants exactly, but
    Code:
    WINDOW_STYLE_DVAR_SHADER
    seems like a good start (click here)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  4. #4
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    I already got the menu with the right dvars.
    Code:
    					self setclientcvar("killstreak_1", "value");
    					self setclientcvar("killstreak_2", "value");
    					self setclientcvar("killstreak_3", "value");
    killstreak_1 is for the first box and must have value 1 if killstreak 1 is chosen , value 2 if killstreak 2 is chosen. Killstreak_2 is for box 2 etc. Same for the other boxes.
    the values of the killstreaks are killstreak1, killstreak2, etc

  5. #5
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Ni3ls View Post
    I already got the menu with the right dvars.
    Code:
    					self setclientcvar("killstreak_1", "value");
    					self setclientcvar("killstreak_2", "value");
    					self setclientcvar("killstreak_3", "value");
    killstreak_1 is for the first box and must have value 1 if killstreak 1 is chosen , value 2 if killstreak 2 is chosen. Killstreak_2 is for box 2 etc. Same for the other boxes.
    the values of the killstreaks are killstreak1, killstreak2, etc
    Yeah, we get that bit, but like Izno says, it is unclear exactly what you want. You say the player selects the killstreaks, then you say they automatically set themselves when the player reaches the right value. So, you need to clarify what you are trying to do.

    I did all this for a COD4 mod where I replicated Black Ops 1 killstreak selection. I had a ton of menu itemdef that represented the selections the player made. Then, when they were fighting and got the right amount of kills, the killstreak that was selected for that value became live and they could call it in. You need to clarify if this is what you are trying to achieve.

  6. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Show some paintskillz to clarify what you wanna achieve
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  7. #7
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    There is a killstreakmenu where you can select up to 3 killstreaks. They have the values killstreak1, killstreak2, killstreak3, killstreak4 and killstreak5. If its 1 its selected, if it has value, not selected.
    Then there is a spawnmenu, where you see some kind of overview what you have selected with dvars. The 3 dvars are
    Code:
    					self setclientcvar("killstreak_1", "value");
    					self setclientcvar("killstreak_2", "value");
    					self setclientcvar("killstreak_3", "value");
    If killstreak 1, 3 and 4 are selected, it should be
    Code:
    					self setclientcvar("killstreak_1", "1");
    					self setclientcvar("killstreak_2", "3");
    					self setclientcvar("killstreak_3", "4");
    So the killstreaks are shown in the boxes and in the right order, so first killstreak1, then 3 and then 4 for example.

    Click image for larger version. 

Name:	ksmenu.jpg 
Views:	96 
Size:	13.5 KB 
ID:	921Click image for larger version. 

Name:	spawnmenu.jpg 
Views:	96 
Size:	17.1 KB 
ID:	922

  8. #8
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    113
    Thanks
    10
    Thanked 74 Times in 45 Posts
    I made a similar solution in the past. If you dont know how to start, I pasted my old code below, but dont forget: its only an example!!! Dont try to implement the script into your mod, because it is only a part of my complete mod. At first understand the code line by line, after you can try to write your own script. I captured 2 pictures what will help you to understand.
    Click image for larger version. 

Name:	hud.jpg 
Views:	88 
Size:	703.5 KB 
ID:	923Click image for larger version. 

Name:	menu.jpg 
Views:	88 
Size:	519.8 KB 
ID:	924

    change_strike.menu
    PHP Code:
    #include "ui_mp/menudef.h"

    #define ORIGIN_CHOICE1        40 52
    #define ORIGIN_CHOICE2        40 84
    #define ORIGIN_CHOICE3        40 116
    #define ORIGIN_CHOICE4        40 148
    #define ORIGIN_CHOICE5        40 180
    #define ORIGIN_CHOICE6        40 212
    #define ORIGIN_CHOICE7        40 244

    #define button(_name, _orig, _text, _response, _dvartest, _showdvar, _dvartest2, _showdvar2, _points, _kills) \
    itemDef \
    { \
        
    name            _name \
        
    style            WINDOW_STYLE_FILLED \
        
    rect            0 0 256 24 0 0 \
        
    origin            _orig \
        
    backcolor        0 0 0 0.9 \
        
    visible            1 \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    style            WINDOW_STYLE_FILLED \
        
    rect            0 0 256 24 0 0 \
        
    origin            _orig \
        
    backcolor        1 1 1 0.9 \
        
    dvartest        _dvartest2 \
        
    showDvar        _showdvar2 } \
        
    visible            1 \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    style            WINDOW_STYLE_SHADER \
        
    rect            0 0 256 24 0 0 \
        
    origin            _orig \
        
    background        "rndl_menu_corner_24" \
        
    visible            1 \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    type            ITEM_TYPE_TEXT \
        
    visible            1 \
        
    rect            8 0 0 0 0 0 \
        
    origin            _orig \
        
    forecolor        1 0.5 0 1 \
        
    text            _text \
        
    textfont        UI_FONT_NORMAL \
        
    textscale        .30 \
        
    textalign        ITEM_ALIGN_LEFT \
        
    textaligny        20 \
        
    dvartest        _dvartest \
        
    showDvar        _showdvar } \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    type            ITEM_TYPE_TEXT \
        
    visible            1 \
        
    rect            8 0 0 0 0 0 \
        
    origin            _orig \
        
    forecolor        GLOBAL_DISABLED_COLOR \
        
    text            _text \
        
    textfont        UI_FONT_NORMAL \
        
    textscale        .30 \
        
    textalign        ITEM_ALIGN_LEFT \
        
    textaligny        20 \
        
    dvartest        _dvartest \
        
    hideDvar        _showdvar } \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    style            WINDOW_STYLE_SHADER \
        
    rect            184 6 12 12 0 0 \
        
    origin            _orig \
        
    background        "rndl_menu_strikepoints" \
        
    visible            1 \
        
    dvartest        _dvartest \
        
    showDvar        _showdvar } \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    style            WINDOW_STYLE_SHADER \
        
    rect            224 6 12 12 0 0 \
        
    origin            _orig \
        
    background        "rndl_menu_strikekills" \
        
    visible            1 \
        
    dvartest        _dvartest \
        
    showDvar        _showdvar } \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    type            ITEM_TYPE_TEXT \
        
    visible            1 \
        
    rect            208 0 0 0 0 0 \
        
    origin            _orig \
        
    forecolor        1 0.5 0 1 \
        
    text            _points \
        
    textfont        UI_FONT_NORMAL \
        
    textscale        .30 \
        
    textalign        ITEM_ALIGN_RIGHT \
        
    textaligny        20 \
        
    dvartest        _dvartest \
        
    showDvar        _showdvar } \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    type            ITEM_TYPE_TEXT \
        
    visible            1 \
        
    rect            248 0 0 0 0 0 \
        
    origin            _orig \
        
    forecolor        1 0.5 0 1 \
        
    text            _kills \
        
    textfont        UI_FONT_NORMAL \
        
    textscale        .30 \
        
    textalign        ITEM_ALIGN_RIGHT \
        
    textaligny        20 \
        
    dvartest        _dvartest \
        
    showDvar        _showdvar } \
        
    decoration \
    } \
    itemDef \
    { \
        
    name            _name \
        
    visible            1 \
        
    rect            0 0 256 24 0 0 \
        
    origin            _orig \
        
    forecolor        GLOBAL_UNFOCUSED_COLOR \
        
    type            ITEM_TYPE_BUTTON \
        
    dvartest        _dvartest \
        
    showDvar        _showdvar } \
        
    action \
        { \
            
    play "mouse_click"; \
            
    setdvar _dvartest2 _showdvar2; \
            
    scriptMenuResponse _response; \
        } \
        
    onFocus \
        { \
            
    play "mouse_over"; \
        } \
    }

    {
        
    menuDef
        
    {
            
    name            "change_strike"
            
    rect            GLOBAL_MENU_SIZE
            focuscolor        GLOBAL_FOCUSED_COLOR
            style            WINDOW_STYLE_EMPTY
            onOpen
            
    {
                
    setdvar ui_background "background_futuremod";
                
    setdvar ui_sidebar "strike";

                
    open "sidebar";
                
    open "profil";
            }
            
    onClose
            
    {
                
    close "sidebar";
                
    close "profil";
            }
            
    onEsc
            
    {
                
    close "change_strike";
            }

            
    itemDef
            
    {
                
    name        background_image
                style        WINDOW_STYLE_DVAR_SHADER
                rect        GLOBAL_BACKGROUND_SIZE
                dvar        
    "ui_background"
                
    visible        1
                decoration
            
    }


            
    itemDef
            
    {
                
    rect        40 20 128 0
                type        ITEM_TYPE_TEXT
                forecolor    GLOBAL_UNFOCUSED_COLOR
                text        
    "@RNDL_STRIKE_POINTS"
                
    textfont    UI_FONT_NORMAL
                textscale    0.30
                textaligny    0
                visible        1
                decoration
            
    }
            
    itemDef
            
    {
                
    rect        168 30 0 0
                type        ITEM_TYPE_TEXT
                forecolor    GLOBAL_UNFOCUSED_COLOR
                dvar        
    "ui_strikepoints"
                
    textfont    UI_FONT_NORMAL
                textscale    0.55
                textaligny    0
                visible        1
                decoration
            
    }
            
    itemDef
            
    {
                
    rect        192 6 20 20 0 0
                style        WINDOW_STYLE_SHADER
                background    
    "rndl_menu_strikepoints"
                
    visible        1
                decoration
            
    }

            
    button("strike_commsat"ORIGIN_CHOICE1"@RNDL_STRIKE_COMMSAT""CommSat""ui_allow_commsat""1"selected_strike1"1"33)
            
    button("strike_emp"ORIGIN_CHOICE2"@RNDL_STRIKE_EMP""EMP""ui_allow_emp""1"selected_strike2"1"34)
            
    button("strike_airstrike"ORIGIN_CHOICE3"@RNDL_STRIKE_AIRSTRIKE""Airstrike""ui_allow_airstrike""1"selected_strike3"1"56)
            
    button("strike_predator"ORIGIN_CHOICE4"@RNDL_STRIKE_PREDATOR""Predator""ui_allow_predator""1"selected_strike4"1"67)
            
    button("strike_sentry"ORIGIN_CHOICE5"@RNDL_STRIKE_SENTRY""Sentry""ui_allow_sentry""1"selected_strike5"1"79)
            
    button("strike_quadrotor"ORIGIN_CHOICE6"@RNDL_STRIKE_QROTOR""QuadRotor""ui_allow_quadrotor""1"selected_strike6"1"811)
            
    button("strike_drone"ORIGIN_CHOICE7"@RNDL_STRIKE_DRONE""Drone""ui_allow_drone""1"selected_strike7"1"1015)

            
    #include "ui_mp/scriptmenus/activitynav.menu"
        
    }

    _strike.gsc
    PHP Code:
    #include scripts\_utils;
    #include scripts\_getset;

    init()
    {
        
    Settings();
        
    initStrikes();

        
    level.functions["onConnect"][ level.functions["onConnect"].size ] = ::RunOnConnect;
        
    level.functions["onDisconnect"][ level.functions["onDisconnect"].size ] = ::RunOnDisconnect;
        
    level.functions["onSpawn_once"][ level.functions["onSpawn_once"].size ] = ::RunOnSpawn;
        
    level.functions["onPlayerKilled"][ level.functions["onPlayerKilled"].size ] = ::RunOnKilled;
    }

    Settings()
    {
        
    level.strikepoints 10;

        
    precache_String(&"RNDL_HUD_STRIKE_PRESS");
    }

    initStrikes()
    {
        
    scripts\strike\_uav::init();
        
    scripts\strike\_emptower::init();
        
    scripts\strike\_airstrike::init();
        
    scripts\strike\_mortar::init();
        
    scripts\strike\_sentry::init();
        
    scripts\strike\_quadrotor::init();
        
    scripts\strike\_drone::init();
    }

    RunOnConnect()
    {
        
    player self;

        
    player endon("disconnect");

        
    player.tmp_strikes = []; // selected strikes
        
    player.pers["strike"] = []; // current strikes
        
    player.strikes = []; // reached strikes
        
    player.kills 0;

        
    player thread RunOnLogin();
        
    player thread RunOnLogout();

        for (;;)
        {
            
    player waittill_any("joined_team""joined_spectators""killed_player");
            
    player notify("end_strike");
        }
    }

    RunOnDisconnect()
    {
        
    player self;

        
    player notify("end_strike");
    }

    RunOnLogin()
    {
        
    player self;

        
    player.strikepoints level.strikepoints;

        for (;;)
        {
            
    player waittill_any("login""update_bonus");
            
    wait 0.05;

            
    spent 0;
            for (
    0player getStrikes().sizei++)
            {
                
    spent += getStrike(player getStrikes()[ ]).point;
            }

            
    player.strikepoints level.strikepoints getBonus("strike") - spent;
            
    player updateStrikeUI();
        }
    }

    RunOnLogout()
    {
        
    player self;

        for (;;)
        {
            
    player waittill("logout");

            
    /*
            for (i = 0; i < player.pers["strike"].size; i++)
            {
                strike = getStrike( player.pers["strike"][ i ] );
                player setClientCvar(strike.slot, "0");
            }*/
            
    player.tmp_strikes = []; // selected strikes
            
    player.pers["strike"] = []; // current strikes
            
    player.strikes = []; // reached strikes
            
    player.strikepoints 0;
        }
    }

    RunOnSpawn()
    {
        
    player self;

        
    player.pers["strike"] = player.tmp_strikes;
        
    player sortStrikes();

        for (
    03i++)
        {
            if (
    isDefined(player.pers["strike"][ ]) && isStrike(player.pers["strike"][ ]))
            {
                
    icon getStrikeplayer.pers["strike"][ ] ).icon;

                if ( 
    isDefined(icon) && icon != "" )
                    
    player setClientCvar("hud_strikeslot" iicon);
            }
            else
            {
                
    player setClientCvar("hud_strikeslot" i"hud_ksicon_empty");
            }
        }

        
    player thread RunLastStrike();
        
    player createStrikeHUD();
        
    player updateStrikeHUD();
    }

    RunOnKilled(eInflictoreAttackeriDamagesMeansOfDeathsWeaponvDirsHitLoctimeOffsetdeathAnimDuration)
    {
        
    player self;
        
    player notify("end_strike");

        
    player.kills 0;
        
    player deleteStrikeHUD();

        if (! 
    isPlayer(eAttacker) || player == eAttacker || player.pers["team"] == eAttacker.pers["team"])
            return;

        if (! 
    isDefined(eAttacker.pers["strike"]) || ! eAttacker.pers["strike"].size)
            return;

        
    oldKills eAttacker.kills;
        
    eAttacker.kills++;

        for (
    0eAttacker.pers["strike"].sizei++)
        {
            
    strike getStrikeeAttacker.pers["strike"][ ] );

            if (
    strike.kill <= oldKills)
                continue;

            if (
    eAttacker.kills >= strike.kill )
            {
                
    eAttacker scripts\gametypes\_notification::Notification(strike.stringstrike.hudstrike.sound);
                
    eAttacker.strikes add_to_array(eAttacker.strikeseAttacker.pers["strike"][ ], false);
            }
        }

        
    eAttacker updateStrikeHUD();
    }

    RunLastStrike()
    {
        
    player self;
        
    player endon("killed_player");

        for (;;)
        {
            
    player waittill("menuresponse"menuresponse);

            if (
    response == "useStrike" && player.sessionstate == "playing")
            {
                
    strikeName player.strikesplayer.strikes.size ];
                if (
    isDefined(strikeName))
                {
                    
    func getStrikestrikeName ).func;

                    if ( 
    isDefined(func) )
                        
    player thread [[ func ]]();
                }
            }

            
    wait 0.5;
        }
    }

    addStrike(strikeName)
    {
        
    player self;

        
    strike getStrikestrikeName );

        if ( ! 
    is_in_arrayplayer.tmp_strikesstrikeName ) && player.tmp_strikes.size && player.strikepoints >= strike.point )
        {
            
    player setClientCvar(strike.slot"1");

            
    player.strikepoints -= strike.point;
            
    //player setStrike( strikeName );
            
    player.tmp_strikes array_add(player.tmp_strikesstrikeName);
        }
        else if ( 
    is_in_arrayplayer.tmp_strikesstrikeName ) )
        {
            
    player setClientCvar(strike.slot"0");

            
    player.strikepoints += strike.point;
            
    //player unSetStrike( strikeName );
            
    player.tmp_strikes array_remove(player.tmp_strikesstrikeName);
        }
        else
        {
            
    player setClientCvar(strike.slot"0");
        }

        
    player updateStrikeUI();
    }

    sortStrikes()
    {
        
    player self;

        if ( 
    isDefined(player.pers["strike"]) )
        {
            
    temp player.pers["strike"];

            for (
    0temp.size 1i++)
            {
                for (
    1temp.sizej++)
                {
                    if (
    getStrike(temp]).kill getStrike(temp]).kill)
                    {
                        var = 
    temp];
                        
    temp] = temp];
                        
    temp] = var;
                    }
                }
            }

            
    player.pers["strike"] = temp;
        }
    }

    updateStrikeUI()
    {
        
    player self;

        
    player setClientCvar("ui_strikepoints"player.strikepoints);
    }

    updateStrikeHUD()
    {
        
    player self;

        
    remaining 0;
        
    strikes player getStrikes();
        for (
    0strikes.sizei++)
        {
            
    strike getStrike(strikes]);
            if (
    strike.kill player.kills)
            {
                
    remaining strike.kill player.kills;
                break;
            }
        }

        if (
    isDefined(player.strikecounterhud))
            
    player.strikecounterhud setValue(remaining);
    }

    createStrikeHUD()
    {
        
    player self;

        if (! 
    isDefined(player.strikecounterhud))
        {
            
    player.strikecounterhud newClientHudElem(player);
            
    player.strikecounterhud.= -48;
            
    player.strikecounterhud.= -150;
            
    player.strikecounterhud.alignX "left";
            
    player.strikecounterhud.alignY "top";
            
    player.strikecounterhud.horzAlign "right";
            
    player.strikecounterhud.vertAlign "bottom";
            
    player.strikecounterhud.foreground 1;
            
    player.strikecounterhud.fontscale 2.4;
            
    player.strikecounterhud.sort 1;
            
    player.strikecounterhud.alpha 1;
            
    player.strikecounterhud.color = (0/255125/255125/255);
        }

        if (! 
    isDefined(player.strikepresshud))
        {
            
    player.strikepresshud newClientHudElem(player);
            
    player.strikepresshud.0;
            
    player.strikepresshud.= -30;
            
    player.strikepresshud.alignX "center";
            
    player.strikepresshud.alignY "top";
            
    player.strikepresshud.horzAlign "center";
            
    player.strikepresshud.vertAlign "bottom";
            
    player.strikepresshud.foreground 1;
            
    player.strikepresshud.fontscale 0.8;
            
    player.strikepresshud.sort 1;
            
    player.strikepresshud.alpha 1;
            
    player.strikepresshud.color = (255/255255/255255/255);
            
    player.strikepresshud setText(&"RNDL_HUD_STRIKE_PRESS");
        }
    }

    deleteStrikeHUD()
    {
        
    player self;

        if (
    isDefined(player.strikecounterhud))
            
    player.strikecounterhud destroy();
        if (
    isDefined(player.strikepresshud))
            
    player.strikepresshud destroy();

    And read Izno's thread: http://killtube.org/showthread.php?9...ng-the-CoD4MoD

    (how the hell can i resize the inserted images?)
    Last edited by randall; 15th August 2015 at 10:18.

  9. The Following User Says Thank You to randall For This Useful Post:

    Ni3ls (15th August 2015)

  10. #9
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    I tried to understand this script, but I think it's too hard for me. In my head it sounded like a really simple idea. But to work it out is impossible for me. Thanks for the script anyway

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •