AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save user team on disconnect - the best way? (https://forums.alliedmods.net/showthread.php?t=243862)

Flick3rR 07-10-2014 17:30

Save user team on disconnect - the best way?
 
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!

Freezo Begin 07-10-2014 18:27

Re: Save user team on disconnect - the best way?
 
look at this plugin

fysiks 07-10-2014 18:34

Re: Save user team on disconnect - the best way?
 
I would use a Trie based on SteamID. Really simple.

Flick3rR 07-10-2014 19:53

Re: Save user team on disconnect - the best way?
 
Quote:

Originally Posted by fysiks (Post 2165403)
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!

mottzi 07-10-2014 20:10

Re: Save user team on disconnect - the best way?
 
https://forums.alliedmods.net/showthread.php?t=201872

Backstabnoob 07-10-2014 20:34

Re: Save user team on disconnect - the best way?
 
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)



Flick3rR 07-10-2014 20:37

Re: Save user team on disconnect - the best way?
 
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!

Backstabnoob 07-10-2014 20:51

Re: Save user team on disconnect - the best way?
 
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 


Flick3rR 07-11-2014 10:09

Re: Save user team on disconnect - the best way?
 
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?)?

mottzi 07-11-2014 11:50

Re: Save user team on disconnect - the best way?
 
The best way to do that is indeed to use a task.


All times are GMT -4. The time now is 21:07.

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