Raised This Month: $ Target: $400
 0% 

Solved Global KeyValue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lolz123
Member
Join Date: Aug 2010
Old 11-06-2016 , 07:43   Global KeyValue
Reply With Quote #1

I've created a global KeyValue which is being used when a player types a command.

My question is if a few players are typing the command together, does the key value functions will scramble together and the data it'll retrieve will be wrong?

Last edited by Lolz123; 11-10-2016 at 05:06.
Lolz123 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-06-2016 , 08:05   Re: Global KeyValue
Reply With Quote #2

More info pls... I am not really sure what you mean.

What is this "global KeyValue"? And how exactly is it used?
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.

Last edited by KissLick; 11-06-2016 at 08:05.
KissLick is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-06-2016 , 18:14   Re: Global KeyValue
Reply With Quote #3

Code code code
__________________
Neuro Toxin is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 11-06-2016 , 18:22   Re: Global KeyValue
Reply With Quote #4

You may want to hold individual per-client KeyValues handles in an array, or at least segment the client entries in it if possible.

Since I assume you're not using a function-scoped variable for a reason, you will have to make sure none of the other clients access the same portion.

Hard to tell what you're going for though; we could use more context.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Lolz123
Member
Join Date: Aug 2010
Old 11-07-2016 , 06:59   Re: Global KeyValue
Reply With Quote #5

It goes like that:

PHP Code:
#pragma semicolon 1

#include <sourcemod>

#pragma newdecls required

KeyValues g_kvRequests;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_request"Command_Request);
    
RegConsoleCmd("sm_showrequests"Command_ShowRequests);
}

public 
void OnMapStart()
{
    
g_kvRequests = new KeyValues("Requests");
}

public 
void OnMapEnd()
{
    
delete g_kvRequests;
}

public 
Action Command_Requestint clientint args )
{
    
char szName[32];
    
GetClientName(clientszNamesizeof(szName) - 1);
    
    
char szAuth[32];
    
GetClientAuthId(clientAuthId_Steam3szAuthsizeof(szAuth) - 1);
    
    
char szArg[15];
    
GetCmdArg(1szArgsizeof(szArg));
    
    if( 
g_kvRequests.JumpToKey(szAuth) ) PrintToChat(client"Your old request has been replaced!");
    else
    {
        
g_kvRequests.JumpToKey(szAuthtrue);
        
        
//g_iTotalRequests++;
    
}
    
    
g_kvRequests.SetString("text"szArg);
    
g_kvRequests.SetString("name"szName );
    
g_kvRequests.SetString("auth"szAuth );
    
    
g_kvRequests.Rewind();
    
    return 
Plugin_Handled;
}

public 
Action Command_ShowRequestsint clientint args )
{
    if (!
g_kvRequests.GotoFirstSubKey())
    {
        return 
Plugin_Handled;
    }
    
    
char szAuth[32], szName[32], szArg[15];
    
    do
    {
        
g_kvRequests.GetSectionName(szAuthsizeof(szAuth));
        
        
g_kvRequests.GetString("name"szNamesizeof(szName));
        
g_kvRequests.GetString("text"szArgsizeof(szArg));
        
        
PrintToConsole(client"%s - %s - %s"szAuthszNameszArg);
        
    } while (
g_kvRequests.GotoNextKey());
    
    
g_kvRequests.Rewind();
    
    return 
Plugin_Handled;

/request - adds a request
/showrequests - shows all requests

Lets assume 2 players are typing /showrequests at the exact same time, and there are 30 keys in the keyvalue.
The function "g_kvRequests.GotoNextKey()" will work good?
What if the first player's loop is at different key from the second player's loop? Won't it scramble together?

And if this is not an effective way to code what i want to do, there's something else i can use but not keyvalues? A way that i can store 3 vars for each player on the server?

Thanks!

Last edited by Lolz123; 11-07-2016 at 07:06.
Lolz123 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-07-2016 , 08:08   Re: Global KeyValue
Reply With Quote #6

Nothing should ever happen at the same time. The SourcePawn VM itself doesn't handle multiple threads and SM will never attempt to run SP code in parallel. Even if two clients run the command on the same server frame, the callbacks will happen serially.

Last edited by Fyren; 11-07-2016 at 08:09.
Fyren is offline
Lolz123
Member
Join Date: Aug 2010
Old 11-07-2016 , 15:10   Re: Global KeyValue
Reply With Quote #7

Quote:
Originally Posted by Fyren View Post
Nothing should ever happen at the same time. The SourcePawn VM itself doesn't handle multiple threads and SM will never attempt to run SP code in parallel. Even if two clients run the command on the same server frame, the callbacks will happen serially.
Thank you!
Lolz123 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 05:55.


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