Member
Join Date: Aug 2016
Location: Việt Nam
|
03-22-2017
, 09:21
I need some help in saving data
|
#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(PLUGIN, VERSION, AUTHOR) 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(0, print_chat, "[VNF] %s vua len rank %s ._.", name, rankz[vg_rank[id]]) vg_rank[id] = vg_rankcandat[id]++ checkrankcandat(id) } } public checkrankcandat(id) { if ( !is_user_connected(id) ) return for (new i = 0; i < charsmax(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(id, steam,31) replace_all(steam, 31, "STEAM_0:0:", "") replace_all(steam, 31, "STEAM_0:1:", "") replace_all(steam, 31, "VALVE_0:4:", "") get_user_name(id,name,31) replace_all(name, charsmax(name), " ", "") formatex(data,127,"%s %d %d",name, vg_exp[id], vg_rank[id]) SaveData(file, steam, data) } public Load(id) { new data[128] new steam[32],name[32] get_user_authid(id, steam,31) replace_all(steam, 31, "STEAM_0:0:", "") replace_all(steam, 31, "STEAM_0:1:", "") replace_all(steam, 31, "VALVE_0:4:", "") LoadData(file, steam, data, 127) new exp[6], rankh[6] parse(data, name,32, exp, 6) new a = str_to_num(exp) new b = 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(readdata, steam, 31, data, 40) 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(id, steam2,31) replace_all(steam2, 31, "STEAM_0:0:", "") replace_all(steam2, 31, "STEAM_0:1:", "") replace_all(steam2, 31, "VALVE_0:4:", "") new id2 = str_to_num(steam2) for(new i = 0; i <= count; i++) { 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(readdata, steam, 31, data, 40) 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(motd, sizeof 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 x = 0; x < 10; x++) { steam2 = top[x][0]; formatex(key, 31, "%d", steam2) LoadData(file, key, data2, 40) parse(data2, name2,31,gp2,7) iLen += formatex(motd[iLen], (sizeof motd - 1) - iLen,"%d %-22.22s %d <hr>", x + 1, name2, top[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(player, PEV_SPEC_TARGET) if (!is_user_alive(player)) return; } set_hudmessage(0, 255, 0, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1) if (player != ID_SHOWHUD) { new player_name[32] get_user_name(player, player_name, charsmax(player_name)) ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "%s^nRank: %s - Exp:%d/%d ^nHP: %d - AP: %d", player_name, rankz[vg_rank[player]],vg_exp[player],expct[vg_rankcandat[player]], get_user_health(player), get_user_armor(player)) } else { ShowSyncHudMsg(ID_SHOWHUD, g_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", where, file); formatex(c, 1023, "^"%s^" ^"%s^"", key, data); if(!dir_exists(where)) mkdir(where); if(!file_exists(where_)) write_file(where_, "", 0); for(new i; read_file(where_, i, txt, 499, len);i++) { parse(txt, arg1, 63); if(equal(key, arg1, strlen(arg1))) { write_file(where_, c, i); s++ } else continue; } if(!s) write_file(where_, c, -1); s = 0 }
/* Load */
public LoadData(const file[], const key[], data[], len) { new txt[1101], len, where_[128]; new arg1[64], arg2[1024]; formatex(where_, 127, "%s/%s", where, file) if(!file_exists(where_)) return PLUGIN_CONTINUE for(new i; read_file(where_, i, txt, 1100, len);i++) { parse(txt, arg1, 63, arg2, 1023); if(equal(key, arg1, strlen(arg1))) copy(data, len, arg2); else continue; } return PLUGIN_CONTINUE }
/* Delete */
public DeleteData(const file[], const key[]) {
new txt[1101], len, where_[128]; new arg1[64], arg2[1024]; formatex(where_, 127, "%s/%s", where, file) if(!file_exists(where_)) return PLUGIN_CONTINUE for(new i; read_file(where_, i, txt, 1100, len);i++) { parse(txt, arg1, 63, arg2, 1023); if(equal(key, arg1, strlen(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.
|
|