Sign in to follow this  
Followers 0
Sheep_Wizard

Customizable HUD menu plugin

5 posts in this topic

Update: Added text alignment option

 

This is a plugin that allows you to add a custom hud menu into your map or mod without having to do all the work of actually making a menu.

In the gsc you can edit the menu settings such as the:

Colours,

Position,

Width,

Slide in time,

Guid options,

And much more :D

Here is a video showing the menu:

https://www.youtube.com/watch?v=f52WTnGw0ZU

Download: https://www.dropbox.com/s/k1qhss6gdt0wqax/menubase.gsc?dl=0

PasteBin: http://pastebin.com/JM8EFJH3

Code:

 

//   ________  ___  ___  _______   _______   ________   
//  |\   ____\|\  \|\  \|\  ___ \ |\  ___ \ |\   __  \  
//  \ \  \___|\ \  \\\  \ \   __/|\ \   __/|\ \  \|\  \ 
//   \ \_____  \ \   __  \ \  \_|/_\ \  \_|/_\ \   ____\
//    \|____|\  \ \  \ \  \ \  \_|\ \ \  \_|\ \ \  \___|
//      ____\_\  \ \__\ \__\ \_______\ \_______\ \__\   
//     |\_________\|__|\|__|\|_______|\|_______|\|__|   
//     \|_________|                                     
// Create by Sheep Wizard
// For use in any mod or map
// Steam: SheepWizard
main()
{

	////////////////Menu Settings/////////////
	/*
	Edit menu settings here
	For colours use rgb colours divided by 255
	*/
	//Colour of menu background
	level.backgroundColour = (255/255,42/255,255/255);
	//Transparacy for background
	level.backgroundAlpha = 0.5;
	//Colour of title of menu
	level.titleColour = (215/255,12/255,70/255);
	//Transparacy for Title
	level.titleAlpha = 1;
	//Colour of menu text
	level.textColour = (55/255,255/255,154/255);
	//Transparacy for text
	level.textAlpha = 1;
	//Colour of item selector
	level.selectorColour = (2/255,2/255,25/255);
	//Transparacy for selector
	level.selectorAlpha = 0.8;
	//colour of seperator
	level.seportatorColour = (2/255,255/255,25/255);
	//Transparacy for seporator
	level.seportatorAlpha = 1;
	//Title text
	level.titleText = "VIP MENU";
	//Size of title text font   1.4 = minimum
	level.titleTextScale = 1.7;
	//Time it takes of selector to scroll in ms
	level.scrollTime = 0.5;
	//If player will freeze when menu is open
	level.freezePlayerControls = false;
	//If you want menu to disble weapons when opened
	level.disableWeapons = true;

	//Menu will only slide if it is on left or right of screen
	//Time it take for menu to slide open
	level.menuSlideInTime = 0.4;
	//Time it take for menu to slide close
	level.menuSlideOutTime = 0.4;
	//If you want menu to slide on when opened
	level.menuSlideIn = true;
	//If you want menu to slide out when closed
	level.menuSlideOut = true;

	//0 = menu will spawn on left side   1 = menu will spawn on right side    2 = menu will spawn in middle   3 = set your own x,y values for menu to spawn
	level.menuSide = 2;
	//Set x positon for menu to spawn   LEVEL.MENUSIDE MUST BE EQUAL TO 3 FOR THIS TO WORK
	level.menuX = 0;
	//Set Y positon for menu to spawn   LEVEL.MENUSIDE MUST BE EQUAL TO 3 FOR THIS TO WORK
	level.menuY = 0;
	//Number of items shown till menu starts to scroll
	level.itemTillScroll = 4;
	//The width of the menu
	level.menuWidth = 200;

	//button to open with set button instead of double pressing frag
	//To open menu with button bind a key to this commands: openScriptMenu -1 open_hud_menu
	//e.g.  bind p openScriptMenu -1 open_hud_menu
	level.openWithButton = false;

	////////////////////////////////////////



	/////////////Player Guids///////////////

	//Set to true if you only people with certain guids to open menu
	level.guidRequired = false;

	level.acceptedguids = [];

	//Add the last 8 digits of a players guid here
	//See example below if stuck

	level.acceptedguids[0] = "11b05456";
	level.acceptedguids[1] = "62b35354";

	///////////////////////////////////////



	/////////////Menus/////////////////////
	/*
	Use this section to add items to menu

	Syntax: addMenuItem("Item text", ::function, true/false if you want menu to stay open when item selected);

	See example below if stuck
	*/

	addMenuItem("Give M40A3", ::givem4, false);
	addMenuItem("Print Name", ::printname, false);
	addMenuItem("Suicide", ::killplayer, true);
	addMenuItem("Bounce", ::bounce, false);

	//////////////////////////////////////

	thread onConnect();
}

////////////////Custom Scripts///////////////////////////
/*
	Add custom scripts here
	Alternatively you can add them into a seperate gsc
*/
givem4()
{
	self giveWeapon("m40a3_mp");
	self switchToWeapon("m40a3_mp");
}

printname()
{
	iPrintLnBold(self.name);
}

killplayer()
{
	self suicide();
}

bounce()
{
	power = 230;
	self.health += power;
    self finishPlayerDamage(self, level.jumpattacker, power, 0, "MOD_FALLING", "jump_mp", self.origin, AnglesToForward((-90,0,0)), "head", 0);
}

////DO NOT EDIT BELOW THIS LINE////or do idc
///////////////////////////////////////////

onConnect()
{
	for(;;)
	{
		level waittill( "connected", player );
		player.menuopen = false;
		player thread onSpawn();
	}
}
onSpawn()
{
	self endon("disconnect");
	for(;;)
	{
		self waittill("spawned_player");

		
		if(level.guidRequired)
		{
			friend = getSubStr(self getGuid(), 24, 32);
			for(i=0; i<level.acceptedguids.size; i++)
			{
				if(friend == level.acceptedguids[i])
					self thread menuCheck();
			}
		}
		else	
			self thread menuCheck();
	}
}
menuCheck()
{
	self endon("disconnect");
	self endon("death");
	if(!level.openWithButton)
	{
		while(1)
		{
			if(self fragButtonPressed())
			{
				x=false;
				for(i = 0;i < 0.5;i += 0.05)
				{
					if(self fragButtonPressed() && x && !self.menuopen)
					{
						self thread openHudMenu();
						if(level.disableWeapons)
							self disableWeapons();
						if(level.freezePlayerControls)
							self freezeControls(1);
						self.menuopen = true;
						self thread onDeath();
						wait 0.75;
						break;
					}
					else if (!self fragButtonPressed())
						x = true;
					wait 0.05;
				}
			}
			wait 0.05;
		}
	}
	else
	{
		while(1)
		{
			self waittill("menuresponse", menu, response);
			if(response == "open_hud_menu")
			{
				self thread openHudMenu();
				if(level.disableWeapons)
					self disableWeapons();
				if(level.freezePlayerControls)
					self freezeControls(1);
				self.menuopen = true;
				self thread onDeath();
				wait 0.75;
			}
		}
	}
}
addMenuItem(text, script, close)
{
	if(!isdefined(level.mainmenuhud))
		level.mainmenuhud = [];
	array_size = level.mainmenuhud.size;
	level.mainmenuhud[array_size] = spawnStruct();
	level.mainmenuhud[array_size].name = text;
	level.mainmenuhud[array_size].script = script;
	level.mainmenuhud[array_size].close = close;
}
openHudMenu()
{
	self endon("death");
	self endon("disconnect");
	self endon("hud_menu_closed");

	self.hudMenu = [];
	self.selector = 1;
	self.scroll = 0;
	scrollamount = 0;
	offsetX = 0;
	offsetY = 0;
	level.slideInValue = level.menuWidth;
	//Work out scroll amount
	if(level.mainmenuhud.size > level.itemTillScroll-1)
		scrollamount = level.mainmenuhud.size - level.itemTillScroll;
	selectamount = level.mainmenuhud.size;
	if(level.mainmenuhud.size > level.itemTillScroll-1)
		selectamount = level.itemTillScroll;

	//work out menu position
	if(level.menuSide == 0)
	{
		if(level.menuSlideIn)
		{
			level.slideInValue = level.menuWidth;
			offsetX = -110 - level.menuWidth;
			offsetY = 40;
		}
		else
		{
			offsetX = -110;
			offsetY = 40;
		}
	}
	if(level.menuSide == 1)
	{
		if(level.menuSlideIn)
		{
			offsetX = 747;
			offsetY = 40;
			level.slideInValue = level.menuWidth*-1;
		}
		else
		{
			offsetX = 747 - level.menuWidth;
			offsetY = 40;
		}
	}
	if(level.menuSide == 2)
	{
		offsetX = 230;
		offsetY = 60;
	}
	if(level.menuSide == 3)
	{
		offsetX = level.menuX;
		offsetY = level.menuY;
	}

	//text
	self.hudMenu[0] = addTextHud( self, (offsetX + 20), (offsetY + 40), level.textAlpha, "left", "top", 1.4, 10 );	//-90 80
	self.hudMenu[0].color = level.textColour;
	self.hudMenu[0] setText(getText(undefined));

	//background
	self.hudMenu[1] = addTextHud( self, (offsetX), (offsetY), level.backgroundAlpha, "left", "top", 0, 0 );	//-110  40
	self.hudMenu[1] setShader("White", level.menuWidth, int(33.5*(selectamount+1)));
	self.hudMenu[1].color = level.backgroundColour;

	//selector
	self.hudMenu[2] = addTextHud( self, (offsetX), (offsetY + 40), level.selectorAlpha, "left", "top", 0, 1 );	//-110  80
	self.hudMenu[2] setShader("White", level.menuWidth, 20);
	self.hudMenu[2].color = level.selectorColour;

	//title
	self.hudMenu[3] = addTextHud( self, (offsetX + 20), (offsetY + 13), level.titleAlpha, "left", "top", level.titleTextScale, 1 );	//-90  53
	self.hudMenu[3].color = level.titleColour;
	self.hudMenu[3] setText(level.titleText);

	//sepertors
	self.hudMenu[4] = addTextHud( self, (offsetX), (offsetY + 37.5), level.seportatorAlpha, "left", "top", 1.7, 1 );	 //-110  77.5
	self.hudMenu[4] setShader("White", level.menuWidth, 2);
	self.hudMenu[4].color = level.seportatorColour;

	if(level.menuSlideIn && level.menuSide == 1 || level.menuSide == 0)
	{
		for(i=0; i<self.hudMenu.size; i++)
			moveHudX(self.hudMenu[i], level.slideInValue, level.menuSlideInTime);
	}

	while(1)
	{
		if(self attackButtonPressed())
		{
			if(self.selector == selectamount)
			{
				if(scrollamount > 0 && self.scroll < scrollamount)
				{
					self.scroll++;
					self.hudMenu[0] setText(getText(self.scroll));	
				}
				else
				{
					self.hudMenu[0] setText(getText(undefined));
					moveHudY(self.hudmenu[2], (-33.5 *(selectamount-1)) , level.scrollTime);
					self.scroll = 0;
					self.selector = 1;
				}
			}
			else if(self.selector < selectamount)
			{
				moveHudY(self.hudmenu[2], 33.5, level.scrollTime);
				self.selector++;
			}

			wait 0.1;
		}
		if(self adsButtonPressed())
		{
			if(self.selector == 1)
			{
				if(self.scroll == 0 )
				{
					self.selector = selectamount;
					self.scroll = scrollamount;
					if(selectamount > level.itemTillScroll-1)
						self.hudMenu[0] setText(getText(self.scroll));
					moveHudY(self.hudmenu[2], (33.5 * (selectamount-1)), level.scrollTime);
				}
				else 
				{
					self.scroll--;
					self.hudMenu[0] setText(getText(self.scroll));	
				}
			}
			else if(self.selector != 1)
			{
				moveHudY(self.hudmenu[2], -33.5, level.scrollTime);
				self.selector--;
			}
			wait 0.1;
		}
		if(self useButtonPressed())
		{
			if(!isString(level.mainmenuhud[self.selector+self.scroll-1].script))
			{
				self thread [[level.mainmenuhud[self.selector+self.scroll-1].script]]();
				if(level.mainmenuhud[self.selector+self.scroll-1].close)
				{
					self thread closeHudMenu();
					self notify("hud_menu_closed");
				}
				wait 0.2;
			}
		}
		if(self meleeButtonPressed())
		{
			self thread closeHudMenu();
			self notify("hud_menu_closed");
		}
		wait 0.05;
	}
}
onDeath()
{
	self waittill("death");
	if(isDefined(self.menuopen) || self.menuopen)
		self thread closeHudMenu();
	self notify("hud_menu_closed");
}
closeHudMenu()
{
	self enableWeapons();
	self freezeControls(0);
	self.menuopen = false;
	if(level.menuSlideIn && level.menuSide == 1 || level.menuSide == 0)
	{
		for(i=0; i<self.hudMenu.size; i++)
		{
			if(isDefined(self.hudMenu[i]))
				moveHudX(self.hudMenu[i], level.slideInValue*-1, level.menuSlideOutTime);
		}
		wait 0.5;
	}
	for(i=0; i<self.hudMenu.size; i++)
	{
		if(isDefined(self.hudMenu[i]))
			self.hudMenu[i] destroy();
	}
}
getText(scroll)
{
	text = "";
	if(!isDefined(scroll))
	{
		if(level.mainmenuhud.size > level.itemTillScroll)
			loop = level.itemTillScroll;
		else
			loop = level.mainmenuhud.size;
		for(i=0; i<loop; i++)
			text += level.mainmenuhud[i].name + "\n \n";
	}
	else
	{
		for(i=scroll; i<scroll + level.itemTillScroll; i++)
			text += level.mainmenuhud[i].name + "\n \n";
	}
	return text;
}
moveHudX(hud, xamount, time)
{
    hud moveOverTime(time); hud.x =  hud.x + xamount;
}
moveHudY(hud, yamount, time)
{
    hud moveOverTime(time); hud.y = hud.y + yamount;
}
addTextHud( who, x, y, alpha, alignX, alignY, fontScale, sort )
{
	if( isPlayer( who ) )
		hud = newClientHudElem( who );
	else
		hud = newHudElem();
	hud.x = x;
	hud.y = y;
	hud.alpha = alpha;
	hud.sort = sort;
	hud.alignX = alignX;
	hud.alignY = alignY;
	if(fontScale != 0)
		hud.fontScale = fontScale;
	return hud;
}

If you find any bugs please tell me and i'll try fix.

5

Share this post


Link to post
Share on other sites
53 minutes ago, Synd said:

Watched the video, and stumbled upon this LOL

 

I make the occasional fresh meme

3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0