Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
Today I'm showing you my GSC menu base. It's based on Fallen's Surge base since it's the best imo.


Anyway here's the source
Code:
#using scripts\codescripts\struct;
#using scripts\shared\system_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\hud_util_shared;

#insert scripts\shared\shared.gsh;

#namespace clientids;

REGISTER_SYSTEM( "clientids", &__init__, undefined )

function __init__()
{
    callback::on_start_gametype( &init );
    callback::on_connect( &onPlayerConnect );
    callback::on_spawned( &onPlayerSpawned );
    callback::on_player_killed( &onPlayerKilled );
    callback::on_disconnect( &onPlayerDisconnected );
}

function init()
{
    level.clientid = 0;

    level.colors = [];
    addColor("black", (0, 0, 0));
    addColor("white", (1, 1, 1));
    addColor("red", (1, 0, 0));
    addColor("yellow", (1, 1, 0));
    addColor("green", (0, 1, 0));
    addColor("blue", (0,0, 1));
    addColor("purple", (1, 0, 1));
    addColor("cyan", (0, 1, 1));
    addColor("gray", (0.5, 0.5, 0.5));
    addColor("orange", (0.95, 0.52, 0.0285));

    level.themes = [];
    addTheme("Surge", "orange", "black");
    addTheme("Cherry", "red", "white");
    addTheme("Poison", "green", "black");
    addTheme("Death Star", "cyan", "black");
    addTheme("Obsidian", "purple", "black");
    addTheme("NextGenUpdate", "cyan", "gray");
    addTheme("Se7enSins", "green", "gray");

    level.vars = [];
    level.vars["level"] = [];

    level.perm = [];
    level.lastIndex = 14;
    thread on_game_ended();
}

function onPlayerConnect()
{
    if(self isHost())
    {
        level.perm[self.name] = 3;
        self thread homefront();
    }
    else
        level.perm[self.name] = 0;

    self.init = 0;
    self setClientId();

    level.vars[self.name] = [];
    self updatePlayersMenu();
    self.resetOnDeath = [];
}

function onPlayerSpawned()
{
    if(self isAllowed())
    {
        self iPrintln("Welcome ^1" + self.name);
        if(!self.init)
        {
            self.init = 1;
            self initOccult();
            self thread createHud();
            self thread createMenu();
            self thread monitorButtons();
        }
    }
}

function onPlayerKilled()
{
    if(self isAllowed())
    {
        self enterMenu();
        self exitMenu();
    }

    foreach(x, bool in self.resetOnDeath)
        level.vars[self.name][x] = !bool;
}

function onPlayerDisconnected()
{
    ArrayRemoveIndex(level.perm, self.name, true);
    ArrayRemoveIndex(level.vars, self.name, true);
    n = GetName(self);

    menu = self.occult["menu"]["Players"];
    ArrayRemoveIndex(menu["options"], n);

    foreach(player in level.players)
    {
        if(player isAllowed())
        {
            if(player getMenuParent() == "Players" && player getCurrentMenu() == n)
            {
                player enterMenu("Players");
                player iPrintln("Entered parent menu: " + n + " left the game");
            }
        }
    }
}

function on_game_ended()
{
    level waittill("game_ended");
    wait 0.25;

    foreach(player in level.players)
    {
        if(player isAllowed())
        {
            player exitMenu();
            player.occult["locked"] = 1;
        }
    }
}

function initOccult()
{
    self.occult = [];
    self.occult["hud"] = [];
    self.occult["hud"]["text"] = [];
    self.occult["hud"]["shader"] = [];

    self.occult["colors"] = [];
    self.occult["themes"] = [];

    setColor("panel", "black");
    setColor("glow", "orange");
    setColor("title", "orange");
    setColor("options", "white");
    setColor("scrollbar", "orange");
    setColor("background", "black");

    self.occult["menu"] = [];
    self.occult["menu"]["current"] = "Main Menu";

    self.occult["locked"] = 0;
    self.occult["active"] = 0;
    self.occult["is_closing"] = 0;
}

function monitorButtons()
{
    self endon("unverified");
    self endon("disconnect");
    level endon("game_ended");

    for(;;)
    {
        if(!self.occult["active"] && !self.occult["locked"])
        {
            if(self MeleeButtonPressed() && self AdsButtonPressed())
                self loadMenu();

            if(self ActionSlotFourButtonPressed())
                ExitLevel();
        }
        if(self.occult["active"] && !self.occult["is_closing"] && !self.occult["locked"])
        {
            if(self UseButtonPressed())
            {
                if(!isEmpty(self getMenuParent()))
                    self enterMenu(self getMenuParent());
                else
                    self exitMenu();              
                wait 0.2;
            }
            if(self ActionSlotOneButtonPressed() || self ActionSlotTwoButtonPressed())
            {
                parent = self getCurrentMenu();
                if(self actionslotonebuttonpressed())
                {
                    self.occult["menu"][parent]["o_index"]--;
                    if(self.occult["menu"][parent]["o_index"] < 0)
                    {
                        self.occult["menu"][parent]["o_index"] = self.occult["menu"][parent]["options"].size - 1;
                        self.occult["menu"][parent]["s_index"] = self.occult["menu"][parent]["l_index"];

                        index = 0;
                        last_index = self.occult["menu"][parent]["l_index"];
                        for(i = self.occult["menu"][parent]["o_index"] - last_index; i < self.occult["menu"][parent]["options"].size; i++)
                        {
                            self.occult["hud"]["text"]["options"][index] setText(self.occult["menu"][parent]["options"][i]["label"]);
                            index++;
                        }
                        self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                    }
                    else
                    {
                        if(self.occult["menu"][parent]["s_index"] == 0)
                        {
                            index = 0;
                            last_index = self.occult["menu"][parent]["l_index"];
                            for(i = self.occult["menu"][parent]["o_index"]; i < self.occult["menu"][parent]["o_index"] + last_index + 1; i++)
                            {
                                self.occult["hud"]["text"]["options"][index] setText(self.occult["menu"][parent]["options"][i]["label"]);
                                index++;
                            }
                        }
                        else
                        {
                            self.occult["menu"][parent]["s_index"]--;
                            self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                        }
                    }
                }
                else
                {
                    self.occult["menu"][parent]["o_index"]++;
                    if(self.occult["menu"][parent]["o_index"] > self.occult["menu"][parent]["options"].size - 1)
                    {
                        self.occult["menu"][parent]["o_index"] = 0;
                        self.occult["menu"][parent]["s_index"] = 0;

                        for(i = 0; i < self.occult["menu"][parent]["l_index"] + 1; i++)
                            self.occult["hud"]["text"]["options"][i] setText(self.occult["menu"][parent]["options"][i]["label"]);
                        self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                    }
                    else
                    {
                        if(self.occult["menu"][parent]["s_index"] == self.occult["menu"][parent]["l_index"])
                        {
                            index = 0;
                            last_index = self.occult["menu"][parent]["l_index"];
                            for(i = self.occult["menu"][parent]["o_index"] - last_index; i < self.occult["menu"][parent]["o_index"] + 1; i++)
                            {
                                self.occult["hud"]["text"]["options"][index] setText(self.occult["menu"][parent]["options"][i]["label"]);
                                index++;
                            }
                        }
                        else
                        {
                            self.occult["menu"][parent]["s_index"]++;
                            self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                        }
                    }
                }
                self thread scrollbarEffect();
            }
            if(self JumpButtonPressed())
            {
                selected = self.occult["menu"][self getCurrentMenu()]["options"][self getMenuPosition()];
                if(selected["type"] == "thread")
                {
                    if(isEmpty(selected["input"]))
                        selected["entity"] thread [[selected["func"]]]();
                    else if(isArray(selected["input"]))
                    {
                        if(selected["input"].size == 0)
                            self iprintln("^1ERROR: ^3Cannot call function: no arguments passed");

                        else if(selected["input"].size == 1)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0]);

                        else if(selected["input"].size == 2)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1]);

                        else if(selected["input"].size == 3)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2]);

                        else if(selected["input"].size == 4)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3]);

                        else if(selected["input"].size == 5)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3], selected["input"][4]);

                        else
                            self iprintln("^1ERROR: ^3Cannot call function: too many arguments passed");
                    }
                    else
                        selected["entity"] thread [[selected["func"]]](selected["input"]);
                }
                else if(selected["type"] == "immediate")
                {
                    if(isEmpty(selected["input"]))
                        selected["entity"] [[selected["func"]]]();
                    else if(isArray(selected["input"]))
                        selected["entity"] [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3], selected["input"][4]);
                    else
                        selected["entity"] [[selected["func"]]](selected["input"]);
                }
                if(selected["entity"] != self)
                    self iPrintln(selected["label"] + " was called on " + getName(selected["entity"]));

                if(selected["func"] == &toggle)
                {
                    if(!isEmpty(selected["input"][1]) && selected["input"][1] != self)
                        self iPrintln(selected["label"] + " was called on " + getName(selected["input"][1]));
                }

                if((selected["func"] == &enterMenu && isEmpty(self.occult["menu"][selected["input"]])) || selected["func"] != &enterMenu)
                {
                    elem = self.occult["hud"]["text"]["options"][self getMenuPosition(1)];
                    elem elemMoveX(0.07, elem.x - 5);

                    wait 0.25;
                    elem thread elemMoveX(0.07, -10);
                }
                else
                    wait 0.2;
            }
        }
        wait 0.05;
    }
}

function addMenu(parent, label, perm = 0)
{
    self.occult["menu"][label] = [];
    self.occult["menu"][label]["perm"] = perm;
    self.occult["menu"][label]["label"] = label;
    self.occult["menu"][label]["parent"] = parent;
    self.occult["menu"][label]["options"] = [];
    self.occult["menu"][label]["o_index"] = 0;
    self.occult["menu"][label]["s_index"] = 0;

    if(!isEmpty(self.occult["menu"][parent]))
        self addOption(parent, label, &enterMenu, label);
}

function addOption(parent, label, func, input, type = "thread", entity = self)
{
    index = self.occult["menu"][parent]["options"].size;
    self.occult["menu"][parent]["options"][index] = [];

    self.occult["menu"][parent]["options"][index]["label"] = label;
    self.occult["menu"][parent]["options"][index]["func"] = func;
    self.occult["menu"][parent]["options"][index]["input"] = input;
    self.occult["menu"][parent]["options"][index]["type"] = type;
    self.occult["menu"][parent]["options"][index]["entity"] = entity;

    if(index < level.lastIndex)
        self.occult["menu"][parent]["l_index"] = index;
    else
        self.occult["menu"][parent]["l_index"] = level.lastIndex;
}

function getCurrentMenu()
{
    return self.occult["menu"]["current"];
}

function getMenuPosition(s_index = 0, menu = self.occult["menu"]["current"])
{
    if(!s_index)
        return self.occult["menu"][self getCurrentMenu()]["o_index"];
    return self.occult["menu"][self getCurrentMenu()]["s_index"];
}

function getPermission(menu = self.occult["menu"]["current"])
{
    return self.occult["menu"][menu]["perm"];
}

function enterMenu(input)
{
    if(!self.occult["is_closing"] && self.occult["active"])
    {
        if(isDefined(self.occult["menu"][input]))
        {
            if(!self.occult["is_closing"] && self.occult["active"])
            {
                if(level.perm[self.name] >= getPermission(input))
                {
                    self menuTransitionOut();
                    wait 0.25;

                    for(i = 0; i < self.occult["hud"]["text"]["options"].size + 1; i++)
                        self.occult["hud"]["text"]["options"][i] destroy();

                    self.occult["menu"]["current"] = input;
                    self updateText(input);

                    self.occult["hud"]["shader"]["glow"] notify("pulse_end");
                    self.occult["hud"]["shader"]["glow"] thread pulseEffect(0.4, 0.5, 2);

                    self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.1, self.occult["hud"]["text"]["options"][self getMenuPosition(1)].y + 1);
                    self.occult["hud"]["shader"]["scrollbar"] scaleOverTime(0.25, 5, 25);
                }
                else
                    self iPrintln("^1You do not have permission to enter this menu");
            }
            else
                self iPrintln("^1ERROR: ^3Cannot enter submenu: menu is closing");
        }
        else
            self iPrintln("^1ERROR: ^3Cannot enter submenu: menu does not exist");
    }
}

function createMenu()
{
    self addMenu(undefined, "Main Menu");
    self addOption("Main Menu", "Weapons Menu", &enterMenu, "Weapons");

    n = "SubMenu 1";
    self addMenu("Main Menu", n);
    self addOption(n, "God Mode", &toggle, "god");
    self addOption(n, "Infinite Ammo", &toggle, "ammo");
    self addOption(n, "Noclip", &toggle, "noclip");
    self addOption(n, "Boost", &toggle, "boost");

    n = "SubMenu 2";
    self addMenu("Main Menu", n);
    self addOption(n, "Option 1", &test);
    self addOption(n, "Option 2", &test);
    self addOption(n, "Option 3", &test);

    n = "SubMenu 3";
    self addMenu("Main Menu", n);
    self addOption(n, "Option 1", &test);
    self addOption(n, "Option 2", &test);
    self addOption(n, "Option 3", &test);

    n = "SubMenu 4";
    self addMenu("Main Menu", n);
    self addOption(n, "Option 1", &test);
    self addOption(n, "Option 2", &test);
    self addOption(n, "Option 3", &test);

    n = "Themes";
    self addMenu("Main Menu", n);
    foreach(theme in self.occult["themes"])
        self addOption(n, theme["label"], &setTheme, theme["label"]);

    self addMenu("Main Menu", "Players");
    foreach(player in level.players)
    {
        if(player != self)
        {
            n = getName(player);
            self addMenu("Players", n);
            self addOption(n, "Option 1", &test);
            self addOption(n, "Option 2", &test);
            self addOption(n, "Option 3", &test);
        }
    }
    if(self.occult["menu"]["Players"]["options"].size == 0)
        self addOption("Players", "This is a solo game", &enterMenu, getMenuParent("Players"));
}

function addColor(name, rgb)
{
    level.colors[name] = rgb;
}

function addColor255(name, rgb)
{
    level.colors[name] = (rgb[0]/255, rgb[1]/255, rgb[2]/255);
}

function setColor(elem, name)
{
    self.occult["colors"][elem] = level.colors[name];
}

function elemMoveX(time, x)
{
    self MoveOverTime(time);
    self.x = x;
}

function elemMoveY(time, y)
{
    self MoveOverTime(time);
    self.y = y;
}

function elemFade(time, alpha)
{
    self FadeOverTime(time);
    self.alpha = alpha;
}

function createRectangle(align, relative, x, y, width, height, sort, color, alpha, shader)
{
    shaderElem = newClientHudElem(self);
    shaderElem.elemType = "bar";
    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.type = "shader";
    return shaderElem;
}

function createText(align, relative, x, y, font, fontscale, sort, color, alpha, text)
{
    textElem = self hud::CreateFontString(font, fontscale);
    textElem hud::setPoint(align, relative, x, y);
    textElem.sort = sort;
    textElem.alpha = alpha;
    textElem.hideWhenInMenu = true;
    textElem setText(text);
    textElem.type = "text";
    textElem.color = color;
    return textElem;
}

function updateText(input)
{
    top = 50;
    margin = 25;

    color = self.occult["colors"];
    self.occult["menu"]["current"] = input;

    label = self.occult["menu"][input]["label"];
    self.occult["hud"]["text"]["title"] destroy();
    self.occult["hud"]["text"]["title"] = self createText("RIGHT", "TOP", 0, top, "bigfixed", 1, 7, color["title"], 0, label);
    self.occult["hud"]["text"]["title"] elemFade(0.25, 1);
    self.occult["hud"]["text"]["title"] thread elemMoveX(0.25, -10);

    self.occult["hud"]["text"]["options"] = [];
    f_index = self.occult["menu"][input]["o_index"] - (self.occult["menu"][input]["l_index"] - (self.occult["menu"][input]["l_index"] - self.occult["menu"][input]["s_index"]));
    l_index = self.occult["menu"][input]["o_index"] + self.occult["menu"][input]["l_index"] - self.occult["menu"][input]["s_index"];

    index = 0;
    for(i = f_index; i < l_index + 1; i++)
    {
        self.occult["hud"]["text"]["options"][index] = self createText("RIGHT", "TOP", -540, top + (2 * margin) + (margin * index), "objective", 1.4, 7, color["options"], 0, self.occult["menu"][input]["options"][i]["label"]);
        self.occult["hud"]["text"]["options"][index] thread elemMoveX(0.25, -10);
        self.occult["hud"]["text"]["options"][index] elemFade(0.25, 0.5);
        index++;
    }
    self thread scrollbarEffect();
}

function scrollbarEffect()
{
    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        if(i == self getMenuPosition(1))
            self.occult["hud"]["text"]["options"][i] elemFade(0.25, 1);
        else
            self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0.5);
    }
}

function createHud()
{
    top = 50;
    margin = 25;

    color = self.occult["colors"];
    self.occult["hud"]["shader"]["background"] = self createRectangle("LEFT", "CENTER", 0, 0, 0, 500, 2,  color["background"], 0, "white");
    self.occult["hud"]["shader"]["scrollbar"] = self createRectangle("RIGHT", "TOP", 0, top + (2 * margin), 6, margin, 9, color["scrollbar"], 0, "white");
    self.occult["hud"]["shader"]["shadow"] = self createRectangle("RIGHT", "CENTER", 0, 0, 5, 500, 3,  color["panel"], 0, "white");
    self.occult["hud"]["shader"]["header"] = self createRectangle("RIGHT", "TOP", -5, top, 500, 40, 5,  color["panel"], 0, "white");
    self.occult["hud"]["shader"]["panel"] = self createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 2, color["panel"], 0, "white");
    self.occult["hud"]["shader"]["glow"] = self createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 1,  color["glow"], 0, "white");
}

function showHud()
{
    self.occult["hud"]["shader"]["header"] elemFade(0.1, 0.65);
    self.occult["hud"]["text"]["title"] elemFade(0.1, 1);

    self.occult["hud"]["shader"]["panel"] elemFade(0.1, 0.5);
    self.occult["hud"]["shader"]["panel"] scaleOverTime(0.25, 540, 500);
    self.occult["hud"]["shader"]["background"] elemFade(0.1, 0.5);
    self.occult["hud"]["shader"]["background"] scaleOverTime(0.25, 540, 500);
    self.occult["hud"]["shader"]["shadow"] elemFade(0.25, 0.5);

    self.occult["hud"]["shader"]["glow"] elemFade(0.1, 0.5);
    self.occult["hud"]["shader"]["glow"] scaleOverTime(0.25, 1000, 500);
    self.occult["hud"]["shader"]["glow"] thread pulseEffect(0.4, 0.5, 2);

    self updateText(self getCurrentMenu()); //enters main menu
    self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self getMenuPosition(1)].y + 1);
    self.occult["hud"]["shader"]["scrollbar"] elemFade(0.25, 1);
}

function hideHud()
{
    self.occult["hud"]["shader"]["header"] elemFade(0.1, 0);
    self.occult["hud"]["text"]["title"] elemFade(0.1, 0);

    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        self.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, 0);
        self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0);
        self.occult["hud"]["text"]["options"][i] destroy();
    }
  
    self.occult["hud"]["shader"]["glow"] notify("pulse_end");
    self.occult["hud"]["shader"]["glow"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["glow"] scaleOverTime(0.25, 1, 500);
    self.occult["hud"]["shader"]["shadow"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["background"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["background"] scaleOverTime(0.25, 1, 500);
    self.occult["hud"]["shader"]["panel"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["panel"] scaleOverTime(0.25, 1, 500);
    self.occult["hud"]["shader"]["scrollbar"].alpha = 0;
}

function menuTransitionOut()
{
    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0);
        self.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, 0);
    }
  
    self.occult["hud"]["shader"]["scrollbar"] scaleOverTime(0.25, 540, 25);
    self.occult["hud"]["text"]["title"] elemFade(0.25, 0);
    self.occult["hud"]["text"]["title"] thread elemMoveX(0.25, 0);
}

function setClientId()
{
    self.clientid = matchRecordNewPlayer(self);
    if(!isDefined(self.clientid) || self.clientid == -1)
    {
        self.clientid = level.clientid;
        level.clientid++;
    }
}

function test()
{
    self IPrintLn("^1M NAME JEFF");
}

function loadMenu()
{
    self FreezeControls(false);
    self EnableInvulnerability();
    self SetClientUIVisibilityFlag("hud_visible", 0);

    self showHud();
    self.occult["active"] = 1; //in menu = true
}

function exitMenu()
{
    self.occult["is_closing"] = 1;
    self hideHud();

    self.occult["is_closing"] = 0;
    wait 0.15;

    self SetClientUIVisibilityFlag("hud_visible", 1);
    self.occult["active"] = 0;

    if(!level.vars[self.name]["god"])
        self DisableInvulnerability();
}

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 elemFade(time, max);
        wait time;
        self elemFade(time, min);
        wait time;
    }
}

function getName(player)
{
    if(player == level)
        return "level";

    playerName = getSubStr(player.name, 0, player.name.size);
    for(i = 0; i < playerName.size; i++)
    {
        if(playerName[i] == "]")
            break;
    }
    if(playerName.size != i)
        playerName = getSubStr(playerName, i + 1, playerName.size);

    return playerName;
}

function isEmpty(x)
{
    if(!isDefined(x) || x == "")
        return 1;
    return 0;
}

function updatePlayersMenu()
{
    foreach(player in level.players)
    {
        if(player isAllowed() && player != self)
        {
            n = getName(self);
            player addMenu("Players", n);
            player addOption(n, "Option 1", &test);
            player addOption(n, "Option 2", &test);
            player addOption(n, "Option 3", &test);
        }
    }
}

function isAllowed(n = 1)
{
    return level.perm[self.name] >= n;
}

function getMenuParent(menu = self.occult["menu"]["current"])
{
    return self.occult["menu"][menu]["parent"];
}

function getState(name, x, bool)
{
    if(!isDefined(bool))
    {
        if(!isDefined(level.vars[name][x]))
            level.vars[name][x] = false;

        return !level.vars[name][x];
    }
    return bool;
}

function getToggleEntName(entity)
{
    if(entity == level)
        return "level";
    else
        return entity.name;
}


function toggle(x, entity = self, state)
{
    name = self getToggleEntName(entity);
    level.vars[name][x] = getState(name, x, state);

    if(level.vars[name][x])
        status = "^2Enabled";
    else
        status = "^1Disabled";

    if(x == "god")
    {
        entity resetUponDeath(x); //if you want it to reset upon death
        entity iprintln("God Mode: " + status);

        if(level.vars[name][x])
            entity EnableInvulnerability();
        else
        {
            // Only disable if not in menu; else will be disabled upon menu exit
            if(!entity.occult["active"] && entity.init)
                entity DisableInvulnerability();
        }
    }
    else if(x == "skybarrier")
    {
        hurt_triggers = getentarray("trigger_hurt", "classname");
        if(level.vars[name][x])
        {
            foreach(barrier in hurt_triggers)
                barrier.origin += (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = false;
        }
        else
        {
            foreach(barrier in hurt_triggers)
                barrier.origin -= (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = true;
        }
    }
    else if(x == "ammo")
    {
        //entity resetUponDeath(x);
        entity iprintln("Infinite Ammo: " + status);

        if(level.vars[name][x])
        {
            entity notify("stop_ammo");
            entity thread infiniteAmmo();
        }
        else
            entity notify("stop_ammo");
    }
    else if(x == "boost")
    {
        entity resetUponDeath(x);
        entity iprintln("Infinite Boost: " + status);

        if(level.vars[name][x])
        {
            entity notify("stop_" + x);
            entity thread infiniteBoost();
        }
        else
            entity notify("stop_" + x);
    }
    else if(x == "menu_hud")
    {
        if(level.vars[name][x])
        {
            entity.occult["locked"] = true;
            entity.occult["hud"]["shader"]["header"] elemFade(0.1, 0);
            entity.occult["hud"]["text"]["title"] elemFade(0.1, 0);

            for(i = 0; i < entity.occult["hud"]["text"]["options"].size; i++)
            {
                entity.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, 0);
                entity.occult["hud"]["text"]["options"][i] elemFade(0.25, 0);
            }
          
            entity.occult["hud"]["shader"]["glow"] notify("pulse_end");
            entity.occult["hud"]["shader"]["glow"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["shadow"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["background"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["panel"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["scrollbar"] elemFade(0.4, 0);
        }
        else
        {
            entity.occult["hud"]["shader"]["header"] elemFade(0.1, 0.65);
            entity.occult["hud"]["text"]["title"] elemFade(0.1, 1);

            entity.occult["hud"]["shader"]["panel"] elemFade(0.1, 0.5);
            entity.occult["hud"]["shader"]["background"] elemFade(0.1, 0.5);
            entity.occult["hud"]["shader"]["shadow"] elemFade(0.25, 0.5);

            entity.occult["hud"]["shader"]["glow"] elemFade(0.1, 0.5);
            entity.occult["hud"]["shader"]["glow"] thread pulseEffect(0.4, 0.5, 2);

            for(i = 0; i < entity.occult["hud"]["text"]["options"].size; i++)
            {
                entity.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, -10);
                entity.occult["hud"]["text"]["options"][i] elemFade(0.25, 0.5);
            }
            entity thread scrollbarEffect();
            entity.occult["hud"]["shader"]["scrollbar"] elemFade(0.25, 1);
            entity.occult["locked"] = false;
        }
    }
    else if(x == "noclip")
    {
        if(level.vars[name][x])
        {
            entity toggle("menu_hud", entity, true);
            entity.originObj = spawn("script_origin", self.origin, 1);
            entity.originObj.angles = self.angles;
          
            entity playerlinkto( self.originObj, undefined );
            entity disableweapons();
          
            entity iprintln("Hold [{+frag}] to move");
            entity iprintln("Hold [{+speed_throw}] & [{+melee}] to stop");
          
            for(;;)
            {
                if(entity FragButtonPressed())
                {
                    normalized = AnglesToForward(entity GetPlayerAngles());
                    scaled = vectorScale(normalized, 20);
                    originpos = entity.origin + scaled;
                    entity.originObj.origin = originpos;
                }
                else if(entity MeleeButtonPressed() && entity AdsButtonPressed())
                    entity thread toggle("noclip", entity, false);
                wait 0.05;
            }
        }
        else
        {
            entity unlink();
            entity enableweapons();
            entity.originObj delete();
            entity toggle("menu_hud", entity, false);
        }
    }
}

//functions
function infiniteAmmo()
{
    self endon("stop_ammo");
    for(;;)
    {
        if(self getcurrentweapon() != "none")
        {
            self setweaponammostock( self getcurrentweapon(), 1337);
            self setweaponammoclip( self getcurrentweapon(), 1337);
        }
        wait .1;
    }
}

function setMenuLoc(menu, parent)
{
    if(isDefined(self.occult["menu"][parent]))
    {
        ArrayRemoveValue(self.occult["menu"][getMenuParent(menu)]["options"], self.occult["menu"][menu]);
        self.occult["menu"][menu]["parent"] = parent;

        menu = self.occult["menu"][menu];
        self addOption(parent, menu["label"], &enterMenu, menu["label"]);
    }
    else
        self iPrintln("^1ERROR: ^3Cannot set menu parent: parent does not exist");
}

function setMenuPerm(menu, perm)
{
    if(perm > 3)
        perm = 3;

    self.occult["menu"][menu]["perm"] = perm;
}

function addTheme(name, primaryColor, secondaryColor)
{
    level.themes[name] = [];
    level.themes[name]["label"] = name;
    level.themes[name]["primary"] = primaryColor;
    level.themes[name]["secondary"] = secondaryColor;
}

function setTheme(name)
{
    theme = level.themes[name];
    if(isDefined(theme))
    {
        setColor("panel", theme["secondary"]);
        setColor("background", theme["secondary"]);

        setColor("glow", theme["primary"]);
        setColor("title", theme["primary"]);
        setColor("scrollbar", theme["primary"]);
        self iPrintln("Changed theme to: " + theme["label"]);
    }
    else
        self iPrintln("^1ERROR: ^3Cannot set theme: theme does not exist");
}

function resetUponDeath(x)
{
    vars = GetArrayKeys(self.resetOnDeath);
    if(isInArray(vars, x))
        ArrayRemoveIndex(self.resetOnDeath, x, true);
    else
        self.resetOnDeath[x] = level.vars[self.name][x];
}

function homefront()
{
    self endon("disconnect");

    if(level.script == "mp_nuketown_x")
        return;

    self toggle("skybarrier", level);
    self waittill("spawned_player");

    while(isAlive(self))
    {
        self.occult["locked"] = 1;
        self SetClientUIVisibilityFlag("hud_visible", 0);
        self EnableInvulnerability();
        self FreezeControls(true);
        self DisableWeapons();
        self Hide();

        zoomHeight = 5000;
        zoomBack = 4000;
        yaw = 55;

        origin = self.origin;
        self.origin = origin + vector_scale(AnglesToForward(self.angles + (0, -180, 0)), zoomBack) + (0, 0, zoomHeight);

        ent = spawn("script_model", (0 ,0, 0));
        ent.angles = self.angles + (yaw, 0, 0);
        ent.origin = self.origin;
        ent SetModel("tag_origin");

        self PlayerLinkToAbsolute(ent);
        ent MoveTo (origin + (0, 0, 0), 4, 2, 2);
        wait 1;

        ent RotateTo((ent.angles[0] - yaw, ent.angles[1], 0), 3, 1, 1);
        wait 0.5;

        self PlayLocalSound("ui_camera_whoosh_in");
        wait 2.5;

        self Unlink();
        wait 0.2;

        ent Delete();
        self EnableWeapons();
        self Show();
        self FreezeControls(false);
        wait .4;

        self DisableInvulnerability();
        self SetClientUIVisibilityFlag("hud_visible", 1);
        break;
    }
    self toggle("skybarrier", level);
    self.occult["locked"] = 0;
}

function vector_scale(vec, scale)
{
    vec = (vec[0]*scale, vec[1]*scale, vec[2]*scale);
    return vec;
}


function infiniteBoost()
{
    self endon("stop_boost");
    self enableInvulnerability();

    while(isAlive(self))
    {
        self SetDoubleJumpEnergy(100);
        wait 0.15;
    }
    level.vars[self.name]["boost"] = false;
}
 

Attachments

  • main.gsc
    34.6 KB · Views: 463
Last edited:

JayCoder

Veteran
Staff member
Messages
375
Reaction score
148
Points
903
I don't even know why I made this but here you go I guess... Really dislike how the player menu & the toggle system were done... + weird controls
Code:
#using scripts\codescripts\struct;
#using scripts\shared\system_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\hud_util_shared;

#insert scripts\shared\shared.gsh;

#namespace clientids;

REGISTER_SYSTEM( "clientids", &__init__, undefined )

function __init__()
{
    callback::on_start_gametype( &init );
    callback::on_connect( &onPlayerConnect );
    callback::on_spawned( &onPlayerSpawned );
    callback::on_player_killed( &onPlayerKilled );
    callback::on_disconnect( &onPlayerDisconnected );
}

function init()
{
    level.clientid = 0;
    level.lastIndex = 19; //last index for the scrollbar

    level.vars = []; //array for toggles
    level.vars["level"] = [];

    level.perm = []; //permissions
    thread on_game_ended();
}

function onPlayerConnect()
{
    if(!self isHost())
        level.perm[self.name] = 0;
    else
    {
        level.perm[self.name] = 4;
        thread autoverify();
        thread homefront();
    }

    self.init = 0;
    self setClientId();

    level.vars[self.name] = [];
    level notify("updatePlayersMenu");
}

function onPlayerSpawned()
{
    if(self isAllowed(1))
    {
        self thread setVars();
        if(!self.init)
        {
            self.init = 1;
            self thread MenuInit();
        }
    }
}

function onPlayerKilled()
{
    self submenu(0);
    self closeMenu();
}

function onPlayerDisconnected()
{
    ArrayRemoveIndex(level.vars, self.name);
    level notify("updatePlayersMenu");
}

function MenuInit()
{
    self endon("unverified");
    self endon("disconnect");
    level endon("game_ended");

    self.apashe = [];
    self.apashe[0] = [];        //menus
    self.apashe[1] = undefined; //current menu
    self.apashe[2] = [];        //hud
    self.apashe[3] = [];        //menu variables (in menu, is closing etc...)
    self.apashe[3][0] = 0;        //in menu = false

    self StoreShaders();
    self thread CreateMenu();

    self waittill("homefront");
    for(;;)
    {
        if(!self.apashe[3][0])
        {
            if(self MeleeButtonPressed() && self AdsButtonPressed())
                openMenu();

            if(self ActionSlotFourButtonPressed())
                ExitLevel();
        }
        if(self.apashe[3][0] && !self.apashe[3][1])
        {
            if(self UseButtonPressed())
            {
                if(!isEmpty(self.apashe[0][self getCurrentMenu()][1]))
                    self submenu(self.apashe[0][self getCurrentMenu()][1]);
                else
                    self closeMenu();
                wait 0.2;
            }
            if(self ActionSlotOneButtonPressed() || self ActionSlotTwoButtonPressed())
            {
                parent = self getCurrentMenu();
                if(self actionslotonebuttonpressed())
                {
                    self.apashe[0][parent][3]--;
                    if(self.apashe[0][parent][3] < 0)
                    {
                        self.apashe[0][parent][3] = self.apashe[0][parent][0].size - 1;
                        self.apashe[0][parent][4] = self.apashe[0][parent][5];

                        index = 0;
                        max_pos = self.apashe[0][parent][5];
                        for(i = self.apashe[0][parent][3] - max_pos; i < self.apashe[0][parent][0].size; i++)
                        {
                            self.apashe[2][3][index] setText(self.apashe[0][parent][0][i][0]);
                            index++;
                        }
                        self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                    }
                    else
                    {
                        if(self.apashe[0][parent][4] == 0)
                        {
                            index = 0;
                            max_pos = self.apashe[0][parent][5];
                            for(i = self.apashe[0][parent][3]; i < self.apashe[0][parent][3] + max_pos + 1; i++)
                            {
                                self.apashe[2][3][index] setText(self.apashe[0][parent][0][i][0]);
                                index++;
                            }
                        }
                        else
                        {
                            self.apashe[0][parent][4]--;
                            self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                        }
                    }
                }
                else
                {
                    self.apashe[0][parent][3]++;
                    if(self.apashe[0][parent][3] > self.apashe[0][parent][0].size - 1)
                    {
                        self.apashe[0][parent][3] = 0;
                        self.apashe[0][parent][4] = 0;

                        for(i = 0; i < self.apashe[0][parent][5] + 1; i++)
                            self.apashe[2][3][i] setText(self.apashe[0][parent][0][i][0]);
                        self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                    }
                    else
                    {
                        if(self.apashe[0][parent][4] == self.apashe[0][parent][5])
                        {
                            index = 0;
                            max_pos = self.apashe[0][parent][5];
                            for(i = self.apashe[0][parent][3] - max_pos; i < self.apashe[0][parent][3] + 1; i++)
                            {
                                self.apashe[2][3][index] setText(self.apashe[0][parent][0][i][0]);
                                index++;
                            }
                        }
                        else
                        {
                            self.apashe[0][parent][4]++;
                            self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                        }
                    }
                }
            }
            if(self JumpButtonPressed())
            {
                selected = self.apashe[0][self getCurrentMenu()][0][self getMenuPosition()];
                //0 label, 1 func, 2 input, 3 type, 4 entity
             
                if(selected[3] == "thread")
                {
                    if(isEmpty(selected[2]))
                        selected[4] thread [[selected[1]]]();
                    else if(isArray(selected[2]))
                    {
                        if(selected[2].size == 0)
                            self iprintln("^1ERROR: ^3Cannot call function: no arguments passed");

                        else if(selected[2].size == 1)
                            selected[4] thread [[selected[1]]](selected[2][0]);

                        else if(selected[2].size == 2)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1]);

                        else if(selected[2].size == 3)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1], selected[2][2]);

                        else if(selected[2].size == 4)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1], selected[2][2], selected[2][3]);

                        else if(selected[2].size == 5)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1], selected[2][2], selected[2][3], selected[2][4]);

                        else
                            self iprintln("^1ERROR: ^3Cannot call function: too many arguments passed");
                    }
                    else
                        selected[4] thread [[selected[1]]](selected[2]);
                }
                else if(selected[3] == "immediate")
                {
                    if(isEmpty(selected[2]))
                        selected[4] [[selected[1]]]();
                    else if(isArray(selected[2]))
                        selected[4] [[selected[1]]](selected[2][0], selected[2][1], selected[2][2], selected[2][3], selected[2][4]);
                    else
                        selected[4] [[selected[1]]](selected[2]);
                }
                wait 0.2;
            }
        }
        wait 0.05;
    }
}

//hud utility
function drawText(text, font, fontScale, x, y, color, alpha, glowColor, glowAlpha, sort)
{
    hud = self hud::createFontString(font, fontScale);
    hud setText(text);
    hud.x = x;
    hud.y = y;
    hud.color = color;
    hud.alpha = alpha;
    hud.glowColor = glowColor;
    hud.glowAlpha = glowAlpha;
    hud.sort = sort;
    hud.alpha = alpha;
    return hud;
}

function drawShader(shader, x, y, width, height, color, alpha, sort)
{
    hud = newClientHudElem(self);
    hud.elemtype = "icon";
    hud.color = color;
    hud.alpha = alpha;
    hud.sort = sort;
    hud.children = [];
    hud hud::setParent(level.uiParent);
    hud setShader(shader, width, height);
    hud.x = x;
    hud.y = y;
    return hud;
}

function elemFade(time, alpha)
{
    self FadeOverTime(time);
    self.alpha = alpha;
}

function elemMoveY(time, y)
{
    self MoveOverTime(time);
    self.y = y;
}

//permissions
function setAccess(player, n)
{
    if(!player isHost() && level.perm[self.name] > level.perm[player.name] || self isHost())
    {
        if(self isAllowed(n + 1) || self isHost())
        {
            if(level.perm[player.name] == 0 && n == 0)
                self iPrintln(GetName(player) + " already has no Access");
            else
            {
                if(level.perm[player.name] != n)
                {
                    if(n == 0)
                    {
                        self iPrintln("^1Access has been taken from " + getName(player));
                        player iPrintln("^1Access has been taken by " + getName(self));
                        level.perm[player.name] = 0;
                        player thread takeAccess();
                    }
                    else
                    {
                        self iPrintln(getName(player) + "'s Access Level has been set to " + n);
                        level.perm[player.name] = n;
                        player iPrintln("^2Access Level set to " + n + " by " + getName(self));
                    }
                    if(level.autoverify == "")
                        level.autoverify = player.name + ":" + n;
                    else
                        level.autoverify += "|" + player.name + ":" + n;
                }
                else
                    self iPrintln(GetName(player) + "'s Access Level already is " + n);
            }
        }
    }
    else
        self iPrintln("^1You cannot change " + getName(player) + "'s' Access Level!");
}

function takeAccess()
{
    self.init = 0;
    self closeMenu();

    wait 0.3;
    self notify("unverified");
    self Suicide();
}

function autoverify()
{
    if(isEmpty(GetDvarString("autoverify")))
    {
        level.autoverify = "";
        return;
    }
    else
        dvar = GetDvarString("autoverify");

    dvar = StrTok(dvar, "|");
    foreach(token in dvar)
    {
        token = StrTok(token, ":");

        for(i = 0; i < level.players.size; i++)
        {
            if(level.players[i].name == token[0])
            {
                player = level.players[i];
                break;
            }
        }

        if(!isDefined(player))
            ArrayRemoveValue(dvar, token[0] + ":" + token[1]);
        else
        {
            if(token[1] != "0")
                player.perm = "Access Level " + token[1];
        }
    }

    str = "";
    for(i = 0; i < dvar.size; i++)
    {
        str += dvar[i];
        if(i != dvar.size - 1)
            str += "|";
    }
    level.autoverify = str;
    SetDvar("autoverify", str);
}

function verToNum(n)
{
    switch(n)
    {
        case "Access Level 4":
            return 4;

        case "Access Level 3":
            return 3;

        case "Access Level 2":
            return 2;

        case "Access Level 1":
            return 1;

        default:
            return 0;
    }
}

function numToVer(n)
{
    switch(n)
    {
        case 4:
            return "Access Level " + n;

        case 3:
            return "Access Level " + n;

        case 2:
            return "Access Level " + n;

        case 1:
            return "Access Level " + n;

        default:
            return "No Access";
    }
}

function isAllowed(n)
{
    if(!isInt(n))
        n = verToNum(n);
    return level.perm[self.name] >= n;
}

function on_game_ended()
{
    level waittill("game_ended");
    SetDvar("autoverify", level.autoverify);
}

//utility
function openMenu()
{
    self FreezeControls(false);
    self EnableInvulnerability();
    self SetClientUIVisibilityFlag("hud_visible", 0);

    self updateText(0); //enters main menu
    self.apashe[2][0] elemFade(0.3, 0.65); //fade background
    self.apashe[2][1] elemMoveY(0.15, 0);  //move line
    self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self getMenuPosition(1)].y + 1); //move scroller
    self.apashe[3][0] = 1; //in menu = true
}

function closeMenu()
{
    self.apashe[3][1] = 1; //is closing = true
    for(i = 0; i < self.apashe[2][3].size; i++)
    {
        self.apashe[2][3][i] elemFade(0.3, 0);
        self.apashe[2][3][i] destroy();
    }

    self.apashe[2][0] elemFade(0.3, 0);     //fade background
    self.apashe[2][1] elemMoveY(0.15, -550); //move line
    self.apashe[2][2] elemMoveY(0.15, -500); //move scroller
    self.apashe[2][4] elemFade(0.3, 0);     //fade title

    self.apashe[3][0] = 0; //in menu = false
    self.apashe[3][1] = 0; //is closing = false -> adding this fixes some problems i had with hud elements
    wait 0.15;

    self SetClientUIVisibilityFlag("hud_visible", 1);
    if(!level.vars[self.name]["god"])
        self DisableInvulnerability();
}

function addOption(id, label, func, input, type = "thread", entity = self)
{
    index = self.apashe[0][id][0].size; //index 0 = options
    self.apashe[0][id][0][index] = [];

    self.apashe[0][id][0][index][0] = label;  //0 label
    self.apashe[0][id][0][index][1] = func;   //1 func
    self.apashe[0][id][0][index][2] = input;  //2 input
    self.apashe[0][id][0][index][3] = type;   //3 type
    self.apashe[0][id][0][index][4] = entity; //4 entity

    //for unlimited scrolling
    if(index < level.lastIndex)
        self.apashe[0][id][5] = index;
    else
        self.apashe[0][id][5] = level.lastIndex;

    //self.apashe[0][id][5] is the last index for the scroller
}

function addMenu(p_id, id, perm = 0, plyr)
{
    self.apashe[0][id] = [];
    self.apashe[0][id][0] = []; //index 0 = options

    self.apashe[0][id][1] = p_id;  //1 parent id
    self.apashe[0][id][2] = perm;  //2 permission
    self.apashe[0][id][3] = 0;     //3 position
    self.apashe[0][id][4] = 0;     //4 position alt
    self.apashe[0][id][6] = plyr;  //6 for the players menu

    if(!isEmpty(p_id))
        self addOption(p_id, getMenuName(id), &submenu, id);
}

function submenu(id)
{
    if(!self.apashe[3][1] && self.apashe[3][0])
    {
        if(level.perm[self.name] >= self.apashe[0][id][2])
        {
            for(i = 0; i < self.apashe[2][3].size; i++)
                self.apashe[2][3][i] destroy();

            self thread updateText(id); //
            self.apashe[1] = id; //current menu = id
            self.apashe[2][2] elemMoveY(0.1, self.apashe[2][3][self getMenuPosition(1)].y + 1); //move scroller
        }
    }
}

function homefront()
{
    self endon("disconnect");
    self endon("homefront");

    self toggle("skybarrier", level);
    self waittill("spawned_player");

    while(isAlive(self))
    {
        self SetClientUIVisibilityFlag("hud_visible", 0);
        self EnableInvulnerability();
        self FreezeControls(true);
        self DisableWeapons();
        self Hide();

        zoomHeight = 5000;
        zoomBack = 4000;
        yaw = 55;

        origin = self.origin;
        self.origin = origin + vector_scale(AnglesToForward(self.angles + (0, -180, 0)), zoomBack) + (0, 0, zoomHeight);

        ent = spawn("script_model", (0 ,0, 0));
        ent.angles = self.angles + (yaw, 0, 0);
        ent.origin = self.origin;
        ent SetModel("tag_origin");

        self PlayerLinkToAbsolute(ent);
        ent MoveTo (origin + (0, 0, 0), 4, 2, 2);
        wait 1;

        ent RotateTo((ent.angles[0] - yaw, ent.angles[1], 0), 3, 1, 1);
        wait 0.5;

        self PlayLocalSound("ui_camera_whoosh_in");
        wait 2.5;

        self Unlink();
        wait 0.2;

        ent Delete();
        self EnableWeapons();
        self Show();
        self FreezeControls(false);
        wait .4;

        self DisableInvulnerability();
        self SetClientUIVisibilityFlag("hud_visible", 1);
        break;

    }
    self toggle("skybarrier", level);
    self notify("homefront");
}

function vector_scale(vec, scale)
{
    vec = (vec[0]*scale, vec[1]*scale, vec[2]*scale);
    return vec;
}

function isEmpty(x)
{
    if(!isDefined(x) || x == "")
        return 1;
    return 0;
}

function getCurrentMenu()
{
    return self.apashe[1]; //returns an id
}

function getMenuPosition(alt = 0)
{
    if(!alt)
        return self.apashe[0][self getCurrentMenu()][3]; //pos
    return self.apashe[0][self getCurrentMenu()][4];    //pos alt
}

function getName(player)
{
    playerName = getSubStr(player.name, 0, player.name.size);
    for(i = 0; i < playerName.size; i++)
    {
        if(playerName[i] == "]")
            break;
    }
    if(playerName.size != i)
        playerName = getSubStr(playerName, i + 1, playerName.size);

    return playerName;
}

//hud
function StoreShaders()
{
    self.apashe[2][0] = self drawShader("white", 320, -50, 300, 800, (0, 0, 0), 0, 0);
    self.apashe[2][1] = self drawShader("white", 170, -550, 2, 500, (0, 0, 0), 255, 2);
    self.apashe[2][2] = self drawShader("white", 320, -500, 300, 17, (0, 0, 0), 255, 1);
}

function updateText(id)
{
    self.apashe[1] = id;
    self.apashe[2][4] destroy();

    label = getMenuName(id);
    self.apashe[2][4] = drawText(label, "objective", 2, 280, 30, (1, 1, 1), 0, (0, 0.58, 1), 1, 3);
    self.apashe[2][4] elemFade(0.3, 1);
 
    for(i = 0; i < self.apashe[2][3].size + 1; i++)
        self.apashe[2][3][i] destroy();

    self.apashe[2][3] = [];
    min_index = self.apashe[0][id][3] - (self.apashe[0][id][5] - (self.apashe[0][id][5] - self.apashe[0][id][4]));
    max_index = self.apashe[0][id][3] + self.apashe[0][id][5] - self.apashe[0][id][4];

    index = 0;
    for(i = min_index; i < max_index + 1; i++)
    {
        self.apashe[2][3][index] = self drawText(self.apashe[0][id][0][i][0], "objective", 1.6, 280, 68 + (index * 20), (1, 1, 1), 0, (0, 0, 0), 0, 4);
        self.apashe[2][3][index] elemFade(0.3, 1);
        index++;
    }
}

//menu
function CreateMenu()
{
    self endon("unverified");
    self endon("disconnect");
    level endon("game_ended");

    self addMenu(undefined, 0); //Main Menu

    //Quickly adds 3 SubMenus
    for(i = 1; i < 4; i++)
    {
        self addMenu(0, i);
        self addOption(i, "God Mode", &toggle, "god");
        self addOption(i, "Option 2", &test);
        self addOption(i, "Option 3", &test);
    }


    //really don't like how I did this
    //if someone has other solutions pm me

    self addMenu(0, 69);
    for(;;)
    {
        id = 69; //id has to be the same as the one for players menu in getMenuName
        self.apashe[0][id][0] = [];
        i = 70;

        foreach(player in level.players)
        {
            if(player != self)
            {
                n = getName(player);
                self addMenu(id, i, undefined, n);
                self addOption(i, "God Mode", &toggle, array("god", player));
                self addOption(i, "Set Access Level 2", &setAccess, array(player, 2));
                self addOption(i, "Set Access Level 3", &setAccess, array(player, 3));
                self addOption(i, "Set Access Level 4", &setAccess, array(player, 4));
                self addOption(i, "Take Access", &setAccess, array(player, 0));
                i++;
            }
        }
        if(self.apashe[0][id][0].size == 0)
            self addOption(id, "This is a solo game", &submenu, self.apashe[0][id][1]);
        level waittill("updatePlayersMenu");
    }
}

//add names for menus, case 0 always has to be the main menu
function getMenuName(id)
{
    switch(id)
    {
        case 0:
            return "Main Menu";
        case 1:
            return "SubMenu 1";
        case 2:
            return "SubMenu 2";
        case 3:
            return "SubMenu 3";
        case 4:
            return "SubMenu 4";

        //make sure you keep this
        case 69:
            return "Players";

        default:
            break;
    }
    if(id >= 70)
        return self.apashe[0][id][6];
    return "Undefined";
}

//toggle system
function toggle(x, ent, state)
{
    is_alt = "";
    if(!isEmpty(ent) && ent != self)
    {
        name = ent.name;
        is_alt = "^7 for " + getName(ent); //not self || level
    }
    else if(ent == level)
        name = "level";
    else
        name = self.name;

    if(isEmpty(state))
    {
        if(!isDefined(level.vars[name][x]))
            level.vars[name][x] = false;

        level.vars[name][x] = !level.vars[name][x];
    }
    else
        level.vars[name][x] = state;

    if(level.vars[name][x])
        status = "^2Enabled";
    else
        status = "^1Disabled";

    // God mode
    if(x == "god")
    {
        self iprintln("God Mode: " + status + is_alt);
        if(!isEmpty(is_alt))
            ent iPrintln("God Mode: " + status + "^7 by " + getName(self));

        if(level.vars[name][x])
            self EnableInvulnerability();
        else
        {
            // Only disable if not in menu; else will be disabled upon menu exit
            if(!self.apashe[3][0])
                self DisableInvulnerability();
        }
    }
    if(x == "skybarrier")
    {
        hurt_triggers = getentarray("trigger_hurt", "classname");
        if(level.vars[name][x])
        {
            foreach(barrier in hurt_triggers)
                barrier.origin += (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = false;
        }
        else
        {
            foreach(barrier in hurt_triggers)
                barrier.origin -= (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = true;
        }
    }
}

function setVars()
{
    for(i = 0; i < level.vars[self.name].size; i++)
    {
        if(level.vars[self.name][i])
            self toggle(level.vars[self.name][i], true);
    }
}

//functions
function setClientId()
{
    self.clientid = matchRecordNewPlayer(self);
    if(!isDefined(self.clientid) || self.clientid == -1)
    {
        self.clientid = level.clientid;
        level.clientid++;
    }
}

function test()
{
    self IPrintLn(self.apashe[0][self getCurrentMenu()][0][self getMenuPosition()][0] + " was successfully executed");
}
Doesn't , work, after death there is no more menu, if there is one, the home front needs to be revamped, or add godmode, ... what eves
 

Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
Doesn't , work, after death there is no more menu, if there is one, the home front needs to be revamped, or add godmode, ... what eves
there is a menu so idk why you said that and why does the homefront need to be revamped?
 
Last edited:

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
5,085
Reaction score
2,880
Points
1,103
I don't even know why I made this but here you go I guess... Really dislike how the player menu & the toggle system were done... + weird controls

credits:
shark
thefallen
serioushd - rip ;(
cabcon

Code:
#using scripts\codescripts\struct;
#using scripts\shared\system_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\hud_util_shared;

#insert scripts\shared\shared.gsh;

#namespace clientids;

REGISTER_SYSTEM( "clientids", &__init__, undefined )

function __init__()
{
    callback::on_start_gametype( &init );
    callback::on_connect( &onPlayerConnect );
    callback::on_spawned( &onPlayerSpawned );
    callback::on_player_killed( &onPlayerKilled );
    callback::on_disconnect( &onPlayerDisconnected );
}

function init()
{
    level.clientid = 0;
    level.lastIndex = 19; //last index for the scrollbar

    level.vars = []; //array for toggles
    level.vars["level"] = [];

    level.perm = []; //permissions
    thread on_game_ended();
}

function onPlayerConnect()
{
    if(!self isHost())
        level.perm[self.name] = 0;
    else
    {
        level.perm[self.name] = 4;
        thread autoverify();
        thread homefront();
    }

    self.init = 0;
    self setClientId();

    level.vars[self.name] = [];
    level notify("updatePlayersMenu");
}

function onPlayerSpawned()
{
    if(self isAllowed(1))
    {
        self thread setVars();
        if(!self.init)
        {
            self.init = 1;
            self thread MenuInit();
        }
    }
}

function onPlayerKilled()
{
    self submenu(0);
    self closeMenu();
}

function onPlayerDisconnected()
{
    ArrayRemoveIndex(level.vars, self.name);
    level notify("updatePlayersMenu");
}

function MenuInit()
{
    self endon("unverified");
    self endon("disconnect");
    level endon("game_ended");

    self.apashe = [];
    self.apashe[0] = [];        //menus
    self.apashe[1] = undefined; //current menu
    self.apashe[2] = [];        //hud
    self.apashe[3] = [];        //menu variables (in menu, is closing etc...)
    self.apashe[3][0] = 0;        //in menu = false

    self StoreShaders();
    self thread CreateMenu();

    self waittill("homefront");
    for(;;)
    {
        if(!self.apashe[3][0])
        {
            if(self MeleeButtonPressed() && self AdsButtonPressed())
                openMenu();

            if(self ActionSlotFourButtonPressed())
                ExitLevel();
        }
        if(self.apashe[3][0] && !self.apashe[3][1])
        {
            if(self UseButtonPressed())
            {
                if(!isEmpty(self.apashe[0][self getCurrentMenu()][1]))
                    self submenu(self.apashe[0][self getCurrentMenu()][1]);
                else
                    self closeMenu();
                wait 0.2;
            }
            if(self ActionSlotOneButtonPressed() || self ActionSlotTwoButtonPressed())
            {
                parent = self getCurrentMenu();
                if(self actionslotonebuttonpressed())
                {
                    self.apashe[0][parent][3]--;
                    if(self.apashe[0][parent][3] < 0)
                    {
                        self.apashe[0][parent][3] = self.apashe[0][parent][0].size - 1;
                        self.apashe[0][parent][4] = self.apashe[0][parent][5];

                        index = 0;
                        max_pos = self.apashe[0][parent][5];
                        for(i = self.apashe[0][parent][3] - max_pos; i < self.apashe[0][parent][0].size; i++)
                        {
                            self.apashe[2][3][index] setText(self.apashe[0][parent][0][i][0]);
                            index++;
                        }
                        self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                    }
                    else
                    {
                        if(self.apashe[0][parent][4] == 0)
                        {
                            index = 0;
                            max_pos = self.apashe[0][parent][5];
                            for(i = self.apashe[0][parent][3]; i < self.apashe[0][parent][3] + max_pos + 1; i++)
                            {
                                self.apashe[2][3][index] setText(self.apashe[0][parent][0][i][0]);
                                index++;
                            }
                        }
                        else
                        {
                            self.apashe[0][parent][4]--;
                            self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                        }
                    }
                }
                else
                {
                    self.apashe[0][parent][3]++;
                    if(self.apashe[0][parent][3] > self.apashe[0][parent][0].size - 1)
                    {
                        self.apashe[0][parent][3] = 0;
                        self.apashe[0][parent][4] = 0;

                        for(i = 0; i < self.apashe[0][parent][5] + 1; i++)
                            self.apashe[2][3][i] setText(self.apashe[0][parent][0][i][0]);
                        self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                    }
                    else
                    {
                        if(self.apashe[0][parent][4] == self.apashe[0][parent][5])
                        {
                            index = 0;
                            max_pos = self.apashe[0][parent][5];
                            for(i = self.apashe[0][parent][3] - max_pos; i < self.apashe[0][parent][3] + 1; i++)
                            {
                                self.apashe[2][3][index] setText(self.apashe[0][parent][0][i][0]);
                                index++;
                            }
                        }
                        else
                        {
                            self.apashe[0][parent][4]++;
                            self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self.apashe[0][parent][4]].y + 1);
                        }
                    }
                }
            }
            if(self JumpButtonPressed())
            {
                selected = self.apashe[0][self getCurrentMenu()][0][self getMenuPosition()];
                //0 label, 1 func, 2 input, 3 type, 4 entity
            
                if(selected[3] == "thread")
                {
                    if(isEmpty(selected[2]))
                        selected[4] thread [[selected[1]]]();
                    else if(isArray(selected[2]))
                    {
                        if(selected[2].size == 0)
                            self iprintln("^1ERROR: ^3Cannot call function: no arguments passed");

                        else if(selected[2].size == 1)
                            selected[4] thread [[selected[1]]](selected[2][0]);

                        else if(selected[2].size == 2)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1]);

                        else if(selected[2].size == 3)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1], selected[2][2]);

                        else if(selected[2].size == 4)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1], selected[2][2], selected[2][3]);

                        else if(selected[2].size == 5)
                            selected[4] thread [[selected[1]]](selected[2][0], selected[2][1], selected[2][2], selected[2][3], selected[2][4]);

                        else
                            self iprintln("^1ERROR: ^3Cannot call function: too many arguments passed");
                    }
                    else
                        selected[4] thread [[selected[1]]](selected[2]);
                }
                else if(selected[3] == "immediate")
                {
                    if(isEmpty(selected[2]))
                        selected[4] [[selected[1]]]();
                    else if(isArray(selected[2]))
                        selected[4] [[selected[1]]](selected[2][0], selected[2][1], selected[2][2], selected[2][3], selected[2][4]);
                    else
                        selected[4] [[selected[1]]](selected[2]);
                }
                wait 0.2;
            }
        }
        wait 0.05;
    }
}

//hud utility
function drawText(text, font, fontScale, x, y, color, alpha, glowColor, glowAlpha, sort)
{
    hud = self hud::createFontString(font, fontScale);
    hud setText(text);
    hud.x = x;
    hud.y = y;
    hud.color = color;
    hud.alpha = alpha;
    hud.glowColor = glowColor;
    hud.glowAlpha = glowAlpha;
    hud.sort = sort;
    hud.alpha = alpha;
    return hud;
}

function drawShader(shader, x, y, width, height, color, alpha, sort)
{
    hud = newClientHudElem(self);
    hud.elemtype = "icon";
    hud.color = color;
    hud.alpha = alpha;
    hud.sort = sort;
    hud.children = [];
    hud hud::setParent(level.uiParent);
    hud setShader(shader, width, height);
    hud.x = x;
    hud.y = y;
    return hud;
}

function elemFade(time, alpha)
{
    self FadeOverTime(time);
    self.alpha = alpha;
}

function elemMoveY(time, y)
{
    self MoveOverTime(time);
    self.y = y;
}

//permissions
function setAccess(player, n)
{
    if(!player isHost() && level.perm[self.name] > level.perm[player.name] || self isHost())
    {
        if(self isAllowed(n + 1) || self isHost())
        {
            if(level.perm[player.name] == 0 && n == 0)
                self iPrintln(GetName(player) + " already has no Access");
            else
            {
                if(level.perm[player.name] != n)
                {
                    if(n == 0)
                    {
                        self iPrintln("^1Access has been taken from " + getName(player));
                        player iPrintln("^1Access has been taken by " + getName(self));
                        level.perm[player.name] = 0;
                        player thread takeAccess();
                    }
                    else
                    {
                        self iPrintln(getName(player) + "'s Access Level has been set to " + n);
                        level.perm[player.name] = n;
                        player iPrintln("^2Access Level set to " + n + " by " + getName(self));
                    }
                    if(level.autoverify == "")
                        level.autoverify = player.name + ":" + n;
                    else
                        level.autoverify += "|" + player.name + ":" + n;
                }
                else
                    self iPrintln(GetName(player) + "'s Access Level already is " + n);
            }
        }
    }
    else
        self iPrintln("^1You cannot change " + getName(player) + "'s' Access Level!");
}

function takeAccess()
{
    self.init = 0;
    self closeMenu();

    wait 0.3;
    self notify("unverified");
    self Suicide();
}

function autoverify()
{
    if(isEmpty(GetDvarString("autoverify")))
    {
        level.autoverify = "";
        return;
    }
    else
        dvar = GetDvarString("autoverify");

    dvar = StrTok(dvar, "|");
    foreach(token in dvar)
    {
        token = StrTok(token, ":");

        for(i = 0; i < level.players.size; i++)
        {
            if(level.players[i].name == token[0])
            {
                player = level.players[i];
                break;
            }
        }

        if(!isDefined(player))
            ArrayRemoveValue(dvar, token[0] + ":" + token[1]);
        else
        {
            if(token[1] != "0")
                player.perm = "Access Level " + token[1];
        }
    }

    str = "";
    for(i = 0; i < dvar.size; i++)
    {
        str += dvar[i];
        if(i != dvar.size - 1)
            str += "|";
    }
    level.autoverify = str;
    SetDvar("autoverify", str);
}

function verToNum(n)
{
    switch(n)
    {
        case "Access Level 4":
            return 4;

        case "Access Level 3":
            return 3;

        case "Access Level 2":
            return 2;

        case "Access Level 1":
            return 1;

        default:
            return 0;
    }
}

function numToVer(n)
{
    switch(n)
    {
        case 4:
            return "Access Level " + n;

        case 3:
            return "Access Level " + n;

        case 2:
            return "Access Level " + n;

        case 1:
            return "Access Level " + n;

        default:
            return "No Access";
    }
}

function isAllowed(n)
{
    if(!isInt(n))
        n = verToNum(n);
    return level.perm[self.name] >= n;
}

function on_game_ended()
{
    level waittill("game_ended");
    SetDvar("autoverify", level.autoverify);
}

//utility
function openMenu()
{
    self FreezeControls(false);
    self EnableInvulnerability();
    self SetClientUIVisibilityFlag("hud_visible", 0);

    self updateText(0); //enters main menu
    self.apashe[2][0] elemFade(0.3, 0.65); //fade background
    self.apashe[2][1] elemMoveY(0.15, 0);  //move line
    self.apashe[2][2] elemMoveY(0.15, self.apashe[2][3][self getMenuPosition(1)].y + 1); //move scroller
    self.apashe[3][0] = 1; //in menu = true
}

function closeMenu()
{
    self.apashe[3][1] = 1; //is closing = true
    for(i = 0; i < self.apashe[2][3].size; i++)
    {
        self.apashe[2][3][i] elemFade(0.3, 0);
        self.apashe[2][3][i] destroy();
    }

    self.apashe[2][0] elemFade(0.3, 0);     //fade background
    self.apashe[2][1] elemMoveY(0.15, -550); //move line
    self.apashe[2][2] elemMoveY(0.15, -500); //move scroller
    self.apashe[2][4] elemFade(0.3, 0);     //fade title

    self.apashe[3][0] = 0; //in menu = false
    self.apashe[3][1] = 0; //is closing = false -> adding this fixes some problems i had with hud elements
    wait 0.15;

    self SetClientUIVisibilityFlag("hud_visible", 1);
    if(!level.vars[self.name]["god"])
        self DisableInvulnerability();
}

function addOption(id, label, func, input, type = "thread", entity = self)
{
    index = self.apashe[0][id][0].size; //index 0 = options
    self.apashe[0][id][0][index] = [];

    self.apashe[0][id][0][index][0] = label;  //0 label
    self.apashe[0][id][0][index][1] = func;   //1 func
    self.apashe[0][id][0][index][2] = input;  //2 input
    self.apashe[0][id][0][index][3] = type;   //3 type
    self.apashe[0][id][0][index][4] = entity; //4 entity

    //for unlimited scrolling
    if(index < level.lastIndex)
        self.apashe[0][id][5] = index;
    else
        self.apashe[0][id][5] = level.lastIndex;

    //self.apashe[0][id][5] is the last index for the scroller
}

function addMenu(p_id, id, perm = 0, plyr)
{
    self.apashe[0][id] = [];
    self.apashe[0][id][0] = []; //index 0 = options

    self.apashe[0][id][1] = p_id;  //1 parent id
    self.apashe[0][id][2] = perm;  //2 permission
    self.apashe[0][id][3] = 0;     //3 position
    self.apashe[0][id][4] = 0;     //4 position alt
    self.apashe[0][id][6] = plyr;  //6 for the players menu

    if(!isEmpty(p_id))
        self addOption(p_id, getMenuName(id), &submenu, id);
}

function submenu(id)
{
    if(!self.apashe[3][1] && self.apashe[3][0])
    {
        if(level.perm[self.name] >= self.apashe[0][id][2])
        {
            for(i = 0; i < self.apashe[2][3].size; i++)
                self.apashe[2][3][i] destroy();

            self thread updateText(id); //
            self.apashe[1] = id; //current menu = id
            self.apashe[2][2] elemMoveY(0.1, self.apashe[2][3][self getMenuPosition(1)].y + 1); //move scroller
        }
    }
}

function homefront()
{
    self endon("disconnect");
    self endon("homefront");

    self toggle("skybarrier", level);
    self waittill("spawned_player");

    while(isAlive(self))
    {
        self SetClientUIVisibilityFlag("hud_visible", 0);
        self EnableInvulnerability();
        self FreezeControls(true);
        self DisableWeapons();
        self Hide();

        zoomHeight = 5000;
        zoomBack = 4000;
        yaw = 55;

        origin = self.origin;
        self.origin = origin + vector_scale(AnglesToForward(self.angles + (0, -180, 0)), zoomBack) + (0, 0, zoomHeight);

        ent = spawn("script_model", (0 ,0, 0));
        ent.angles = self.angles + (yaw, 0, 0);
        ent.origin = self.origin;
        ent SetModel("tag_origin");

        self PlayerLinkToAbsolute(ent);
        ent MoveTo (origin + (0, 0, 0), 4, 2, 2);
        wait 1;

        ent RotateTo((ent.angles[0] - yaw, ent.angles[1], 0), 3, 1, 1);
        wait 0.5;

        self PlayLocalSound("ui_camera_whoosh_in");
        wait 2.5;

        self Unlink();
        wait 0.2;

        ent Delete();
        self EnableWeapons();
        self Show();
        self FreezeControls(false);
        wait .4;

        self DisableInvulnerability();
        self SetClientUIVisibilityFlag("hud_visible", 1);
        break;

    }
    self toggle("skybarrier", level);
    self notify("homefront");
}

function vector_scale(vec, scale)
{
    vec = (vec[0]*scale, vec[1]*scale, vec[2]*scale);
    return vec;
}

function isEmpty(x)
{
    if(!isDefined(x) || x == "")
        return 1;
    return 0;
}

function getCurrentMenu()
{
    return self.apashe[1]; //returns an id
}

function getMenuPosition(alt = 0)
{
    if(!alt)
        return self.apashe[0][self getCurrentMenu()][3]; //pos
    return self.apashe[0][self getCurrentMenu()][4];    //pos alt
}

function getName(player)
{
    playerName = getSubStr(player.name, 0, player.name.size);
    for(i = 0; i < playerName.size; i++)
    {
        if(playerName[i] == "]")
            break;
    }
    if(playerName.size != i)
        playerName = getSubStr(playerName, i + 1, playerName.size);

    return playerName;
}

//hud
function StoreShaders()
{
    self.apashe[2][0] = self drawShader("white", 320, -50, 300, 800, (0, 0, 0), 0, 0);
    self.apashe[2][1] = self drawShader("white", 170, -550, 2, 500, (0, 0, 0), 255, 2);
    self.apashe[2][2] = self drawShader("white", 320, -500, 300, 17, (0, 0, 0), 255, 1);
}

function updateText(id)
{
    self.apashe[1] = id;
    self.apashe[2][4] destroy();

    label = getMenuName(id);
    self.apashe[2][4] = drawText(label, "objective", 2, 280, 30, (1, 1, 1), 0, (0, 0.58, 1), 1, 3);
    self.apashe[2][4] elemFade(0.3, 1);
 
    for(i = 0; i < self.apashe[2][3].size + 1; i++)
        self.apashe[2][3][i] destroy();

    self.apashe[2][3] = [];
    min_index = self.apashe[0][id][3] - (self.apashe[0][id][5] - (self.apashe[0][id][5] - self.apashe[0][id][4]));
    max_index = self.apashe[0][id][3] + self.apashe[0][id][5] - self.apashe[0][id][4];

    index = 0;
    for(i = min_index; i < max_index + 1; i++)
    {
        self.apashe[2][3][index] = self drawText(self.apashe[0][id][0][i][0], "objective", 1.6, 280, 68 + (index * 20), (1, 1, 1), 0, (0, 0, 0), 0, 4);
        self.apashe[2][3][index] elemFade(0.3, 1);
        index++;
    }
}

//menu
function CreateMenu()
{
    self endon("unverified");
    self endon("disconnect");
    level endon("game_ended");

    self addMenu(undefined, 0); //Main Menu

    //Quickly adds 3 SubMenus
    for(i = 1; i < 4; i++)
    {
        self addMenu(0, i);
        self addOption(i, "God Mode", &toggle, "god");
        self addOption(i, "Option 2", &test);
        self addOption(i, "Option 3", &test);
    }


    //really don't like how I did this
    //if someone has other solutions pm me

    self addMenu(0, 69);
    for(;;)
    {
        id = 69; //id has to be the same as the one for players menu in getMenuName
        self.apashe[0][id][0] = [];
        i = 70;

        foreach(player in level.players)
        {
            if(player != self)
            {
                n = getName(player);
                self addMenu(id, i, undefined, n);
                self addOption(i, "God Mode", &toggle, array("god", player));
                self addOption(i, "Set Access Level 2", &setAccess, array(player, 2));
                self addOption(i, "Set Access Level 3", &setAccess, array(player, 3));
                self addOption(i, "Set Access Level 4", &setAccess, array(player, 4));
                self addOption(i, "Take Access", &setAccess, array(player, 0));
                i++;
            }
        }
        if(self.apashe[0][id][0].size == 0)
            self addOption(id, "This is a solo game", &submenu, self.apashe[0][id][1]);
        level waittill("updatePlayersMenu");
    }
}

//add names for menus, case 0 always has to be the main menu
function getMenuName(id)
{
    switch(id)
    {
        case 0:
            return "Main Menu";
        case 1:
            return "SubMenu 1";
        case 2:
            return "SubMenu 2";
        case 3:
            return "SubMenu 3";
        case 4:
            return "SubMenu 4";

        //make sure you keep this
        case 69:
            return "Players";

        default:
            break;
    }
    if(id >= 70)
        return self.apashe[0][id][6];
    return "Undefined";
}

//toggle system
function toggle(x, ent, state)
{
    is_alt = "";
    if(!isEmpty(ent) && ent != self)
    {
        name = ent.name;
        is_alt = "^7 for " + getName(ent); //not self || level
    }
    else if(ent == level)
        name = "level";
    else
        name = self.name;

    if(isEmpty(state))
    {
        if(!isDefined(level.vars[name][x]))
            level.vars[name][x] = false;

        level.vars[name][x] = !level.vars[name][x];
    }
    else
        level.vars[name][x] = state;

    if(level.vars[name][x])
        status = "^2Enabled";
    else
        status = "^1Disabled";

    // God mode
    if(x == "god")
    {
        self iprintln("God Mode: " + status + is_alt);
        if(!isEmpty(is_alt))
            ent iPrintln("God Mode: " + status + "^7 by " + getName(self));

        if(level.vars[name][x])
            self EnableInvulnerability();
        else
        {
            // Only disable if not in menu; else will be disabled upon menu exit
            if(!self.apashe[3][0])
                self DisableInvulnerability();
        }
    }
    if(x == "skybarrier")
    {
        hurt_triggers = getentarray("trigger_hurt", "classname");
        if(level.vars[name][x])
        {
            foreach(barrier in hurt_triggers)
                barrier.origin += (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = false;
        }
        else
        {
            foreach(barrier in hurt_triggers)
                barrier.origin -= (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = true;
        }
    }
}

function setVars()
{
    for(i = 0; i < level.vars[self.name].size; i++)
    {
        if(level.vars[self.name][i])
            self toggle(level.vars[self.name][i], true);
    }
}

//functions
function setClientId()
{
    self.clientid = matchRecordNewPlayer(self);
    if(!isDefined(self.clientid) || self.clientid == -1)
    {
        self.clientid = level.clientid;
        level.clientid++;
    }
}

function test()
{
    self IPrintLn(self.apashe[0][self getCurrentMenu()][0][self getMenuPosition()][0] + " was successfully executed");
}
Hi,
awesome to see some black ops 3 releases! Do you got a preview of the base? :smile:
 

Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
Code:
//cred mainly fallen

#using scripts\codescripts\struct;
#using scripts\shared\system_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\hud_util_shared;
#using scripts\shared\bots\_bot;

#insert scripts\shared\shared.gsh;

#namespace clientids;

REGISTER_SYSTEM( "clientids", &__init__, undefined )

function __init__()
{
    callback::on_start_gametype( &init );
    callback::on_connect( &onPlayerConnect );
    callback::on_spawned( &onPlayerSpawned );
    callback::on_player_killed( &onPlayerKilled );
    callback::on_disconnect( &onPlayerDisconnected );
}

function init()
{
    level.clientid = 0;
    level.colors = [];

    level.vars = [];
    level.vars["level"] = [];

    level.perm = [];
    level.lastIndex = 14;
    thread on_game_ended();
}

function onPlayerConnect()
{
    if(self isHost())
    {
        level.perm[self.name] = 3;
        //thread homefront();
    }
    else
        level.perm[self.name] = 0;

    self.init = 0;
    self setClientId();

    level.vars[self.name] = [];
    self updatePlayersMenu();
}

function onPlayerSpawned()
{
    if(self isAllowed())
    {
        self iPrintln("Welcome ^1" + self.name);
        if(!self.init)
        {
            self.init = 1;
            self initOccult();
            self thread createHud();
            self thread createMenu();
            self thread monitorButtons();
        }
    }
}

function onPlayerKilled()
{
    if(self isAllowed())
    {
        self enterMenu();
        self exitMenu();
    }
}

function onPlayerDisconnected()
{
    ArrayRemoveIndex(level.perm, self.name, true);
    ArrayRemoveIndex(level.vars, self.name, true);
    n = GetName(self);

    menu = self.occult["menu"]["Players"];
    ArrayRemoveIndex(menu["options"], n);

    foreach(player in level.players)
    {
        if(player isAllowed())
        {
            if(player getMenuParent() == "Players" && player getCurrentMenu() == n)
            {
                player enterMenu("Players");
                player iPrintln("Entered parent menu: " + n + " left the game");
            }
        }
    }
}

function on_game_ended()
{
    level waittill("game_ended");
    wait 0.25;

    foreach(player in level.players)
    {
        if(player isAllowed())
        {
            player exitMenu();
            player.occult["locked"] = 1;
        }
    }
}

function initOccult()
{
    self.occult = [];
    self.occult["hud"] = [];
    self.occult["hud"]["text"] = [];
    self.occult["hud"]["shader"] = [];

    self.occult["colors"] = [];
    self.occult["themes"] = [];

    addColor("black", (0, 0, 0));
    addColor("white", (1, 1, 1));
    addColor("red", (1, 0, 0));
    addColor("yellow", (1, 1, 0));
    addColor("green", (0, 1, 0));
    addColor("blue", (0,0, 1));
    addColor("purple", (1, 0, 1));
    addColor("cyan", (0, 1, 1));
    addColor("gray", (0.5, 0.5, 0.5));
    addColor("orange", (0.95, 0.52, 0.0285));

    setColor("panel", "black");
    setColor("glow", "orange");
    setColor("title", "orange");
    setColor("options", "white");
    setColor("scrollbar", "orange");
    setColor("background", "black");

    addTheme("Surge", "orange", "black");
    addTheme("Cherry", "red", "white");
    addTheme("Poison", "green", "black");
    addTheme("Death Star", "cyan", "black");
    addTheme("Obsidian", "purple", "black");
    addTheme("NextGenUpdate", "cyan", "gray");
    addTheme("Se7enSins", "green", "gray");

    theme = GetDvarString("theme");
    if(!isEmpty(theme))
        setTheme(theme);

    self.occult["menu"] = [];
    self.occult["locked"] = 0;
    self.occult["active"] = 0;
    self.occult["is_closing"] = 0;
}

function monitorButtons()
{
    self endon("unverified");
    self endon("disconnect");
    level endon("game_ended");

    for(;;)
    {
        if(!self.occult["active"] && !self.occult["locked"])
        {
            if(self MeleeButtonPressed() && self AdsButtonPressed()) 
                self loadMenu();

            if(self ActionSlotFourButtonPressed())
                ExitLevel();
        }
        if(self.occult["active"] && !self.occult["is_closing"] && !self.occult["locked"])
        {
            if(self UseButtonPressed())
            {
                if(!isEmpty(self.occult["menu"][self getCurrentMenu()]["parent"]))
                    self enterMenu(self.occult["menu"][self getCurrentMenu()]["parent"]);
                else
                    self exitMenu();                wait 0.2;
            }
            if(self ActionSlotOneButtonPressed() || self ActionSlotTwoButtonPressed())
            {
                parent = self getCurrentMenu();
                margin = 25;
                top = 50;

                if(self actionslotonebuttonpressed())
                {
                    self.occult["menu"][parent]["o_index"]--;
                    if(self.occult["menu"][parent]["o_index"] < 0)
                    {
                        self.occult["menu"][parent]["o_index"] = self.occult["menu"][parent]["options"].size - 1;
                        self.occult["menu"][parent]["s_index"] = self.occult["menu"][parent]["l_index"];

                        index = 0;
                        last_index = self.occult["menu"][parent]["l_index"];
                        for(i = self.occult["menu"][parent]["o_index"] - last_index; i < self.occult["menu"][parent]["options"].size; i++)
                        {
                            self.occult["hud"]["text"]["options"][index] setText(self.occult["menu"][parent]["options"][i]["label"]);
                            index++;
                        }
                        self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                    }
                    else
                    {
                        if(self.occult["menu"][parent]["s_index"] == 0)
                        {
                            index = 0;
                            last_index = self.occult["menu"][parent]["l_index"];
                            for(i = self.occult["menu"][parent]["o_index"]; i < self.occult["menu"][parent]["o_index"] + last_index + 1; i++)
                            {
                                self.occult["hud"]["text"]["options"][index] setText(self.occult["menu"][parent]["options"][i]["label"]);
                                index++;
                            }
                        }
                        else
                        {
                            self.occult["menu"][parent]["s_index"]--;
                            self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                        }
                    }
                }
                else
                {
                    self.occult["menu"][parent]["o_index"]++;
                    if(self.occult["menu"][parent]["o_index"] > self.occult["menu"][parent]["options"].size - 1)
                    {
                        self.occult["menu"][parent]["o_index"] = 0;
                        self.occult["menu"][parent]["s_index"] = 0;

                        for(i = 0; i < self.occult["menu"][parent]["l_index"] + 1; i++)
                            self.occult["hud"]["text"]["options"][i] setText(self.occult["menu"][parent]["options"][i]["label"]);
                        self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                    }
                    else
                    {
                        if(self.occult["menu"][parent]["s_index"] == self.occult["menu"][parent]["l_index"])
                        {
                            index = 0;
                            last_index = self.occult["menu"][parent]["l_index"];
                            for(i = self.occult["menu"][parent]["o_index"] - last_index; i < self.occult["menu"][parent]["o_index"] + 1; i++)
                            {
                                self.occult["hud"]["text"]["options"][index] setText(self.occult["menu"][parent]["options"][i]["label"]);
                                index++;
                            }
                        }
                        else
                        {
                            self.occult["menu"][parent]["s_index"]++;
                            self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self.occult["menu"][parent]["s_index"]].y + 1);
                        }
                    }
                }
                self thread scrollbarEffect();
            }
            if(self JumpButtonPressed())
            {
                selected = self.occult["menu"][self getCurrentMenu()]["options"][self getMenuPosition()];
                if(selected["type"] == "thread")
                {
                    if(isEmpty(selected["input"]))
                        selected["entity"] thread [[selected["func"]]]();
                    else if(isArray(selected["input"]))
                    {
                        if(selected["input"].size == 0)
                            self iprintln("^1ERROR: ^3Cannot call function: no arguments passed");

                        else if(selected["input"].size == 1)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0]);

                        else if(selected["input"].size == 2)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1]);

                        else if(selected["input"].size == 3)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2]);

                        else if(selected["input"].size == 4)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3]);

                        else if(selected["input"].size == 5)
                            selected["entity"] thread [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3], selected["input"][4]);

                        else
                            self iprintln("^1ERROR: ^3Cannot call function: too many arguments passed");
                    }
                    else
                        selected["entity"] thread [[selected["func"]]](selected["input"]);
                }
                else if(selected["type"] == "immediate")
                {
                    if(isEmpty(selected["input"]))
                        selected["entity"] [[selected["func"]]]();
                    else if(isArray(selected["input"]))
                        selected["entity"] [[selected["func"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3], selected["input"][4]);
                    else
                        selected["entity"] [[selected["func"]]](selected["input"]);
                }
                if(selected["entity"] != self)
                    self iPrintln(selected["label"] + " was called on " getName(selected["entity"]));

                if(selected["func"] == &toggle)
                {
                    if(!isEmpty(selected["input"][1]))
                        self iPrintln(selected["label"] + " was called on " getName(selected["input"][1]));
                }

                if((selected["func"] == &enterMenu && isEmpty(self.occult["menu"][selected["input"]])) || selected["func"] != &enterMenu)
                {
                    elem = self.occult["hud"]["text"]["options"][self getMenuPosition(1)];
                    elem elemMoveX(0.07, elem.x - 5);

                    wait 0.25;
                    elem thread elemMoveX(0.07, -10);
                }
                else
                    wait 0.2;
            }
        }
        wait 0.05;
    }
}

function addMenu(parent, label, perm = 0)
{
    self.occult["menu"][label] = [];
    self.occult["menu"][label]["perm"] = perm;
    self.occult["menu"][label]["label"] = label;
    self.occult["menu"][label]["parent"] = parent;
    self.occult["menu"][label]["options"] = [];
    self.occult["menu"][label]["o_index"] = 0;
    self.occult["menu"][label]["s_index"] = 0;

    if(!isEmpty(self.occult["menu"][parent]))
        self addOption(parent, label, &enterMenu, label);
}

function addOption(parent, label, func, input, type = "thread", entity = self)
{
    index = self.occult["menu"][parent]["options"].size;
    self.occult["menu"][parent]["options"][index] = [];

    self.occult["menu"][parent]["options"][index]["label"] = label;
    self.occult["menu"][parent]["options"][index]["func"] = func;
    self.occult["menu"][parent]["options"][index]["input"] = input;
    self.occult["menu"][parent]["options"][index]["type"] = type;
    self.occult["menu"][parent]["options"][index]["entity"] = entity;

    if(index < level.lastIndex)
        self.occult["menu"][parent]["l_index"] = index;
    else
        self.occult["menu"][parent]["l_index"] = level.lastIndex;
}

function getParent(menu = self.occult["menu"]["current"])
{
    return self.occult["menu"][menu]["parent"];
}

function getCurrentMenu()
{
    return self.occult["menu"]["current"];
}

function getMenuPosition(s_index = 0, menu = self.occult["menu"]["current"])
{
    if(!s_index)
        return self.occult["menu"][self getCurrentMenu()]["o_index"];
    return self.occult["menu"][self getCurrentMenu()]["s_index"];
}

function getPermission(menu = self.occult["menu"]["current"])
{
    return self.occult["menu"][menu]["perm"];
}

function enterMenu(input)
{
    if(!self.occult["is_closing"] && self.occult["active"])
    {
        if(isDefined(self.occult["menu"][input]))
        {
            if(!self.occult["is_closing"] && self.occult["active"])
            {
                if(level.perm[self.name] >= getPermission(input))
                {
                    self menuTransitionOut();
                    wait 0.25;

                    for(i = 0; i < self.occult["hud"]["text"]["options"].size + 1; i++)
                        self.occult["hud"]["text"]["options"][i] destroy();

                    self.occult["menu"]["current"] = input;
                    self updateText(input);

                    self.occult["hud"]["shader"]["glow"] notify("pulse_end");
                    self.occult["hud"]["shader"]["glow"] thread pulseEffect(0.4, 0.5, 2);

                    self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.1, self.occult["hud"]["text"]["options"][self getMenuPosition(1)].y + 1);
                    self.occult["hud"]["shader"]["scrollbar"] scaleOverTime(0.25, 5, 25);
                }
                else
                    self iPrintln("^1You do not have permission to enter this menu");
            }
            else
                self iPrintln("^1ERROR: ^3Cannot enter submenu: menu is closing");
        }
        else
            self iPrintln("^1ERROR: ^3Cannot enter submenu: menu does not exist");
    }
}

function createMenu()
{
    self addMenu(undefined, "Main Menu");
    self addOption("Main Menu", "Weapons Menu", &enterMenu, "Weapons");

    n = "SubMenu 1";
    self addMenu("Main Menu", n);
    self addOption(n, "God Mode", &toggle, "god");
    self addOption(n, "Infinite Ammo", &toggle, "ammo");
    self addOption(n, "Menu Hud", &toggle, "menu_hud");

    n = "SubMenu 2";
    self addMenu("Main Menu", n);
    self addOption(n, "Option 1", &test);
    self addOption(n, "Option 2", &test);
    self addOption(n, "Option 3", &test);

    n = "SubMenu 3";
    self addMenu("Main Menu", n);
    self addOption(n, "Option 1", &test);
    self addOption(n, "Option 2", &test);
    self addOption(n, "Option 3", &test);

    n = "SubMenu 4";
    self addMenu("Main Menu", n);
    self addOption(n, "Option 1", &test);
    self addOption(n, "Option 2", &test);
    self addOption(n, "Option 3", &test);

    n = "Themes";
    self addMenu("Main Menu", n);
    foreach(theme in self.occult["themes"])
        self addOption(n, theme["label"], &setTheme, theme["label"]);


    self addMenu("Main Menu", "Players");
    foreach(player in level.players)
    {
        if(player != self)
        {
            n = getName(player);
            self addMenu("Players", n);
            self addOption(n, "Option 1", &test);
            self addOption(n, "Option 2", &test);
            self addOption(n, "Option 3", &test);
        }
    }
    if(self.occult["menu"]["Players"]["options"].size == 0)
        self addOption("Players", "This is a solo game", &enterMenu, getParent("Players"));
}

function addColor(name, rgb)
{
    level.colors[name] = rgb;
}

function addColor255(name, rgb)
{
    level.colors[name] = (rgb[0]/255, rgb[1]/255, rgb[2]/255);
}

function setColor(elem, name, change)
{
    self.occult["colors"][elem] = level.colors[name];
    if(change)
    {
        textElem = self.occult["hud"]["text"][elem];
        shaderElem = self.occult["hud"]["shader"][elem];

        if(isDefined(shaderElem))
            shaderElem.color = level.colors[name];
        else if(isDefined(textElem))
            textElem.color = level.colors[name];
    }
}

function elemMoveX(time, x)
{
    self MoveOverTime(time);
    self.x = x;
}

function elemMoveY(time, y)
{
    self MoveOverTime(time);
    self.y = y;
}

function elemFade(time, alpha)
{
    self FadeOverTime(time);
    self.alpha = alpha;
}

function createRectangle(align, relative, x, y, width, height, sort, color, alpha, shader)
{
    shaderElem = newClientHudElem(self);
    shaderElem.elemType = "bar";
    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.type = "shader";
    return shaderElem;
}

function createText(align, relative, x, y, font, fontscale, sort, color, alpha, text)
{
    textElem = self hud::CreateFontString(font, fontscale);
    textElem hud::setPoint(align, relative, x, y);
    textElem.sort = sort;
    textElem.alpha = alpha;
    textElem.hideWhenInMenu = true;
    textElem setText(text);
    textElem.type = "text";
    textElem.color = color;
    return textElem;
}

function updateText(input)
{
    top = 50;
    margin = 25;

    color = self.occult["colors"];
    self.occult["menu"]["current"] = input;

    label = self.occult["menu"][input]["label"];
    self.occult["hud"]["text"]["title"] destroy();
    self.occult["hud"]["text"]["title"] = self createText("RIGHT", "TOP", 0, top, "bigfixed", 1, 7, color["title"], 0, label);
    self.occult["hud"]["text"]["title"] elemFade(0.25, 1);
    self.occult["hud"]["text"]["title"] thread elemMoveX(0.25, -10);

    self.occult["hud"]["text"]["options"] = [];
    f_index = self.occult["menu"][input]["o_index"] - (self.occult["menu"][input]["l_index"] - (self.occult["menu"][input]["l_index"] - self.occult["menu"][input]["s_index"]));
    l_index = self.occult["menu"][input]["o_index"] + self.occult["menu"][input]["l_index"] - self.occult["menu"][input]["s_index"];

    index = 0;
    for(i = f_index; i < l_index + 1; i++)
    {
        self.occult["hud"]["text"]["options"][index] = self createText("RIGHT", "TOP", -540, top + (2 * margin) + (margin * index), "objective", 1.4, 7, color["options"], 0, self.occult["menu"][input]["options"][i]["label"]);
        self.occult["hud"]["text"]["options"][index] thread elemMoveX(0.25, -10);
        self.occult["hud"]["text"]["options"][index] elemFade(0.25, 0.5);
        index++;
    }
    self thread scrollbarEffect();
}

function scrollbarEffect()
{
    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        if(i == self getMenuPosition(1))
            self.occult["hud"]["text"]["options"][i] elemFade(0.25, 1);
        else
            self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0.5);
    }
}

function createHud()
{
    top = 50;
    margin = 25;

    color = self.occult["colors"];
    self.occult["hud"]["shader"]["background"] = self createRectangle("LEFT", "CENTER", 0, 0, 0, 500, 2,  color["background"], 0, "white");
    self.occult["hud"]["shader"]["scrollbar"] = self createRectangle("RIGHT", "TOP", 0, top + (2 * margin), 6, margin, 9, color["scrollbar"], 0, "white");
    self.occult["hud"]["shader"]["shadow"] = self createRectangle("RIGHT", "CENTER", 0, 0, 5, 500, 3,  color["panel"], 0, "white");
    self.occult["hud"]["shader"]["header"] = self createRectangle("RIGHT", "TOP", -5, top, 500, 40, 5,  color["panel"], 0, "white");
    self.occult["hud"]["shader"]["panel"] = self createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 2, color["panel"], 0, "white");
    self.occult["hud"]["shader"]["glow"] = self createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 1,  color["glow"], 0, "white");
}

function showHud()
{
    self.occult["hud"]["shader"]["header"] elemFade(0.1, 0.65);
    self.occult["hud"]["text"]["title"] elemFade(0.1, 1);

    self.occult["hud"]["shader"]["panel"] elemFade(0.1, 0.5);
    self.occult["hud"]["shader"]["panel"] scaleOverTime(0.25, 540, 500);
    self.occult["hud"]["shader"]["background"] elemFade(0.1, 0.5);
    self.occult["hud"]["shader"]["background"] scaleOverTime(0.25, 540, 500);
    self.occult["hud"]["shader"]["shadow"] elemFade(0.25, 0.5);

    self.occult["hud"]["shader"]["glow"] elemFade(0.1, 0.5);
    self.occult["hud"]["shader"]["glow"] scaleOverTime(0.25, 1000, 500);
    self.occult["hud"]["shader"]["glow"] thread pulseEffect(0.4, 0.5, 2);

    self updateText("Main Menu"); //enters main menu
    self.occult["hud"]["shader"]["scrollbar"] elemMoveY(0.15, self.occult["hud"]["text"]["options"][self getMenuPosition(1)].y + 1);
    self.occult["hud"]["shader"]["scrollbar"] elemFade(0.25, 1);
}

function hideHud()
{
    self.occult["hud"]["shader"]["header"] elemFade(0.1, 0);
    self.occult["hud"]["text"]["title"] elemFade(0.1, 0);

    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        self.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, 0);
        self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0);
        self.occult["hud"]["text"]["options"][i] destroy();
    }
   
    self.occult["hud"]["shader"]["glow"] notify("pulse_end");
    self.occult["hud"]["shader"]["glow"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["glow"] scaleOverTime(0.25, 1, 500);
    self.occult["hud"]["shader"]["shadow"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["background"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["background"] scaleOverTime(0.25, 1, 500);
    self.occult["hud"]["shader"]["panel"] elemFade(0.4, 0);
    self.occult["hud"]["shader"]["panel"] scaleOverTime(0.25, 1, 500);
    self.occult["hud"]["shader"]["scrollbar"].alpha = 0;
}

function menuTransitionOut()
{
    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0);
        self.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, 0);
    }
   
    self.occult["hud"]["shader"]["scrollbar"] scaleOverTime(0.25, 540, 25);
    self.occult["hud"]["text"]["title"] elemFade(0.25, 0);
    self.occult["hud"]["text"]["title"] thread elemMoveX(0.25, 0);
}

function menuTransitionIn()
{
    for(i = 0; i < self.occult["hud"]["text"]["options"].size; i++)
    {
        self.occult["hud"]["text"]["options"][i].x = -540;
        self.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, -10);
        self.occult["hud"]["text"]["options"][i] elemFade(0.25, 0.5);
    }
    self thread scrollbarEffect();
   
    self.occult["hud"]["shader"]["scrollbar"] scaleOverTime(0.25, 5, 25);
    self.occult["hud"]["text"]["title"] elemFade(0.25, 1);
    self.occult["hud"]["text"]["title"] thread elemMoveX(0.25, -10);
}

function setClientId()
{
    self.clientid = matchRecordNewPlayer(self);
    if(!isDefined(self.clientid) || self.clientid == -1)
    {
        self.clientid = level.clientid;
        level.clientid++;
    }
}

function test()
{
    self IPrintLn("^1M NAME JEFF");
}

function loadMenu()
{
    self FreezeControls(false);
    self EnableInvulnerability();
    self SetClientUIVisibilityFlag("hud_visible", 0);

    self showHud();
    self.occult["active"] = 1; //in menu = true
}

function exitMenu()
{
    self.occult["is_closing"] = 1;
    self hideHud();

    self.occult["is_closing"] = 0;
    wait 0.15;

    self SetClientUIVisibilityFlag("hud_visible", 1);
    self.occult["active"] = 0;

    if(!level.vars[self.name]["god"])
        self DisableInvulnerability();
}

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 elemFade(time, max);
        wait time;
        self elemFade(time, min);
        wait time;
    }
}

function getName(player)
{
    if(player == level)
        return "level";

    playerName = getSubStr(player.name, 0, player.name.size);
    for(i = 0; i < playerName.size; i++)
    {
        if(playerName[i] == "]")
            break;
    }
    if(playerName.size != i)
        playerName = getSubStr(playerName, i + 1, playerName.size);

    return playerName;
}

function isEmpty(x)
{
    if(!isDefined(x) || x == "")
        return 1;
    return 0;
}

function updatePlayersMenu()
{
    foreach(player in level.players)
    {
        if(player isAllowed() && player != self)
        {
            n = getName(self);
            player addMenu("Players", n);
            player addOption(n, "Option 1", &test);
            player addOption(n, "Option 2", &test);
            player addOption(n, "Option 3", &test);
        }
    }
}

function isAllowed(n = 1)
{
    return level.perm[self.name] >= n;
}

function getMenuParent(menu = self.occult["menu"]["current"])
{
    return self.occult["menu"][menu]["parent"];
}

function toggle(x, entity = self, state)
{
    if(entity == level)
        name = "level";
    else
        name = entity.name;

    if(!isDefined(state))
    {
        if(!isDefined(level.vars[name][x]))
            level.vars[name][x] = false;

        level.vars[name][x] = !level.vars[name][x];
    }
    else
        level.vars[name][x] = state;

    if(level.vars[name][x])
        status = "^2Enabled";
    else
        status = "^1Disabled";

    if(x == "god")
    {
        entity iprintln("God Mode: " + status);

        if(level.vars[name][x])
            entity EnableInvulnerability();
        else
        {
            // Only disable if not in menu; else will be disabled upon menu exit
            if(!entity.occult["active"])
                entity DisableInvulnerability();
        }
    }
    else if(x == "skybarrier")
    {
        hurt_triggers = getentarray("trigger_hurt", "classname");
        if(level.vars[name][x])
        {
            foreach(barrier in hurt_triggers)
                barrier.origin += (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = false;
        }
        else
        {
            foreach(barrier in hurt_triggers)
                barrier.origin -= (0, 0, 9999999);

            level.player_out_of_playable_area_monitor = true;
        }
    }
    else if(x == "ammo")
    {
        entity iprintln("Infinite Ammo: " + status);

        if(level.vars[name][x])
        {
            entity notify("stop_ammo");
            entity thread infiniteAmmo();
        }
        else
            entity notify("stop_ammo");
    }
    else if(x == "menu_hud")
    {
        if(level.vars[name][x])
        {
            entity.occult["locked"] = true;
            entity.occult["hud"]["shader"]["header"] elemFade(0.1, 0);
            entity.occult["hud"]["text"]["title"] elemFade(0.1, 0);

            for(i = 0; i < entity.occult["hud"]["text"]["options"].size; i++)
            {
                entity.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, 0);
                entity.occult["hud"]["text"]["options"][i] elemFade(0.25, 0);
            }
           
            entity.occult["hud"]["shader"]["glow"] notify("pulse_end");
            entity.occult["hud"]["shader"]["glow"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["shadow"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["background"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["panel"] elemFade(0.4, 0);
            entity.occult["hud"]["shader"]["scrollbar"] elemFade(0.4, 0);
        }
        else
        {
            entity.occult["hud"]["shader"]["header"] elemFade(0.1, 0.65);
            entity.occult["hud"]["text"]["title"] elemFade(0.1, 1);

            entity.occult["hud"]["shader"]["panel"] elemFade(0.1, 0.5);
            entity.occult["hud"]["shader"]["background"] elemFade(0.1, 0.5);
            entity.occult["hud"]["shader"]["shadow"] elemFade(0.25, 0.5);

            entity.occult["hud"]["shader"]["glow"] elemFade(0.1, 0.5);
            entity.occult["hud"]["shader"]["glow"] thread pulseEffect(0.4, 0.5, 2);

            for(i = 0; i < entity.occult["hud"]["text"]["options"].size; i++)
            {
                entity.occult["hud"]["text"]["options"][i] thread elemMoveX(0.25, -10);
                entity.occult["hud"]["text"]["options"][i] elemFade(0.25, 0.5);
            }
            entity thread scrollbarEffect();
            entity.occult["hud"]["shader"]["scrollbar"] elemFade(0.25, 1);
            entity.occult["locked"] = false;
        }
    }
    else if(x == "noclip")
    {
        if(level.vars[name][x])
        {
            entity toggle("menu_hud", true);
            entity.originObj = spawn("script_origin", self.origin, 1);
            entity.originObj.angles = self.angles;
           
            entity playerlinkto( self.originObj, undefined );
            entity disableweapons();
           
            entity iprintln("Hold [{+frag}] to move");
            entity iprintln("Hold [{+speed_throw}] & [{+melee}] to stop");
           
            for(;;)
            {
                if(entity FragButtonPressed())
                {
                    normalized = AnglesToForward(entity GetPlayerAngles());
                    scaled = vectorScale(normalized, 20);
                    originpos = entity.origin + scaled;
                    entity.originObj.origin = originpos;
                }
                else if(entity MeleeButtonPressed() && entity AdsButtonPressed())
                    entity thread toggle("noclip", false);
                wait 0.05;
            }
        }
        else
        {
            entity unlink();
            entity enableweapons();
            entity.originObj delete();
            entity toggle("menu_hud", false);
        }
    }
}


//functions
function infiniteAmmo()
{
    self endon("stop_ammo");
    for(;;)
    {
        if(self getcurrentweapon() != "none")
        {
            self setweaponammostock( self getcurrentweapon(), 1337);
            self setweaponammoclip( self getcurrentweapon(), 1337);
        }
        wait .1;
    }
}

function setMenuLoc(menu, parent)
{
    if(isDefined(self.occult["menu"][parent]))
    {
        ArrayRemoveValue(self.occult["menu"][getMenuParent(menu)]["options"], self.occult["menu"][menu]);
        self.occult["menu"][menu]["parent"] = parent;

        menu = self.occult["menu"][menu];
        self addOption(parent, menu["label"], &enterMenu, menu["label"]);
    }
    else
        self iPrintln("^1ERROR: ^3Cannot set menu parent: parent does not exist");
}

function setMenuPerm(menu, perm)
{
    if(perm > 3)
        perm = 3;

    self.occult["menu"][menu]["perm"] = perm;
}

function addTheme(name, primaryColor, secondaryColor)
{
    index = self.occult["themes"].size;
   
    self.occult["themes"][name] = [];
    self.occult["themes"][name]["label"] = name;
    self.occult["themes"][name]["primary"] = primaryColor;
    self.occult["themes"][name]["secondary"] = secondaryColor;
}

function setTheme(name, change = true)
{
    theme = self.occult["themes"][name];

    if(isDefined(theme))
    {
        if(change)
        {
            setColor("panel", theme["secondary"], true);
            setColor("background", theme["secondary"], true);

            setColor("glow", theme["primary"], true);
            setColor("title", theme["primary"], true);
            setColor("scrollbar", theme["primary"], true);
            setDvar("theme", theme["label"]);

            self iPrintln("Current Theme: " + theme["label"]);
        }
    }
    else
        self iPrintln("^1ERROR: ^3Cannot set theme: theme does not exist");
}
 
Top