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

Using list[client]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 03-23-2010 , 13:33   Using list[client]
Reply With Quote #1

First, sorry for creating one Thread after another. But there is one thing i want to ask. For example we have a plugin witch allowing every player to receive one cookie every round. So we need a global g_iCount[client] = 1 on GetCookie event and we need to clear it every round.
If we got 24/24 players on server and playerA with client index 19 getting the cookie and disconnecting the server. So g_iCount[19] = 1(1 = no more cookies for him) right now. And another player(playerB) joined the game. I beleive he will get the same client index(19). So if he managed to play in the same round, no cookie for him...

Sorry if it's kinda confusing...
And if this statement is true. I don't rly see a good way to do it. For example if we will make g_iCount[userid] it would be VERY large(i guess).

We can use CreateArray() and use array index as incrementing value(we can clean it every round start\map cahnge anyway) and userid as a value. So we can FindValueInArray() function to be sure userid is existing there. It's might be the best solution because we can clean the array, but we cannot define if player can have more than 1 cookie....

Next idea is to use
CreateTrie()
I thing it's a very nice thing to use. The most important thing i concern is performance. We need to get\set value every round, cleaning ang etc... I just wanted to ask: can it effect on game(server?) performance. I mean it's kinda complicated thing, of course we don't using 100+ keys and values.
So if usefullness/performance_problems will be > 1?

Even if my way of understanding client id is wrong, please give me some advise about Trie, maybe u had experience using it...

Sorry if my Thread is a little confusing, it's just kinda hard to explain that i need.
xf117 is offline
Send a message via ICQ to xf117
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 03-23-2010 , 18:14   Re: Using list[client]
Reply With Quote #2

Why don't you just reset the value on disconnecting clients? Every time a client connect or disconnect you might want to reset or clean up client data in your plugin, so it's ready for whoever get it next time.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 03-23-2010 at 18:16.
rhelgeby is offline
Send a message via MSN to rhelgeby
Mnkras
Senior Member
Join Date: Mar 2009
Location: 127.0.0.1
Old 03-23-2010 , 19:28   Re: Using list[client]
Reply With Quote #3

i don't think they get the same index... so
24 players join the server with index's 1-24 player 24 disconnects (index 24) a new player connects he is player 24 but has the index 25. these are reset on map change
__________________
Mnkras is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 03-23-2010 , 20:16   Re: Using list[client]
Reply With Quote #4

That doesn't matter. When someone disconnect you mark that index in the array as unused (maybe with -1 as the value).

Then you'll know that all values that are non-zero are used items in the list. Those with -1 are ignored.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 03-23-2010 , 22:29   Re: Using list[client]
Reply With Quote #5

The reason not to reset the value is: if someone will rejoing to get free cookie? =)
We don't want that to happen...

But i'm not sure witch index will he get after rejoining...
xf117 is offline
Send a message via ICQ to xf117
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-23-2010 , 22:46   Re: Using list[client]
Reply With Quote #6

PHP Code:
new bool:g_bGotCookie[MAXPLAYERS 1];
new 
g_iDisconnectedCookieUsers[MAXPLAYERS];    //could be more players disconnecting during a round, but thats highly improbable
new g_iDisconnectedCount;

public 
OnClientDisconnect(client) {
    if(
g_bGotCookie[client] && g_iDisconnectedCount != sizeof(g_iDisconnectedCookieUsers)) {
        
g_iDisconnectedCookieUsers[g_iDisconnectedCount++] = GetClientUserId(client);
    }

    
g_bGotCookie[client] = false;
}

public 
OnClientPutInServer(client) {
    new 
userid GetClientUserId(client);

    for(new 
0g_iDisconnectedCounti++) {
        if(
userid == g_iDisconnectedCookieUsers[i]) {
            
g_iDisconnectedCookieUsers[i] = g_iDisconnectedCookieUsers[--g_iDisconnectedCount];    //drop the index from the array
            
g_bGotCookie[client] = true;
            break;
        }
    }
}

public 
Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast) {
    
g_iDisconnectedCount 0;    //reset on round start

The cookie state is restored for reconnecting clients and the array doesnt get too large since its purged on every round start. Everyone is happy.
__________________
plop
p3tsin is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 03-23-2010 , 22:51   Re: Using list[client]
Reply With Quote #7

Loop through clients on round end and give em all a cookie? That way it doesn't matter when they join/leave. They played the round, GIVE EM A COOKIE!
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
FaTony
Veteran Member
Join Date: Aug 2008
Old 03-24-2010 , 02:09   Re: Using list[client]
Reply With Quote #8

You can also store SteamID's along with cookie counts.
FaTony 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 11:49.


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