Raised This Month: $51 Target: $400
 12% 

What is more optimized ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BaD CopY
Senior Member
Join Date: Oct 2014
Location: Home
Old 08-19-2018 , 10:32   What is more optimized ?
Reply With Quote #1

What is more optimized way, for making vars for player data, then this

PHP Code:
new    Golds[33], 
    
Rank[33], 
    
XP[33],
    
Kills[33],
    
Deaths[33]; 
I'm saving all data to sql database in real time like this

PHP Code:
public onDeathMsg()
{
    new 
iKiller read_data(1);
    new 
iVictim read_data(2);
    new 
Headshot read_data(3);
    
    if(
task_exists(iVictim mainHudID))
    {
        
remove_task(iVictim mainHudID);
    }
    
    new 
button pev(iKillerpev_button)
    new 
Wpn get_user_weapon(iKiller)
    
    if( 
iKiller != iVictim && ( <= iKiller <= MAXPLAYERS ) && ( <= iVictim <= MAXPLAYERS ) && !is_user_bot(iKiller))
    {
        
XP[iKiller] ++
        
Golds[iKiller] ++
        
Kills[iKiller] ++
        
Deaths[iVictim] ++
        
        
SQL_SaveData(iKiller)
        
SQL_SaveData(iVictim)
    }
}

stock SQL_SaveData(id)
{
    new 
nick[33];
    
get_user_name(idnickcharsmax(nick));
    
    new 
HandleSQL_Connection SQL_Connect(SQL_GlobalConnectionErrorCodeg_Errorcharsmax(g_Error));
    
    new 
HandleSQL_Query;
    
    
SQL_Query SQL_PrepareQuery(SQL_Connection"UPDATE `r` SET (`g` = '%i', `x` = '%i', `k` = '%i', `d` = '%i') WHERE (`r`.`n` = '%s')"Golds[id], XP[id], Kills[id], Deaths[id], nick);
    
SQL_Execute(SQL_Query);
    
    
SQL_FreeHandle(SQL_Query);
    
SQL_FreeHandle(SQL_Connection);

BaD CopY is offline
Send a message via Yahoo to BaD CopY Send a message via Skype™ to BaD CopY
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-19-2018 , 13:32   Re: What is more optimized ?
Reply With Quote #2

It is perfectly fine.
__________________
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-19-2018 , 14:04   Re: What is more optimized ?
Reply With Quote #3

You do not need quotes around numerical values in your SQL statement.

`g` = '%i' -> `g` = %i

Should be fine with this:

Code:
UPDATE r SET (g = %i, x = %i, k = %i, d = %i) WHERE ( r.n = '%s' )
__________________

Last edited by Bugsy; 08-19-2018 at 14:05.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-19-2018 , 14:58   Re: What is more optimized ?
Reply With Quote #4

PHP Code:
enum _:PlayerData
{
    
Golds,
    
Rank,
    
XP,
    
Kills,
    
Deaths
}

new 
g_ePlayerData[33][PlayerData
I don't know if it's more optimized or not, but it's easier to use.
__________________

Last edited by OciXCrom; 08-19-2018 at 14:58.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-19-2018 , 16:05   Re: What is more optimized ?
Reply With Quote #5

Agree with oxixcrom, use enum sized arrays instead of individual arrays if the data is associated with the same object, in this case a player. Much more organized.
__________________
Bugsy is offline
BaD CopY
Senior Member
Join Date: Oct 2014
Location: Home
Old 08-22-2018 , 15:46   Re: What is more optimized ?
Reply With Quote #6

Okay, what about sql saving ? What is best time to call sql save function (ex. onDeath, onSpawn, client_diconnect, plugin_end, ... ?)

EDIT:
What about Queries, SQL_PrepareQuery or SQL_ThreadQuery ? Now every time when I call sql function, plugin call database. How to reduce database calling ?

Last edited by BaD CopY; 08-22-2018 at 15:50.
BaD CopY is offline
Send a message via Yahoo to BaD CopY Send a message via Skype™ to BaD CopY
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-22-2018 , 15:49   Re: What is more optimized ?
Reply With Quote #7

If it's a threaded query then it doesn't matter.
__________________

Last edited by klippy; 08-22-2018 at 15:49.
klippy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-22-2018 , 17:31   Re: What is more optimized ?
Reply With Quote #8

Save it when a client disconnects, load it on connect.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 04:32.


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