AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   sm_last (https://forums.alliedmods.net/showthread.php?t=301224)

PinHeaDi 09-12-2017 11:33

sm_last
 
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); 


Halt 09-12-2017 11:50

Re: sm_last
 
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


PinHeaDi 09-12-2017 11:53

Re: sm_last
 
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.

Halt 09-12-2017 11:59

Re: sm_last
 
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 :twisted::twisted:

PinHeaDi 09-12-2017 12:05

Re: sm_last
 
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
// ---------------------------------------- 


headline 09-12-2017 12:13

Re: sm_last
 
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;



xines 09-12-2017 12:41

Re: sm_last
 
Quote:

Originally Posted by Headline (Post 2548415)
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;



headline 09-12-2017 12:47

Re: sm_last
 
Quote:

Originally Posted by xines (Post 2548421)
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

xines 09-12-2017 12:58

Re: sm_last
 
Quote:

Originally Posted by Headline (Post 2548423)
If you're gonna do it like that the blocksize shouldn't be MAX_NAME_LENGTH

True, i was simply being to fast.

PinHeaDi 09-12-2017 13:55

Re: sm_last
 
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); 
        } 



All times are GMT -4. The time now is 03:51.

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