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

Solved Tracking leavers with time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dtn
Junior Member
Join Date: Apr 2018
Old 09-09-2018 , 19:49   Tracking leavers with time
Reply With Quote #1

Hello.

At first I thought I had some code working to track leavers. I stored the Client ID and GetTime(), but then found out that Client IDs are not unique and change values upon disconnect/reconnect.

So tracking leavers this way wouldn't work, if Player 0 leaves, rejoins, and gets assigned ID 3, the server would still think this player has left and not reconnected...

My idea:
I want to store Steam ID64's in arrays when they disconnect, and I want to get the time from when they left the server. I am not experienced in SP, so I need some help with crafting this piece of code. I'm usually working with PHP, so my idea (if I had to solve it in PHP) was to create arrays like these, when a player leaves...

Is it possible to create these sorts of arrays in SP, and then have a script loop through each array element to check the "time" item?

PHP Code:
Array (

    
=> [
        
'steamId' => 'xxxxxxxxxxx',
        
'time' => 123456789
    
],

    
=> [
        
'steamId' => 'xxxxxxxxxxx',
        
'time' => 123456789
    
],


Is my approach possible in SP? Any other ideas/suggestions are much welcome too!

Last edited by dtn; 09-17-2018 at 07:11.
dtn is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-10-2018 , 02:58   Re: Tracking leavers with time
Reply With Quote #2

Have you considered using MySQL?
__________________
Neuro Toxin is offline
dtn
Junior Member
Join Date: Apr 2018
Old 09-10-2018 , 04:21   Re: Tracking leavers with time
Reply With Quote #3

Quote:
Originally Posted by Neuro Toxin View Post
Have you considered using MySQL?
I have not, because I want to create the logic in the code - and when a player has been absent for 5 minutes without rejoining, then I'll log it in MySQL.

I have the code logic working to loop through clients, that have left the server. But the logging part itself just needs a bit of tweaking to be able to work.

But is my approach not possible in SP?
dtn is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-10-2018 , 06:42   Re: Tracking leavers with time
Reply With Quote #4

Use a StringMap and the SnapShot to iterate.

You could also use Dynamic.

https://github.com/ntoxin66/Dynamic/wiki
__________________
Neuro Toxin is offline
dtn
Junior Member
Join Date: Apr 2018
Old 09-11-2018 , 18:10   Re: Tracking leavers with time
Reply With Quote #5

Quote:
Originally Posted by Neuro Toxin View Post
Use a StringMap and the SnapShot to iterate.

You could also use Dynamic.

https://github.com/ntoxin66/Dynamic/wiki
Thanks for the tip.

I'm new to this - any chance you can guide me towards my goal (by the example of array structure I wrote in my first post). I've tried searching around the forums and found some results, but they seem a bit too complicated and confusing, I'm wondering if it can be done any simpler (https://forums.alliedmods.net/showpo...62&postcount=4)

I want to keep it as clean as possible and not use any external plugins for this, because I'm hoping it's just a small task to solve.
dtn is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-12-2018 , 00:32   Re: Tracking leavers with time
Reply With Quote #6

GetSteamAccountID returns a 32-bit integer value unique to a Steam account, so you could store it plus the timestamp from GetTime in an ArrayList with a blocksize of 2 provided you don't need the full SteamID64 (though you should be able to use these stock functions to convert between the two).

I'd partially write it like so. TODOs left as an exercise for you and for things unique to your implementation.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 09-12-2018 at 00:34.
nosoop is offline
dtn
Junior Member
Join Date: Apr 2018
Old 09-12-2018 , 04:20   Re: Tracking leavers with time
Reply With Quote #7

Quote:
Originally Posted by nosoop View Post
GetSteamAccountID returns a 32-bit integer value unique to a Steam account, so you could store it plus the timestamp from GetTime in an ArrayList with a blocksize of 2 provided you don't need the full SteamID64 (though you should be able to use these stock functions to convert between the two).

I'd partially write it like so. TODOs left as an exercise for you and for things unique to your implementation.
Thanks a lot for the code example.

Your code looks simple and doable for me to implement into my own project - I'll try it out!
dtn is offline
dtn
Junior Member
Join Date: Apr 2018
Old 09-12-2018 , 21:08   Re: Tracking leavers with time
Reply With Quote #8

@nosoop:

Following up on your post, I tried my ways around integrating it and made some good progress. However, I am right now facing one issue.

When a player leaves, I want the present client name to be saved into the enum as a string, so I can easily access this name when iterating through the ArrayList of leavers. I searched around the forums and found some results and tried my way around with the following:

PHP Code:
enum eLeaverData {
  
Leaver_Account 0,
  
Leaver_Time 0,
  
String:Leaver_Name[64]
};

ArrayList g_Leavers
On plugin start:
PHP Code:
g_Leavers = new ArrayList(eLeaverData); 
On player disconnect:
PHP Code:
int account GetSteamAccountID(client);

char clientName[64];
GetClientName(clientclientNamesizeof(clientName));

int entry g_Leavers.Push(account);
g_Leavers.Set(entryGetTime(), Leaver_Time);
g_Leavers.Set(entryclientNameLeaver_Name); 
But I get the following error when compiling:
error 035: argument type mismatch (argument 3)

Any suggestions?
dtn is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 09-12-2018 , 21:26   Re: Tracking leavers with time
Reply With Quote #9

Your third parameter for g_Leavers.Set(entry, clientName, Leaver_Name); is a char when it expects an int.
https://www.sourcemod.net/new-api/ad.../ArrayList/Set
PHP Code:
void Set(int indexany valueint blockbool asChar
Maxximou5 is offline
dtn
Junior Member
Join Date: Apr 2018
Old 09-12-2018 , 21:41   Re: Tracking leavers with time
Reply With Quote #10

Quote:
Originally Posted by Maxximou5 View Post
Your third parameter for g_Leavers.Set(entry, clientName, Leaver_Name); is a char when it expects an int.
https://www.sourcemod.net/new-api/ad.../ArrayList/Set
PHP Code:
void Set(int indexany valueint blockbool asChar
So it is not possible for me to push a string into my ArrayList like this?
dtn 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 03:27.


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