Raised This Month: $52 Target: $400
 13% 

Saving data in multidimensional array/object (CSGO)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
McSnaggit
Junior Member
Join Date: Feb 2019
Old 02-12-2019 , 11:31   Saving data in multidimensional array/object (CSGO)
Reply With Quote #1

Hi,

I'm new here and have been searching for a good solution for my CSGO plugin for a while now and haven't found it yet. I have some experience with javascript and can understand a bit of the SourcePawn language with help of other plugins. However it might be that the solution for my problem is closer than I think.

Background information
So I'm working on a plugin that logs Armsrace stats (yes, that's what we play on our server ). I want to log the end score and send it to my MySQL database. This is not the thing I'm worried about.

The difficult thing will be the logging of all the events. I want to make sure that I'm not lagging the server with SQL queries and I first want to collect all the events of a match before sending it to the database. Events like deaths, disconnects etc. Later I can then create a nice interface where we can view the amount of knifes on each other, most killed by, who killed most bots etc.

So what I want is logging events to an array and then at the end of the match iterate over it and sending it to my database. I have read about adt_arrays and static arrays. And because I don't know the end size of my array of events I should use the adt_array. However, I don't know how to combine it with an enum (which I use kind of as an object).

Current code
Example of my current code. Global scope:
PHP Code:
enum GameEvent
{
    
String:Event_Type[32],
    
String:Involved_Player_Name[64],
    
String:Involved_Player_Id[64],
    
String:Weapon[64],
    
Headshot,
    
Penetrated,
    
String:Victim_Player_Name[64],
    
String:Victim_Player_Id[64]
}

new 
g_Events[1024][ GameEvent ];

int LastEventIndex 0
Code in the death event (all the variables are working):

PHP Code:
strcopy(g_EventsLastEventIndex ][ Event_Type ], 32"death");
strcopy(g_EventsLastEventIndex ][ Involved_Player_Name ], 64killerName);
strcopy(g_EventsLastEventIndex ][ Involved_Player_Id ], 64InvolvedPlayerSteamId);
strcopy(g_EventsLastEventIndex ][ Weapon], 64weapon);
g_EventsLastEventIndex ][ Headshot] = headshot;
g_EventsLastEventIndex ][ Penetrated] = penetrated;
strcopy(g_EventsLastEventIndex ][ Victim_Player_Name ], 64victimName);
strcopy(g_EventsLastEventIndex ][ Victim_Player_Id ], 64VictimPlayerSteamId);

LastEventIndex LastEventIndex 1
The problem
My problem is that I don't know if this is the correct way of doing the thing I want. Maybe it's too resource intensive or maybe it's error-sensitive. Also when firing multiple death events at the same time, my index may be the same for 2 events, thus overwriting a part of my array. That's why I'd rather use an adt_array so I can store a new value at the end of the array instead of pre-defining it, and then "hacking" into it. I just want to make sure I gather the correct data and be efficient about it.

Do you guys know if this should be done differently. Please let me know if the problem is still not clear.

Last edited by McSnaggit; 02-12-2019 at 11:32.
McSnaggit is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 02-12-2019 , 13:00   Re: Saving data in multidimensional array/object (CSGO)
Reply With Quote #2

The events are destroyed, you should save the data of them in a stringmap.
Also, use threaded queries. You can use them whenever you want.

Also, you can store the kills, knife kills in Integer Arrays and then you can update the database when players leaves.

PHP Code:

#include <sourcemod> 
#include <sdktools> 
#include <sdkhooks> 

int g_Kills[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
HookEvent("player_death"PlayerDeath);

public 
void OnClientConnected(int client)
{
    
g_Kills[client] = 0;
}

public 
void PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    
    if (
attacker)
    {
        
g_Kills[attacker]++;
    }
}

public 
void OnClientDisconnect(int client)
{
    
// update database with g_Kills[client];

__________________
Ilusion9 is offline
McSnaggit
Junior Member
Join Date: Feb 2019
Old 02-12-2019 , 15:55   Re: Saving data in multidimensional array/object (CSGO)
Reply With Quote #3

Thank you for replying so quickly.

About storing the client stats:
I was thinking about only saving that data if the client played the entire match (we always play with friends only). Therefore I think I'm safe getting the kills etc. from the game itself on match end:

PHP Code:
int PlayerLevel GetEntProp(GetPlayerResourceEntity(), Prop_Send"m_iGunGameLevel"_attacker); //This one was hard to find by the way!
int PlayerKills GetEntProp(GetPlayerResourceEntity(), Prop_Send"m_iKills"_attacker);
etc... 
The thing is that I need to store an event like on match "w" player "x" killed player "y" with weapon "z". If that information is threaded to the database I can easily generate stats on my web application based on a match.

But maybe I'm thinking to much in one direction, it's just that I find it difficult to save an array of people that the attacker killed in the match. So for "kills" it's just an int, but for let's say "killedPlayers" it will be an array of killed players. Again, the "killedWithWeapon" should be an array of weapons that should again be linked to the "killedPlayers".

Can you maybe give an example based on my previous code for a stringmap?
McSnaggit 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 14:24.


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