Raised This Month: $51 Target: $400
 12% 

sm_last


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 09-12-2017 , 11:33   sm_last
Reply With Quote #1

PHP Code:
#include <sourcemod>

#define LIST_LIMIT    5

//ArrayList
ArrayList g_hList;

public 
Plugin myinfo =  

    
name "Mashiro"
    
author "Instinct"
    
description "Test"
    
version "1.0"
    
url "..." 
}; 

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_list"Command_ListADMFLAG_SLAY"Shows disconnected list"); 
}

public 
void OnClientDisconnect(int iClient)
{
    if(
g_hList == null)
    {
        
g_hList = new ArrayList(MAX_NAME_LENGTH);
    }
    
    if(
g_hList.Length >= LIST_LIMIT)
    {
        
g_hList.Erase(0);
    }
    
    
char sName[MAX_NAME_LENGTH];
    
GetClientName(iClientsNamesizeof(sName));
    
    
g_hList.PushString(sName);
}

public 
Action Command_List(int iClientint iArgs
{
    if(
g_hList == null)
    {
        return 
Plugin_Handled;
    }

    
char sName[MAX_NAME_LENGTH];

    for(
int ig_hList.Lengthi++)
    {
        
g_hList.GetString(isNamesizeof(sName));
    
        
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
        
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: %s]:."sName); 
        
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
    }
    
    return 
Plugin_Handled

So, this sould work but only gets the name. (The original plugin is with
PHP Code:
PrintToChat(iClient"Leaver: %s"sName); 
and I give you the edited one:
PHP Code:
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: %s]:."sName); 
"

But I don't know how to edit it so that it can't print name, steamid and IP, something like that should be:
PHP Code:
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: %s]:."sNamesSteamIDsIP); 
__________________
PinHeaDi is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-12-2017 , 11:50   Re: sm_last
Reply With Quote #2

You're only grabbing the users name?

PHP Code:
public void OnClientDisconnect(int iClient

    if(
g_hList == null
    { 
        
g_hList = new ArrayList(MAX_NAME_LENGTH); 
    } 
     
    if(
g_hList.Length >= LIST_LIMIT
    { 
        
g_hList.Erase(0); 
    } 
     
    
char sName[MAX_NAME_LENGTH]; 
    
GetClientName(iClientsNamesizeof(sName)); 
     
    
g_hList.PushString(sName); 

You also need to grab and store the other info you're trying to print.

PHP Code:
int GetServerSteamAccountId() 
PHP Code:
GetClientIP(int clientchar[] ipint maxlenbool remport

Last edited by Halt; 09-12-2017 at 11:50.
Halt is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 09-12-2017 , 11:53   Re: sm_last
Reply With Quote #3

That's problem, I took the plugin from an old thread and it's only printing the name. I want from it to print also the SteamID and the IP and I don't know how to add that check, beside the print message.
__________________
PinHeaDi is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-12-2017 , 11:59   Re: sm_last
Reply With Quote #4

Try this

PHP Code:
public void OnClientDisconnect(int iClient

    if(
g_hList == null
    { 
        
g_hList = new ArrayList(MAX_NAME_LENGTH); 
    } 
     
    if(
g_hList.Length >= LIST_LIMIT
    { 
        
g_hList.Erase(0); 
    } 
     
    
char sName[MAX_NAME_LENGTH];
    
char sIP[32];
    
ClientSteamID GetSteamAccountID(iClientfalse);
    
GetClientName(iClientsNamesizeof(sName)); 
    
GetClientIP(iClientsIPsizeof(sIP), true);
    
g_hList.PushString(sName); 

I didn't compile it myself but it should work. You need to declare "ClientSteamID" as a string globally at the top of your plugin.


Edit: Then your print to chat should look like this
PHP Code:
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: %s]:."sNameClientSteamIDsIP); 
I didn't use your variables

Last edited by Halt; 09-12-2017 at 12:01.
Halt is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 09-12-2017 , 12:05   Re: sm_last
Reply With Quote #5

PHP Code:
#include <sourcemod>

#define LIST_LIMIT    5

//ArrayList
ArrayList g_hList;
int ClientSteamID;

public 
Plugin myinfo =   
{  
    
name "Mashiro",  
    
author "Instinct",  
    
description "Test",  
    
version "1.0",  
    
url "..."  
};  

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_list"Command_ListADMFLAG_SLAY"Shows disconnected list"); 
}

public 
void OnClientDisconnect(int iClient)  
{  
    if(
g_hList == null)  
    {  
        
g_hList = new ArrayList(MAX_NAME_LENGTH);  
    }  
      
    if(
g_hList.Length >= LIST_LIMIT)  
    {  
        
g_hList.Erase(0);  
    }  
      
    
char sName[MAX_NAME_LENGTH]; 
    
char sIP[32]; 
    
ClientSteamID GetSteamAccountID(iClientfalse); 
    
GetClientName(iClientsNamesizeof(sName));  
    
GetClientIP(iClientsIPsizeof(sIP), true); 
    
g_hList.PushString(sName);  
}  

public 
Action Command_List(int iClientint iArgs
{
    if(
g_hList == null)
    {
        return 
Plugin_Handled;
    }

    
char sName[MAX_NAME_LENGTH];

    for(
int ig_hList.Lengthi++)
    {
        
g_hList.GetString(isNamesizeof(sName));
        
        if (
IsPlayerGenericAdmin(iClient))
        {
    
            
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
            
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: %s]:."sNameClientSteamIDsIP);  
            
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
        }
        else
        {
            
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
            
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: ADMINS ONLY]:."sNameClientSteamID); 
            
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
        }
    }
    
    return 
Plugin_Handled
}  

bool:IsPlayerGenericAdmin(iClient

    return 
CheckCommandAccess(iClient"generic_admin"ADMFLAG_GENERICfalse); 


PHP Code:
//SourceMod Batch Compiler
// by the SourceMod Dev Team


//// last.sp
//
// C:\Users\SSadistic\Desktop\SMCompile\last.sp(60) : error 017: undefined symbol "sIP"
//
// 1 Error.
//
// Compilation Time: 0,2 sec
// ---------------------------------------- 
__________________

Last edited by PinHeaDi; 09-12-2017 at 12:06.
PinHeaDi is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-12-2017 , 12:13   Re: sm_last
Reply With Quote #6

PHP Code:
#include <sourcemod>

#define LIST_LIMIT    5

//ArrayList
ArrayList g_hList;

public 
Plugin myinfo =  

    
name "Mashiro"
    
author "Instinct"
    
description "Test"
    
version "1.0"
    
url "..." 
}; 

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_list"Command_ListADMFLAG_SLAY"Shows disconnected list"); 
}

public 
void OnClientDisconnect(int iClient)
{
    if(
g_hList == null)
    {
        
g_hList = new ArrayList();
    }
    
    if(
g_hList.Length >= LIST_LIMIT)
    {
        
delete view_as<StringMap>(g_hList.Get(0));
        
g_hList.Erase(0);
    }
    
    
char name[MAX_NAME_LENGTH];
    
GetClientName(iClientnamesizeof(name));

    
char ip[32];
    
GetClientIP(iClientipsizeof(ip));
    
    
char steamid[32];
    
GetClientAuthId(iClientAuthId_Steam2steamidsizeof(steamid));

    
StringMap map CreateStringMap(namesteamidip);
    
g_hList.Push(map);
}

public 
Action Command_List(int iClientint iArgs
{
    if(
g_hList == null)
    {
        return 
Plugin_Handled// might wanna tell then why they didn't get a response
    
}

    
char name[MAX_NAME_LENGTH];
    
char ip[32];
    
char steamid[32];

    
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");
    for(
int ig_hList.Lengthi++)    
    {    
        
StringMap map g_hList.Get(i);
        
        
map.GetString("name"namesizeof(name));
        
map.GetString("ip"ipsizeof(ip));
        
map.GetString("steamid"steamidsizeof(steamid));
        
        
PrintToConsole(iClient".:[Name: %s | Steam ID: %s | IP: %s]:."namesteamidip); 
    }
    
PrintToConsole(iClient"=============== LAST DISCONNECTED PLAYERS ===============");

    return 
Plugin_Handled
}

StringMap CreateStringMap(const char[] playerName, const char[] steamid, const char[] ip)
{
    
StringMap map = new StringMap();
    
map.SetString("name"playerName);
    
map.SetString("steamid"steamid);
    
map.SetString("ip"ip);
    return 
map;

headline is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 09-12-2017 , 12:41   Re: sm_last
Reply With Quote #7

Quote:
Originally Posted by Headline View Post
PHP Code:
StringMap CreateStringMap(const char[] playerName, const char[] steamid, const char[] ip)
{
    
StringMap map = new StringMap();
    
map.SetString("name"playerName);
    
map.SetString("steamid"steamid);
    
map.SetString("ip"ip);
    return 
map;

Personally i wouldnt use a stringmap for this, also i noticed you arent checking for true/false upon the bools: GetClientName, GetClientIP, GetClientAuthId

Tell me what your opinion on this is.

PHP Code:
#include <sourcemod> 

#define LIST_LIMIT    5

//ArrayList
ArrayList g_hList;

public 
Plugin myinfo =
{
    
name "Mashiro",
    
author "Instinct",
    
description "Test",
    
version "1.0",
    
url "..."
};

public 
void OnPluginStart() 

    
RegAdminCmd("sm_list"Command_ListADMFLAG_SLAY"Shows disconnected list");


public 
void OnClientDisconnect(int client
{
    
char iauth[64];
    if (
GetClientAuthId(clientAuthId_Steam2iauthsizeof(iauth))) //Make sure we gathered SteamID, else do nothing...
    
{
        if(
g_hList == null
        { 
            
g_hList = new ArrayList(256); 
        } 
         
        if(
g_hList.Length >= LIST_LIMIT
        { 
            
g_hList.Erase(0); 
        }
        
        
//Variables for storage
        
char ListBuffer[256], ipaddr[24];
        
        
//Get IP, if possible else we display x.x.x.x
        
if(GetClientIP(clientipaddrsizeof(ipaddr))) {}
        else 
Format(ipaddrsizeof(ipaddr), "x.x.x.x");
        
        
//Combine to final string.
        
Format(ListBuffersizeof(ListBuffer), ".:[Name: %N | Steam ID: %s | IP: %s]:."clientiauthipaddr);
        
        
//Push to dat list
        
g_hList.PushString(ListBuffer);
    }
}

public 
Action Command_List(int clientint iArgs)

    if(
g_hList == null
    { 
        return 
Plugin_Handled
    }
    
    
PrintToConsole(client"=============== LAST DISCONNECTED PLAYERS ===============");
    
char ListBuffer[256];
    for(
int ig_hList.Lengthi++)
    {
        
g_hList.GetString(iListBuffersizeof(ListBuffer));
        
PrintToConsole(client"%s"ListBuffer);
    }
    
PrintToConsole(client"=============== LAST DISCONNECTED PLAYERS ===============");
    
    return 
Plugin_Handled;

__________________

Last edited by xines; 09-12-2017 at 12:54. Reason: ...
xines is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-12-2017 , 12:47   Re: sm_last
Reply With Quote #8

Quote:
Originally Posted by xines View Post
Personally i wouldnt use a stringmap for this, also i noticed you arent checking for true/false upon the bools: GetClientName, GetClientIP, GetClientAuthId

Tell me what your opinion on this is.
If you're gonna do it like that the blocksize shouldn't be MAX_NAME_LENGTH
headline is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 09-12-2017 , 12:58   Re: sm_last
Reply With Quote #9

Quote:
Originally Posted by Headline View Post
If you're gonna do it like that the blocksize shouldn't be MAX_NAME_LENGTH
True, i was simply being to fast.
__________________
xines is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 09-12-2017 , 13:55   Re: sm_last
Reply With Quote #10

This works flawlessly, thank you. One last think - I renamed the sm_list to sm_last, so it is possible to add sm_list as a command that prints all the current online players like this:

PHP Code:
RegConsoleCmd("sm_list"Command_List"Shows player list"); 
PHP Code:
        if (IsPlayerGenericAdmin(iClient))
        {     
            
PrintToConsole(iClient"Name: %s | SteamID: %s | IP: %s"namesteamidip);  
        }
        else
        {
            
PrintToConsole(iClient"Name: %s | SteamID: %s | IP: ADMINS ONLY"namesteamid); 
        } 
__________________

Last edited by PinHeaDi; 09-12-2017 at 13:56.
PinHeaDi is offline
Reply



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 09:32.


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