CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Gaming
Call of Duty Classics
Tutorial Section
General GSC Coding: How to create a basic menu base
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="P!X" data-source="post: 103" data-attributes="member: 24"><p><span style="font-size: 12px"><span style="color: #0000FF">Since everyone is using the same menu bases i thought im going to try to explain as good as i can how to make your own <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></span></span></p><p><span style="font-size: 12px"><span style="color: #0000FF">This Tutorial hopefully will show you how a basic menu base is working ,if not im sorry.</span></span></p><p><span style="font-size: 12px"><span style="color: #0000FF"></span></span></p><p><span style="font-size: 12px"><span style="color: #0000FF">Sooo im going to show you how to create a menu base with Menu Text,Menu Title,Background Shader,Scrollbar,Sub Menus and without Verifycation System or Player Menu!</span></span></p><p><span style="font-size: 12px"><span style="color: #0000FF">I also show you how to do it with and without \n Fix.</span></span></p><p></p><p><span style="color: #ff0000">Little Info:</span> you dont have to code it like i do there are millions of ways to code best thing is to play around with some basic menu bases,learn from them and then try to find the best way for you to code <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></p><p><span style="color: #000000"><span style="font-size: 12px"></span></span></p><p><span style="color: #000000"><span style="font-size: 12px">There are alot of ways to create a menu base but this is how i learned it and i hope you are able to learn something from this <img src="/styles/default/xenforo/smilies.emoji/people/smile.emoji.svg" class="smilie" loading="lazy" alt=":grinning:" title="Grinning :grinning:" data-shortname=":grinning:" /></span></span></p><p><span style="color: #000000"><span style="font-size: 12px">Im sorry if you are not able to understand some things cause my english is not the best and im also not very good at explaining <img src="/styles/default/xenforo/smilies.emoji/people/disappointed.emoji.svg" class="smilie" loading="lazy" alt=":disappointed:" title="Disappointed :disappointed:" data-shortname=":disappointed:" /></span></span></p><p><span style="color: #000000"><span style="font-size: 12px">But i tried my best and its also my first tutorial ever.</span></span></p><p><span style="color: #000000"><span style="font-size: 12px"></span></span></p><p></p><p><span style="color: #FF0000"><span style="font-size: 12px">Steps:</span></span></p><p>[CODE]</p><p>1.)How to Start</p><p>2.)Button Handling Start</p><p>3.)Menu Structure</p><p>4.)Menu Hud(Background,Scrollbar,Menu Title)</p><p>5.)Menu Loading + Menu Text</p><p>6.)Cursor Update + Scrollbar Position</p><p>7.)Button Handling Finish</p><p>[/CODE]</p><p></p><p></p><p></p><p><span style="font-size: 12px"><span style="color: #FF0000">1.)How to Start</span></span></p><p>[SPOILER]</p><p>This is how our script should look like when we are starting</p><p>[CODE]</p><p>#include maps\mp\_utility;</p><p>#include common_scripts\utility;</p><p>#include maps\mp\gametypes\_hud_util;</p><p>#include maps\mp\gametypes\_hud_message;</p><p></p><p>init()</p><p>{</p><p> level thread onPlayerConnect();</p><p>}</p><p>onPlayerConnect()</p><p>{</p><p> for(;;)</p><p> {</p><p> level waittill("connected", player);</p><p> player thread onPlayerSpawned();</p><p> }</p><p>}</p><p>onPlayerSpawned()</p><p>{</p><p> self endon("disconnect");</p><p> level endon("game_ended");</p><p> for(;;)</p><p> {</p><p> self waittill("spawned_player");</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>This are Functions we will need for creating Text Elems and Shader Elems</p><p>Just add them somewhere in your script</p><p>[CODE]</p><p>createText(font, fontscale, align, relative, x, y, sort, color, alpha, glowColor, glowAlpha, text)</p><p>{</p><p> textElem = CreateFontString( font, fontscale );</p><p> textElem setPoint( align, relative, x, y );</p><p> textElem.sort = sort;</p><p> textElem.type = "text";</p><p> textElem setText(text);</p><p> textElem.color = color;</p><p> textElem.alpha = alpha;</p><p> textElem.glowColor = glowColor;</p><p> textElem.glowAlpha = glowAlpha;</p><p> textElem.hideWhenInMenu = true;</p><p> return textElem;</p><p>}</p><p>createRectangle(align, relative, x, y, width, height, color, alpha, sorting, shadero)</p><p>{</p><p> barElemBG = newClientHudElem( self );</p><p> barElemBG.elemType = "bar";</p><p> if ( !level.splitScreen )</p><p> {</p><p> barElemBG.x = -2;</p><p> barElemBG.y = -2;</p><p> }</p><p> barElemBG.width = width;</p><p> barElemBG.height = height;</p><p> barElemBG.align = align;</p><p> barElemBG.relative = relative;</p><p> barElemBG.xOffset = 0;</p><p> barElemBG.yOffset = 0;</p><p> barElemBG.children = [];</p><p> barElemBG.color = color;</p><p> if(isDefined(alpha))</p><p> barElemBG.alpha = alpha;</p><p> else</p><p> barElemBG.alpha = 1;</p><p> barElemBG setShader( shadero, width , height );</p><p> barElemBG.hidden = false;</p><p> barElemBG.sort = sorting;</p><p> barElemBG setPoint(align,relative,x,y);</p><p> return barElemBG;</p><p>}</p><p>[/CODE]</p><p></p><p>Ok now we are going to create the starting function for the base</p><p>lets call the function initMenu</p><p>self.Menu = spawnStruct(); = We are going to store all menu things with this like the current opened submenu or the menu texts</p><p>self.Hud = spawnStruct(); = We are going to store all Menu Hud stuff with this</p><p>self.Menu.Opened = false; = A bool if its true thats means the menu is opened if its false it means the menu is closed</p><p>[CODE]</p><p>initMenu()</p><p>{</p><p> self.Menu = spawnStruct();</p><p> self.Hud = spawnStruct();</p><p> self.Menu.Opened = false;</p><p>}</p><p>[/CODE]</p><p></p><p>So Now we are going to thread the initMenu function from onPlayerConnect like that</p><p>[CODE]</p><p>onPlayerConnect()</p><p>{</p><p> for(;;)</p><p> {</p><p> level waittill("connected", player);</p><p> player thread onPlayerSpawned();</p><p> if(player isHost())</p><p> {</p><p> player thread initMenu();</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: #FF0000">2.)Button Handling Start</span></span></p><p>[SPOILER]</p><p>Now we are going to create the Button Handling so again create a function lets call it menuButtons with a for loop in it</p><p>this function is threaded from the initMenu() function</p><p>[CODE]</p><p>menuButtons()</p><p>{</p><p> self endon("disconnect");</p><p> for(;;)</p><p> {</p><p> wait 0.05;</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>Now add buttons to it using if statements</p><p>[CODE]</p><p>menuButtons()</p><p>{</p><p> self endon("disconnect");</p><p> for(;;)</p><p> {</p><p> if(self FragButtonPressed())</p><p> {</p><p> wait .3;</p><p> }</p><p> if(self AdsButtonPressed())</p><p> {</p><p> wait .1;</p><p> }</p><p> if(self AttackButtonPressed())</p><p> {</p><p> wait .1;</p><p> }</p><p> if(self UseButtonPressed())</p><p> {</p><p> wait .3;</p><p> }</p><p> if(self MeleeButtonPressed())</p><p> {</p><p> wait .3;</p><p> }</p><p> wait 0.05;</p><p> }</p><p>}</p><p>[/CODE]</p><p>Dont forget to add a little wait at the end of the for loop cause if you dont add that your menu will crash</p><p>Also add a wait for every button cause that makes the menu easier to use <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></p><p></p><p>Ok now you have to add your menu opened bool to the buttons to make it so that some buttons only work when the menu is opened or closed</p><p>[CODE]</p><p>menuButtons()</p><p>{</p><p> self endon("disconnect");</p><p> for(;;)</p><p> {</p><p> if(self FragButtonPressed() && self.Menu.Opened==false)</p><p> {</p><p> wait .3;</p><p> }</p><p> if(self AdsButtonPressed() && self.Menu.Opened==true)</p><p> {</p><p> wait .1;</p><p> }</p><p> if(self AttackButtonPressed()&& self.Menu.Opened==true)</p><p> {</p><p> wait .1;</p><p> }</p><p> if(self UseButtonPressed()&& self.Menu.Opened==true)</p><p> {</p><p> wait .3;</p><p> }</p><p> if(self MeleeButtonPressed()&& self.Menu.Opened==true)</p><p> {</p><p> wait .3;</p><p> }</p><p> wait 0.05;</p><p> }</p><p>}</p><p>[/CODE]</p><p>So now we have a button handling that does nothing atm xD</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: #FF0000">3.)Menu Structure</span></span></p><p>[SPOILER]</p><p>The Menu Structure is where you add all your sub menus and options</p><p></p><p>We are going to create a simple function like this</p><p>This functions is threaded on initMenu()</p><p>[CODE]</p><p>menuStructure()</p><p>{</p><p>}</p><p>[/CODE]</p><p></p><p>We also will need two other functions for this</p><p></p><p>Function to create a menu</p><p>self.Menu.title[menu] = title; = Used to store the Menu Title</p><p>self.Menu.parent[menu] = parent; = Used to Store the Menu Parent so the menu knows what to do when the Back button is pressed</p><p>[CODE]</p><p>CreateMenu(menu,title,parent)</p><p>{</p><p> self.Menu.title[menu] = title;</p><p> self.Menu.parent[menu] = parent;</p><p>}</p><p>[/CODE]</p><p></p><p>and a function to create options</p><p>[CODE]</p><p>addOption(menu,index,text,func,input)</p><p>{</p><p> self.Menu.Text[menu][index] = text;</p><p> self.Menu.Func[menu][index] = func;</p><p> self.Menu.Input[menu][index] = input;</p><p>}</p><p>[/CODE]</p><p></p><p>Also add this somewhere in your script its just a test function</p><p>[CODE]</p><p>Test()</p><p>{</p><p> self iprintln("^1TEST");</p><p>}</p><p>[/CODE]</p><p></p><p>Ok now lets create the Main Menu</p><p>[CODE]</p><p>menuStructure()</p><p>{</p><p> self CreateMenu("main","Main Menu","Exit");</p><p> self addOption("main",0,"Option 1",::Test,"");</p><p> self addOption("main",1,"Option 2",::Test,"");</p><p> self addOption("main",2,"Option 3",::Test,"");</p><p> self addOption("main",3,"Option 4",::Test,"");</p><p> self addOption("main",4,"Option 5",::Test,"");</p><p> self addOption("main",5,"Option 6",::Test,"");</p><p> self addOption("main",6,"Option 7",::Test,"");</p><p> self addOption("main",7,"Option 8",::Test,"");</p><p> self addOption("main",8,"Option 9",::Test,"");</p><p> self addOption("main",9,"Option 10",::Test,"");</p><p> self addOption("main",10,"Option 11",::Test,"");</p><p> self addOption("main",11,"Option 12",::Test,"");</p><p> self addOption("main",12,"Option 13",::Test,"");</p><p> self addOption("main",13,"Option 14",::Test,"");</p><p> self addOption("main",14,"Option 15",::Test,"");</p><p>}</p><p>[/CODE]</p><p></p><p>Sorry i cant explain that better cause of my english <img src="/styles/default/xenforo/smilies.emoji/people/disappointed.emoji.svg" class="smilie" loading="lazy" alt=":disappointed:" title="Disappointed :disappointed:" data-shortname=":disappointed:" /></p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: #FF0000">4.)Menu Hud(Background,Scrollbar,Menu Title)</span></span></p><p>[SPOILER]</p><p>We are going to need two functions one to create and one to destroy our menu Hud</p><p>[CODE]</p><p>createHud()</p><p>{</p><p>}</p><p>destroyHud()</p><p>{</p><p>}</p><p>[/CODE]</p><p></p><p>Now we are adding a Background shader,Scrollbar Shader and a Menu Title Text Elems to them</p><p>[CODE]</p><p>createHud()</p><p>{</p><p> self.Hud.Title = createText("default",2.0,"CENTER","TOP",0,10,0,(1,1,1),1,(0,0,0),0,"");</p><p> self.Hud.Title.foreground = true;</p><p> self.Hud.Background = createRectangle("CENTER","CENTER",0,0,200,1000,(0,0,0),.5,0,"white");</p><p> self.Hud.Scrollbar = createRectangle("CENTER","TOP",0,40,200,20,(0,0,0),1,0,"white");</p><p>}</p><p>destroyHud()</p><p>{</p><p> self.Hud.Title destroy();</p><p> self.Hud.Background destroy();</p><p> self.Hud.Scrollbar destroy();</p><p>}</p><p>[/CODE]</p><p>self.Hud.Title.foreground = true; = Used to make the text always stand in front of the shaders</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: rgb(255, 0, 0)">5.)Menu Loading + Menu Text</span></span></p><p>[SPOILER]</p><p>For that we are going to create another function</p><p>lets call it _loadMenu and add some things to it</p><p>this function also has a input its needed to tell the function what menu to load</p><p>self.Menu.CurrentMenu = menu; = This is used to store the current opened menu</p><p>self.Scroller = 0; = Sets our scroller/Cursor back to 0</p><p>self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]); = Sets the menu title</p><p>[CODE]</p><p>_loadMenu(menu)</p><p>{</p><p> self.Menu.CurrentMenu = menu;</p><p> self.Scroller = 0;</p><p> self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]);</p><p>}</p><p>[/CODE]</p><p></p><p>Ok now we need two functions to create and destroy the menu text</p><p>Without \n Fix</p><p>[CODE]</p><p>createMenuText()</p><p>{</p><p> for(i=0;i<self.Menu.Text[self.Menu.CurrentMenu].size;i++)</p><p> {</p><p> self.Hud.Text[i] = createText("default",1.5,"CENTER","TOP",0,40+(18*i),0,(1,1,1),1,(0,0,0),0,self.Menu.Text[self.Menu.CurrentMenu][i]);</p><p> self.Hud.Text[i].foreground = true;</p><p> }</p><p>}</p><p>destroyMenuText()</p><p>{</p><p> if(isDefined(self.Hud.Text))</p><p> {</p><p> for(i=0;i<self.Hud.Text.size;i++)</p><p> {</p><p> self.Hud.Text[i] destroy();</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>With \n Fix</p><p>[CODE]</p><p>createMenuText()</p><p>{</p><p> string = "";</p><p> for(i=0;i<self.Menu.Text[self.Menu.CurrentMenu].size;i++)</p><p> {</p><p> string += self.Menu.Text[self.Menu.CurrentMenu][i]+"\n";</p><p> }</p><p> self.Hud.Text = createText("default",1.5,"CENTER","TOP",0,40,0,(1,1,1),1,(0,0,0),0,string);</p><p> self.Hud.Text.foreground = true;</p><p>}</p><p>destroyMenuText()</p><p>{</p><p> if(isDefined(self.Hud.Text))</p><p> {</p><p> self.Hud.Text destroy();</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>Then thread those functions on your _loadMenu function like this</p><p>[CODE]</p><p>_loadMenu(menu)</p><p>{</p><p> self destroyMenuText();</p><p> self.Menu.CurrentMenu = menu;</p><p> self.Scroller = 0;</p><p> self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]);</p><p> self createMenuText();</p><p>}</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: rgb(255, 0, 0)">6.)Cursor Update + Scrollbar Position</span></span></p><p>[SPOILER]</p><p>Now Create a function called _scrollUpdate or something else</p><p>[CODE]</p><p>_scrollUpdate()</p><p>{</p><p>}</p><p>[/CODE]</p><p></p><p>Now use if statements to make it so if the scroller is smaller then 0 then set the scroller to the amount of menu text/options in the current menu.</p><p>And also if the scroller is bigger then the amount of menu text/options in the current menu set it to 0</p><p>[CODE]</p><p>_scrollUpdate()</p><p>{</p><p> if(self.Scroller<0)</p><p> {</p><p> self.Scroller = self.Menu.Text[self.Menu.CurrentMenu].size-1;</p><p> }</p><p> if(self.Scroller>self.Menu.Text[self.Menu.CurrentMenu].size-1)</p><p> {</p><p> self.Scroller = 0;</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>So now we need something that makes the scrollbar move</p><p>it works like that</p><p>self.Hud.Scrollbar.y = SpawnPosition+(SpaceBetweenTexts*self.Scroller);</p><p>this should look like that</p><p>[CODE]</p><p>_scrollUpdate()</p><p>{</p><p> if(self.Scroller<0)</p><p> {</p><p> self.Scroller = self.Menu.Text[self.Menu.CurrentMenu].size-1;</p><p> }</p><p> if(self.Scroller>self.Menu.Text[self.Menu.CurrentMenu].size-1)</p><p> {</p><p> self.Scroller = 0;</p><p> }</p><p> self.Hud.Scrollbar.y = 40+(18*self.Scroller);</p><p>}</p><p>[/CODE]</p><p></p><p>After that we are going to update our _loadMenu function again</p><p>[CODE]</p><p>_loadMenu(menu)</p><p>{</p><p> self destroyMenuText();</p><p> self.Menu.CurrentMenu = menu;</p><p> self.Scroller = 0;</p><p> self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]);</p><p> self createMenuText();</p><p> self _scrollUpdate();</p><p>}</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: rgb(255, 0, 0)">7.)Button Handling Finish</span></span></p><p>[SPOILER]</p><p>We are going to start with our Open Menu Button</p><p>We are going to add:</p><p>Set Menu Opened bool to true</p><p>Freeze User</p><p>Create the Hud</p><p>and load the Main Menu</p><p>[CODE]</p><p>if(self FragButtonPressed() && self.Menu.Opened==false)</p><p>{</p><p> self.Menu.Opened = true;</p><p> self freezeControls(true);</p><p> self thread createHud();</p><p> self _loadMenu("main");</p><p> wait .3;</p><p>}</p><p>[/CODE]</p><p></p><p>Now the scrolling Buttons(Aim and Attack)</p><p>[CODE]</p><p>if(self AdsButtonPressed() && self.Menu.Opened==true)</p><p>{</p><p> self.Scroller --;</p><p> self _scrollUpdate();</p><p> wait .1;</p><p>}</p><p>if(self AttackButtonPressed() && self.Menu.Opened==true)</p><p>{</p><p> self.Scroller ++;</p><p> self _scrollUpdate();</p><p> wait .1;</p><p>}</p><p>[/CODE]</p><p></p><p>Select Button</p><p>Function of Current Selected Option = self.Menu.Func[menu][scroller/cursor]</p><p>Input of Current Selected Option = self.Menu.Input[menu][scroller/cursor]</p><p>self thread [[Function of Current Selected Option]](Input of Current Selected Option);</p><p>[CODE]</p><p>if(self UseButtonPressed() && self.Menu.Opened==true)</p><p>{</p><p> self thread [[self.Menu.Func[self.Menu.CurrentMenu][self.Scroller]]](self.Menu.Input[self.Menu.CurrentMenu][self.Scroller]);</p><p> wait .3;</p><p>}</p><p>[/CODE]</p><p></p><p>a little example to make it easier to understand</p><p>[CODE]</p><p>doIt()</p><p>{</p><p> self MainFunction(::printSomething,"Hello");</p><p>}</p><p>MainFunction(function,input)</p><p>{</p><p> self thread [[function]](input);</p><p>}</p><p>printSomething(text)</p><p>{</p><p> self iprintln(text);</p><p>}</p><p>[/CODE]</p><p></p><p>Back/Exit Button</p><p>when the parent of your current opened sub menu is Exit then close the menu if not then load the parent of the current opened sub menu</p><p>[CODE]</p><p>if(self MeleeButtonPressed() && self.Menu.Opened==true)</p><p>{</p><p> if(self.Menu.parent[self.Menu.CurrentMenu]=="Exit")</p><p> {</p><p> self.Menu.Opened = false;</p><p> self freezeControls(false);</p><p> self thread destroyMenuText();</p><p> self thread destroyHud();</p><p> }</p><p> else</p><p> {</p><p> self _loadMenu(self.Menu.parent[self.Menu.CurrentMenu]);</p><p> }</p><p> wait .3;</p><p>}</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: rgb(255, 0, 0)">Extra: How to add a submenu</span></span></p><p>[SPOILER]</p><p>[CODE]</p><p>menuStructure()</p><p>{</p><p> self CreateMenu("main","Main Menu","Exit");</p><p> self addOption("main",0,"Open Sub Menu",::_loadMenu,"sub");</p><p> self addOption("main",1,"Option 2",::Test,"");</p><p> self addOption("main",2,"Option 3",::Test,"");</p><p> self addOption("main",3,"Option 4",::Test,"");</p><p> self addOption("main",4,"Option 5",::Test,"");</p><p> self addOption("main",5,"Option 6",::Test,"");</p><p> self addOption("main",6,"Option 7",::Test,"");</p><p> self addOption("main",7,"Option 8",::Test,"");</p><p> self addOption("main",8,"Option 9",::Test,"");</p><p> self addOption("main",9,"Option 10",::Test,"");</p><p> self addOption("main",10,"Option 11",::Test,"");</p><p> self addOption("main",11,"Option 12",::Test,"");</p><p> self addOption("main",12,"Option 13",::Test,"");</p><p> self addOption("main",13,"Option 14",::Test,"");</p><p> self addOption("main",14,"Option 15",::Test,"");</p><p></p><p></p><p> self CreateMenu("sub","Sub Menu","main");</p><p> self addOption("sub",0,"Sub Menu Option 1",::Test,"");</p><p> self addOption("sub",1,"Sub Menu Option 2",::Test,"");</p><p> self addOption("sub",2,"Sub Menu Option 3",::Test,"");</p><p> self addOption("sub",3,"Sub Menu Option 4",::Test,"");</p><p> self addOption("sub",4,"Sub Menu Option 5",::Test,"");</p><p>}</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p><span style="font-size: 12px"><span style="color: rgb(0, 0, 255)">This is how it should look like when you are finished:</span></span> <a href="http://pastebin.com/5SMU9RLm" target="_blank">[C++] [TUT]Simple Menu Base - Pastebin.com</a></p><p><img src="http://puu.sh/jsCIs/eb51ee365c.jpg" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p></blockquote><p></p>
[QUOTE="P!X, post: 103, member: 24"] [SIZE=3][COLOR=#0000FF]Since everyone is using the same menu bases i thought im going to try to explain as good as i can how to make your own :) This Tutorial hopefully will show you how a basic menu base is working ,if not im sorry. Sooo im going to show you how to create a menu base with Menu Text,Menu Title,Background Shader,Scrollbar,Sub Menus and without Verifycation System or Player Menu! I also show you how to do it with and without \n Fix.[/COLOR][/SIZE] [COLOR=#ff0000]Little Info:[/COLOR] you dont have to code it like i do there are millions of ways to code best thing is to play around with some basic menu bases,learn from them and then try to find the best way for you to code :) [COLOR=#000000][SIZE=3] There are alot of ways to create a menu base but this is how i learned it and i hope you are able to learn something from this :D Im sorry if you are not able to understand some things cause my english is not the best and im also not very good at explaining :( But i tried my best and its also my first tutorial ever. [/SIZE][/COLOR] [COLOR=#FF0000][SIZE=3]Steps:[/SIZE][/COLOR] [CODE] 1.)How to Start 2.)Button Handling Start 3.)Menu Structure 4.)Menu Hud(Background,Scrollbar,Menu Title) 5.)Menu Loading + Menu Text 6.)Cursor Update + Scrollbar Position 7.)Button Handling Finish [/CODE] [SIZE=3][COLOR=#FF0000]1.)How to Start[/COLOR][/SIZE] [SPOILER] This is how our script should look like when we are starting [CODE] #include maps\mp\_utility; #include common_scripts\utility; #include maps\mp\gametypes\_hud_util; #include maps\mp\gametypes\_hud_message; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); player thread onPlayerSpawned(); } } onPlayerSpawned() { self endon("disconnect"); level endon("game_ended"); for(;;) { self waittill("spawned_player"); } } [/CODE] This are Functions we will need for creating Text Elems and Shader Elems Just add them somewhere in your script [CODE] createText(font, fontscale, align, relative, x, y, sort, color, alpha, glowColor, glowAlpha, text) { textElem = CreateFontString( font, fontscale ); textElem setPoint( align, relative, x, y ); textElem.sort = sort; textElem.type = "text"; textElem setText(text); textElem.color = color; textElem.alpha = alpha; textElem.glowColor = glowColor; textElem.glowAlpha = glowAlpha; textElem.hideWhenInMenu = true; return textElem; } createRectangle(align, relative, x, y, width, height, color, alpha, sorting, shadero) { barElemBG = newClientHudElem( self ); barElemBG.elemType = "bar"; if ( !level.splitScreen ) { barElemBG.x = -2; barElemBG.y = -2; } barElemBG.width = width; barElemBG.height = height; barElemBG.align = align; barElemBG.relative = relative; barElemBG.xOffset = 0; barElemBG.yOffset = 0; barElemBG.children = []; barElemBG.color = color; if(isDefined(alpha)) barElemBG.alpha = alpha; else barElemBG.alpha = 1; barElemBG setShader( shadero, width , height ); barElemBG.hidden = false; barElemBG.sort = sorting; barElemBG setPoint(align,relative,x,y); return barElemBG; } [/CODE] Ok now we are going to create the starting function for the base lets call the function initMenu self.Menu = spawnStruct(); = We are going to store all menu things with this like the current opened submenu or the menu texts self.Hud = spawnStruct(); = We are going to store all Menu Hud stuff with this self.Menu.Opened = false; = A bool if its true thats means the menu is opened if its false it means the menu is closed [CODE] initMenu() { self.Menu = spawnStruct(); self.Hud = spawnStruct(); self.Menu.Opened = false; } [/CODE] So Now we are going to thread the initMenu function from onPlayerConnect like that [CODE] onPlayerConnect() { for(;;) { level waittill("connected", player); player thread onPlayerSpawned(); if(player isHost()) { player thread initMenu(); } } } [/CODE] [/SPOILER] [SIZE=3][COLOR=#FF0000]2.)Button Handling Start[/COLOR][/SIZE] [SPOILER] Now we are going to create the Button Handling so again create a function lets call it menuButtons with a for loop in it this function is threaded from the initMenu() function [CODE] menuButtons() { self endon("disconnect"); for(;;) { wait 0.05; } } [/CODE] Now add buttons to it using if statements [CODE] menuButtons() { self endon("disconnect"); for(;;) { if(self FragButtonPressed()) { wait .3; } if(self AdsButtonPressed()) { wait .1; } if(self AttackButtonPressed()) { wait .1; } if(self UseButtonPressed()) { wait .3; } if(self MeleeButtonPressed()) { wait .3; } wait 0.05; } } [/CODE] Dont forget to add a little wait at the end of the for loop cause if you dont add that your menu will crash Also add a wait for every button cause that makes the menu easier to use :) Ok now you have to add your menu opened bool to the buttons to make it so that some buttons only work when the menu is opened or closed [CODE] menuButtons() { self endon("disconnect"); for(;;) { if(self FragButtonPressed() && self.Menu.Opened==false) { wait .3; } if(self AdsButtonPressed() && self.Menu.Opened==true) { wait .1; } if(self AttackButtonPressed()&& self.Menu.Opened==true) { wait .1; } if(self UseButtonPressed()&& self.Menu.Opened==true) { wait .3; } if(self MeleeButtonPressed()&& self.Menu.Opened==true) { wait .3; } wait 0.05; } } [/CODE] So now we have a button handling that does nothing atm xD [/SPOILER] [SIZE=3][COLOR=#FF0000]3.)Menu Structure[/COLOR][/SIZE] [SPOILER] The Menu Structure is where you add all your sub menus and options We are going to create a simple function like this This functions is threaded on initMenu() [CODE] menuStructure() { } [/CODE] We also will need two other functions for this Function to create a menu self.Menu.title[menu] = title; = Used to store the Menu Title self.Menu.parent[menu] = parent; = Used to Store the Menu Parent so the menu knows what to do when the Back button is pressed [CODE] CreateMenu(menu,title,parent) { self.Menu.title[menu] = title; self.Menu.parent[menu] = parent; } [/CODE] and a function to create options [CODE] addOption(menu,index,text,func,input) { self.Menu.Text[menu][index] = text; self.Menu.Func[menu][index] = func; self.Menu.Input[menu][index] = input; } [/CODE] Also add this somewhere in your script its just a test function [CODE] Test() { self iprintln("^1TEST"); } [/CODE] Ok now lets create the Main Menu [CODE] menuStructure() { self CreateMenu("main","Main Menu","Exit"); self addOption("main",0,"Option 1",::Test,""); self addOption("main",1,"Option 2",::Test,""); self addOption("main",2,"Option 3",::Test,""); self addOption("main",3,"Option 4",::Test,""); self addOption("main",4,"Option 5",::Test,""); self addOption("main",5,"Option 6",::Test,""); self addOption("main",6,"Option 7",::Test,""); self addOption("main",7,"Option 8",::Test,""); self addOption("main",8,"Option 9",::Test,""); self addOption("main",9,"Option 10",::Test,""); self addOption("main",10,"Option 11",::Test,""); self addOption("main",11,"Option 12",::Test,""); self addOption("main",12,"Option 13",::Test,""); self addOption("main",13,"Option 14",::Test,""); self addOption("main",14,"Option 15",::Test,""); } [/CODE] Sorry i cant explain that better cause of my english :( [/SPOILER] [SIZE=3][COLOR=#FF0000]4.)Menu Hud(Background,Scrollbar,Menu Title)[/COLOR][/SIZE] [SPOILER] We are going to need two functions one to create and one to destroy our menu Hud [CODE] createHud() { } destroyHud() { } [/CODE] Now we are adding a Background shader,Scrollbar Shader and a Menu Title Text Elems to them [CODE] createHud() { self.Hud.Title = createText("default",2.0,"CENTER","TOP",0,10,0,(1,1,1),1,(0,0,0),0,""); self.Hud.Title.foreground = true; self.Hud.Background = createRectangle("CENTER","CENTER",0,0,200,1000,(0,0,0),.5,0,"white"); self.Hud.Scrollbar = createRectangle("CENTER","TOP",0,40,200,20,(0,0,0),1,0,"white"); } destroyHud() { self.Hud.Title destroy(); self.Hud.Background destroy(); self.Hud.Scrollbar destroy(); } [/CODE] self.Hud.Title.foreground = true; = Used to make the text always stand in front of the shaders [/SPOILER] [SIZE=3][COLOR=rgb(255, 0, 0)]5.)Menu Loading + Menu Text[/COLOR][/SIZE] [SPOILER] For that we are going to create another function lets call it _loadMenu and add some things to it this function also has a input its needed to tell the function what menu to load self.Menu.CurrentMenu = menu; = This is used to store the current opened menu self.Scroller = 0; = Sets our scroller/Cursor back to 0 self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]); = Sets the menu title [CODE] _loadMenu(menu) { self.Menu.CurrentMenu = menu; self.Scroller = 0; self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]); } [/CODE] Ok now we need two functions to create and destroy the menu text Without \n Fix [CODE] createMenuText() { for(i=0;i<self.Menu.Text[self.Menu.CurrentMenu].size;i++) { self.Hud.Text[i] = createText("default",1.5,"CENTER","TOP",0,40+(18*i),0,(1,1,1),1,(0,0,0),0,self.Menu.Text[self.Menu.CurrentMenu][i]); self.Hud.Text[i].foreground = true; } } destroyMenuText() { if(isDefined(self.Hud.Text)) { for(i=0;i<self.Hud.Text.size;i++) { self.Hud.Text[i] destroy(); } } } [/CODE] With \n Fix [CODE] createMenuText() { string = ""; for(i=0;i<self.Menu.Text[self.Menu.CurrentMenu].size;i++) { string += self.Menu.Text[self.Menu.CurrentMenu][i]+"\n"; } self.Hud.Text = createText("default",1.5,"CENTER","TOP",0,40,0,(1,1,1),1,(0,0,0),0,string); self.Hud.Text.foreground = true; } destroyMenuText() { if(isDefined(self.Hud.Text)) { self.Hud.Text destroy(); } } [/CODE] Then thread those functions on your _loadMenu function like this [CODE] _loadMenu(menu) { self destroyMenuText(); self.Menu.CurrentMenu = menu; self.Scroller = 0; self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]); self createMenuText(); } [/CODE] [/SPOILER] [SIZE=3][COLOR=rgb(255, 0, 0)]6.)Cursor Update + Scrollbar Position[/COLOR][/SIZE] [SPOILER] Now Create a function called _scrollUpdate or something else [CODE] _scrollUpdate() { } [/CODE] Now use if statements to make it so if the scroller is smaller then 0 then set the scroller to the amount of menu text/options in the current menu. And also if the scroller is bigger then the amount of menu text/options in the current menu set it to 0 [CODE] _scrollUpdate() { if(self.Scroller<0) { self.Scroller = self.Menu.Text[self.Menu.CurrentMenu].size-1; } if(self.Scroller>self.Menu.Text[self.Menu.CurrentMenu].size-1) { self.Scroller = 0; } } [/CODE] So now we need something that makes the scrollbar move it works like that self.Hud.Scrollbar.y = SpawnPosition+(SpaceBetweenTexts*self.Scroller); this should look like that [CODE] _scrollUpdate() { if(self.Scroller<0) { self.Scroller = self.Menu.Text[self.Menu.CurrentMenu].size-1; } if(self.Scroller>self.Menu.Text[self.Menu.CurrentMenu].size-1) { self.Scroller = 0; } self.Hud.Scrollbar.y = 40+(18*self.Scroller); } [/CODE] After that we are going to update our _loadMenu function again [CODE] _loadMenu(menu) { self destroyMenuText(); self.Menu.CurrentMenu = menu; self.Scroller = 0; self.Hud.Title setText(self.Menu.title[self.Menu.CurrentMenu]); self createMenuText(); self _scrollUpdate(); } [/CODE] [/SPOILER] [SIZE=3][COLOR=rgb(255, 0, 0)]7.)Button Handling Finish[/COLOR][/SIZE] [SPOILER] We are going to start with our Open Menu Button We are going to add: Set Menu Opened bool to true Freeze User Create the Hud and load the Main Menu [CODE] if(self FragButtonPressed() && self.Menu.Opened==false) { self.Menu.Opened = true; self freezeControls(true); self thread createHud(); self _loadMenu("main"); wait .3; } [/CODE] Now the scrolling Buttons(Aim and Attack) [CODE] if(self AdsButtonPressed() && self.Menu.Opened==true) { self.Scroller --; self _scrollUpdate(); wait .1; } if(self AttackButtonPressed() && self.Menu.Opened==true) { self.Scroller ++; self _scrollUpdate(); wait .1; } [/CODE] Select Button Function of Current Selected Option = self.Menu.Func[menu][scroller/cursor] Input of Current Selected Option = self.Menu.Input[menu][scroller/cursor] self thread [[Function of Current Selected Option]](Input of Current Selected Option); [CODE] if(self UseButtonPressed() && self.Menu.Opened==true) { self thread [[self.Menu.Func[self.Menu.CurrentMenu][self.Scroller]]](self.Menu.Input[self.Menu.CurrentMenu][self.Scroller]); wait .3; } [/CODE] a little example to make it easier to understand [CODE] doIt() { self MainFunction(::printSomething,"Hello"); } MainFunction(function,input) { self thread [[function]](input); } printSomething(text) { self iprintln(text); } [/CODE] Back/Exit Button when the parent of your current opened sub menu is Exit then close the menu if not then load the parent of the current opened sub menu [CODE] if(self MeleeButtonPressed() && self.Menu.Opened==true) { if(self.Menu.parent[self.Menu.CurrentMenu]=="Exit") { self.Menu.Opened = false; self freezeControls(false); self thread destroyMenuText(); self thread destroyHud(); } else { self _loadMenu(self.Menu.parent[self.Menu.CurrentMenu]); } wait .3; } [/CODE] [/SPOILER] [SIZE=3][COLOR=rgb(255, 0, 0)]Extra: How to add a submenu[/COLOR][/SIZE] [SPOILER] [CODE] menuStructure() { self CreateMenu("main","Main Menu","Exit"); self addOption("main",0,"Open Sub Menu",::_loadMenu,"sub"); self addOption("main",1,"Option 2",::Test,""); self addOption("main",2,"Option 3",::Test,""); self addOption("main",3,"Option 4",::Test,""); self addOption("main",4,"Option 5",::Test,""); self addOption("main",5,"Option 6",::Test,""); self addOption("main",6,"Option 7",::Test,""); self addOption("main",7,"Option 8",::Test,""); self addOption("main",8,"Option 9",::Test,""); self addOption("main",9,"Option 10",::Test,""); self addOption("main",10,"Option 11",::Test,""); self addOption("main",11,"Option 12",::Test,""); self addOption("main",12,"Option 13",::Test,""); self addOption("main",13,"Option 14",::Test,""); self addOption("main",14,"Option 15",::Test,""); self CreateMenu("sub","Sub Menu","main"); self addOption("sub",0,"Sub Menu Option 1",::Test,""); self addOption("sub",1,"Sub Menu Option 2",::Test,""); self addOption("sub",2,"Sub Menu Option 3",::Test,""); self addOption("sub",3,"Sub Menu Option 4",::Test,""); self addOption("sub",4,"Sub Menu Option 5",::Test,""); } [/CODE] [/SPOILER] [SIZE=3][COLOR=rgb(0, 0, 255)]This is how it should look like when you are finished:[/COLOR][/SIZE] [URL='http://pastebin.com/5SMU9RLm'][C++] [TUT]Simple Menu Base - Pastebin.com[/URL] [IMG]http://puu.sh/jsCIs/eb51ee365c.jpg[/IMG] [/QUOTE]
Verification
Post reply
Forums
Gaming
Call of Duty Classics
Tutorial Section
General GSC Coding: How to create a basic menu base
CabConModding is now on facebook! Check the latest Updates, the Site Status and much more now!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top