View Single Post
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 03-20-2023 , 11:49   Re: [ANY]How can I use userid to store and retreive a variable?
Reply With Quote #5

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:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

int g_iPoints [MAXPLAYERS+1];
StringMap g_smCampaign;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_mypoints"Command_MyPoints"Test To Show My Points");
    
RegConsoleCmd("sm_addpoints"Command_AddPoints"Test To Add 5 Points");
    
    
g_smCampaign = new StringMap();
}

public 
void OnMapStart()
{
    
// Clear all clients points at start of every map
    
g_smCampaign.Clear();
}

Action Command_MyPoints(int clientint args)
{
    
//Display points command
    
PrintToChat(client"Your Points: %d"g_iPoints[client]);
    return 
Plugin_Handled;
}

Action Command_AddPoints(int clientint args)
{
    
//Add points command
    
g_iPoints[client] += 5;
    return 
Plugin_Handled;
}

public 
void OnClientAuthorized(int client, const char[] auth)
{
    if (
IsFakeClient(client))return;
    
    
int StoredPoints;
    
//If clients have been here before, give them their stored points
    
if(g_smCampaign.GetValue(authStoredPoints)) g_iPoints[client] = StoredPoints;
    
    
// Else reset their points to what you need like 0 etc
    
else g_iPoints[client] = 0;
}

public 
void OnClientDisconnect(int client)
{
    if (
IsFakeClient(client)) return;
    
    
//Save clients points when disconnecting
    
char auth[32];
    
GetClientAuthId(clientAuthId_Steam2authsizeof(auth));
    
g_smCampaign.SetValue(authg_iPoints[client], true);

__________________

Last edited by alasfourom; 03-20-2023 at 12:02.
alasfourom is offline