UGX-Mods

Call of Duty 5: World at War => Tutorial Desk => Scripting => Topic started by: BluntStuffy on August 18, 2015, 10:18:15 pm

Title: [TUT] Make a button do something + add a keybind option to a menu
Post by: BluntStuffy on August 18, 2015, 10:18:15 pm
This tutorial will show you how you can make any button preform an action, and how to add a keybind option for it in a menu. After this tutorial it will only print a line on the screen, you have to work from there on..
( i'm not 100% sure if there's a better way to get this working, menu-scripting is still kinda new to me. This was pretty much the only thing i got working so far though )

-I'll start with the menu, in this example we'll add the line to the main menu so it's easy to find, but you can put it in any menu in the same way ( controlls-options, pause menu etc ).
(https://www.ugx-mods.com/forum/proxy.php?request=http%3A%2F%2Fimgur.com%2FjGBIQVl.jpeg&hash=987ebeb425d1796da4d26fd938f5a07f9e3b146d)

Go to your root\raw\ui\ folder and find the file main.menu copy that file and rename it to anything you like, i'll use:

main_new.menu

open the renamed file, and look for this line:

Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1, "@MENU_SOLO_CAP", SETUP_ACTION_SOLO; LOCAL_ZOMBIE_RESET, when( !localvarBool( ui_hideBack ) ); )


Above that line add:
Code Snippet
Plaintext
CHOICE_BIND( 11, "Print text on screen:", "openScriptMenu print_text print_text" , ; )
CHOICE_KEYBINDHELP

Note: The number 11 determine's at wich position the tekst will appear in the menu, the lower the number the higher it will appear to the top of your screen.

Open launcher and add this line to your mod.csv fastfile:

Code Snippet
Plaintext
menufile,ui/main_new.menu



Now we need to make a script to make something happen. Create a new .gsc in your mods\mapname\maps\ folder and give it any name, i'll use:

button_print.gsc

inside it, paste this:
Code Snippet
Plaintext
#include maps\_utility; 
#include common_scripts\utility;
#include maps\_zombiemode_utility;

init()
{
level thread opc();
}

opc()
{
while(1)
{
level waittill( "connecting", player );
player thread player_ops();
}
}


player_ops()
{
self endon( "disconnect" );
while(1)
{
self waittill( "spawned_player" );
self thread button_response();
}
}


button_response()
{
self endon("death");
self endon("disconnect");
while(1)
{
self waittill("menuresponse", menu, response );

self thread button_pressed(response);
}
}
button_pressed(response)
{
self endon("death");
self endon("disconnect");

switch( response )
{
case "print_text":
self iprintlnbold( "^2Button Pressed" );
break;

default:
break;
}
}




Last thing to do is call the script from _zombiemode.gsc, open it and under this line:
Code Snippet
Plaintext
	maps\_zombiemode_auto_turret::init();

Add:
Code Snippet
Plaintext
	maps\button_print::init();

Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: Harry Bo21 on August 18, 2015, 10:24:10 pm
I needed this so bad, legend, thank you
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: BluntStuffy on August 19, 2015, 05:54:54 pm
legend

most people i know would disagree  :D :D


thank you

np
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: Dust on August 19, 2015, 06:16:10 pm
You are a beast man! This will definitely come in handy.
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: Harry Bo21 on August 19, 2015, 06:43:19 pm
Oh no you definitely are a legend :)
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: Eternal_Fire on August 23, 2015, 09:14:13 am
1+.... For being a legend :please:
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: Eternal_Fire on August 24, 2015, 11:11:51 am
Not sure why but i dont have this line in the menu file
Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1, "@MENU_SOLO_CAP", SETUP_ACTION_SOLO; LOCAL_ZOMBIE_RESET, when( !localvarBool( ui_hideBack ) ); )
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: BluntStuffy on August 24, 2015, 12:14:53 pm
Not sure why but i dont have this line in the menu file
Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1, "@MENU_SOLO_CAP", SETUP_ACTION_SOLO; LOCAL_ZOMBIE_RESET, when( !localvarBool( ui_hideBack ) ); )

Are you using UGX-mod? Try looking for this line instead:

Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1, "", SETUP_ACTION_SOLO, when( !localvarBool( ui_hideBack )); )
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: Eternal_Fire on August 24, 2015, 02:23:29 pm
Are you using UGX-mod? Try looking for this line instead:

Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1, "", SETUP_ACTION_SOLO, when( !localvarBool( ui_hideBack )); )

I'm not using the ugx mod, i am using the ugx script placer and it cannot find ^^ code either.
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: HitmanVere on August 24, 2015, 02:28:37 pm
I'm not using the ugx mod, i am using the ugx script placer and it cannot find ^^ code either.

Just search for
Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1,

Script placers modify the solo button to work. I have done it manually, so mine looks like this:
Code Snippet
Plaintext
CHOICE_BUTTON_VIS( 1, "SOLO", exec "map nazi_zombie_tworema"; , when( !localvarBool( ui_hideBack ) ); )
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: DeletedUser on August 24, 2015, 04:39:13 pm
most people i know would disagree  :D :D
Meanwhile, I know more menufile stuff and I'm called a legend only by jammy.
Title: Re: [TUT] Make a button do something + add a keybind option to a menu
Post by: smasher248 on August 24, 2015, 05:00:58 pm
Meanwhile, I know more menufile stuff and I'm called a legend only by jammy.

do u want a hug?