Raised This Month: $278 Target: $400
 69% 

[ANY]How can I use userid to store and retreive a variable?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Morning
Member
Join Date: May 2021
Old 03-18-2023 , 14:51   [ANY]How can I use userid to store and retreive a variable?
Reply With Quote #1

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?
Morning is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 03-18-2023 , 18:59   Re: [ANY]How can I use userid to store and retreive a variable?
Reply With Quote #2

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
PC Gamer is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old Yesterday , 04:23   Re: [ANY]How can I use userid to store and retreive a variable?
Reply With Quote #3

...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.
__________________
Do not Private Message @me

Last edited by Bacardi; Yesterday at 04:29.
Bacardi is offline
Morning
Member
Join Date: May 2021
Old Today , 08:33   Re: [ANY]How can I use userid to store and retreive a variable?
Reply With Quote #4

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

Last edited by Morning; Today at 08:36.
Morning is offline
Reply


Thread Tools
Display Modes

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 09:27.


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