Возможно ли убрать рандом в проигрывании музыки на сервере?

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
30
Реакции
-1
Обратите внимание, если вы хотите заключить сделку с этим пользователем, он заблокирован
Есть исходник плагина проигрывания музыки в конце раунда на сервере
У меня загружено 52 трека, они играют рандомно
Возможно ли сделать чтобы треки игрались по порядку строго с 1 по 52ой? (Треки все пронумерованы и лежат в соответствующей папке в форме - 1.mp3)
23 Июн 2020

Код:
#include <amxmodx>

#include <amxmisc>



#define PLUGIN "End Round Music"

#define VERSION "2.0"

#define AUTHOR "Sho0ter"



#define TRACKSNUM 100



new ALLMusic[TRACKSNUM][128]

new CTMusic[TRACKSNUM][128]

new TMusic[TRACKSNUM][128]



new PlaylistSize

new CTNum

new TNum

new ALLNum

new SayText



new Mode[32]

new Configsdir[64]

new CurrentMap[64]

new File[96]

new Playlist[128]

new Play[128]

new PlayCommand[128]

new CheckFile[128]



new bool:Ermon[33]



new PcvarMode

new PcvarVol

new PcvarRadio

new PcvarDelay



public plugin_init()

{

    register_plugin(PLUGIN, VERSION, AUTHOR)

    register_dictionary("endroundmusic.txt")

    register_event("SendAudio", "t_win", "a", "2&%!MRAD_terwin")

    register_event("SendAudio", "ct_win", "a", "2&%!MRAD_ctwin")

    PcvarMode = register_cvar("erm_mode", "1")

    PcvarVol = register_cvar("erm_autovol", "0.5")

    PcvarRadio = register_cvar("erm_radio", "1")

    PcvarDelay = register_cvar("erm_delay", "20.0")

      register_clcmd("say /ermon", "cmd_ermon", 0, " - turn on end round music")

      register_clcmd("say /ermoff", "cmd_ermoff", 0, " - turn off end round music")

    SayText = get_user_msgid("SayText");

    return PLUGIN_CONTINUE

}



public plugin_precache()

{

    get_configsdir(Configsdir, 63)

    get_mapname(CurrentMap, 63)

    formatex(Playlist, 127, "%s/endroundmusic/%s.ini", Configsdir, CurrentMap)

    new Index = 0

    while(CurrentMap[Index] != '_' && CurrentMap[Index] != '^0')

    {

        Index++

    }

    if(!file_exists(Playlist) && CurrentMap[Index] == '_')

    {

        CurrentMap[Index] = '^0'

        formatex(Playlist, 127, "%s/endroundmusic/%s_.ini", Configsdir, CurrentMap)

    }

    if(!file_exists(Playlist))

    {

        formatex(Playlist, 127, "%s/endroundmusic/default.ini", Configsdir)

    }

    if(!file_exists(Playlist))

    {

        log_amx("Playlist <%s> not found.", Playlist)

        set_fail_state("Playlist not found")

        return PLUGIN_CONTINUE

    }

    PlaylistSize = file_size(Playlist, 1)

    for(new i = 0; i <= PlaylistSize; i++)

    {

        new Buffer[128], len, Result

        Result = read_file(Playlist, i, Buffer, sizeof(Buffer)-1, len)

        if(!Result)

        {

            continue

        }

        parse(Buffer, File, 95, Mode, 31)

        if(File[0] == ';' || File[0] == '/' || File[0] == ' ' || equal(File, ""))

        {

            continue

        }

        formatex(CheckFile, 127, "sound/%s", File)

        if(!file_exists(CheckFile))

        {

            log_amx("File not found <%s>", CheckFile)

            continue

        }

        if(equal(Mode, "CT"))

        {

            formatex(CTMusic[CTNum], 127, "%s", File)

            CTNum++

            precache_sound(File)

        }

        else if(equal(Mode, "TER"))

        {

            formatex(TMusic[TNum], 127, "%s", File)

            TNum++

            precache_sound(File)

        }

        else if(equal(Mode, "ALL"))

        {

            formatex(ALLMusic[ALLNum], 127, "%s", File)

            ALLNum++

            precache_sound(File)

        }

    }

    if(CTNum == 0 && TNum == 0 && ALLNum == 0)

    {

        log_amx("Not found tracks in playlist.")

        set_fail_state("Playlist empty")

        return PLUGIN_CONTINUE

    }

    log_amx("Loaded tracks: CT <%d> TER <%d> ALL <%d>", CTNum, TNum, ALLNum)

    return PLUGIN_CONTINUE

}



public client_disconnect(id)

{

    remove_task(id)

    return PLUGIN_CONTINUE

}



public client_putinserver(id)

{

    set_task(get_pcvar_float(PcvarDelay), "showerminfo", id)

    return PLUGIN_HANDLED

}



public t_win()

{

    if(!get_pcvar_num(PcvarMode))

    {

        return PLUGIN_HANDLED

    }

    if((!CTNum || !TNum) && ALLNum && get_pcvar_num(PcvarMode) != 2)

    {

        set_pcvar_num(PcvarMode, 2)

    }

    switch(get_pcvar_num(PcvarMode))

    {

        case 1:

        {

            formatex(Play, 127, "%s", TMusic[random_num(0, TNum-1)])

        }

        case 2:

        {

            formatex(Play, 127, "%s", ALLMusic[random_num(0, ALLNum-1)])

        }

        case 3:

        {

            new Randomizer = random_num(1, 2)

            switch(Randomizer)

            {

                case 1:

                {

                    formatex(Play, 127, "%s", TMusic[random_num(0, TNum-1)])

                }

                case 2:

                {

                    formatex(Play, 127, "%s", ALLMusic[random_num(0, ALLNum-1)])

                }

            }

        }

        case 4:

        {

            new Randomizer = random_num(1, 3)

            switch(Randomizer)

            {

                case 1:

                {

                    formatex(Play, 127, "%s", CTMusic[random_num(0, CTNum-1)])

                }

                case 2:

                {

                    formatex(Play, 127, "%s", TMusic[random_num(0, TNum-1)])

                }

                case 3:

                {

                    formatex(Play, 127, "%s", ALLMusic[random_num(0, ALLNum-1)])

                }

            }

        }

    }

    if(containi(Play, ".wav") != -1)

    {

        formatex(PlayCommand, 127, "spk %s", Play)

    }

    else if(containi(Play, ".mp3") != -1)

    {

        formatex(PlayCommand, 127, "mp3 play sound/%s", Play)

    }

    else

    {

        log_amx("Unsupported file type <%s>", Play)

        return PLUGIN_HANDLED

    }

    for(new id = 0; id <= get_maxplayers(); id++)

    {

        if(!is_user_connected(id) || !Ermon[id])

        {

            continue

        }

        client_cmd(id, "stopsound")

        client_cmd(id, "%s", PlayCommand)

        if(get_pcvar_num(PcvarRadio))

        {

            client_cmd(id, "spk radio/terwin")

        }

    }

    return PLUGIN_HANDLED

}



public ct_win()

{

    if(!get_pcvar_num(PcvarMode))

    {

        return PLUGIN_HANDLED

    }

    if((!CTNum || !TNum) && ALLNum && get_pcvar_num(PcvarMode) != 2)

    {

        set_pcvar_num(PcvarMode, 2)

    }

    switch(get_pcvar_num(PcvarMode))

    {

        case 1:

        {

            formatex(Play, 127, "%s", CTMusic[random_num(0, CTNum-1)])

        }

        case 2:

        {

            formatex(Play, 127, "%s", ALLMusic[random_num(0, ALLNum-1)])

        }

        case 3:

        {

            new Randomizer = random_num(1, 2)

            switch(Randomizer)

            {

                case 1:

                {

                    formatex(Play, 127, "%s", CTMusic[random_num(0, CTNum-1)])

                }

                case 2:

                {

                    formatex(Play, 127, "%s", ALLMusic[random_num(0, ALLNum-1)])

                }

            }

        }

        case 4:

        {

            new Randomizer = random_num(1, 3)

            switch(Randomizer)

            {

                case 1:

                {

                    formatex(Play, 127, "%s", CTMusic[random_num(0, CTNum-1)])

                }

                case 2:

                {

                    formatex(Play, 127, "%s", TMusic[random_num(0, TNum-1)])

                }

                case 3:

                {

                    formatex(Play, 127, "%s", ALLMusic[random_num(0, ALLNum-1)])

                }

            }

        }

    }

    if(containi(Play, ".wav") != -1)

    {

        formatex(PlayCommand, 127, "spk %s", Play)

    }

    else if(containi(Play, ".mp3") != -1)

    {

        formatex(PlayCommand, 127, "mp3 play sound/%s", Play)

    }

    else

    {

        log_amx("Unsupported file type <%s>", PLUGIN, Play)

        return PLUGIN_HANDLED

    }

    for(new id = 0; id <= get_maxplayers(); id++)

    {

        if(!is_user_connected(id) || !Ermon[id])

        {

            continue

        }

        client_cmd(id, "stopsound")

        client_cmd(id, "%s", PlayCommand)

        if(get_pcvar_num(PcvarRadio))

        {

            client_cmd(id, "spk radio/ctwin")

        }

    }

    return PLUGIN_HANDLED

}



public cmd_ermon(id)

{

    Ermon[id] = true

    client_cmd(id, "mp3volume %f", get_pcvar_float(PcvarVol))

    client_cmd(id, "spk vox/activated")

    green_print(id, "ERMON_MSG")

    return PLUGIN_CONTINUE

}





public cmd_ermoff(id)

{

    Ermon[id] = false

    client_cmd(id, "mp3 stop")

    client_cmd(id, "spk vox/deactivated")

    green_print(id, "ERMOFF_MSG")

    return PLUGIN_CONTINUE

}



public showerminfo(id)

{

    Ermon[id] = true

    client_cmd(id, "mp3volume %f", get_pcvar_float(PcvarVol))

    green_print(id, "ERMINFO_MSG")

}



stock green_print(index, const message[])

{

    new finalmsg[192];

    formatex(finalmsg, 191, "^x04[ERM] ^x01%L", index, message);

    message_begin(MSG_ONE, SayText, _, index);

    write_byte(index);

    write_string(finalmsg);

    message_end();

}
 
Последнее редактирование модератором:
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу