Raised This Month: $ Target: $400
 0% 

Save user team on disconnect - the best way?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-10-2014 , 17:30   Save user team on disconnect - the best way?
Reply With Quote #1

Hey, guys! I've been requested to add a simple feature in a plugin, but now I'm wondering which is the best way to do it. It's about saving player team on disconnect and putting the player back in the same team if he reconnects within 60 seconds. In other words - player disconnects and if he connects within 60 seconds, he is put back in the same team as he was before disconnecting. Waiting for suggestions!
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 07-10-2014 , 18:27   Re: Save user team on disconnect - the best way?
Reply With Quote #2

look at this plugin

Last edited by Freezo Begin; 07-10-2014 at 18:27.
Freezo Begin is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-10-2014 , 18:34   Re: Save user team on disconnect - the best way?
Reply With Quote #3

I would use a Trie based on SteamID. Really simple.
__________________
fysiks is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-10-2014 , 19:53   Re: Save user team on disconnect - the best way?
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
I would use a Trie based on SteamID. Really simple.
For you it's simple, for me - it's unknow arrea. I've never worked with tries (or arrays), so I will have to take a look if this is the best way.
P.S.: Any tricks, shortways, advices for easier use are welcome here. Examples also. Thanks!
__________________

Last edited by Flick3rR; 07-10-2014 at 20:24.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-10-2014 , 20:10   Re: Save user team on disconnect - the best way?
Reply With Quote #5

https://forums.alliedmods.net/showthread.php?t=201872
mottzi is offline
Send a message via MSN to mottzi
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-10-2014 , 20:34   Re: Save user team on disconnect - the best way?
Reply With Quote #6

It's simple for everyone, it's a simple hashtable, not rocket science.

PHP Code:
new Trie:g_Teams

public plugin_init()
{
    
g_Teams TrieCreate()
}

public 
plugin_end()
{
    
//apparently tries aren't destroyed automatically anymore
    
TrieDestroy(g_Teams)
}

public 
client_disconnect(id)
{
    new 
Authid[34]
    
get_user_authid(idAuthidcharsmax(Authid))

    
TrieSetCell(g_TeamsAuthidget_user_team(id))
}

public 
client_connect(id)
{
    new 
Authid[34]
    
get_user_authid(idAuthidcharsmax(Authid))

    new 
Team
    TrieGetCell
(g_TeamsAuthidTeam)


Last edited by Backstabnoob; 07-10-2014 at 20:35.
Backstabnoob is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-10-2014 , 20:37   Re: Save user team on disconnect - the best way?
Reply With Quote #7

Yes, yes, I was about to reach that in this or other way. Only one thing left - is the best way to detect 60 seconds passed with task? If there are any other suggestions (the code will be super proper) I will be glad to see them. Thanks to all!
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-10-2014 , 20:51   Re: Save user team on disconnect - the best way?
Reply With Quote #8

I'm sure you could find this if you tried searching... Try to think a bit, you can get the current time with multiple ways, such as get_systime() (not really optimal, returns unix timestamp) or get_gametime() (which returns the time passed from map start). So obviously, the best way is to store that time somewhere and compare it again later.

PHP Code:
new Float:g_Time


public called_first()
{
    
g_Time get_gametime() + 60.0 // cache it
}

public 
called_later()
{
    if(
g_Time get_gametime())
    {
        
// 60 seconds have passed
    
}

Don't know what you mean by task? If you're using a task for 60 seconds, you can check if it was already completed with task_exists.

PHP Code:
const TASK_ID 159252
set_task
(60.0"TaskFunc"TASK_ID)

if(
task_exists(TASK_ID)) // not yet passed 
Backstabnoob is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-11-2014 , 10:09   Re: Save user team on disconnect - the best way?
Reply With Quote #9

No, it was about to delete that Trie with user's team if 60 seconds have passed after his disconnect. Which is the best way (I doubt it's task?)?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-11-2014 , 11:50   Re: Save user team on disconnect - the best way?
Reply With Quote #10

The best way to do that is indeed to use a task.
mottzi is offline
Send a message via MSN to mottzi
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 21:07.


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