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

I need some help in saving data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VINAGHOST
Member
Join Date: Aug 2016
Location: Việt Nam
Old 03-22-2017 , 09:21   I need some help in saving data
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <savev>
#include <hamsandwich>
#include <cstrike>
#include <fakemeta>

#define PLUGIN "Rank"
#define VERSION "1.3"
#define AUTHOR "VINAGHOST"

#define TASK_SHOWHUD 100
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)

const PEV_SPEC_TARGET pev_iuser2

const Float:HUD_SPECT_X 0.6
const Float:HUD_SPECT_Y 0.8
const Float:HUD_STATS_X 0.6
const Float:HUD_STATS_Y 0.8

new g_MsgSync

#define HS 5
#define CT 1
new file[] = "rankzomswarm.ini"
new file2[] = "addons/amxmodx/rank/rankzomswarm.ini"

new vg_exp[33], vg_rankcandat[33], vg_rank[33]



new const 
rankz[][] = 
{
    
"Newbie",
    
"Chicken LOL",
    
"Dong doan",
    
"Bac doan",
    
"Vang doan",
    
"Bach kim doan",
    
"Kim cuong doan",
    
"Cao thu",
    
"Thach dau",
    
"Trum server"
}
new const 
expct[] = 
{
    
0,
    
10,
    
50,
    
100,
    
200,
    
500,
    
1000,
    
2000,
    
5000,
    
10000,
    
100000000
}
    
public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_Spawn"player""HamSpawn"1)
    
g_MsgSync CreateHudSyncObj()
    
register_clcmd("say /rankz","rank")
    
register_clcmd("say /topz","top10")
}
public 
HamSpawn(id)
{
    if ( 
is_user_connected(id) )
        
Save(id)
}
public 
checkrank(id)
{
    if ( !
is_user_connected(id) )
        return
    
    if (
vg_exp[id] >= expct[vg_rankcandat[id]])
    {
        new 
name[33]
        
get_user_name(id,name,33)
        
client_print(0print_chat"[VNF] %s vua len rank %s ._."namerankz[vg_rank[id]])
        
        
vg_rank[id] = vg_rankcandat[id]++
        
checkrankcandat(id)
    }
}
public 
checkrankcandat(id)
{
    if ( !
is_user_connected(id) )
        return
    for (new 
0charsmax(expct); i++)
    {
        if (
vg_exp[id] >= expct[i] && vg_exp[id] < expct[i++])
        {
            
vg_rankcandat[id] = i++;
            break;
        }
    }
}
        
        
public 
client_death(killer,victim,wpnindex,hitplace,TK)
{
    if(
TK || killer == victim)
        return 
PLUGIN_HANDLED
    
    
if(hitplace == HIT_HEAD)
    {
        if (
cs_get_user_team(killer) == CS_TEAM_CT
            
vg_exp[killer] = vg_exp[killer] + HS CT
        
else 
            
vg_exp[killer] = vg_exp[killer] + HS
    
}
    else
    {
        if (
cs_get_user_team(killer) == CS_TEAM_CT
            
vg_exp[killer] = vg_exp[killer] + CT
        
else 
            
vg_exp[killer] ++
        
    }
    
checkrank(killer)
    
Save(killer)
    
    return 
PLUGIN_CONTINUE
}
public 
Save(id)
{
    new 
data[128]
    new 
steam[32],name[32]
    
    
get_user_authid(idsteam,31)
    
replace_all(steam31"STEAM_0:0:""")
    
replace_all(steam31"STEAM_0:1:""")
    
replace_all(steam31"VALVE_0:4:""")
    
    
get_user_name(id,name,31)
    
replace_all(namecharsmax(name), " """)
    
    
formatex(data,127,"%s %d %d",namevg_exp[id], vg_rank[id])
    
SaveData(filesteamdata)
}
public 
Load(id)
{
    new 
data[128]
    new 
steam[32],name[32]
    
    
get_user_authid(idsteam,31)
    
replace_all(steam31"STEAM_0:0:""")
    
replace_all(steam31"STEAM_0:1:""")
    
replace_all(steam31"VALVE_0:4:""")
    
    
LoadData(filesteamdata127)
        
    new 
exp[6], rankh[6]
    
    
parse(dataname,32exp6)
    
    new 
str_to_num(exp)
    new 
str_to_num(rankh)
    
    
vg_exp[id] = a
    vg_rank
[id] = b
}

public 
client_putinserver(id)
{
    
set_task(2.0"loadep"id)
    if (!
is_user_bot(id))
    {
        
set_task(1.0"ShowHUD"id+TASK_SHOWHUD__"b")
    }
}
public 
loadep(id)
{
    
Load(id)
}
public 
client_disconnect id )
{
    
remove_task(id)
    
Save(id)
    
remove_task(id+TASK_SHOWHUD)
}
public 
rank(id)
{    
    new 
count
    
static top[101][3];
    
    new 
mofile fopen(file2,"r")
    
    if(
mofile)
    {
        new 
readdata[128]
        new 
steam[32], data[41]
        new 
name[32],rankh[8],exp[8]
        
        while(
fgets(mofile,readdata,127))
        {   
            
parse(readdatasteam31data40)
            new 
id str_to_num(steam)
            
top[count][0] = id;
            
            
parse(data,name,31,exp,8,rankh,8)
            new 
exp2 str_to_num(exp)
            new 
rankh2 str_to_num(rankh)
            
top[count][1] = exp2;
            
top[count][1] = rankh2;
            
            
count++;
        }
        
fclose(mofile)
    }
    else
    {
        
server_print("[VNF] Ko the load file")
    }
    
    
SortCustom2D(top,count,"CompareXp");
    
    new 
steam2[32]
    
get_user_authid(idsteam2,31)
    
replace_all(steam231"STEAM_0:0:""")
    
replace_all(steam231"STEAM_0:1:""")
    
replace_all(steam231"VALVE_0:4:""")
    new 
id2 str_to_num(steam2)
    for(new 
0<= counti++)
    {
        if(
top[i][0] == id2)
        {
            
client_print(id,print_chat"[VNF] Ban dung thu %d"i+1)
            
        }
    }
    
}
public 
top10(id)
{
    new 
count
    
static top[101][2];
    
    new 
mofile fopen(file2,"r")
    
    if(
mofile)
    {
        new 
readdata[128]
        new 
steam[32], data[41]
        new 
name[32], exp[8]
        
        while(
fgets(mofile,readdata,127))
        {   
            
parse(readdatasteam31data40)
            new 
id str_to_num(steam)
            
top[count][0] = id;
            
            
parse(data,name,31,exp,7)
            new 
exp2 str_to_num(exp)
            
top[count][1] = exp2;
            
            
count++;
        }
        
fclose(mofile)
    }
    else
    {
        
server_print("[NTC] Ko the load file")
    }
    
    
SortCustom2D(top,count,"CompareXp");
    new 
motd[1501],iLen;
    
iLen formatex(motdsizeof motd 1,"<body bgcolor=#303020 text=#c1b689> <pre>");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s %-22.22s %3s <hr>""#""Name""Exp");
    
    new 
name2[32],steam2,gp2[8];
    new 
key[32], data2[41]
    
    for(new 
010x++)
    {
        
steam2 top[x][0];
        
formatex(key31"%d"steam2)
        
LoadData(filekeydata240)
        
parse(data2name2,31,gp2,7)
        
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%d %-22.22s %d <hr>"1name2top[x][1]);
    }
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"</body></pre>");
    
    
show_motd(id,motd"Top 10 SERVER");
}

public 
CompareXp(elem1[], elem2[])
{
    if(
elem1[1] > elem2[1])
        return -
1;
    else if(
elem1[1] < elem2[1])
        return 
1;
    
    return 
0;
}
public 
ShowHUD(taskid)
{
    new 
player ID_SHOWHUD
    
    
if (!is_user_alive(player))
    {
        
player pev(playerPEV_SPEC_TARGET)
        if (!
is_user_alive(player))
            return;
    }
    
set_hudmessage(02550HUD_SPECT_XHUD_SPECT_Y06.01.10.00.0, -1)    
    
    if (
player != ID_SHOWHUD)
    {
        new 
player_name[32]
        
get_user_name(playerplayer_namecharsmax(player_name))
        
        
ShowSyncHudMsg(ID_SHOWHUDg_MsgSync"%s^nRank: %s - Exp:%d/%d ^nHP: %d - AP: %d",  player_namerankz[vg_rank[player]],vg_exp[player],expct[vg_rankcandat[player]], get_user_health(player), get_user_armor(player))
    }
    else
    {    
        
ShowSyncHudMsg(ID_SHOWHUDg_MsgSync"Rank: %s - Exp: %d/%d^nHP: %d - AP: %d"rankz[vg_rank[player]],vg_rank[player],expct[vg_rankcandat[player]],get_user_health(player), get_user_armor(player))
    }

savev.inc
PHP Code:
#if defined _Save_included
  #endinput
#endif

#include <amxmodx>

new where[]    = "addons/amxmodx/rank"

/* Savev */

public SaveData(const file[], const key[], const data[])
{
    new 
s
    
new c[1024], where_[128], arg1[64], txt[500], len;
    
    
formatex(where_127"%s/%s"wherefile);
    
    
formatex(c1023"^"%s^" ^"%s^""keydata);
    
    if(!
dir_exists(where))
        
mkdir(where);    
        
    if(!
file_exists(where_))
        
write_file(where_""0);
        
    for(new 
iread_file(where_itxt499len);i++)
    {
        
parse(txtarg163);
        
        if(
equal(keyarg1strlen(arg1)))
        {
            
write_file(where_ci); 
            
s++
        }    
        else    
            continue;
    }
    if(!
s)
        
write_file(where_c, -1);
    
0
}

/* Load */

public LoadData(const file[], const key[], data[], len)
{
    new 
txt[1101], lenwhere_[128];
    new 
arg1[64], arg2[1024];
    
    
formatex(where_127"%s/%s"wherefile
    
    if(!
file_exists(where_))
        return 
PLUGIN_CONTINUE
    
for(new iread_file(where_itxt1100len);i++)
    {
        
parse(txtarg163arg21023);
        
        if(
equal(keyarg1strlen(arg1)))
            
copy(datalenarg2); 
        else    
            continue;
    }
    return 
PLUGIN_CONTINUE
}

/* Delete */

public DeleteData(const file[], const key[])
{

    new 
txt[1101], lenwhere_[128];
    new 
arg1[64], arg2[1024];
    
    
formatex(where_127"%s/%s"wherefile
    
    if(!
file_exists(where_))
        return 
PLUGIN_CONTINUE
    
for(new iread_file(where_itxt1100len);i++)
    {
        
parse(txtarg163arg21023);
        
        if(
equal(keyarg1strlen(arg1)))
            
write_file(where_""i);
        else    
            continue;
    }
    return 
PLUGIN_CONTINUE

I complie it fine but when I play then it cannot show right the exp my player in HUD
it show that is 0/0 and rank is Newbie (the first rank) but when I say /topz then it show right player's exp

I cannot find out the mistake
Please help me
Sorry for my bad English ._.

Last edited by VINAGHOST; 03-22-2017 at 09:25.
VINAGHOST 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 19:31.


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