Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Custom Menu System by Seby v2.0 for Vice City Multiplayer.
- VC:MP Website: http://www.vc-mp.org
- VC:MP Forum: http://forum.vc-mp.org
- ===================================================================================================================================================================
- CREDITS:
- Scripter: Seby (aka sseebbyy)
- Special credits goes to shadow.heekz, Knucis and Gudio because I learnt new squirrel stuff from them.
- DO NOT REMOVE THEM, OR WE WILL NEVER OFFER YOU HELP OR SCRIPTS AGAIN !
- ===================================================================================================================================================================
- Description:
- Custom Menu System by Seby ( aka CMSS ) is a system that gives scripters the ability to create their own INTERACTIVE MENU,
- up to 10 options, but every option can also have a submenu (with another 10 options) !!
- Version 2.0 works a lot different than v1.0:
- -Now there are 9 sprites, created when the script is loaded. We only show them when needed.
- -The textdraws are all created right in the moment of accessing the menu, but don't worry, it will not reach the
- VC:MP limit (256) that fast, because it works in this way: when a player X wants to see a menu that is also shown for
- player Y, the textdraws will be just shown to X, not re-created ! So the textdraws will be removed only when there will be
- no viewer.
- -No more double textdraws. ( 2 textdraws were used for one option, in v1.0, one grey, one white )
- -To avoid the bugs, a player that is watching a menu and leave the server or just get killed without closing it,
- everything related to menus will be instantly canceled for him. ( menuRageQuit( player ) )
- -You are now able to set the title of a submenu. (not like before, where the title were auto-set)
- -No need to manually hide the main menu, when you want to show the submenu ! Just use "menuInstance.ShowSubmenu( player, 5 )"
- and it will do everything for you. Same goes for HideSubmenu function.
- And maybe more, but I don't remember right now... but take a look at the script, and you will understand. :)
- I made it as understable as I could.
- The single thing that stays the same as in v1.0, is the way we save menus' instance: " menu[ ID ] "
- So, when you want to add a submenu for that menu, you will do like this: " menu[3].AddSubmenu( 3, "/Option 3 - blabla", "option 1", "option 2", ... ) "
- Keys used to interact with the menu, used in my example, are: UP_ARROW, DOWN_ARROW, SPACEBAR (select), BACKSPACE (back)
- I hope I didn't miss anything important.
- ===================================================================================================================================================================
- Here is the list with the new functions'n'events:
- Menu functions: CreateMenu( title, option1, option2, ... ),
- menuRageQuit( player ),
- menuRageQuitAll( ),
- menuInstance.ShowMenu( player ),
- menuInstance.HideMenu( player ),
- menuInstance.AddSubmenu( optionID of mainmenu, title, option1, option2, ... ),
- menuInstance.ShowSubmenu( player, option ),
- menuInstance.HideSubmenu( player, option );
- Menu events: onPlayerEnterMenu( player, menuID ),
- onPlayerExitMenu( player, menuID ),
- onPlayerSwitchOptionsInMenu( player, menuID, oldOption, newOption )
- onPlayerSelectInMenu( player, menuID, option );
- Submenu events: onPlayerEnterSubmenu( player, menuID, submenuID ),
- onPlayerExitSubmenu( player, menuID, submenuID ),
- onPlayerSwitchOptionsInSubmenu( player, menuID, submenuID, oldOption, newOption )
- onPlayerSelectInSubmenu( player, menuID, submenuID, option );
- ===================================================================================================================================================================
- */
- print( "Custom Menu System by Seby (v2.0) was successfully loaded !" );
- // Bind Keys ==========================================================
- KEY_MENU_UP <- BindKey(true, 0x26, 0, 0); // UP_ARROW
- KEY_MENU_DOWN <- BindKey(true, 0x28, 0, 0); // DOWN_ARROW
- KEY_MENU_SELECT <- BindKey(true, 0x20, 0, 0); // SPACEBAR
- KEY_MENU_BACK <- BindKey(true, 0x08, 0, 0); // BACKSPAGE
- // ====================================================================
- // Changeable settings
- menuX <- 80; // menu pos x
- menuY <- 310; // menu pos y
- menuSpritePosX <- menuX - 10; // sprite pos x
- menuSpritePosY <- menuY - 10; // sprite pos y
- menuSpriteAlpha <- 200; // sprites' alpha
- menuOptionPrefix <- "::"; // options' prefix
- menuOptionPosX <- menuX + 50; // options' pos x
- menuTitleColor <- 0xFF00FFFF; // menus' title color
- menuOptionColorSelected <- 0xFFFFFFFF; // selected options' color
- menuOptionColorUnselected <- 0xFFAAAAAA; // unselected options' color
- // Don't touch this !
- menu <- array( 100, null );
- menuCount <- 0;
- menuSprite <- array( 9, null );
- menuOptionPosY <- array( 11, null );
- menuOptionPosY[0] = menuY;
- menuOnScreen <- array( GetMaxPlayers(), null );
- menuOptionChoosen <- array( GetMaxPlayers(), null );
- submenuOnScreen <- array( GetMaxPlayers(), null );
- submenuOptionChoosen <- array( GetMaxPlayers(), null );
- for(local i = 0; i < menuSprite.len(); i++)
- menuSprite[i] = CreateSprite( "menuBackType" + i + ".png", menuSpritePosX, menuSpritePosY, 0, 0, 0, menuSpriteAlpha);
- class menuTextdrawClass
- {
- instance = null;
- text = null;
- number = null;
- constructor( paramText, paramNumber )
- {
- text = paramText;
- number = paramNumber;
- }
- function Show( player, way )
- {
- switch( way )
- {
- case 0:
- if( number == 0 )
- // number 0 is the title
- instance = ::CreateTextdraw( text, menuX, menuY, menuTitleColor );
- else
- {
- menuOptionPosY[number] = menuOptionPosY[number-1] + 15;
- instance = ::CreateTextdraw( menuOptionPrefix + " " + text, menuOptionPosX, menuOptionPosY[number], menuOptionColorUnselected );
- }
- break;
- default: break;
- }
- instance.ShowForPlayer( player );
- }
- function Hide( player, way )
- {
- instance.HideFromPlayer( player );
- switch( way )
- {
- case -1:
- case 0:
- instance.Delete( );
- break;
- default: break;
- }
- }
- function BeSelected( player )
- {
- instance.SetColourForPlayer( player, menuOptionColorSelected );
- }
- function BeUnselected( player )
- {
- instance.SetColourForPlayer( player, menuOptionColorUnselected );
- }
- }
- class ExCreateMenu
- {
- ID = null;
- title = null;
- menuOption = null;
- params = null;
- subtitle = null;
- subparams = null;
- viewers = null;
- submenuViewers = null;
- constructor( menuID, ... )
- {
- if ( vargv.len() < 3 || vargv.len() > 11 ) print("[CMSS Error] CreateMenu failed - the number of options written is under 2 or bigger than 10 !");
- else
- {
- title = vargv[0].tostring();
- viewers = 0;
- submenuViewers = array( 11, null );
- subparams = array( 11, null );
- menuOption = array( 11, null );
- for( local i = 0; i < menuOption.len(); i++)
- {
- menuOption[i] = array( 11, null );
- }
- params = vargv.len();
- for(local i = 0; i < vargv.len(); i++)
- menuOption[0][i] = menuTextdrawClass( vargv[i], i );
- ID = menuID;
- }
- }
- function ShowMenu( player )
- {
- if( !player ) return;
- else
- {
- menuSprite[ params - 3 ].ShowForPlayer( player );
- for(local i = 0; i < params; i++)
- if( menuOption[0][i] ) menuOption[0][i].Show( player, viewers );
- menuOption[0][1].BeSelected( player );
- menuOptionChoosen[ player.ID ] = 1;
- if( menuOnScreen[ player.ID ] == -1 )
- {
- menuOnScreen[ player.ID ] = ID;
- player.IsFrozen = true;
- viewers++;
- onPlayerEnterMenu( player, ID );
- onPlayerSwitchOptionsInMenu( player, ID, 0, 1 );
- }
- }
- }
- function HideMenu( player )
- {
- if( !player ) return;
- else
- {
- menuSprite[ params - 3 ].HideFromPlayer( player );
- for(local i = 0; i < params; i++)
- if( menuOption[0][i] )
- if( submenuOnScreen[ player.ID ] == 1 ) menuOption[0][i].Hide( player, viewers );
- else menuOption[0][i].Hide( player, viewers - 1 );
- if( menuOnScreen[ player.ID ] != -1 && submenuOnScreen[ player.ID ] == 0 )
- {
- menuOnScreen[ player.ID ] = -1;
- menuOptionChoosen[ player.ID ] = 0;
- player.IsFrozen = false;
- viewers--;
- onPlayerExitMenu( player, ID );
- }
- }
- }
- function AddSubmenu( option, ... )
- {
- if( option < 1 || option > 10 ) print( "[CMSS Error] AddSubmenu failed - the specified option doesn't exist. It needs to be from 1 to 10." );
- else if ( vargv.len() < 3 || vargv.len() > 11 ) print( "[CMSS Error] AddSubmenu failed - the number of suboptions written is under 2 or bigger than 10 !" );
- else
- {
- subtitle = vargv[0].tostring();
- subparams[ option ] = vargv.len();
- for(local i = 0; i < vargv.len(); i++)
- menuOption[ option ][ i ] = menuTextdrawClass( vargv[i], i );
- submenuViewers[ option ] = 0;
- }
- }
- function ShowSubmenu( player, option )
- {
- if( !player ) return;
- else
- {
- for( local i = 0; i < subparams[ option ]; i++ )
- if( menuOption[ option ][ i ] ) menuOption[ option ][ i ].Show( player, submenuViewers[ option ] );
- menuOption[ option ][ 1 ].BeSelected( player );
- submenuOnScreen[ player.ID ] = 1;
- submenuOptionChoosen[ player.ID ] = 1;
- submenuViewers[ option ]++;
- menu[ ID ].HideMenu( player );
- menuSprite[ subparams[ option ] - 3 ].ShowForPlayer( player );
- onPlayerEnterSubmenu( player, ID, option );
- onPlayerSwitchOptionsInSubmenu( player, ID, option, 0, 1 );
- }
- }
- function HideSubmenu( player, option )
- {
- if( !player ) return;
- else
- {
- menuSprite[ subparams[ option ] - 3 ].HideFromPlayer( player );
- menu[ ID ].ShowMenu( player );
- for(local i = 0; i < subparams[ option ]; i++ )
- if( menuOption[ option ][ i ] ) menuOption[ option ][ i ].Hide( player, submenuViewers[ option ] - 1 );
- submenuOnScreen[ player.ID ] = 0;
- submenuOptionChoosen[ player.ID ] = 0;
- submenuViewers[ option ]--;
- onPlayerExitSubmenu( player, ID, option );
- }
- }
- }
- function CreateMenu( ... )
- {
- if ( vargv.len() < 3 || vargv.len() > 11 ) print("[CMSS Error] CreateMenu failed - the number of options written is under 2 or bigger than 10 !");
- else
- {
- switch( vargv.len() )
- {
- case 3:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2] );
- menuCount++;
- return menu[menuCount];
- case 4:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3] );
- menuCount++;
- return menu[menuCount];
- case 5:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4] );
- menuCount++;
- return menu[menuCount];
- case 6:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4], vargv[5] );
- menuCount++;
- return menu[menuCount];
- case 7:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4], vargv[5], vargv[6] );
- menuCount++;
- return menu[menuCount];
- case 8:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4], vargv[5], vargv[6], vargv[7] );
- menuCount++;
- return menu[menuCount];
- case 9:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4], vargv[5], vargv[6], vargv[7], vargv[8] );
- menuCount++;
- return menu[menuCount];
- case 10:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4], vargv[5], vargv[6], vargv[7], vargv[8], vargv[9] );
- menuCount++;
- return menu[menuCount];
- case 11:
- menu[menuCount] = ExCreateMenu( menuCount, vargv[0], vargv[1], vargv[2], vargv[3], vargv[4], vargv[5], vargv[6], vargv[7], vargv[8], vargv[9], vargv[10] );
- menuCount++;
- return menu[menuCount];
- }
- }
- }
- function menuJoin( player )
- {
- menuOnScreen[ player.ID ] = -1;
- menuOptionChoosen[ player.ID ] = 0;
- submenuOnScreen[ player.ID ] = 0;
- submenuOptionChoosen[ player.ID ] = 0;
- }
- // ====================================== C U S T O M M E N U E V E N T S =========================================
- /*
- function onPlayerEnterMenu( player, menuID )
- {
- print( player.Name + " entered in menu " + menuID );
- }
- function onPlayerExitMenu( player, menuID )
- {
- print( player.Name + " left the menu " + menuID );
- }
- function onPlayerEnterSubmenu( player, menuID, submenuID )
- {
- print( player.Name + " entered in submenu " + submenuID + " of menu " + menuID );
- }
- function onPlayerExitSubmenu( player, menuID, submenuID )
- {
- print( player.Name + " left the submenu " + submenuID + " of menu " + menuID );
- }
- function onPlayerSwitchOptionsInMenu( player, menuID, oldOption, newOption )
- {
- print( player.Name + " switched options in menu ID " + menuID + ". (old: " + oldOption + ") (new: " + newOption + ")");
- }
- function onPlayerSwitchOptionsInSubmenu( player, menuID, submenuID, oldOption, newOption )
- {
- print( player.Name + " switched options in submenu ID " + submenuID + " of menu ID " + menuID + ". (old: " + oldOption + ") (new: " + newOption + ")");
- }
- function onPlayerSelectInMenu( player, menuID, option )
- {
- print( player.Name + " selected option " + option + " from menu " + menuID);
- }
- function onPlayerSelectInSubmenu( player, menuID, submenuID, option )
- {
- print( player.Name + " selected option " + option + " from submenu " + submenuID + " of menu " + menuID );
- }
- */
- // ================================== E N D OF O F F I C I A L E V E N T S ======================================
- function menuRageQuit( player )
- {
- if( player )
- {
- if( menuOnScreen[ player.ID ] != -1 )
- {
- local menuID = menuOnScreen[ player.ID ],
- menuInstance = menu[ menuID ],
- option = menuOptionChoosen[ player.ID ];
- if( submenuOnScreen[ player.ID ] != 0 )
- {
- menuInstance.HideSubmenu( player, option );
- }
- menuInstance.HideMenu( player );
- }
- }
- }
- function menuRageQuitAll( )
- {
- for( local plr, i = 0; i <= GetPlayers(); i++ )
- {
- plr = FindPlayer(i);
- if( plr ) menuRageQuit( plr );
- }
- }
- function menuKeyDown( player, key )
- {
- if( menuOnScreen[ player.ID ] > -1 )
- {
- local menuID = menuOnScreen[ player.ID ],
- menuInstance = menu[ menuID ],
- option = menuOptionChoosen[ player.ID ],
- upperOption = option - 1,
- downerOption = option + 1,
- paramsNumber = menuInstance.params - 1,
- suboption = submenuOptionChoosen[ player.ID ],
- upperSubOption = suboption - 1,
- downerSubOption = suboption + 1,
- subparamsNumber = menuInstance.subparams[ menuOptionChoosen[ player.ID ] ];
- switch( key )
- {
- case KEY_MENU_UP:
- if( submenuOnScreen[ player.ID ] != 1 )
- {
- menuInstance.menuOption[ 0 ][ option ].BeUnselected( player );
- if( option != 1 )
- {
- menuInstance.menuOption[ 0 ][ upperOption ].BeSelected( player );
- menuOptionChoosen[ player.ID ]--;
- }
- else
- {
- menuInstance.menuOption[ 0 ][ paramsNumber ].BeSelected( player );
- menuOptionChoosen[ player.ID ] = paramsNumber;
- }
- onPlayerSwitchOptionsInMenu( player, menuID, option, menuOptionChoosen[ player.ID ] );
- }
- else
- {
- menuInstance.menuOption[ option ][ suboption ].BeUnselected( player );
- if( suboption != 1 )
- {
- menuInstance.menuOption[ option ][ upperSubOption ].BeSelected( player );
- submenuOptionChoosen[ player.ID ]--;
- }
- else
- {
- menuInstance.menuOption[ option ][ subparamsNumber - 1 ].BeSelected( player );
- submenuOptionChoosen[ player.ID ] = subparamsNumber - 1;
- }
- onPlayerSwitchOptionsInSubmenu( player, menuID, option, suboption, submenuOptionChoosen[ player.ID ] );
- }
- break;
- case KEY_MENU_DOWN:
- if( submenuOnScreen[ player.ID ] != 1 )
- {
- menuInstance.menuOption[0][option].BeUnselected( player );
- if( option != paramsNumber )
- {
- menuInstance.menuOption[0][downerOption].BeSelected( player );
- menuOptionChoosen[ player.ID ]++;
- }
- else
- {
- menuInstance.menuOption[0][1].BeSelected( player );
- menuOptionChoosen[ player.ID ] = 1;
- }
- onPlayerSwitchOptionsInMenu( player, menuID, option, menuOptionChoosen[ player.ID ] );
- }
- else
- {
- menuInstance.menuOption[ option ][ suboption ].BeUnselected( player );
- if( suboption != subparamsNumber - 1 )
- {
- menuInstance.menuOption[ option ][ downerSubOption ].BeSelected( player );
- submenuOptionChoosen[ player.ID ]++;
- }
- else
- {
- menuInstance.menuOption[ option ][ 1 ].BeSelected( player );
- submenuOptionChoosen[ player.ID ] = 1;
- }
- onPlayerSwitchOptionsInSubmenu( player, menuID, option, suboption, submenuOptionChoosen[ player.ID ] );
- }
- break;
- case KEY_MENU_SELECT:
- if( subparamsNumber > 0 )
- {
- if( submenuOnScreen[ player.ID ] == 0 ) menuInstance.ShowSubmenu( player, option );
- else onPlayerSelectInSubmenu( player, menuID, option, suboption );
- }
- else onPlayerSelectInMenu( player, menuID, option );
- break;
- case KEY_MENU_BACK:
- if( submenuOnScreen[ player.ID ] == 1 ) menuInstance.HideSubmenu( player, option );
- else menuInstance.HideMenu( player );
- break;
- default: break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement