AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   I tried to do stock for the menu that getting online player but i got bug in rehlds (https://forums.alliedmods.net/showthread.php?t=333612)

Supremache 07-25-2021 03:15

I tried to do stock for the menu that getting online player but i got bug in rehlds
 
I tried to optimize the code by doing stock for the menu that getting the online players but i got bug in rehlds server, when i choose one of players it choice other one!!.

This is the code:
Code:

public DonateMenu(id)
{       
        PlayerMenu(id, DONATE_ACCESS, "\yChoose a player: \r[Donate]", "Donate_Handler", "ch")
}

public Donate_Handler(id, iMenu, iItem)
{
        if(iItem != MENU_EXIT)
        {
                new iAccess, iCallback, iData[6], szName[MAX_PLAYERS * 2];
                menu_item_getinfo(iMenu, iItem, iAccess, iData, charsmax(iData), szName, charsmax(szName), iCallback);
               
                g_iPlayerData[ id ][ Donate ] = str_to_num(iData);
               
                if (!g_iPlayerData[ id ][ Donate ])
                {
                        CC_SendMessage(id,"This player does not exist.");
                        menu_display(id, iMenu)
                        return PLUGIN_HANDLED;
                }
               
                client_cmd(id, "messagemode EnterAmount");
               
                set_hudmessage(255, 255, 85, 0.01, 0.18, 2, 0.5, 6.0, 0.05, 0.05, -1);
                show_hudmessage(id, "Type how much you want to give.");
        }
        menu_destroy(iMenu);
        return PLUGIN_HANDLED
}

public ResetMenu(id)
{       
        PlayerMenu(id, RESET_ACCESS, "\yChoose a player: \r[Reset Bank]", "Reset_Handler", "ch")
}

public Reset_Handler(id, iMenu, iItem)
{
        if(iItem != MENU_EXIT)
        {
                new iAccess, iCallback, iData[6];
                menu_item_getinfo(iMenu, iItem, iAccess, iData, charsmax(iData), _, _, iCallback);
               
                new iPlayer = str_to_num(iData);
               
                ResetBank(id, iPlayer)
        }
        menu_destroy(iMenu);
        return PLUGIN_HANDLED
}

public OnDonate(id)
{
        static szValue[32], iValue, iPlayer, iCash
        iPlayer = get_user_userid( g_iPlayerData[ id ][ Donate ] );
        read_argv(1, szValue, charsmax(szValue));
        iValue = str_to_num(szValue)
        iCash = get_user_cash(id)

        if( iCash < iValue || iValue <= 0)
        {
                CC_SendMessage(id,"You do not have enough money or invalid value.");
                return PLUGIN_CONTINUE
        }
       
        set_user_cash( iPlayer, get_user_cash(iPlayer) + iValue)
        set_user_cash( id, iCash - iValue)
       
        CC_SendMessage(0,"Player^4 %s^1 donated^4 $%i^1 for^4 %s.", g_iPlayerData[ id ][ Name ], iValue, g_iPlayerData[ iPlayer ][ Name ]);
       
        client_cmd(iPlayer, "spk ^"items/9mmclip1.wav^"")
   
        return PLUGIN_HANDLED;
}

public ResetBank(id, iPlayer)
{
        if (!iPlayer)
        {
                CC_SendMessage(id,"This player does not exist.");
                return PLUGIN_HANDLED;
        }
       
        g_iPlayerData[ iPlayer ][ Cash ] = 0
       
        CC_SendMessage(id,"^1[ADMIN]^4 %s:^1 reset bank of^4 %s.", g_iPlayerData[ id ][ Name ], g_iPlayerData[ iPlayer ][ Name ]);
                               
        SaveData(iPlayer);
        return PLUGIN_HANDLED;
}

PlayerMenu(id, iAccess, const szTitle[ ], const szHandler[ ], const szGetPlayersFlag[ ])
{               
        static iPlayers[MAX_PLAYERS], iNum, szUserID[32], szData[MAX_MENU_LENGTH], iMenu
       
        if(!access(id, iAccess))
        {
                CC_SendMessage(id, "You don't have access to this command.");
                return PLUGIN_HANDLED
        }
                               
        formatex(szData, charsmax(szData), szTitle)
       
        iMenu = menu_create(szData, szHandler); get_players(iPlayers, iNum, szGetPlayersFlag);
       
        for(new iPlayer, i; i < iNum; i++)
        {
                iPlayer = iPlayers[i]
               
                formatex(szData, charsmax(szData), "%s", g_iPlayerData[ iPlayer ][ Name ]);
                num_to_str(get_user_userid(iPlayer), szUserID, charsmax(szUserID));
                menu_additem(iMenu, szData, szUserID)
        }
       
        menu_setprop(iMenu, MPROP_BACKNAME, "Previous page")
        menu_setprop(iMenu, MPROP_NEXTNAME, "Next page")
        menu_setprop(iMenu, MPROP_EXITNAME, "\rClose")

        menu_display(id, iMenu)
        return PLUGIN_HANDLED
}


Natsheh 07-25-2021 06:38

Re: I tried to do stock for the menu that getting online player but i got bug in rehl
 
PHP Code:

g_iPlayerDataid ][ Donate ] = find_player("k"str_to_num(iData)) 

PHP Code:

iPlayer g_iPlayerDataid ][ Donate ]; 

PHP Code:

new iPlayer find_player("k"str_to_num(iData)); 


Supremache 07-25-2021 16:15

Re: I tried to do stock for the menu that getting online player but i got bug in rehl
 
Quote:

Originally Posted by Natsheh (Post 2753627)
PHP Code:

g_iPlayerDataid ][ Donate ] = find_player("k"str_to_num(iData)) 

PHP Code:

iPlayer g_iPlayerDataid ][ Donate ]; 

PHP Code:

new iPlayer find_player("k"str_to_num(iData)); 


Thanks, but the issue isn't thier i tested my code on hlds server and it worked, but when i tested it on rehlds i found this bug! and also i found the same issue in reset menu so i think the issue from the stock of the menu !

Natsheh 07-25-2021 18:18

Re: I tried to do stock for the menu that getting online player but i got bug in rehl
 
Quote:

Originally Posted by Supremache (Post 2753664)
Thanks, but the issue isn't thier i tested my code on hlds server and it worked, but when i tested it on rehlds i found this bug! and also i found the same issue in reset menu so i think the issue from the stock of the menu !

Have you even understood what i just posted ?

Its not a bug its mis-understanding what is the userid is...

Supremache 07-25-2021 18:46

Re: I tried to do stock for the menu that getting online player but i got bug in rehl
 
Quote:

Originally Posted by Natsheh (Post 2753671)
Have you even understood what i just posted ?

Its not a bug its mis-understanding what is the userid is...

Well, I will test it.
Thanks :)


All times are GMT -4. The time now is 02:37.

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