AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Players List Menu (https://forums.alliedmods.net/showthread.php?t=339154)

alasfourom 08-19-2022 19:41

Players List Menu
 
Hello Everyone,

I have started scripting and reading about scripts almost 3 months ago, I have read from here on how to create menu Here.

I got the basics a little bit.

I wanted to create a simple survivors bot list > for l4d2, but not necessary since the concept is the same. I read few scripts but they are either old or too complicated for me with more than 800 lines on simple function.

I made this one, which display the bots, but I cant target each of their names, I tried to select for example "Nick", but it showed me I selected the wrong bot. In fact, it only shows me the first survivor bot. I would really appreciate some helps here, thanks

PHP Code:

public void OnPluginStart()
{
    
RegConsoleCmd("sm_bot"Command_ShowBotsMenu"Show Bots Menu.");
}

public 
Action Command_ShowBotsMenu(int clientint args)
{
    
PrintToChat(client"Menu Opened");
    
Create_SurvivorsBotListMenu(client);
    return 
Plugin_Handled;
}

void Create_SurvivorsBotListMenu(int client)
{
    
Menu menu = new Menu(BotsListMENU_ACTIONS_ALL);
    
menu.SetTitle("Select A Bot:");
    
    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i) || !IsFakeClient(i) || !IsPlayerAlive(i) || GetClientTeam(i) != 2)
            continue;
        
        
char sID[32];
        
char sName[64];
        
        
GetClientName(isNamesizeof(sName));
        
Format(sIDsizeof(sID), "%N"i);
        
        
menu.AddItem(sIDsName);
    }
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int BotsList(Menu menuMenuAction actionint param1int param2)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[64];
            
menu.GetItem(param2sInfosizeof(sInfo));
            
            for (
int i 1<= MaxClientsi++)
            {
                if (!
IsClientInGame(i) || !IsFakeClient(i) || !IsPlayerAlive(i) || GetClientTeam(i) != && (StringToInt(sInfo) != i))
                    continue;
                    
                
PrintToChatAll("%N has selected %N."param1i);
                return;
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }



alasfourom 08-19-2022 20:02

Re: [Issue] Players List Menu
 
Quote:

for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || !IsFakeClient(i) || !IsPlayerAlive(i) || GetClientTeam(i) != 2 && (StringToInt(sInfo) != i))
continue;

PrintToChatAll("%N has selected %N.", param1, i);
return;
}
I'm sure this is the main issue, I dont know how to target the exact bot selected, which seems like I'm targeting all the bots instead of only the selected one.

Bacardi 08-19-2022 22:04

Re: [Issue] Players List Menu
 
https://wiki.alliedmods.net/Format_C...mat_Specifiers

You add player name, two times. %N
Try %i

*edit
If you want make it more correctly, you should use player UserId. With this you can try search client index, is player still in game.
But try client index first.

Code:

    for (int i = 1; i <= MaxClients; i++)
    {
        if (!IsClientInGame(i) || !IsFakeClient(i) || !IsPlayerAlive(i) || GetClientTeam(i) != 2)
            continue;
       
        char sID[32];
        char sName[64];
       
        GetClientName(i, sName, sizeof(sName));
        Format(sID, sizeof(sID), "%N", i);
       
        menu.AddItem(sID, sName);
    }
    menu.Display(client, MENU_TIME_FOREVER);


alasfourom 08-20-2022 02:07

Re: [Issue] Players List Menu
 
Thank You Bacardi,

I was finally able to detect them with their "GetClientOfUserId",

Thanks a lot :up:

Grey83 08-20-2022 04:02

Re: Players List Menu
 
PHP Code:

public void OnPluginStart()
{
    
RegConsoleCmd("sm_bot"Cmd_ShowBotsMenu"Show Bots Menu.");
}

public 
Action Cmd_ShowBotsMenu(int clientint args)
{
    if(!
client || !IsClientInGame(client))
        return 
Plugin_Handled;

    
PrintToChat(client"Menu Opened");
    
Menu menu = new Menu(BotsList);
    
menu.SetTitle("Select A Bot:");

    
char uid[8], sName[MAX_NAME_LENGTH];
    for(
int i 1<= MaxClientsi++)
        if(
IsClientInGame(i) && IsFakeClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2)
        {
            
GetClientName(isNamesizeof(sName));
            
FormatEx(uidsizeof(uid), "%i"GetClientUserId(i));
            
menu.AddItem(uidsName);
        }

    if(!
menu.ItemCountmenu.AddItem("""Bots not found"ITEMDRAW_DISABLED);
    
menu.Display(clientMENU_TIME_FOREVER);

    return 
Plugin_Handled;
}

public 
int BotsList(Menu menuMenuAction actionint clientint param)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[8];
            
menu.GetItem(paramsInfosizeof(sInfo));
            
int target StringToInt(sInfo);
            if(
target && (target GetClientUserId(target)))
                
PrintToChatAll("%N has selected %N."clienttarget);
            else 
Cmd_ShowBotsMenu(client0);
        }
        case 
MenuAction_Enddelete menu;
    }

    return 
0;



alasfourom 08-20-2022 04:27

Re: Players List Menu
 
Quote:

Originally Posted by Grey83 (Post 2786950)
PHP Code:

public void OnPluginStart()
{
    
RegConsoleCmd("sm_bot"Cmd_ShowBotsMenu"Show Bots Menu.");
}

public 
Action Cmd_ShowBotsMenu(int clientint args)
{
    if(!
client || !IsClientInGame(client))
        return 
Plugin_Handled;

    
PrintToChat(client"Menu Opened");
    
Menu menu = new Menu(BotsList);
    
menu.SetTitle("Select A Bot:");

    
char uid[8], sName[MAX_NAME_LENGTH];
    for(
int i 1<= MaxClientsi++)
        if(
IsClientInGame(i) && IsFakeClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2)
        {
            
GetClientName(isNamesizeof(sName));
            
FormatEx(uidsizeof(uid), "%i"GetClientUserId(i));
            
menu.AddItem(uidsName);
        }

    if(!
menu.ItemCountmenu.AddItem("""Bots not found"ITEMDRAW_DISABLED);
    
menu.Display(clientMENU_TIME_FOREVER);

    return 
Plugin_Handled;
}

public 
int BotsList(Menu menuMenuAction actionint clientint param)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[8];
            
menu.GetItem(paramsInfosizeof(sInfo));
            
int target StringToInt(sInfo);
            if(
target && (target GetClientUserId(target)))
                
PrintToChatAll("%N has selected %N."clienttarget);
            else 
Cmd_ShowBotsMenu(client0);
        }
        case 
MenuAction_Enddelete menu;
    }

    return 
0;



Awwww, Excellent Grey83


All times are GMT -4. The time now is 01:00.

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