PDA

View Full Version : Automatically set killstreak in order in a menu



Ni3ls
13th August 2015, 09:01
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 :)

Tally
13th August 2015, 10:38
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.

IzNoGoD
13th August 2015, 10:52
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


WINDOW_STYLE_DVAR_SHADER
seems like a good start (click here (http://killtube.org/showthread.php?2035-WINDOW_STYLE_DVAR_SHADER))

Ni3ls
13th August 2015, 11:05
I already got the menu with the right dvars.

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

Tally
13th August 2015, 13:57
I already got the menu with the right dvars.

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.

IzNoGoD
13th August 2015, 14:05
Show some paintskillz to clarify what you wanna achieve

Ni3ls
13th August 2015, 17:28
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

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

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.

921922

randall
15th August 2015, 10:07
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.
923924

change_strike.menu

#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", 3, 3)
button("strike_emp", ORIGIN_CHOICE2, "@RNDL_STRIKE_EMP", "EMP", "ui_allow_emp", "1", selected_strike2, "1", 3, 4)
button("strike_airstrike", ORIGIN_CHOICE3, "@RNDL_STRIKE_AIRSTRIKE", "Airstrike", "ui_allow_airstrike", "1", selected_strike3, "1", 5, 6)
button("strike_predator", ORIGIN_CHOICE4, "@RNDL_STRIKE_PREDATOR", "Predator", "ui_allow_predator", "1", selected_strike4, "1", 6, 7)
button("strike_sentry", ORIGIN_CHOICE5, "@RNDL_STRIKE_SENTRY", "Sentry", "ui_allow_sentry", "1", selected_strike5, "1", 7, 9)
button("strike_quadrotor", ORIGIN_CHOICE6, "@RNDL_STRIKE_QROTOR", "QuadRotor", "ui_allow_quadrotor", "1", selected_strike6, "1", 8, 11)
button("strike_drone", ORIGIN_CHOICE7, "@RNDL_STRIKE_DRONE", "Drone", "ui_allow_drone", "1", selected_strike7, "1", 10, 15)

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

_strike.gsc

#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 (i = 0; i < player getStrikes().size; i++)
{
spent += getStrike(player getStrikes()[ i ]).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 (i = 0; i < 3; i++)
{
if (isDefined(player.pers["strike"][ i ]) && isStrike(player.pers["strike"][ i ]))
{
icon = getStrike( player.pers["strike"][ i ] ).icon;

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

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

RunOnKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
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 (i = 0; i < eAttacker.pers["strike"].size; i++)
{
strike = getStrike( eAttacker.pers["strike"][ i ] );

if (strike.kill <= oldKills)
continue;

if (eAttacker.kills >= strike.kill )
{
eAttacker scripts\gametypes\_notification::Notification(stri ke.string, strike.hud, strike.sound);
eAttacker.strikes = add_to_array(eAttacker.strikes, eAttacker.pers["strike"][ i ], false);
}
}

eAttacker updateStrikeHUD();
}

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

for (;;)
{
player waittill("menuresponse", menu, response);

if (response == "useStrike" && player.sessionstate == "playing")
{
strikeName = player.strikes[ player.strikes.size - 1 ];
if (isDefined(strikeName))
{
func = getStrike( strikeName ).func;

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

wait 0.5;
}
}

addStrike(strikeName)
{
player = self;

strike = getStrike( strikeName );

if ( ! is_in_array( player.tmp_strikes, strikeName ) && player.tmp_strikes.size < 3 && player.strikepoints >= strike.point )
{
player setClientCvar(strike.slot, "1");

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

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

player updateStrikeUI();
}

sortStrikes()
{
player = self;

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

for (i = 0; i < temp.size - 1; i++)
{
for (j = i + 1; j < temp.size; j++)
{
if (getStrike(temp[ i ]).kill > getStrike(temp[ j ]).kill)
{
var = temp[ i ];
temp[ i ] = temp[ j ];
temp[ j ] = var;
}
}
}

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

updateStrikeUI()
{
player = self;

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

updateStrikeHUD()
{
player = self;

remaining = 0;
strikes = player getStrikes();
for (i = 0; i < strikes.size; i++)
{
strike = getStrike(strikes[ i ]);
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.x = -48;
player.strikecounterhud.y = -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/255, 125/255, 125/255);
}

if (! isDefined(player.strikepresshud))
{
player.strikepresshud = newClientHudElem(player);
player.strikepresshud.x = 0;
player.strikepresshud.y = -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/255, 255/255, 255/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?923-Rebuilding-the-CoD4MoD

(how the hell can i resize the inserted images?)

Ni3ls
18th August 2015, 14:01
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 ;)