Raised This Month: $ Target: $400
 0% 

[Help] Need add save/load data to SQL


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
newcomer
Member
Join Date: Aug 2011
Old 10-02-2011 , 15:15   [Help] Need add save/load data to SQL
Reply With Quote #1

Here's plugin working, but it only save/load in a text file. Please help me convert it to save/load in SQL (any SQL)

PHP Code:
#define VERSION    "2.0"

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

new bank[33]
new 
configfile[200]
new 
authid[33][32]
new 
pcvar

public plugin_init()
{
    
register_plugin("Simple CS Bank",VERSION,"GHW_Chronic")
    
pcvar register_cvar("bank_save","1")

    new 
configsdir[200]
    
get_configsdir(configsdir,199)
    
format(configfile,199,"%s/cs_bank.ini",configsdir)

    
register_dictionary("GHW_CS_Bank.txt")
}

public 
client_putinserver(id)
{
    if(!
is_user_bot(id)) set_task(5.0,"client_authorized2",id)
}

public 
client_authorized2(id)
{
    
bank[id] = 0
    
if(get_pcvar_num(pcvar))
        
set_task(10.0,"read_file2",id)
    
set_task(0.1,"cpt",id,"",0,"b")
}

public 
client_disconnect(id)
{
    if(!
is_user_bot(id) && get_pcvar_num(pcvar))
        
save_money(id)
}

public 
cpt(id)
{
    if(
is_user_alive(id))
    {
        if(
cs_get_user_money(id)>10000)
        {
            
bank[id]+= cs_get_user_money(id) - 10000
            cs_set_user_money
(id,10000)
        }
        if(
cs_get_user_money(id)<10000)
        {
            if(
bank[id] < 10000 cs_get_user_money(id))
            {
                
cs_set_user_money(id,cs_get_user_money(id)+bank[id])
                
bank[id]=0
            
}
            else
            {
                
bank[id]-=  10000 cs_get_user_money(id)
                
cs_set_user_money(id,10000)
            }
        }
        
set_hudmessage(025500.70.8706.00.10.10.2next_hudchannel(id) )
        
show_hudmessage(id,"%L",id,"MSG_BANK",bank[id])
    }
}

public 
read_file2(id)
{
    if(
is_user_connected(id) && file_exists(configfile))
    {
        
get_user_authid(id,authid[id],31)
        new 
read[32]
        new 
filepointer fopen(configfile,"r")
        while(
fgets(filepointer,read,31))
        {
            
replace(read,31,"^n","")
            if(
equali(read,authid[id]))
            {
                
fgets(filepointer,read,31)
                if(
cs_get_user_money(id)<10000)
                {
                    if(
cs_get_user_money(id) + str_to_num(read)<=10000)
                    {
                        
cs_set_user_money(id,cs_get_user_money(id) + str_to_num(read))
                    }
                    if(
cs_get_user_money(id) + str_to_num(read)>10000)
                    {
                        
bank[id] += (str_to_num(read) + cs_get_user_money(id)) - 10000
                        cs_set_user_money
(id,10000)
                    }
                }
                else
                {
                    
bank[id] += str_to_num(read)
                }
                break;
                
            }
        }
        
fclose(filepointer)
    }
}

public 
save_money(id)
{
    new 
string[32]
    
format(string,31,"%d",bank[id])
    new 
iline
    
new filepointer fopen(configfile,"r")
    if(
filepointer)
    {
        new 
read[32]
        while(
fgets(filepointer,read,31))
        {
            
replace(read,31,"^n","")
            
server_print("%d. %s",i,read)
            if(
equali(read,authid[id]))
            {
                
line=1
                
break;
            }
            
i++
        }
    }
    
fclose(filepointer)
    if(!
linewrite_file(configfile,authid[id],i)
    
write_file(configfile,string,i+1)

Attached Files
File Type: sma Get Plugin or Get Source (GHW_CS_Bank.sma - 530 views - 3.2 KB)
File Type: txt GHW_CS_Bank.txt (155 Bytes, 133 views)

Last edited by newcomer; 10-02-2011 at 15:36.
newcomer is offline
 



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 19:42.


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