vampytwist
"Don't you trust me?"
- Messages
- 644
- Reaction score
- 620
- Points
- 758
Code:
#using scripts\codescripts\struct;
#using scripts\shared\callbacks_shared;
#using scripts\shared\system_shared;
#using scripts\shared\array_shared;
#using scripts\shared\hud_util_shared;
#using scripts\shared\hud_message_shared;
#using scripts\shared\util_shared;
#insert scripts\shared\shared.gsh;
#namespace clientids;
REGISTER_SYSTEM("clientids", & __init__, undefined)
function __init__() {
callback::on_start_gametype( & init);
callback::on_connect( & on_player_connect);
callback::on_spawned( & on_player_spawned);
}
function init() {
level.clientid = 0;
level.debug = true;
//level.debug = false;
// Main
level.orange = (0.95, 0.52, 0.0285);
level.black = (0,0,0);
level.white = (1,1,1);
// Other
level.red = (1, 0, 0);
level.yellow = (1, 1, 0);
level.green = (0, 1, 0);
level.blue = (0,0, 1);
level.purple = (1, 0, 1);
level.cyan = (0, 1, 1);
level.gray = (0.5, 0.5, 0.5);
level initPlayerAccess();
}
function on_player_connect() {
self.clientid = matchRecordNewPlayer(self);
if (!isdefined(self.clientid) || self.clientid == -1) {
self.clientid = level.clientid;
level.clientid++;
}
}
function on_player_spawned() {
self initSurge();
self thread monitorButtons();
if(self isHost())
self setAccessLevel(3);
else
self setAccessLevel(0);
}
function initPlayerAccess()
{
// level.accessLevelStatuses = strtok("Unverified,Verified,Admin,Host", ",");
level.accessLevelStatuses = [];
level.accessLevelStatuses[0] = "No Access";
level.accessLevelStatuses[1] = "Limited Access";
level.accessLevelStatuses[2] = "Admin";
level.accessLevelStatuses[3] = "Host";
}
function checkAccess()
{
if(self getAccessLevel() > 0)
{
self thread hud_message::hintMessage("Welcome to Surge", 5);
self iPrintln("Press [{+actionslot 2}] for menu");
self updateMenu();
if(self.surge["menu"]["hudCreated"] == true)
self updateHud();
}
}
function setAccessLevel(accessLevel)
{
self.accessLevel = accessLevel;
if(self.surge["menu"]["active"] == true)
self exitMenu();
wait 0.25;
self checkAccess();
}
function getAccessLevel()
{
return self.accessLevel;
}
function getAccessLevelStatus()
{
return level.accessLevelStatuses[self getAccessLevel()];
}
function initSurge()
{
self.surge = [];
self.surge["version"] = "Beta 1.5 (Stable)";
self.surge["info"] = [];
self.surge["info"][0] = "Surge " + self.surge["version"];
self.surge["info"][1] = "Created by TheFallen";
self.surge["info"][2] = "[{+attack}][{+speed_throw}]Up/Down";
self.surge["info"][3] = "[{+gostand}]Select [{+stance}]Back";
self.surge["info"][4] = "[{+melee}]Exit";
// menu settings
self.surge["menu"] = [];
self.surge["menu"]["active"] = false;
self.surge["menu"]["hudCreated"] = false;
self.surge["menu"]["current"] = "main";
setColor("menu", "scrollbar", level.orange);
setColor("menu", "background", level.black);
setColor("menu", "glow", level.orange);
setColor("menu", "title", level.orange);
setColor("menu", "options", level.white);
self.surge["text"] = [];
self.surge["text"]["title"] = "";
self.surge["text"]["options"] = [];
self.surge["shaders"] = [];
}
function monitorButtons()
{
self endon( "disconnect" );
self endon("change_access");
// While we are alive watch our button actions
for(;;)
{
if(self.surge["menu"]["active"] == false && self getAccessLevel() > 0 && isAlive(self))
{
// Opens the menu
if(self actionSlotTwoButtonPressed())
{
wait 0.45; // This needs to be here or we will scroll on menu open.
self thread monitorPlayerMenu();
self updatePlayersMenu();
runMenu(self.surge["menu"]["current"]);
}
// Exits the game
if(level.debug == true)
if(self actionSlotOneButtonPressed())
exitLevel(true);
}
wait 0.05;
}
}
function monitorPlayerMenu()
{
self endon("menu_exit");
for( ;; )
{
level waittill( "connected", player );
foreach( player in level.players )
{
if(player getAccessLevel() > 0)
{
player updatePlayersMenu();
if( player getCurrentMenu() == "players" )
player changeMenu( "players" );
}
}
}
}
function updateMenu()
{
self.surge["menu"]["current"] = "main";
self addMenu("", "main", "Surge");
self addMenu("main", "self", "Me");
self addMenu("main", "surge_settings", "Surge Settings");
self addMenu("surge_settings", "surge_colors", "Colors");
self addOption("surge_colors", "Red", &changeColor, level.red, "thread");
self addOption("surge_colors", "Orange", &changeColor, level.orange, "thread");
self addOption("surge_colors", "Yellow", &changeColor, level.yellow, "thread");
self addOption("surge_colors", "Green", &changeColor, level.green, "thread");
self addOption("surge_colors", "Blue", &changeColor, level.blue, "thread");
self addOption("surge_colors", "Purple", &changeColor, level.purple, "thread");
self addOption("surge_colors", "Cyan", &changeColor, level.cyan, "thread");
self addOption("surge_colors", "Black", &changeColor, level.black, "thread");
self addOption("surge_colors", "Gray", &changeColor, level.gray, "thread");
self addOption("surge_colors", "White", &changeColor, level.white, "thread");
self addMenu("surge_settings", "surge_positions", "Position");
self addOption("surge_positions", "Left (Default)", &test, "", "thread");
self addOption("surge_positions", "Center", &test, "", "thread");
self addOption("surge_positions", "Right", &test, "", "thread");
self addMenu("surge_settings", "surge_themes", "Theme");
self addOption("surge_themes", "Surge (Default)", &test, "", "thread");
self addOption("surge_settings", "Menu Tracking", &test, "", "thread");
self addOption("surge_settings", "Submenu Tracking", &test, "", "thread");
self addMenu("main", "destiny", "Destiny");
self addOption("destiny", "Hunter", &test, "", "thread");
self addOption("destiny", "Terminator", &test, "", "thread");
if(self getAccessLevel() > 1)
self addMenu("main", "players", "Players");
}
function updatePlayersMenu()
{
self.surge["menu"]["players"]["options"] = [];
foreach(player in level.players)
{
name = player getName();
menu = "player_" + name;
accessLevelsMenu = name + "_access_levels";
self addMenu("players", menu, name);
if(player isHost() == false)
{
self addMenu(menu, accessLevelsMenu, "Change Access Level (" + player getAccessLevelStatus() + ")");
self addOption(accessLevelsMenu, "Level 0 (" + level.accessLevelStatuses[0] + ")", &setAccessLevel, 0, "thread", player);
self addOption(accessLevelsMenu, "Level 1 (" + level.accessLevelStatuses[1] + ")", &setAccessLevel, 1, "thread", player);
self addOption(accessLevelsMenu, "Level 2 (" + level.accessLevelStatuses[2] + ")", &setAccessLevel, 2, "thread", player);
}
}
if(isEmpty(self.surge["menu"]["players"]["options"][self.surge["menu"]["players"]["position"]]))
self.surge["menu"]["players"]["position"] = 0;
}
/**
Menu Utilities
**/
function addMenu(parent, name, title)
{
// Create the menu data struct
self.surge["menu"][name] = [];
self.surge["menu"][name]["title"] = title;
self.surge["menu"][name]["options"] = [];
self.surge["menu"][name]["position"] = 0;
self.surge["menu"][name]["parent"] = parent;
// If a parent is defined add an option to open this menu
if(parent)
self addOption(parent, title, &changeMenu, name, "thread");
}
function addOption(parent, label, func, input, type, entity)
{
index = self.surge["menu"][parent]["options"].size;
// Create the option data struct
self.surge["menu"][parent]["options"][index] = [];
self.surge["menu"][parent]["options"][index]["label"] = label;
self.surge["menu"][parent]["options"][index]["function"] = func;
self.surge["menu"][parent]["options"][index]["input"] = input;
self.surge["menu"][parent]["options"][index]["type"] = type;
if(isEmpty(entity))
entity = self;
self.surge["menu"][parent]["options"][index]["entity"] = entity;
}
function runMenu(menu)
{
self endon("death");
self endon("disconnect");
self.surge["menu"]["active"] = true;
self freezeControls(true);
self setClientUiVisibilityFlag( "hud_visible", 0 );
self enableInvulnerability();
self thread exitOnDeath();
self thread feed();
self.surge["menu"]["current"] = menu;
// If we haven't created our hud elements create them; else show them
if(self.surge["menu"]["hudCreated"] == false)
self createHud();
else
{
self thread showHud();
scroll();
}
while(self.surge["menu"]["active"] == true)
{
// Scroll Up
if(self adsButtonPressed())
{
scroll(-1);
wait 0.25;
}
// Scroll Down
if(self attackButtonPressed())
{
scroll(1);
wait 0.25;
}
// Select
if(self jumpButtonPressed())
{
select();
wait 0.25;
}
// Close Menu
if(self stanceButtonPressed())
{
if(!isEmpty(self.surge["menu"][self getCurrentMenu()]["parent"]))
self changeMenu(self.surge["menu"][self getCurrentMenu()]["parent"]);
else
exitMenu();
}
// Exit
if(self meleeButtonPressed())
exitMenu();
wait 0.05;
}
}
function changeMenu(menu)
{
// Transition out old menu
for(i = 0; i < 10; i++)
{
self.surge["text"]["options"][i] fadeTo(0, 0.25);
self.surge["text"]["options"][i] thread moveTo("x", 0, 0.25);
}
self.surge["shaders"]["scrollbar"] scaleOverTime(0.25, 540, 25);
self.surge["text"]["options"][self getMenuPosition()] pulse(false);
wait 0.25;
// Update to our new menu
self.surge["menu"]["current"] = menu;
self updateHud();
// Transition in new menu
for(i = 0; i < 10; i++)
{
self.surge["text"]["options"][i].x = -540;
self.surge["text"]["options"][i] thread moveTo("x", -10, 0.25);
if(i == getMenuPosition())
self.surge["text"]["options"][i] fadeTo(1, 0.25);
else
self.surge["text"]["options"][i] fadeTo(0.5, 0.25);
}
self.surge["shaders"]["scrollbar"] scaleOverTime(0.25, 5, 25);
wait 0.25;
// Reset our scroll
scroll();
}
function exitOnDeath()
{
self endon("menu_exit");
for(;;)
{
self waittill("death");
exitMenu();
}
}
function exitMenu()
{
thread hideHud();
self freezeControls(false);
self setClientUiVisibilityFlag("hud_visible", 1);
self disableInvulnerability();
self.surge["menu"]["active"] = false;
self notify("menu_exit");
}
function getCurrentMenu()
{
return self.surge["menu"]["current"];
}
function getMenuPosition()
{
return self.surge["menu"][self getCurrentMenu()]["position"];
}
function select()
{
selected = self.surge["menu"][self getCurrentMenu()]["options"][self getMenuPosition()];
// Allows for better function handling
switch(selected["type"])
{
// Run along side
case "thread":
if(isEmpty(selected["input"]))
selected["entity"] thread [[selected["function"]]]();
else
selected["entity"] thread [[selected["function"]]](selected["input"]);
break;
// Runs before continuing code execution
default:
if(isEmpty(selected["input"]))
selected["entity"] [[selected["function"]]]();
else
selected["entity"] [[selected["function"]]](selected["input"]);
break;
}
}
function scroll(amount)
{
if(!isDefined(amount))
amount = 0;
menu = getCurrentMenu();
options = self.surge["menu"][menu]["options"];
size = options.size;
textSize = self.surge["text"]["options"].size;
lastPosition = self.surge["menu"][menu]["position"];
lastTextIndex = lastPosition;
position = lastPosition + amount;
textIndex = position;
// If we scroll past the bottom return to the top
if(position > size - 1)
{
position = 0;
textIndex = position;
lastTextIndex = size - 1;
if(size > 11)
{
lastTextIndex = textSize - 1;
self updateHud(position);
}
}
// If we scroll past the top return to the bottom
else if(position < 0)
{
position = size - 1;
textIndex = position;
lastTextIndex = 0;
if(size > 11)
{
textIndex = textSize - 1;
self updateHud(size - textSize);
}
}
// If we have more than 11 options and are not in the top half of our menu
if(size > 11 && isDefined(options[position - 5]))
{
// If we are somewhere in the middle of the menu
// - holds scrollbar in middle and moves text
if(isDefined(options[position + 5]))
{
if(lastPosition < position)
lastTextIndex = 4;
else
lastTextIndex = 6;
textIndex = 5;
self updateHud(position - textIndex);
}
// If we are in the bottom half of our menu
// - scrolls normally
else
{
if(lastPosition != 0)
lastTextIndex = (lastPosition - size) + textSize;
textIndex = (position - size) + textSize;
}
}
// If the last highlighted option is pulsing stop it
if(self.surge["text"]["options"][lastTextIndex].pulsing == true)
{
self.surge["text"]["options"][lastTextIndex] pulse(false);
self.surge["text"]["options"][lastTextIndex] fadeTo(0.5, 0.1);
}
// If the current option is not pulsing start it
if(self.surge["text"]["options"][lastTextIndex].pulsing == false)
self.surge["text"]["options"][textIndex] pulse(true);
self.surge["shaders"]["scrollbar"] thread moveTo("y", 100 + (textIndex * 25), 0.1);
self.surge["menu"][menu]["position"] = position;
}
function createHud()
{
top = 50;
margin = 25;
padding = -10;
string = "";
menu = self.surge["menu"][self getCurrentMenu()];
colors = self.surge["menu"]["colors"];
self.surge["text"]["title"] = createText("bigfixed", 1, "RIGHT", "TOP", padding, top, 3, colors["title"], 1, (0, 0, 0), 0, menu["title"]);
for(i = 0; i < 11; i++)
{
//string = "option "+i;
if(isEmpty(menu["options"][i]["label"]))
string = "";
else
string = menu["options"][i]["label"];
self.surge["text"]["options"][i] = createText("objective", 1.25, "RIGHT", "TOP", padding, top + (2 * margin) + (margin * i), 3, colors["options"], 0, (0, 0, 0), 0, string);
}
self.surge["shaders"]["background"] = createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 1, colors["background"], 0, "white");
self.surge["shaders"]["glow"] = createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 1, colors["glow"], 0, "line_horizontal");
self.surge["shaders"]["scrollbar"] = createRectangle("RIGHT", "TOP", 0, top + (2 * margin), 5, margin, 2, colors["scrollbar"], 0, "white");
//self.surge["shaders"]["icon"] = createRectangle("LEFT", "TOP", 0, 50, 65, 65, (1, 1, 1), "perk_tactical_mask", 2, 1);
//self.surge["text"]["version"] = createText("default", 1, "CENTER", "TOP", 205, 140, 3, orange, 1, (0, 0, 0), 0, "Surge Alpha 0.1");
// self.surge["text"]["info"][0].horzalign = "user_left";
// self.surge["text"]["info"][1].horzalign = "user_left";
//self.surge["text"]["instructions"].horzalign = "user_left";
//self.surge["text"]["instructions"].vertalign = "user_bottom";
showHud();
self.surge["menu"]["hudCreated"] = true;
}
function feed()
{
self endon("menu_exit");
while(self.surge["menu"]["active"])
{
for(i = 0; i < 5; i++)
{
self iPrintln(self.surge["info"][i]);
wait 5;
}
}
}
function updateHud(offset)
{
if(isEmpty(offset))
offset = 0;
for(i = 0; i < 11; i++)
{
self.surge["text"]["options"][i] setText(self.surge["menu"][self getCurrentMenu()]["options"][offset]["label"]);
offset++;
}
}
function showHud()
{
self.surge["text"]["title"].alpha = 1;
self.surge["shaders"]["background"] fadeTo(0.75, 0.1);
self.surge["shaders"]["background"] scaleOverTime(0.25, 540, 500);
self.surge["shaders"]["glow"] fadeTo(0.5, 0.1);
self.surge["shaders"]["glow"] scaleOverTime(0.25, 1000, 500);
self.surge["shaders"]["glow"] thread pulseEffect(0.4, 0.5, 2);
for(i = 0; i < self.surge["text"]["options"].size; i++)
self.surge["text"]["options"][i] thread moveTo("x", -10, 0.25);
for(i = 0; i < self.surge["text"]["options"].size; i++)
{
if(i == getMenuPosition())
{
self.surge["text"]["options"][i] pulse(true);
self.surge["shaders"]["scrollbar"] fadeTo(1, 0.25);
}
else
self.surge["text"]["options"][i] fadeTo(0.5, 0.25);
wait 0.1;
}
}
function hideHud()
{
self.surge["text"]["title"].alpha = 0;
for(i = 0; i < self.surge["text"]["options"].size; i++)
{
self.surge["text"]["options"][i] thread moveTo("x", 0, 0.25);
self.surge["text"]["options"][i] fadeTo(0, 0.25);
self.surge["text"]["options"][i] pulse(false);
}
self.surge["shaders"]["glow"] notify("pulse_end");
self.surge["shaders"]["glow"] fadeTo(0, 0.4);
self.surge["shaders"]["glow"] scaleOverTime(0.25, 1, 500);
self.surge["shaders"]["background"] fadeTo(0, 0.4);
self.surge["shaders"]["background"] scaleOverTime(0.25, 1, 500);
self.surge["shaders"]["scrollbar"].alpha = 0;
self setClientUiVisibilityFlag( "hud_visible", 1 );
}/**
Script Utilities
**/
function getName()
{
name = getSubStr(self.name, 0, self.name.size);
for(i = 0; i < name.size; i++)
{
if(name[i]=="]")
break;
}
if(name.size != i)
name = getSubStr(name, i + 1, name.size);
return name;
}
function isEmpty(var1)
{
if(var1 == "" || !isDefined(var1))
return true;
else
return false;
}
/**
Hud Utilities
**/
// Colors
function setColor(type, elem, color)
{
self.surge["menu"]["colors"][elem] = color;
}
function changeColor(type, elem, color)
{
setColor("menu", "title", color);
self.surge["text"]["title"].color = color;
}
function pulse(state)
{
if(state == true)
self thread pulseEffect(0.5, 1, 0.5);
else
self notify("pulse_end");
self.pulsing = state;
}
function pulseEffect(min, max, time)
{
self endon("pulse_end");
for(;;)
{
self fadeTo(max, time);
wait time;
self fadeTo(min, time);
wait time;
}
}
function fadeTo(alpha, time)
{
self fadeOverTime(time);
self.alpha = alpha;
}
function moveTo(axis, position, time)
{
self moveOverTime(time);
if(axis=="x")
self.x = position;
else
self.y = position;
}
function scaleFont(value, time)
{
self changeFontScaleOverTime(time);
self.fontScale = value;
}
function createText(font, fontscale, align, relative, x, y, sort, color, alpha, glowColor, glowAlpha, text)
{
textElem = hud::CreateFontString( font, fontscale );
textElem hud::setPoint( align, relative, x, y );
textElem.sort = sort;
textElem setText( text );
textElem.color = color;
textElem.alpha = alpha;
textElem.glowColor = glowColor;
textElem.glowAlpha = glowAlpha;
textElem.hideWhenInMenu = true;
return textElem;
}
function createRectangle(align, relative, x, y, width, height, sort, color, alpha, shader)
{
shaderElem = newClientHudElem( self );
shaderElem.elemType = "bar";
shaderElem.width = width;
shaderElem.height = height;
shaderElem.xOffset = 0;
shaderElem.yOffset = 0;
shaderElem.children = [];
shaderElem.sort = sort;
shaderElem.color = color;
shaderElem.alpha = alpha;
shaderElem hud::setParent( level.uiParent );
shaderElem setShader( shader, width , height );
shaderElem.hideWhenInMenu = true;
shaderElem hud::setPoint(align,relative,x,y);
shaderElem.align = align;
shaderElem.relative = relative;
return shaderElem;
}
function test(inp1) {
self IPrintLn(inp1);
}
Here's an alternative menu base that you can use BUT keep in mind this menu is still in beta so it is not perfect. If you find any bugs quote me and I will look into them. Also if you have any ideas for what I should change/add (besides mods, this is not a completed menu release it is only a base) let me know and I will see what I can do.
Features
- Verification System
- Menu Tracking
- Function Control
- Paging
- Easy-to-use Control System
Code:
level.<color name>= (r, g, b);
Ex:
level.white = (1, 1, 1);
...
self.myShader.color = level.white;
Code:
setColor(type, elem, color);
Ex:
setColor("menu", "background", black);
or
setColor("menu", "background", (0, 0, 0));
To add options to the root menu use the following in the function updateMenu()
To add options to the player menu use the following in the function updatePlayersMenu()
Adding a Menu/Submenu:
Code:
/*
* parent = menu to add to
* name = menu id/reference
* title = text to display for menu title
*/
[entity] addMenu(parent, name, title);
Adding an Option:
Code:
/*
* parent = menu to add to
* label= text to display
* title = function to call
* input = parameter to pass to function
* type = "thread" for async calls or blank for immediate calls; default is immediate
* entity = entity to call function on; default is self
*/
[entity] addOption(parent, label, function, input, type, entity);
Changing Access Level:
Code:
/*
* accessLevel = integer from 0-3
*/
[entity] setAccessLevel(accessLevel);
Code:
/*
* returns integer value; default is 0 (no access)
*/
[entity] getAccessLevel();
Code:
/*
* returns string matching access level (No Access, Limited Access, Admin, Host)
*/
[entity] getAccessLevelStatus();
Credits
- TheFallen
- ItsLollo
- Exelo for line_horizontal material
- Taylor
- Adidas
- iMCSx