[ANY]How can I use userid to store and retreive a variable?
I want to store a variable for a player, but I want to access it across map changes. At the moment I am using client as an array index, but it can change.
From my understanding, a player userid will be unique for the lifetime of the game server, so it seems like I need to somehow use that. Would this involve storing userid first in an array, and then using that to get a new client number after a map change? Does anyone have any working code of this so I can see how it's done? |
Re: [ANY]How can I use userid to store and retreive a variable?
You may wish to consider using Client Preferences. It writes a cookie on the client machine that can be read by your code whenever you need it. Here's a good tutorial: https://forums.alliedmods.net/showthread.php?t=228244
|
Re: [ANY]How can I use userid to store and retreive a variable?
...cookie is saved on server, sqlite database file in ...sourcemod/data/
But use that system only for saving settings, not for ban/rank/stats system. Sqlite is second way to store anything data. Third one would be keyvalues, but it could cause headcache. - client index is entity index, it is like player slot on server. - userid is like ticket number, when player reconnect to server he get new ticket number. - each player have steamid, you find player with that in any day. |
Re: [ANY]How can I use userid to store and retreive a variable?
Currently one reason is for storing session stats which just get reset / discarded at the end of the session and not stored in database - I'm running L4D2, and a campaign session usually consists of 4 mapchanges and clients can get moved around slots. I'm firstly looking to fix this.
There would be other small things too, and I could use clientprefs or database, but I'm wary of adding more database calls than I really need because it can cause lag because I dont have good I/O speed and I don't use threaded query. If clientprefs is threaded that could be okay but otherwise it would be good to keep things in memory. I will try to use multidimensional array where I store and update userid, client, ect. If that fails I will try database, I guess. But yeah, if anyone has code of a fast and simple way to do it in memory, that would be very helpful! Thanks all for the help :mrgreen: |
Re: [ANY]How can I use userid to store and retreive a variable?
I would say using StringMap would be the best for you as previously mentioned by "ddhoward ", I cant find his snippet now, but here how it looks like, using it to store points and reset at the start of next chapter
You can reset clients stats every round, or every map according to your need PHP Code:
|
Re: [ANY]How can I use userid to store and retreive a variable?
This looks exactly like what I am looking for! Thanks so much for the help! :twisted:
|
All times are GMT -4. The time now is 15:43. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.