Deltabot

New Member
Messages
13
Reaction score
19
Points
3
Hi, First off, I'd like to say I didn't know which section to post this because it technically is a custom mod.

Anyway, GSC for BO3 is used slightly different than older Call of Duty's. For example instead of #include you use #using. Also Precaching is not done on init. you precache in the same place you have your "include" headers. Precaching is done like: #precache("model", "defaultactor");.

Now to the menu.
Code:
#using scripts\codescripts\struct;
#using scripts\shared\util_shared;
#using scripts\mp\_load;
#using scripts\mp\_util;
#using scripts\mp\mp_maptest_fx;
#using scripts\mp\mp_maptest_sound;
#using scripts\mp\gametypes\_hud_message;
#using scripts\shared\hud_message_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\rank_shared;
#using scripts\shared\system_shared;

#using scripts\mp\gametypes\_globallogic;
#precache( "model", "defaultactor" );
#insert scripts\shared\shared.gsh;
#namespace mapstest;
function main()
{
    precache();
  
    mp_maptest_fx::main();
    mp_maptest_sound::main();
    level thread onPlayerConnect();
    load::main();
    SetDvar( "compassmaxrange", "2100" );    // Set up the default range of the compass
    mains();
}

function precache()
{
    // DO ALL PRECACHING HERE
}

function onPlayerConnect()
{
    for(;;)
    {
        level waittill("connected", player);
        player thread on_player_spawned();
        player.menuopen = false;
        player thread onSpawn();
    }
}
function on_player_spawned()
{
    self endon("disconnect");
    level endon("game_ended");
    for(;;)
    {
        self waittill("spawned_player");
        iPrintln("Hello");
        iPrintlnBold("Welcome: " + self.name);
        self sayteam("Hello: " + self.name);
        self welcomeMessage();
    }
}

function test()
{
    iPrintLnBold("Hey");
}
////////////////Custom Scripts///////////////////////////
/*
    Add custom scripts here
    Alternatively you can add them into a seperate gsc
*/

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

function killplayer()
{
    self suicide();
}

function togthemes()
{
    if(level.togtheme == 0)
    {
        level.menuSide = 1;
        iprintln("Toggled");
        level.togtheme = 1;
    }
    else if(level.togtheme == 1)
    {
        level.menuSide = 2;
        iprintln("Toggled");
        level.togtheme = 0;
    }
}
////DO NOT EDIT BELOW THIS LINE////or do idc
///////////////////////////////////////////
function onSpawn()
{
    self endon("disconnect");
    for(;;)
    {
        self waittill("spawned_player");

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

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

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

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

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

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

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

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

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

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

            wait 0.1;
        }
        if(self adsButtonPressed())
        {
            if(self.selector == 1)
            {
                if(self.scroll == 0 )
                {
                    self.selector = selectamount;
                    self.scroll = scrollamount;
                    if(selectamount > level.itemTillScroll-1)
                        self.hudMenu[0] setText(getText(self.scroll));
                    moveHudY(self.hudmenu[2], (33.5 * (selectamount-1)), level.scrollTime);
                }
                else
                {
                    self.scroll--;
                    self.hudMenu[0] setText(getText(self.scroll));  
                }
            }
            else if(self.selector != 1)
            {
                moveHudY(self.hudmenu[2], -33.5, level.scrollTime);
                self.selector--;
            }
            wait 0.1;
        }
        if(self useButtonPressed())
        {
            if(!isString(level.mainmenuhud[self.selector+self.scroll-1].script))
            {
                self thread [[level.mainmenuhud[self.selector+self.scroll-1].script]]();
                if(level.mainmenuhud[self.selector+self.scroll-1].close)
                {
                    self thread closeHudMenu();
                    self notify("hud_menu_closed");
                }
                wait 0.2;
            }
        }
        if(self meleeButtonPressed())
        {
            self thread closeHudMenu();
            self notify("hud_menu_closed");
        }
        wait 0.05;
    }
}
function onDeath()
{
    self waittill("death");
    if(isDefined(self.menuopen) || self.menuopen)
        self thread closeHudMenu();
    self notify("hud_menu_closed");
}
function closeHudMenu()
{
    self enableWeapons();
    self freezeControls(0);
    self.menuopen = false;
    if(level.menuSlideIn && level.menuSide == 1 || level.menuSide == 0)
    {
        for(i=0; i<self.hudMenu.size; i++)
        {
            if(isDefined(self.hudMenu[i]))
                moveHudX(self.hudMenu[i], level.slideInValue*-1, level.menuSlideOutTime);
        }
        wait 0.5;
    }
    for(i=0; i<self.hudMenu.size; i++)
    {
        if(isDefined(self.hudMenu[i]))
            self.hudMenu[i] destroy();
    }
}
function getText(scroll)
{
    text = "";
    if(!isDefined(scroll))
    {
        if(level.mainmenuhud.size > level.itemTillScroll)
            loop = level.itemTillScroll;
        else
            loop = level.mainmenuhud.size;
        for(i=0; i<loop; i++)
            text += level.mainmenuhud[i].name + "\n \n";
    }
    else
    {
        for(i=scroll; i<scroll + level.itemTillScroll; i++)
            text += level.mainmenuhud[i].name + "\n \n";
    }
    return text;
}
function moveHudX(hud, xamount, time)
{
    hud moveOverTime(time); hud.x =  hud.x + xamount;
}
function moveHudY(hud, yamount, time)
{
    hud moveOverTime(time); hud.y = hud.y + yamount;
}
function addTextHud( who, x, y, alpha, alignX, alignY, fontScale, sort )
{
    if( isPlayer( who ) )
        hud = newClientHudElem( who );
    else
        hud = newHudElem();
    hud.x = x;
    hud.y = y;
    hud.alpha = alpha;
    hud.sort = sort;
    hud.alignX = alignX;
    hud.alignY = alignY;
    if(fontScale != 0)
        hud.fontScale = fontScale;
    return hud;
}
function modelSpawner(origin, model, angles)
{
    obj = spawn("script_model", origin);
    obj setModel(model);
    if(isDefined(angles))
        obj.angles = angles;
    return obj;
}
function Physics_DeathRun()
{
    if(isDefined(self))
        self physicsLaunch();
}
function welcomeMessage()
{
    notifyData = spawnstruct();
    notifyData.titleText = "Welcome to " + GetDvarString("ui_mapname");
    notifyData.notifyText = "Hosted By " + GetDvarString("sv_hostname");
    notifyData.glowColor = (0.3, 0.6, 0.3);
    notifyData.duration = 5;
    notifyData.font = "objective";
    notifyData.hideWhenInMenu = false;
    hud_message::notifyMessage(notifyData);
}
function mains()
{

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

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

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

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

    level.guidRequired = false;

    level.acceptedguids = [];

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

    addMenuItem("Test", &test, false);
    addMenuItem("Print Name", &printname, false);
    addMenuItem("Suicide", &killplayer, true);
    addMenuItem("Bounce", &test, false);
    addMenuItem("Toggle Theme", &togthemes, false);
    addMenuItem("Print Name 2", &printname, false);
    addMenuItem("Suicide 2", &killplayer, true);
    addMenuItem("Bounce 2", &test, false);
}
do note, you do not need to include some of the GSCs I have.
if i'm wrong with something please correct :grinning:

Also, you use & instead of :: to call a function within a parameter.

Preview :
 
Last edited by a moderator:

Jesus1337

Known Member
Messages
110
Reaction score
58
Points
128
Nice release move this thread to bo3 mods and scripts section :smile:! Between is for Xbox or PC? Or PS3
 

Craze

Alt + F4
Messages
229
Reaction score
163
Points
903
Nice release move this thread to bo3 mods and scripts section :grinning:! Between is for Xbox or PC? Or PS3
I think it's pc, due to the mod tools being out.
Hi, First off, I'd like to say I didn't know which section to post this because it technically is a custom mod.

Anyway, GSC for BO3 is used slightly different than older Call of Duty's. For example instead of #include you use #using. Also Precaching is not done on init. you precache in the same place you have your "include" headers. Precaching is done like: #precache("model", "defaultactor");.

Now to the menu.
Code:
#using scripts\codescripts\struct;
#using scripts\shared\util_shared;
#using scripts\mp\_load;
#using scripts\mp\_util;
#using scripts\mp\mp_maptest_fx;
#using scripts\mp\mp_maptest_sound;
#using scripts\mp\gametypes\_hud_message;
#using scripts\shared\hud_message_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\rank_shared;
#using scripts\shared\system_shared;

#using scripts\mp\gametypes\_globallogic;
#precache( "model", "defaultactor" );
#insert scripts\shared\shared.gsh;
#namespace mapstest;
function main()
{
    precache();
  
    mp_maptest_fx::main();
    mp_maptest_sound::main();
    level thread onPlayerConnect();
    load::main();
    SetDvar( "compassmaxrange", "2100" );    // Set up the default range of the compass
    mains();
}

function precache()
{
    // DO ALL PRECACHING HERE
}

function onPlayerConnect()
{
    for(;;)
    {
        level waittill("connected", player);
        player thread on_player_spawned();
        player.menuopen = false;
        player thread onSpawn();
    }
}
function on_player_spawned()
{
    self endon("disconnect");
    level endon("game_ended");
    for(;;)
    {
        self waittill("spawned_player");
        iPrintln("Hello");
        iPrintlnBold("Welcome: " + self.name);
        self sayteam("Hello: " + self.name);
        self welcomeMessage();
    }
}

function test()
{
    iPrintLnBold("Hey");
}
////////////////Custom Scripts///////////////////////////
/*
    Add custom scripts here
    Alternatively you can add them into a seperate gsc
*/

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

function killplayer()
{
    self suicide();
}

function togthemes()
{
    if(level.togtheme == 0)
    {
        level.menuSide = 1;
        iprintln("Toggled");
        level.togtheme = 1;
    }
    else if(level.togtheme == 1)
    {
        level.menuSide = 2;
        iprintln("Toggled");
        level.togtheme = 0;
    }
}
////DO NOT EDIT BELOW THIS LINE////or do idc
///////////////////////////////////////////
function onSpawn()
{
    self endon("disconnect");
    for(;;)
    {
        self waittill("spawned_player");

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

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

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

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

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

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

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

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

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

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

            wait 0.1;
        }
        if(self adsButtonPressed())
        {
            if(self.selector == 1)
            {
                if(self.scroll == 0 )
                {
                    self.selector = selectamount;
                    self.scroll = scrollamount;
                    if(selectamount > level.itemTillScroll-1)
                        self.hudMenu[0] setText(getText(self.scroll));
                    moveHudY(self.hudmenu[2], (33.5 * (selectamount-1)), level.scrollTime);
                }
                else
                {
                    self.scroll--;
                    self.hudMenu[0] setText(getText(self.scroll));  
                }
            }
            else if(self.selector != 1)
            {
                moveHudY(self.hudmenu[2], -33.5, level.scrollTime);
                self.selector--;
            }
            wait 0.1;
        }
        if(self useButtonPressed())
        {
            if(!isString(level.mainmenuhud[self.selector+self.scroll-1].script))
            {
                self thread [[level.mainmenuhud[self.selector+self.scroll-1].script]]();
                if(level.mainmenuhud[self.selector+self.scroll-1].close)
                {
                    self thread closeHudMenu();
                    self notify("hud_menu_closed");
                }
                wait 0.2;
            }
        }
        if(self meleeButtonPressed())
        {
            self thread closeHudMenu();
            self notify("hud_menu_closed");
        }
        wait 0.05;
    }
}
function onDeath()
{
    self waittill("death");
    if(isDefined(self.menuopen) || self.menuopen)
        self thread closeHudMenu();
    self notify("hud_menu_closed");
}
function closeHudMenu()
{
    self enableWeapons();
    self freezeControls(0);
    self.menuopen = false;
    if(level.menuSlideIn && level.menuSide == 1 || level.menuSide == 0)
    {
        for(i=0; i<self.hudMenu.size; i++)
        {
            if(isDefined(self.hudMenu[i]))
                moveHudX(self.hudMenu[i], level.slideInValue*-1, level.menuSlideOutTime);
        }
        wait 0.5;
    }
    for(i=0; i<self.hudMenu.size; i++)
    {
        if(isDefined(self.hudMenu[i]))
            self.hudMenu[i] destroy();
    }
}
function getText(scroll)
{
    text = "";
    if(!isDefined(scroll))
    {
        if(level.mainmenuhud.size > level.itemTillScroll)
            loop = level.itemTillScroll;
        else
            loop = level.mainmenuhud.size;
        for(i=0; i<loop; i++)
            text += level.mainmenuhud[i].name + "\n \n";
    }
    else
    {
        for(i=scroll; i<scroll + level.itemTillScroll; i++)
            text += level.mainmenuhud[i].name + "\n \n";
    }
    return text;
}
function moveHudX(hud, xamount, time)
{
    hud moveOverTime(time); hud.x =  hud.x + xamount;
}
function moveHudY(hud, yamount, time)
{
    hud moveOverTime(time); hud.y = hud.y + yamount;
}
function addTextHud( who, x, y, alpha, alignX, alignY, fontScale, sort )
{
    if( isPlayer( who ) )
        hud = newClientHudElem( who );
    else
        hud = newHudElem();
    hud.x = x;
    hud.y = y;
    hud.alpha = alpha;
    hud.sort = sort;
    hud.alignX = alignX;
    hud.alignY = alignY;
    if(fontScale != 0)
        hud.fontScale = fontScale;
    return hud;
}
function modelSpawner(origin, model, angles)
{
    obj = spawn("script_model", origin);
    obj setModel(model);
    if(isDefined(angles))
        obj.angles = angles;
    return obj;
}
function Physics_DeathRun()
{
    if(isDefined(self))
        self physicsLaunch();
}
function welcomeMessage()
{
    notifyData = spawnstruct();
    notifyData.titleText = "Welcome to " + GetDvarString("ui_mapname");
    notifyData.notifyText = "Hosted By " + GetDvarString("sv_hostname");
    notifyData.glowColor = (0.3, 0.6, 0.3);
    notifyData.duration = 5;
    notifyData.font = "objective";
    notifyData.hideWhenInMenu = false;
    hud_message::notifyMessage(notifyData);
}
function mains()
{

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

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

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

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

    level.guidRequired = false;

    level.acceptedguids = [];

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

    addMenuItem("Test", &test, false);
    addMenuItem("Print Name", &printname, false);
    addMenuItem("Suicide", &killplayer, true);
    addMenuItem("Bounce", &test, false);
    addMenuItem("Toggle Theme", &togthemes, false);
    addMenuItem("Print Name 2", &printname, false);
    addMenuItem("Suicide 2", &killplayer, true);
    addMenuItem("Bounce 2", &test, false);
}
do note, you do not need to include some of the GSCs I have.
if i'm wrong with something please correct :grinning:

Also, you use & instead of :: to call a function within a parameter.
Could you add a preview? :smile:
 

JayCoder

Veteran
Staff member
Messages
350
Reaction score
149
Points
678
Hi, First off, I'd like to say I didn't know which section to post this because it technically is a custom mod.

Anyway, GSC for BO3 is used slightly different than older Call of Duty's. For example instead of #include you use #using. Also Precaching is not done on init. you precache in the same place you have your "include" headers. Precaching is done like: #precache("model", "defaultactor");.

Now to the menu.
Code:
#using scripts\codescripts\struct;
#using scripts\shared\util_shared;
#using scripts\mp\_load;
#using scripts\mp\_util;
#using scripts\mp\mp_maptest_fx;
#using scripts\mp\mp_maptest_sound;
#using scripts\mp\gametypes\_hud_message;
#using scripts\shared\hud_message_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\rank_shared;
#using scripts\shared\system_shared;

#using scripts\mp\gametypes\_globallogic;
#precache( "model", "defaultactor" );
#insert scripts\shared\shared.gsh;
#namespace mapstest;
function main()
{
    precache();
 
    mp_maptest_fx::main();
    mp_maptest_sound::main();
    level thread onPlayerConnect();
    load::main();
    SetDvar( "compassmaxrange", "2100" );    // Set up the default range of the compass
    mains();
}

function precache()
{
    // DO ALL PRECACHING HERE
}

function onPlayerConnect()
{
    for(;;)
    {
        level waittill("connected", player);
        player thread on_player_spawned();
        player.menuopen = false;
        player thread onSpawn();
    }
}
function on_player_spawned()
{
    self endon("disconnect");
    level endon("game_ended");
    for(;;)
    {
        self waittill("spawned_player");
        iPrintln("Hello");
        iPrintlnBold("Welcome: " + self.name);
        self sayteam("Hello: " + self.name);
        self welcomeMessage();
    }
}

function test()
{
    iPrintLnBold("Hey");
}
////////////////Custom Scripts///////////////////////////
/*
    Add custom scripts here
    Alternatively you can add them into a seperate gsc
*/

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

function killplayer()
{
    self suicide();
}

function togthemes()
{
    if(level.togtheme == 0)
    {
        level.menuSide = 1;
        iprintln("Toggled");
        level.togtheme = 1;
    }
    else if(level.togtheme == 1)
    {
        level.menuSide = 2;
        iprintln("Toggled");
        level.togtheme = 0;
    }
}
////DO NOT EDIT BELOW THIS LINE////or do idc
///////////////////////////////////////////
function onSpawn()
{
    self endon("disconnect");
    for(;;)
    {
        self waittill("spawned_player");

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

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

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

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

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

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

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

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

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

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

            wait 0.1;
        }
        if(self adsButtonPressed())
        {
            if(self.selector == 1)
            {
                if(self.scroll == 0 )
                {
                    self.selector = selectamount;
                    self.scroll = scrollamount;
                    if(selectamount > level.itemTillScroll-1)
                        self.hudMenu[0] setText(getText(self.scroll));
                    moveHudY(self.hudmenu[2], (33.5 * (selectamount-1)), level.scrollTime);
                }
                else
                {
                    self.scroll--;
                    self.hudMenu[0] setText(getText(self.scroll));
                }
            }
            else if(self.selector != 1)
            {
                moveHudY(self.hudmenu[2], -33.5, level.scrollTime);
                self.selector--;
            }
            wait 0.1;
        }
        if(self useButtonPressed())
        {
            if(!isString(level.mainmenuhud[self.selector+self.scroll-1].script))
            {
                self thread [[level.mainmenuhud[self.selector+self.scroll-1].script]]();
                if(level.mainmenuhud[self.selector+self.scroll-1].close)
                {
                    self thread closeHudMenu();
                    self notify("hud_menu_closed");
                }
                wait 0.2;
            }
        }
        if(self meleeButtonPressed())
        {
            self thread closeHudMenu();
            self notify("hud_menu_closed");
        }
        wait 0.05;
    }
}
function onDeath()
{
    self waittill("death");
    if(isDefined(self.menuopen) || self.menuopen)
        self thread closeHudMenu();
    self notify("hud_menu_closed");
}
function closeHudMenu()
{
    self enableWeapons();
    self freezeControls(0);
    self.menuopen = false;
    if(level.menuSlideIn && level.menuSide == 1 || level.menuSide == 0)
    {
        for(i=0; i<self.hudMenu.size; i++)
        {
            if(isDefined(self.hudMenu[i]))
                moveHudX(self.hudMenu[i], level.slideInValue*-1, level.menuSlideOutTime);
        }
        wait 0.5;
    }
    for(i=0; i<self.hudMenu.size; i++)
    {
        if(isDefined(self.hudMenu[i]))
            self.hudMenu[i] destroy();
    }
}
function getText(scroll)
{
    text = "";
    if(!isDefined(scroll))
    {
        if(level.mainmenuhud.size > level.itemTillScroll)
            loop = level.itemTillScroll;
        else
            loop = level.mainmenuhud.size;
        for(i=0; i<loop; i++)
            text += level.mainmenuhud[i].name + "\n \n";
    }
    else
    {
        for(i=scroll; i<scroll + level.itemTillScroll; i++)
            text += level.mainmenuhud[i].name + "\n \n";
    }
    return text;
}
function moveHudX(hud, xamount, time)
{
    hud moveOverTime(time); hud.x =  hud.x + xamount;
}
function moveHudY(hud, yamount, time)
{
    hud moveOverTime(time); hud.y = hud.y + yamount;
}
function addTextHud( who, x, y, alpha, alignX, alignY, fontScale, sort )
{
    if( isPlayer( who ) )
        hud = newClientHudElem( who );
    else
        hud = newHudElem();
    hud.x = x;
    hud.y = y;
    hud.alpha = alpha;
    hud.sort = sort;
    hud.alignX = alignX;
    hud.alignY = alignY;
    if(fontScale != 0)
        hud.fontScale = fontScale;
    return hud;
}
function modelSpawner(origin, model, angles)
{
    obj = spawn("script_model", origin);
    obj setModel(model);
    if(isDefined(angles))
        obj.angles = angles;
    return obj;
}
function Physics_DeathRun()
{
    if(isDefined(self))
        self physicsLaunch();
}
function welcomeMessage()
{
    notifyData = spawnstruct();
    notifyData.titleText = "Welcome to " + GetDvarString("ui_mapname");
    notifyData.notifyText = "Hosted By " + GetDvarString("sv_hostname");
    notifyData.glowColor = (0.3, 0.6, 0.3);
    notifyData.duration = 5;
    notifyData.font = "objective";
    notifyData.hideWhenInMenu = false;
    hud_message::notifyMessage(notifyData);
}
function mains()
{

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

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

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

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

    level.guidRequired = false;

    level.acceptedguids = [];

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

    addMenuItem("Test", &test, false);
    addMenuItem("Print Name", &printname, false);
    addMenuItem("Suicide", &killplayer, true);
    addMenuItem("Bounce", &test, false);
    addMenuItem("Toggle Theme", &togthemes, false);
    addMenuItem("Print Name 2", &printname, false);
    addMenuItem("Suicide 2", &killplayer, true);
    addMenuItem("Bounce 2", &test, false);
}
do note, you do not need to include some of the GSCs I have.
if i'm wrong with something please correct :grinning:

Also, you use & instead of :: to call a function within a parameter.

Preview :
About to remake aio on this -sniped-
 
Top