AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu shows server players?!?! (https://forums.alliedmods.net/showthread.php?t=13303)

LynX 05-11-2005 17:35

Menu shows server players?!?!
 
I have this:

Code:
public NewMenu( id ) {     new szMenuBody[256]     new keys     format( szMenuBody, 255, "Choose :^n1. Option 1^n2  Option 2^n3. Option 3^n^n0. Exit" )     keys = (1<<0|1<<1|1<<2|1<<9)           show_menu( id, keys, szMenuBody, -1 )     return PLUGIN_HANDLED } public MenuCommand( id , key ) {     switch( key )     {         case 0:  {                                    client_print(id, print_chat,"Option 1")                  }         case 1:  {                  client_print(id, print_chat, "Option2")                  }         case 2:  {                  client_print(id, print_chat, "Option 3")                  }         case 3: client_print( id, print_chat, "Closed the selection menu" )     }     return PLUGIN_HANDLED }
I'd like that it shows current players in server, and gets their origin. Please don't change how menu is done, as this DOES NOT crashes server, I want only changes that this code above shows all players currently in server, and gets their origin so I can do set_user_origin on them.
But, I would be happy that it just shows all players in server. I'll do the rest.

sambro 05-12-2005 19:32

:rtfm: :P

Seriously, the manual is your friend. I come from a land of AMX scripting, where documentation is unheard of, and constant lookup of functions was done inside the include files.

You come from a rich and fertile land, where your many forefathers have fought the evcilness of ignorance with all their might.

ANYWAYS! :oops:

find_player is your friend. You'll be wanting to use the "f" flag, as setting the origin of a dead person may not end well :shock:

Once you got their id, it's a simple matter of "set_user_origin" (from the land of the Fun Module). If you're trying to set their origin to something relative of their old position (like dropping them from a height for example :twisted: ), then you might want to use get_user_origin, and manipulate their origin from there, then use set_user_origin.

KyleD 05-12-2005 19:47

You misunderstood his WHOLE problem..

sambro 05-12-2005 20:19

Quote:

I'd like that it shows current players in server, and gets their origin. Please don't change how menu is done, as this DOES NOT crashes server, I want only changes that this code above shows all players currently in server, and gets their origin so I can do set_user_origin on them.
But, I would be happy that it just shows all players in server. I'll do the rest.
Wow yeah, that's what happens when you try and help when you just wake up :(.

Well I kinda answered his question! :D.

He'll need to use find_players to get all the alive players.

xeroblood 05-12-2005 21:44

Here is a very basic version of a player menu, completely ready to go, just add your commands to it, to do what you want when you select a player..

Study the code so you understand it, and then you can manipulate it, and notice that the menu displays dead players too (but grey) and you cannot select them from the menu.. that is optional, but I left the code there so you can see how that works.. it is easy to remove though..

Code:
#include <amxmodx> #include <amxmisc> #define MENU_SIZE    256 #define MENU_PLAYERS 8 new g_nMenuPosition new g_nMenuPlayers[32] public plugin_init() {     register_clcmd( "player_menu", "PlayerMenu", ADMIN_LEVEL_A, "Shows The Player Menu" )     register_menucmd( register_menuid("\rPlayer Menu:"), 1023, "MenuAction" ) } public PlayerMenu( id, lvl, cid ) {     if( cmd_access( id, lvl, cid, 0 ) )         ShowPlayerMenu( id, g_nMenuPosition = 0 )     return PLUGIN_HANDLED } public MenuAction( id, key ) {     switch( key )     {         case 8: ShowPlayerMenu( id, ++g_nMenuPosition )         case 9: ShowPlayerMenu( id, --g_nMenuPosition )         default:         {             new nPlayerID = g_nMenuPlayers[g_nMenuPosition * MENU_PLAYERS + key]             DoAction( id, nPlayerID )             // If you dont want to keep the menu Open after selecting a command,             // then simply remove the following line:             ShowPlayerMenu( id, g_nMenuPosition )         }     }     return PLUGIN_HANDLED } public ShowPlayerMenu( id, pos ) {     if( pos < 0 ) return     new i, iPlayerID     new szMenuBody[MENU_SIZE]     new nCurrKey = 0     new szUserName[32]     new nStart = pos * MENU_PLAYERS     new nNum     get_players( g_nMenuPlayers, nNum )     if( nStart >= nNum )         nStart = pos = g_nMenuPosition = 0     new nLen = format( szMenuBody, MENU_SIZE-1, "\rPlayer Menu:\R%d/%d^n\w^n", pos+1, (nNum / MENU_PLAYERS + ((nNum % MENU_PLAYERS) ? 1 : 0 )) )     new nEnd = nStart + MENU_PLAYERS     new nKeys = (1<<9)     if( nEnd > nNum )         nEnd = nNum     for( i = nStart; i < nEnd; i++ )     {         iPlayerID = g_nMenuPlayers[i]         get_user_name( iPlayerID, szUserName, 31 )         if( (get_user_flags(iPlayerID) & ADMIN_IMMUNITY) || !is_user_alive(iPlayerID) )         {             nCurrKey++             nLen += format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "\d%d. %s^n\w", nCurrKey, szUserName )         }else         {             nKeys |= (1<<nCurrKey++)             nLen += format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "%d. %s^n", nCurrKey, szUserName )         }     }     if( nEnd != nNum )     {         format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "^n9. More...^n0. %s", pos ? "Back" : "Exit" )         nKeys |= (1<<8)     }     else         format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "^n0. %s", pos ? "Back" : "Exit" )     show_menu( id, nKeys, szMenuBody, -1 )     return } public DoAction( nAdminID, nPlayerID ) {     // Do something to the selected player here using nPlayerID...     // nAdminID will be the ID of the Admin/User who ran the menu...     return PLUGIN_HANDLED }

I hope that helps..


All times are GMT -4. The time now is 16:45.

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