AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how to get server name,map,player (https://forums.alliedmods.net/showthread.php?t=188515)

RuRuRu612754 06-27-2012 09:34

how to get server name,map,player
 
Hello

how to get server name,map,player?
i think use Sockets ...
but, i can't use this

best regards,

Aooka 06-27-2012 10:31

Re: how to get server name,map,player
 
What do you say lol ?

I give you an example to have a player name :
Code:
#include < amxmodx > public plugin_init( ) {     register_plugin( "test" , "1.0" , "Aooka" );         register_clcmd( "say /name" , "CmdName" ); } public CmdName( const id ) {     new szName[ 32 ];         get_user_name( id , szName , 31 );         client_print( id , print_chat , "My name is : %s" , szName ); }

For the name of a map use it : http://www.amxmodx.org/funcwiki.php?go=func&id=244

For the server name good question ^^

Waleed 06-27-2012 11:25

Re: how to get server name,map,player
 
To get player name:

Spoiler


I think same method will be used to get map name:

Spoiler


Don't know we could get server name :D ?

hornet 06-27-2012 11:31

Re: how to get server name,map,player
 
Code:
#include <amxmodx> public plugin_init() {     register_clcmd( "say /details", "ClientCommand_Details" ); } public ClientCommand_Details( id ) {     new szName[ 32 ], szMapName[ 32 ], szHostName[ 64 ];         get_user_name( id, szName, charsmax( szName ) );     get_mapname( szMapName, charsmax( szMapName ) );     get_cvar_string( "hostname", szHostName, charsmax( szHostName ) );         client_print( id, print_chat, "->  Server name is %s  -> Map name is %s  -> Your name is %s", szName, szMapName, szHostName ); }

Neeeeeeeeeel.- 06-27-2012 11:34

Re: how to get server name,map,player
 
Maybe he want to take it from another server because he said 'sockets'.

hornet 06-27-2012 11:39

Re: how to get server name,map,player
 
Oh, whoops :S Well best take a look here if Neel's right http://forums.alliedmods.net/showthread.php?t=169315

RuRuRu612754 06-27-2012 12:36

Re: how to get server name,map,player
 
Quote:

Originally Posted by Neeeeeeeeeel.- (Post 1737242)
Maybe he want to take it from another server because he said 'sockets'.

Yes
I want get another server "server name" "server map" "server activeplayer count" "server maxplayer count"

Quote:

Originally Posted by hornet (Post 1737259)
Oh, whoops :S Well best take a look here if Neel's right http://forums.alliedmods.net/showthread.php?t=169315

Thanks
But, Here is my information seeking is not available.
Official wiki information is missing also.

Best regards,

Aooka 06-27-2012 12:44

Re: how to get server name,map,player
 
@Hornet: Thanks for that :)
Code:
get_cvar_string( "hostname", szHostName, charsmax( szHostName ) );

Neeeeeeeeeel.- 06-27-2012 13:04

Re: how to get server name,map,player
 
Not tested but should work, i'm n00b at sockets. I started with them like two weeks ago, let me know if there are any other better way to do this:3

PHP Code:

#include < amxmodx >
#include < sockets >

#define PLUGIN "Sockets example"
#define VERSION "1.0"
#define AUTHOR "Neeeeeeeeeel.-"

new iSocket;

new 
iConnected;

new const 
szHost[ ] = { "XXX.XXX.XXX.XXX" };

new const 
szGetmap[ ] = { "getmap" };

const 
iPort 27015;

const 
TASK_SOCKETINIT 3391;
const 
TASK_RECVSOCKET 3378;

public 
plugin_init( ) 
{
    
register_pluginPLUGINVERSIONAUTHOR );
    
    
set_task20.0"CheckConnection"TASK_SOCKETINIT__"b" );
    
    
set_task10.0"RecvSocket"TASK_RECVSOCKET__"b" );
    
    
register_concmd"say /getmap""cmdGetMap" );
}

public 
cmdGetMap( )
{
    if( 
iConnected )
        
socket_sendiSocketszGetmapcharsmaxszGetmap ) );
    else
        
client_print0print_chat"Server not connected" );
}

public 
SocketInit( )
{
    new 
iError;

    
iSocket socket_openszHostiPortSOCKET_UDPiError );
    
    if( 
iSocket || iError )
        return;
    
    new 
data32 ];
    
    
get_user_ip0datacharsmaxdata ) );
    
    
formatexdatacharsmaxdata ), "%s on"data );
    
    
socket_sendiSocketdatacharsmaxdata ) );
}

public 
RecvSocket( )
{    
    if( 
socket_changeiSocket110000 ) )
    {
        static 
data512 ];
        
        
socket_recviSocketdatacharsmaxdata ) );
        
        if( 
containidata"off" ) != -)
        {
            
socket_closeiSocket );
            
            
iConnected 0;
            
            static 
szIP32 ];
            
parsedataszIPcharsmaxszIP ) );
            
            
client_print0print_chat"%s disconnected"szIP );
            
            
set_task20.0"CheckConnection"TASK_SOCKETINIT__"b" );
        }
        
        else if( 
containidata"connected" ) != -)
            
iConnected 1;
        
        else if( 
containidata"on" ) != -)
        {
            static 
szIP24 ];
            
parsedataszIPcharsmaxszIP ) );
            
            
client_print0print_chat"%s connected"szIP );
        }
        
        else if( 
containidata"getmap" ) != -)
        {
            static 
szMapname64 ];
            
get_mapnameszMapnamecharsmaxszMapname ) );
            
            
formatexszMapnamecharsmaxszMapname ), "^"%s^" mapname" );
            
            
socket_sendiSocketszMapnamecharsmaxszMapname ) );
        }
        
        else if( 
containidata"mapname" ) != -)
        {
            static 
szMapname64 ];
            
parsedataszMapnamecharsmaxszMapname ) );
            
            
remove_quotesszMapname );
            
            
client_print0print_chat"The map from the other server is %s"szMapname );
        }
    }
}

public 
CheckConnection( )
{
    if( 
iConnected )
        
remove_taskTASK_SOCKETINIT );
    else
        
SocketInit( );
}

public 
plugin_end( )
{
    new 
data32 ], ip32 ];
    
    
get_user_ipipcharsmaxip ) );
    
formatexdatacharsmaxdata ), "%s off"ip );
    
    
socket_sendiSocketdatacharsmaxdata ) );
    
    
socket_closeiSocket );



Exolent[jNr] 06-27-2012 15:30

Re: how to get server name,map,player
 
https://forums.alliedmods.net/showthread.php?t=142858

Code:
public CmdServerInfo( iPlayer ) {     new iData[ 2 ], iError;     iData[ 0 ] = iPlayer;         sq_query( "12.34.56.78", 27015, SQ_Server, "SQueryInfo", iError, _, iData, sizeof( iData ) ); } public SQueryInfo( iQueryID, iType, Trie:tBuffer, Float:flTime, bool:bFailed, iData[ ], iDataSize ) {     new iPlayer = iData[ 0 ];         if( bFailed )     {         client_print( iPlayer, print_chat, "* Failed to get server information" );     }     else     {         new szServerName[ 64 ], szMap[ 64 ], iNumPlayers, iMaxPlayers;                 TrieGetString( tBuffer, "server_name", szServerName, charsmax( szServerName ) );         TrieGetString( tBuffer, "map", szMap, charsmax( szMap ) );         TrieGetCell( tBuffer, "num_players", iNumPlayers );         TrieGetCell( tBuffer, "max_players", iMaxPlayers );                 client_print( iPlayer, print_chat, "* Server Name: %s | Map: %s | Players: %d / %d", szServerName, szMap, iNumPlayers, iMaxPlayers );     } }


All times are GMT -4. The time now is 06:19.

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