Modme Forums
Menu:

Jukebox

Game Modding | Call of Duty: Black Ops 3 | Scripting


Spiki:

Jukebox V2

I present to you a clickable jukebox that plays 2d songs (for all players in the map).
I was going to make it so that you can choose if you want to hear it but then I remembered that I don't like streamers cuz many of them don't even mention your name or the map name.
Imma level with you. I'm not good in lua so if you don't like the design you can go suck a lemon.
I pulled parts of the lua code from previous projects, idk who the original scripter was. Prob quentin



Instructions:

1: You need to have lua in your map. If you don't know what that is, this tutorial will be hell for you.
2: Download the GSC from the attachment (change txt to gsc) and drop it in mapname/scripts/zm (or where ever you want i don't care :p).
3: Add the jukebox gsc to your main gsc with a #using and add it to your zone file
4: Copy the following lua code to the bottom your main lua file (not bottom of function):

function LUI.createMenu.JukeboxMenu(InstanceRef)
    --CoD.Menu.CommonHudRequire()
    local HudRef = CoD.Menu.NewForUIEditor("JukeboxMenu")



    local AliasTable = {"mus_roundstart1_intro", "mus_roundstart2_intro", "mus_roundstart3_intro"}
    local TitlesTable = {"Girls girls girls", "Straight outta compton", "Send nudes"}


    local max_vert = 9


    HudRef:setUseStencil(false) --maybe true?
    HudRef.id = "JukeboxMenu"
    HudRef.soundSet = "default"
    HudRef:setLeftRight(true, true, 0.0, 0.0)
    HudRef:setTopBottom(true, true, 0.0, 0.0)
    HudRef:playSound("menu_open", InstanceRef)
    HudRef.buttonModel = Engine.CreateModel(Engine.GetModelForController(Instance), "JukeboxMenu.buttonPrompts")





    HudRef.JukeboxTitle = LUI.UIText.new()
    HudRef.JukeboxTitle:setLeftRight(false, false, -150, 150)
    HudRef.JukeboxTitle:setTopBottom(true, false, 20, 50)
    HudRef.JukeboxTitle:setText("Jukebox")
    HudRef:addElement(HudRef.JukeboxTitle)


    local function MakeButton( HudRef, InstanceRef, DisplayText, x, y, str_to_gsc, index )

        if str_to_gsc == nil then
            str_to_gsc = "X"
        end

        if index == nil then
            index = 0
        end
   

        local offx = 250
        local offy = 30

        if DisplayText == "X" then
            offx = 50
            offy = 50
        end



        local Text = LUI.UIText.new(Hud, Instance)
        local Button = LUI.UIButton.new(HudRef, InstanceRef)

        Text:setText(DisplayText)

        Text:setTopBottom(true, false, y, y+offy)
        Text:setLeftRight(true, false, x, x+offx)

        Button:setTopBottom(true, false, y, y+offy)
        Button:setLeftRight(true, false, x, x+offx)


        if index > max_vert then
            Text:setLeftRight(false, true, -x-offx, -x)
            Button:setLeftRight(false, true, -x-offx, -x)
        end

        HudRef:addElement(Text)
        HudRef:addElement(Button)



        local function OnButtonMouseDown(Sender, EventArgs)
            Text:setText("Mouse Down")
            Engine.SendMenuResponse(HudRef, HudRef.menuName, tostring(str_to_gsc) )
            Engine.SendMenuResponse(HudRef, HudRef.menuName, tostring(str_to_gsc) )
            Engine.SendMenuResponse(HudRef, HudRef.menuName, tostring(str_to_gsc) )
            HudRef:close()
        end

       local function SetMouseButton(arg0, arg1)
            arg0.m_button = arg1
        end

        Button:setHandleMouse(true)
        Button:registerEventHandler("button_action", OnButtonMouseDown)
        Button.setButton = SetMouseButton

    end


    if #AliasTable == #TitlesTable then
        MakeButton( HudRef, InstanceRef, "X", 0, 0, "X" )
    else
        MakeButton( HudRef, InstanceRef, "Mismatch", 0, 0, "Error" )
    end

    MakeButton( HudRef, InstanceRef, "Stop Music", 0, 70, "Stop" )

    for i=1, #AliasTable do
        if i > max_vert then
            MakeButton( HudRef, InstanceRef, tostring(TitlesTable[i]), 300, (100+(50*(i-max_vert))), AliasTable[i], i)
        else
            MakeButton( HudRef, InstanceRef, tostring(TitlesTable[i]), 300, (100+(50*i)), AliasTable[i])
        end
    end





    local function HudCloseCallback(MainHUD)
        Engine.GetModel(Engine.GetModelForController(Instance), "JukeboxMenu.buttonPrompts")
        Engine.UnsubscribeAndFreeModel()
    end

    LUI.OverrideFunction_CallOriginalSecond(HudRef, "close", HudCloseCallback)


    return HudRef
end



4: Make some aliases
Example:
mus_slender_page_collected,,streamed,mus\zm\zod\meatball_round\meatball_round_end_mas_edited.wav,,,UIN_MOD,,,,,BUS_MUSIC,,,,,,100,100,,,,,,,,2,oldest,,,1,1,,,,,,2d,,,NONLOOPING,,,,,,,,,,,,,,,,,,,,,,,,,,,yes,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

5: Add aliases to the lua file.
In the top of my code you'll see AliasTable and TitlesTable

AliasTable contains aliases
TitlesTable contains the names displayed on screen
The aliases and titles must be in the same order otherwise wrong sounds will play
If ingame it says "Mismatch" in the top left, there aren't the same amount of aliases as titles

You can change the amount of entries per column by changing max_vert from 9 to whatever (check pic above)

ATTENTION: This is a mouse only menu. Controllers are useless here.

Changelog:
2020 04 20 - Release


ModmeBot:

Reply By: Lapin123
How to add new sounds? Can you help me to add sound
Do you have a tutorial for this ?


ModmeBot:

Reply By: mathfag

Lapin123
How to add new sounds? Can you help me to add sound Do you have a tutorial for this ?

this is a tutorial. to change sounds just change the alias in the array


ModmeBot:

Reply By: tygo246
Script and sounds are working however the text is not showing up when you are next to the trigger


ModmeBot:

Reply By: mathfag

tygo246
Script and sounds are working however the text is not showing up when you are next to the trigger

fixed


ModmeBot:

Reply By: tygo246
Thanks it's working fine now


ModmeBot:

Reply By: Artleck
I'm trying to use this myself. But it isn't working at all, Not even running the script. I have no clue what is happening. But i did make sure that the Trigger multiple has targetname - trig_jukebox and that the code is in MAP_NAME.GSC. Any ideas why this is happening?


ModmeBot:

Reply By: modric
Did you thread it properly


ModmeBot:

Reply By: Artleck

modric
Did you thread it properly

Yea that was my issue, Thank you!


ModmeBot:

Reply By: Lokii
Hey math, just one quick issue, i don't know if i could take this any further in discord but basically, whenever someone walks upto the jukebox and doesn't activate it, the jukebox enable message stays on the screen indefinitely, i have added everything, i even tried to add my own little destroy HUD command, but alas, that didn't work.


ChiefMustardo:

Hi there, I am currently receiving and unexpected token error and I have had a look through the line specified but I can't identify where the typo is. Anybody got any solutions or ran into this problem before?

The Error

UNRECOVERABLE ERROR:


^1SCRIPT ERROR: No generated data for 'scripts/zm/zm_actual.gsc'


ERR(0) scripts/zm/zm_actual.gsc (340,44) in "song_switch()" : syntax error, unexpected TOKEN_EQUALS :     for( i=0;i<level.juke_songs.size;i++) {=

Linker will now terminate.

********************************************************************************

==================================================

Linker summary:

There were no errors or warnings.

==================================================

^1    for( i=0;i<level.juke_songs.size;i++) {=

^1-------------------------------------------^

^1ERR(0) scripts/zm/zm_actual.gsc (340,44) in "song_switch()" : syntax error, unexpected TOKEN_EQUALS :     for( i=0;i<level.juke_songs.size;i++) {=

The Function
function song_switch()
{
    //IPrintLnBold("song change start");
    for( i=0;i<level.juke_songs.size;i++) {="" wait(0.05);="" iprintlnbold(level.juke_songs[i]);="" player="GetPlayers();" player="ArrayGetClosest(self.origin,player,100);" level.juke="i;" player="" iprintlnbold(level.juke_songs[level.juke]);="" thread="" setgunhint(level.juke_songs[level.juke],="" self);="" wait(1);="" wait(0.1);="" self="" stopsound(level.juke_songs[i-1]);="" iprintlnbold(i);="" if(i="">=level.juke_songs.size-1);
        i=-1;
       
        level waittill("song_change");
        //wait(0.1);
        continue;
        }
}


ChiefMustardo:

I've gotten numerous errors from the script now even after fixing the one above so I assume it just fails to work as of 16/10/19


Haxxatoic:

I've gotten numerous errors from the script now even after fixing the one above so I assume it just fails to work as of 16/10/19

I had to parse out a lot of odd characters out of the song_switch function but this is what I ended up with.
function song_switch()
{
    //IPrintLnBold("song change start");

    for( i=0;i<level.juke_songs.size;i++)
        {
        wait(0.05);
        //iprintlnbold(level.juke_songs[i]); <Removed the name being printed twice>
        player=GetPlayers();
        player=ArrayGetClosest(self.origin,player,100);
        level.juke=i;
        player= iprintlnbold(level.juke_songs[level.juke]);
        thread setgunhint(level.juke_songs[level.juke], self);
        wait(1);
        wait(0.1);
        self stopsound(level.juke_songs[i-1]);
        //iprintlnbold(i); <Removed the number of the song being printed in game>
        if(i>=level.juke_songs.size-1)
        {
            i=-1;
        }
        level waittill("song_change");
        //wait(0.1);
        continue;
        }
}
The jukebox worked fine for me once I added my linked song aliases to the juke_songs array. Hopefully this helps you.


ChiefMustardo:

Ah ok. I will give it another shot and see. Thanks!


Spiki:

Updated to lua
https://forum.modme.co/threads/jukebox.1136/


ChiefMustardo:

Ayyy, you gem!