Raised This Month: $32 Target: $400
 8% 

Solved Players List Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-19-2022 , 19:41   Players List Menu
Reply With Quote #1

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;
        }
    }

__________________

Last edited by alasfourom; 08-20-2022 at 02:51.
alasfourom is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-19-2022 , 20:02   Re: [Issue] Players List Menu
Reply With Quote #2

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.
__________________

Last edited by alasfourom; 08-19-2022 at 20:03.
alasfourom is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-19-2022 , 22:04   Re: [Issue] Players List Menu
Reply With Quote #3

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);
__________________
Do not Private Message @me

Last edited by Bacardi; 08-19-2022 at 22:07.
Bacardi is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-20-2022 , 02:07   Re: [Issue] Players List Menu
Reply With Quote #4

Thank You Bacardi,

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

Thanks a lot
__________________
alasfourom is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 08-20-2022 , 04:02   Re: Players List Menu
Reply With Quote #5

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;

__________________
Grey83 is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-20-2022 , 04:27   Re: Players List Menu
Reply With Quote #6

Quote:
Originally Posted by Grey83 View Post
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
__________________
alasfourom is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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