AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Does not randomly display all g_szGame (https://forums.alliedmods.net/showthread.php?t=327593)

Fuck For Fun 09-28-2020 17:00

Does not randomly display all g_szGame
 
I have a PLUGIN that has a special Round/Event that works according to rounds, 7 games GAME_MODE
So that comes the special round it shows a menu for everyone who has to choose what they want to run so I have 7 games and it always shows the first 4 I don't know why also I vote something else it picks me the Event of GAME: Weapon

Code:

#define SPECIAL_DAY 6
#define GAME_MODE 7

new const g_szGame[GAME_MODE][] = {
        "NoScope",
        "Fog",
        "knife",
        "p228",
        "weapon",
        "grenade",
        "Invisibility"
};

Code:

public Open_DayModeMenu(id)
{
        if(g_iDayModeVoteTime < 1)
                return PLUGIN_HANDLED;
 
        new szMenu[512], iBitKeys = (1<<9), iLen;
        title_menu(szMenu, iLen, "\d- \wPlease choose your favorite day^n^n\d- Time: %d secs -^n^n", g_iDayModeVoteTime);

        if (!g_bVoteStarted)
        {
                new iRandom, x = 0;
       
                while (x < 4)
                {
                        iRandom = random_num(0, 4);
                        if (IsRandomInArray(g_aChoses, iRandom))
                                continue;

                        ArrayPushCell(g_aChoses, iRandom);
                        x++;
                }

                ArrayPushCell(g_aChoses, x);
        }

        new i;
        for(i = 0; i < 4; i++)
        {
                if(!g_bUserVoted[id])
                {
                        add_item_menu(szMenu, iLen, "\y[%d] \w%s \y(%d Votes)^n", i+1, g_szGame[ArrayGetCell(g_aChoses, i)], g_aDataDayMode[ArrayGetCell(g_aChoses, i)][VOTES_NUM]);
                        iBitKeys |= (1<<i);
                }
                else
                {
                       
                        add_item_menu(szMenu, iLen, "\d[%d] %s \y(%d Votes)^n", i+1, g_szGame[ArrayGetCell(g_aChoses, i)], g_aDataDayMode[ArrayGetCell(g_aChoses, i)][VOTES_NUM]);
                }
        }

        /*if(!g_bUserVoted[id])
        {
                add_item_menu(szMenu, iLen, "^n\y[5] \wRandomize \y(%d Votes)^n", g_aDataDayMode[ArrayGetCell(g_aChoses, i)][VOTES_NUM]);
                iBitKeys |= (1<<i);
        }
        else
        {
               
                add_item_menu(szMenu, iLen, "^n\d[5] Randomize \y(%d Votes)^n", g_aDataDayMode[ArrayGetCell(g_aChoses, i)][VOTES_NUM]);
        }*/

        return menu_show(id, iBitKeys, szMenu, "Open_DayModeMenu");
}

public Close_DayModeMenu(id, iKey)
{
        if(iKey == 9)
                return PLUGIN_HANDLED;

        g_bUserVoted[id] = true;
        new iDay = ArrayGetCell(g_aChoses, iKey);
        g_aDataDayMode[iDay][VOTES_NUM]++;
       
        if (iKey < 4)
                client_print_color(0, print_team_default, "%s ^3%n ^1has voted to ^x04%s^x01.", PREFIX, id, g_szGame[iDay] );
        /*else
                client_print_color(0, print_team_default, "%s ^3%n ^1has randomized^x01.", PREFIX, id );*/
       
        return PLUGIN_HANDLED;
}

stock IsRandomInArray(Array:aRandomArray, iRandom)
{
        for(new i = 0; i < ArraySize(aRandomArray); i++)
        {               
                if (ArrayGetCell(aRandomArray, i) == iRandom)
                {
                        return true;
                }
        }
       
        return false;
}

public vote_day_mode_timer()
{
        if(_get_alive_players() > 1)
        {
                if(--g_iDayModeVoteTime)
                {
                       
                        for(new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++)
                        {
                                if(!is_user_alive(iPlayer))
                                        continue;
                               
                                Open_DayModeMenu(iPlayer);
                               
                                if (!g_bVoteStarted)
                                {
                                        g_bVoteStarted = true;
                                }
                        }
                }
                else
                {                       
                        vote_day_mode_ended();
                }
        }
}

public vote_day_mode_ended()
{
        for(new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++)
        {
                if(!is_user_connected(iPlayer))
                        continue;
               
                show_menu(iPlayer, 0, "^n");
        }

        if (g_aDataDayMode[ArrayGetCell(g_aChoses, ArraySize(g_aChoses) - 1)][VOTES_NUM])
        {
                for (new i = 0; i < g_aDataDayMode[ArrayGetCell(g_aChoses, ArraySize(g_aChoses) - 1)][VOTES_NUM]; i++)
                        g_aDataDayMode[ArrayGetCell(g_aChoses, random(ArraySize(g_aChoses) - 1))][VOTES_NUM]++;
        }

        new iVotesNum = 0;
        for(new iGame = 0; iGame < GAME_MODE; iGame++)
        {
                if (!g_aDataDayMode[iGame][VOTES_NUM])
                        continue;

                if(g_aDataDayMode[iGame][VOTES_NUM] >= iVotesNum)
                {
                        iVotesNum = g_aDataDayMode[iGame][VOTES_NUM];
                        g_iGame = iGame;
                }
        }
        ArrayClear(g_aChoses);

        if (!iVotesNum)
        {
                g_iGame = random_num(0, 4);
                client_print_color(0, print_team_default, "There was no votes. Day^4 %s ^1has been chosen automaically.", PREFIX, g_szGame[g_iGame]);
        }
        else       
                client_print_color(0, print_team_default, "%s Day^4 %s ^1has earned the most votes.", PREFIX, g_szGame[g_iGame]);

        g_iTimeToStart = 15;
        day_mode_start();
}

So how can make it look random all that's on the list and not just the first four?

fysiks 09-28-2020 22:42

Re: Does not randomly display all g_szGame
 
The one thing that I notice is that when you choose the options to put in the menu, you are only choosing from the indices 0 to 4 (which is 5 total options). So, you are getting a random 4 items from a list of 5 without regard for the items that are actually in the list. Here is the change that you should make to address this part:

PHP Code:

iRandom random_num(04); 

:arrow:

PHP Code:

iRandom random(sizeof g_szGame); 

Also, you will need to remove the following because it will cause a potential duplicate ("weapon" in this case) in your menu:

PHP Code:

ArrayPushCell(g_aChosesx); 



P.S. I think you should consider using a translator. It is very hard to understand what you are saying.


All times are GMT -4. The time now is 13:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.