Advertisement
aokmikey

Menu base for se7ensins commented on all line

Aug 1st, 2014
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.04 KB | None | 0 0
  1. #include maps\_utility;
  2. #include common_scripts\utility;
  3. #include maps\_hud_util;
  4.  
  5. //--------Header----------------------------------------//
  6. // If you use this menu base then all i ask for is      //
  7. // credit and this header to be left here               //
  8. //----------------------------------------End-----------//
  9.  
  10. onPlayerConnect()
  11. {
  12.     for(;;)
  13.     {
  14.         level waittill( "connected", player );
  15.         player thread onPlayerSpawned();
  16.     }
  17. }
  18.  
  19. onPlayerSpawned()
  20. {
  21.     for(;;)
  22.     {
  23.         self waittill( "spawned_player" ); //this waits until the player spawns until it can exicute the functions bellow
  24.         self thread Spawn(); //This is where we will be handeling each players functions
  25.         self setClientDvar( "loc_warnings", "0" ); //makes sure there is no wanings on HUD (heads up display)
  26.         self setClientDvar( "loc_warningsAsErrors", "0" ); //same as above
  27.         self setClientDvar("sv_cheats", 1);
  28.     }
  29. }
  30.  
  31.  
  32. Spawn()
  33. {
  34.     //First we are going to make sure the menu can work for each player in the right way
  35.     //so we are going to have to make sure it does not double thread the menu.
  36.     //this is simple.
  37.  
  38.     //------------header---------------------------------------------------------------------------
  39.     /*
  40.     Do not read untill you have read all the rest
  41.  
  42.     I have put this here because i need to explain that i am added the menu addition last and
  43.     that is it being put up here because it needs to run for every player even if they are not
  44.     going to be having the mod menu.
  45.     i have hadded argument into the function AddMenuSet() because it will need it for the
  46.     verification.
  47.     */
  48.     //----------------------------------------------------end--------------------------------------
  49.  
  50.     self AddMenuSet();
  51.  
  52.     //first we are going to check for if the player it is looking at is the host
  53.     //like this
  54.     if(self == get_players()[0] && !isDefined(self.threaded)) //once we have this we need to make sure it can only thread once.
  55.     {
  56.         /* By putting the ! befor isDefined it means its checking if self.threaded is not defined.
  57.             we are now going to put self.threaded = true at the bottom on this if statment to make
  58.             sure it can only thread once */
  59.         self.score += 100000;
  60.         self thread menuBase(); /*By putting self thread for this it means that the function will not stall.
  61.             if you put self menuBase() because menu base is going to be a for loop (more on that later) it
  62.             would mean the function would never move on. */
  63.         self.hasMenu = true; //this is for verfication if it is true then you will be able to take the menu and not give it but if its false you can give the menu but not take it.
  64.         self.functionThreaded = true;
  65.         self.verfication = "Admin";//because this will have verfication i am going to add this now all it does is sets the player via a var to host
  66.         self.threaded = true; //Done  :)
  67.  
  68.     }
  69.     //right now the host has the menu we are going to make sure we can thread things for other players so here we go
  70.     if(self != get_players()[0]) //by putting != it means if the player is not host then continue with the statment
  71.     {
  72.         self.hasMenu = false;
  73.         self.functionThreaded = false;
  74.         self.verfication = "unverfied";//because this will have verfication i am going to add this now all it does is sets the player via a var to unverfied
  75.         self.score += 100000; //because we are nice lets give them noobs some points
  76.         //because we are adding verification into the menubase we are going to to thread the menu base now for other players.
  77.     }
  78. }
  79.  
  80. //very simple test function
  81. test(text)
  82. {
  83.     self iprintLn(text); //prints text on the screen.
  84. }
  85.  
  86.  
  87. AddMenuSet(main)
  88. {
  89.     AddMenu("mainMenu"); //this adds a menu and by not putting anything in the next argument we are not defining a parent.
  90.     if(self returnVerfication() > 0) //menus for verfided people
  91.     {
  92.         AddMenuChild("main Menu options 1", ::newMenu, "subMenu"); //this adds a menu with function and a argument
  93.         AddMenuChild("main Menu options 2"); //this adds a black menu with only text
  94.         AddMenuChild("main Menu options 3");
  95.     }
  96.     if(self returnVerfication() > 1) //menus for cohost
  97.     {
  98.         AddMenuChild("main Menu options 4");
  99.         AddMenuChild("main Menu options 5");
  100.         AddMenuChild("main Menu options 6");
  101.         AddMenuChild("main Menu options 7");
  102.     }
  103.     if(self returnVerfication() > 2) //menus for host
  104.     {
  105.         AddMenuChild("main Menu options 8");
  106.         AddMenuChild("main Menu options 9");
  107.         AddMenuChild("main Menu options 10");
  108.         AddMenuChild("main Menu options 11");
  109.         AddMenuChild("Player verfication", ::newMenu, "playersVe");
  110.     }
  111.  
  112.     //this supply the menu with a quick and simple way of redefining all the menus for the main menu.
  113.     if(isDefined(main))
  114.         return;
  115.  
  116.     AddMenu("subMenu", "mainMenu"); //doing this defines parent so when you click back it will see this menu has a parent and it will go back to the parent menu which is mainMenu for this menu.
  117.     AddMenuChild("sub menu options 1", ::test, "subMenu"); //this makes a menu with a test function to run when clicked.
  118.     AddMenuChild("sub menu options 2");
  119.     AddMenuChild("sub menu options 3");
  120.     AddMenuChild("sub menu options 4");
  121.     AddMenuChild("sub menu options 5");
  122.     AddMenuChild("sub menu options 6");
  123.     AddMenuChild("sub menu options 7");
  124.     AddMenuChild("sub menu options 8");
  125.     AddMenuChild("sub menu options 9");
  126.  
  127.     /*
  128.         Now i hope you are ready because this is going to be one of the hardest things to understand
  129.         because of how much is going on at just one time so we can watch everything. this is not a nice
  130.         thing to code or to read but this is the best way to add verfication into your mod menu.
  131.     */
  132.  
  133.     AddMenu("playersVe", "mainMenu"); // this defines the menu set for whats to come
  134.     for(a = 0; a < get_players().size; a++)
  135.     { //this is being done like this because of the menumemory is the add menu function.
  136.         //if(a == get_players()[0])
  137.         //  continue;
  138.         AddMenuChild("Options for "+get_players()[a].playername, ::newMenu, "playerOptions"+get_players()[a].playername);
  139.     }
  140.  
  141.     for(a = 0; a< get_players().size;a ++) //this counts how many players are in the game. this is used to make a menu for each player
  142.     {
  143.         //the code bellow that is commented out will make the menu not show the host in the options menu. if you whish for this to happen then uncomment the code.
  144.         //if(a == get_players()[0])
  145.         //  continue;
  146.         ply = get_players()[a]; //this is just defining ply as the player the for loop is on
  147.         plyName = get_players()[a].playername; //this defines the current players name the for loop is on.
  148.         AddMenu("playerOptions"+plyName, "playersVe");
  149.         AddMenuChild("Give "+plyName+" The Menu at Admin Stage", ::verficationOpt, "giveMenuAt", ply, "admin"); //this calls a function and defines what player it is calling for.
  150.         AddMenuChild("Give "+plyName+" The Menu at Co-host Stage", ::verficationOpt, "giveMenuAt", ply, "cohost");
  151.         AddMenuChild("Give "+plyName+" The Menu at verfided Stage", ::verficationOpt, "giveMenuAt", ply, "verfi");
  152.         AddMenuChild("Take "+plyName+"'s Menu", ::verficationOpt, "takeMenu", ply);
  153.     }
  154. }
  155.  
  156. /* ---header-----------------------------------------------------------------------
  157.     Right lets start will the menu base this is going to be a lot fast so be ready
  158.     the menu base structure is in reason very simple all it is doing is checking
  159.     for what button is pressed every frame of the game. When the button is pressed
  160.     it stalls the loop for x ammount of time until the function with in that
  161.     button have completed. So simple. But there is a lot of extra clutter. like hud
  162.     and things like that  
  163. ---------------------------------------------------------------end---------------*/
  164.  
  165. menuBase()
  166. {
  167.     self.menu = spawnStruct(); // okay this is confusing so the simple versions is that self.menu can now have a extra .something after it.
  168.     self.menu.curs = 0; //this is setting the curs by defauly to 0;
  169.     self.menu.locked = false; //by putting it to false it is tell the for loop the menu base is not locked and can watch for controls
  170.     self.menu.userIn = false; //this tells the menu base that the player is not yet in so the for lopp watches the open controls
  171.     self.menu.current = ""; //just a current menu save. this will be getting used in most of the for loop and the newMenu function
  172.     for(;;) //well thats the for loop
  173.     {
  174.         if(!self.menu.locked && self.verfication != "unverfied") /*checks if the var self.menu.locked is = to false and if so the continue
  175.             by putting self.verfication != "unverfied" then the for loop will no longer continue which means there is no
  176.             need to put self endon() because by ending the function makes things more complicated.
  177.         */
  178.         {
  179.             if(!self.menu.userIn) //checks if the var self.menu.userIn is = to false this is to make sure the player can not scroll or use the menu untill they are in it
  180.             {
  181.                 if(self meleeButtonPressed() && self adsButtonPressed()) //this is checking for if the melee button and the aim button is being pressed at the same time because of the &&
  182.                 {
  183.                     self menuOpenSet("mainMenu"); //we have not set what main is yet but it will come to it. //also this is opening are menu at a certian menu the "main" is a argument
  184.                     wait 0.2; //this is important to make sure the function can not be spammed.
  185.                 }
  186.             }  
  187.             else //this is seeing is self.menu.userIn is = true and if so the continue //basically a toggle switch for the controls
  188.             {
  189.                 if(self adsButtonPressed() || self attackButtonPressed()) //this is what i call a multi-control check meaning it checks and handels two diffent controls.
  190.                 {
  191.                     //by putting || it means that Button OR that button but not both at the same time
  192.                     self.menu.curs += self attackButtonPressed(); // but putting this it means when attackButton is pressed it +1 to the self.menu.curs
  193.                     self.menu.curs -= self adsButtonPressed();    //same as above but it takes one.
  194.  
  195.                     if(self.menu.curs > self.options[self.menu.current].opt.size-1) //it has to be -1 its hard to explain. i will edit if some can give me a simple explaination
  196.                         self.menu.curs = 0; // i put a indent here because it keeps the code tidy also because there is only one this happening on this if statment it does not need the { }
  197.                     if(self.menu.curs < 0)
  198.                         self.menu.curs = self.options[self.menu.current].opt.size-1;
  199.  
  200.                     //now to move the hud very simple.
  201.                     self.menu.scroller moveOverTime(0.2); //move over time calls a function to make it if the x or y is changed it animates it.
  202.                     self.menu.scroller.y = self.menu.text[self.menu.curs].y; //this makes it move to the HUD text on screen. simple if you look at it for a bit.
  203.                     wait 0.2;
  204.                 }
  205.                 if(self meleeButtonPressed()) //checks to see if meleebutton is being pressed
  206.                 {
  207.                     //i find that not many people add parent systems into there menu base so i thought i would explain and show how it works.
  208.                     //right first of we are going to need to find if when we added a menu it has self.options[self.menu.current].parent defined.
  209.                     //so
  210.                     if(isDefined(self.options[self.menu.current].parent)) //if this is true then we need to make it go to that parent menu
  211.                         self newMenu(self.options[self.menu.current].parent); //by putting self.options[self.menu.current].parent as the argument it tells new menu to go to what evere self.options[self.menu.current].parent is
  212.                     else //checks if it is not defined
  213.                         self closeMenus(); //simple if it is defined go back if it is not close.
  214.                     wait 0.2;
  215.                 }
  216.                 if(self fragButtonPressed()) //checks if frag button is being pressed
  217.                 {
  218.                     self closeMenus(); //if frag button pressed then close menu. simple.
  219.                     wait 0.2;
  220.                 }
  221.                 /* Right selecting needs a new paragraph this bit is hard to understand and even more annoy to code. the base line of this is that if you put [[]] you are able
  222.                 to put a var into it that is defineing your function you want to call. this is the whole reason menu bases are so small. if the [[]] was not in the game then
  223.                 the menu base would have to be like ibetrays and have every function listed out and watched.
  224.  
  225.                 so now we know that you also need to know how to use this [[]]. If you where to have [[::hello]](); then it would call the function hello(). If you where to have
  226.                 [[::hello]]("you ginger ninja"); then it would call the function hello with the argument "you ginger ninja" as a string. So sort of simple. but when you need to put
  227.                 this in to a menu base it starts to get harder. so you need to put
  228.                 self.options["main"].function = ::hello;
  229.                 so now we have a var that has been set to have the function as its defining feature we can then put self [[self.options["main"].function]]()  now this is all good but
  230.                 we then need to have this working for more than one menu being in the menu base and this is where it get very comfusing because you know that .Current thing we have
  231.                 we have to use that instead of "main" so we are not handeling it for every menu you could be on. From this the options use the same structure because they are being
  232.                 defined as the target threads arguments. */
  233.                 if(self useButtonPressed()) //checks if the x button is pressed
  234.                 {
  235.                     self thread [[self.options[self.menu.current].function[self.menu.curs]/* because this comment ends i can put it here. now the function is set we need to add arguments so >*/]](
  236.                         /*you can hit enter on this bit not sure why but you can */
  237.                         self.options[self.menu.current].arg1[self.menu.curs],
  238.                         self.options[self.menu.current].arg2[self.menu.curs],
  239.                         self.options[self.menu.current].arg3[self.menu.curs]); //this is cool because you can space it out and see what argurent is being set.
  240.                     wait 0.2;
  241.                     //yeah for that very big paragraph all we got out of it was 4 lines of code which can be 1 so yeah.
  242.                 }
  243.             }
  244.         }
  245.         wait 0.05; //if you do not have this here the for loop is incomplete and can not contiue so it crashes it self. not of the controls are pressed this will repeat every frame.
  246.     }
  247. }
  248. //YAY MENU BASE DONE now for all the extra functions
  249.  
  250. //First of lets open the menu.
  251. menuOpenSet(menu) //menu is a argument which is completed when the function is called.  so menuOpenSet("you"); then makes menu = "you"; Simple ish :P
  252. {
  253.     //                                                                                              sort = over lap basically if you have to sorts the same the hud will colide.
  254.     //                                          Placement, placement, X, Y, width, height, color, sort, alpha, shader < shader default = "white"
  255.     self.menu.background = self createRectangle("CENTER", "CENTER", 0, 0, 280, 1000, (0, 0, 0), 0, 0, "white");
  256.     //                                       Placement, placement, X, Y, width, height, color, sort, alpha, shader < shader default = "white"
  257.     self.menu.scroller = self createRectangle("CENTER", "CENTER", 0, -170, 280, 30, (1, 0, 0), 1, 0, "white");
  258.     self.menu.background fadeOverTime(0.2); //animates the alpha
  259.     self.menu.scroller fadeOverTime(0.2); //animates the alpha
  260.     self.menu.background.alpha = 1; //makes it able to be seen.
  261.     self.menu.scroller.alpha = 1; //makes it able to be seen.
  262.     self.menu.userIn = true; //this allows the for loop to change to the other set of controls to watch.
  263.     self loadOptions(menu); //creates the text;
  264. }
  265.  
  266. loadOptions(menu) //this function will be to quickly open up menu text simple function than can be used loads of times
  267. {
  268.     self.menu.current = menu; //this is very very important it tells the whole menu structer what menu is loaded.
  269.  
  270.     /*Okay just noticed i have not explained this one. Right its called a for loop but it can be used to select a lot of this
  271.     by this i mean if i = 0 in the for loop and i is set to ++ then it will add +1 until it hits the i < a ammount of something.
  272.     hard to explain but basically it does the same for a lot of things at a time */
  273.     self.menu.text = []; //defines self.menu.text as a array.
  274.     for(i = 0;i < self.options[menu].opt.size; i++)
  275.     //                                        Placement, placement, X, Y, font size, text
  276.         self.menu.text[i] = self createHUDtext("LEFT", "CENTER", -100, -170+(i*25)/*(i*25) adds spacing between each bit of text*/, 1.4, self.options[menu].opt[i]); //done that creates the text.
  277. }
  278.  
  279. //Right now we need to make a new menu for when we want to switch to a sub menu.
  280. newMenu(menu)
  281. {
  282.     self.menu.curs = 0; //reset our cursor
  283.     //first we need to destroy all the text on screen so we dont have an overlap so
  284.     for( i = 0;i < self.options[self.menu.current].opt.size;i++)
  285.         self.menu.text[i] destroy(); //destroy deletes and undefined the hud element so there is nothing left of self.menu.text
  286.     wait 0.2; //just make it wait for a few milla seconds xD fail safe really.
  287.     //create the new menu
  288.     self loadOptions(menu);
  289.     //move the cursor back to the top of the text
  290.     self.menu.scroller moveOverTime(0.2); //move over time calls a function to make it if the x or y is changed it animates it.
  291.     self.menu.scroller.y = self.menu.text[self.menu.curs].y; //this makes it move to the HUD text on screen. simple if you look at it for a bit.
  292. }
  293. //Done :P
  294.  
  295. //Now to close the menu
  296. closeMenus()
  297. {
  298.     //this one is very small and simple all you need to do is reset a few vars and delete all the UI (HUD basically)
  299.     //first lets grab the text and delete it. we can take this from the newMenu function
  300.     for( i = 0;i < self.options[self.menu.current].opt.size;i++)
  301.         self.menu.text[i] destroy();
  302.     //Once we have deleted all the text we now need to make it delete/destroy all the hud showing on the screen.
  303.     //so for this we will go back to the menuOpenSet(menu); and grab what we defined the menu UI as
  304.     self.menu.background destroy();
  305.     self.menu.scroller destroy();
  306.     //Now we need to reset the cursor and tell the menu we are nolonger in the menu. so this is simple.
  307.     self.menu.userIn = false; //by putting false we are nolonger in the menu.
  308.     self.menu.curs = 0; //this means its reset to 0 for when the menu is the openned again.
  309. }
  310.  
  311. //Now we have set have set the main part of the menu base we are going to add the functions in that are need for use to be able to add a menu.
  312. //this is not easy so explain but we are basically creating a array of menus that we can call on at any time to display the text and any
  313. //functions that are need.
  314.  
  315. AddMenu(menu, parent) //i am doing this because i have found that it is nice to secion off the menu and parent define from the menus.
  316. {
  317.     if(!isDefined(self.options[menu])) //this checks if the array has not already been made. so if you make a main menu then a nother one it will not over lap.
  318.     {
  319.         self.options[menu] = spawnStruct(); //we have been over this before.
  320.         self.options[menu].opt = []; // by putting the = [] means that self.options[menu].opt is now declared as a array.
  321.         self.options[menu].function = [];
  322.         self.options[menu].arg1 = [];
  323.         self.options[menu].arg2 = [];
  324.         self.options[menu].arg3 = [];
  325.  
  326.         //now we are going to check if the parent argument has been defined so we can tell the mod menu if it has a parent menu to go back to before it closes.
  327.         if(!isDefined(parent))
  328.             self.options[menu].parent = undefined; //by putting this if the parent is not defined then it sets that menu set to have no parent menu so when you knife it closes.
  329.         else
  330.             self.options[menu].parent = parent; // this sets what the parent menu is.
  331.     }
  332.     self.menumemory = menu; //every time addmenu is called this will change so it acts as a one time only set for your memorys.
  333. }
  334.  
  335. AddMenuChild(option, function, arg1, arg2, arg3)
  336. {
  337.     memory = self.menumemory; //this is to just make the code smaller by making a local var = a global var it means that memory = self.menumemory so we can use memory as self.menumemory.
  338.     count = self.options[memory].opt.size; //every time we add a new menu the size increases so it acts just like counting from 0 to the amount of menus.
  339.     self.options[memory].opt[count] = option; //this defines what .opt is
  340.     self.options[memory].function[count] = function;
  341.     self.options[memory].arg1[count] = arg1;
  342.     self.options[memory].arg2[count] = arg2;
  343.     self.options[memory].arg3[count] = arg3;
  344. }
  345.  
  346. //this bit sort of easy to understand it basically complies 5 lines of code into one.
  347. createHUDtext(align, relevent, x, y, font, string, alpha, color) {
  348.     text = createFontString("default", font, self); //text = what ever has called the function. so this line creates the UI
  349.     text setPoint(align, relevent, x, y); //this sets its posision
  350.     text setText(string); //sets the text
  351.     if(isDefined(alpha))
  352.         text.alpha = alpha; //sets the alpha if it is defined
  353.     if(IsDefined(color))
  354.         text.color = color; //sets the color if it is defined.
  355.     return text;    //returns all the arguments back to what ever called the function.
  356. }
  357.  
  358. //same as createHUDtext()
  359. createRectangle(align, relative, x, y, width, height, color, sort, alpha, shader)
  360. {
  361.     barElemBG = newClientHudElem( self );
  362.     barElemBG.elemType = "bar";
  363.     barElemBG.width = width;
  364.     barElemBG.height = height;
  365.     barElemBG.align = align;
  366.     barElemBG.relative = relative;
  367.     barElemBG.xOffset = 0;
  368.     barElemBG.yOffset = 0;
  369.     barElemBG.children = [];
  370.     barElemBG.sort = sort;
  371.     barElemBG.color = color;
  372.     barElemBG.alpha = alpha;
  373.     barElemBG setParent( level.uiParent );
  374.     barElemBG setShader( shader, width , height );
  375.     barElemBG.hidden = false;
  376.     barElemBG setPoint(align,relative,x,y);
  377.     return barElemBG;
  378. }
  379.  
  380. /* This is a function that will handal all the functions for the verfication options */
  381. verficationOpt(id, player, valEx) //id is the type of option, player is the player, valEx is for any extra argments that are needed.
  382. {
  383.     //this can be done with case breake but i find that if statments are tider
  384.     if(id == "giveMenuAt")
  385.     {
  386.         self iprintLn(player);
  387.         self iprintLn(self);
  388.         player closeMenus(); //closes the mod menu to allow the menu to reset.
  389.         player undefineMenuSet("mainMenu"); //undefines the main menu for reset.
  390.         player.menu.locked = true;
  391.         player.verfication = valEx; //changes the players verfication.
  392.         player AddMenuSet(true); //redefines menus for new verfication set
  393.         wait 0.2;
  394.         player menuOpenSet("mainMenu");
  395.         player.menu.locked = false; //makes sure the menu is not locked.
  396.         player iprintLn("Your Menu has Been given at "+player.verfication);
  397.         self iprintLn(player.playername+ "has been given the menu at "+player.verfication);
  398.     }
  399.     if(id == "takeMenu")
  400.     {
  401.         if(player.hasMenu == false)
  402.             return self iprintLn("player already does not have the menu");
  403.         if(player.menu.userIn) //checks if the player is in the menu and if they are then the menu will close.
  404.             player closeMenus();
  405.         player.menu.locked = true;
  406.         player iprintLn("You menu has been taken away");
  407.         self iprintLn("You have taken "+player.playername+" menu");
  408.     }
  409. }
  410. //this function will allow you to simply undefine any menu set so you can change or reset it.
  411. //this is very important for verfication.
  412. undefineMenuSet(menu)
  413. {
  414.     for(i= 0;i< 16;i ++)
  415.     {
  416.         self.options[menu].opt[i] = undefined;
  417.         self.options[menu].function[i] = undefined;
  418.         self.options[menu].arg1[i] = undefined;
  419.         self.options[menu].arg2[i] = undefined;
  420.         self.options[menu].arg3[i] = undefined;
  421.     }
  422. }
  423. //this function will return what type of verfication a player is in the menu.
  424. returnVerfication()
  425. {
  426.     //if you add a new type of verfication the name the numbers match so the highest is at the top and the lowest is at the bottom.
  427.     if(self.verfication == "admin")
  428.         return 3;
  429.     if(self.verfication == "cohost")
  430.         return 2;
  431.     if(self.verfication == "verfi")
  432.         return 1;
  433.     if(self.verfication == "unverfied")
  434.         return 0;
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement