How to fix this code? Xp isn't loading/saving
Xp isn't loading/saving... :(
/* Credits: xuntric - for his great tutorial jtp10181 Charr */ #include <amxmodx> #include <amxmisc> #include <fun> #include <cstrike> #include <nvault> #include <engine> #define CLASS_NOTHING 0 #define CLASS_VIPAR 1 #define CLASS_SPEEDMAN 2 #define CLASS_MEDIC 3 #define CLASS_COW 4 #define MAXCLASSES 5 new PlayerClass[33] new PlayerXP[33] new PlayerLevel[33] new ip[32] new vaultkey[64] new vaultdata[64] // blood sprites new blood_normal new blood_bleed new gStatusText //nVault //new sxnV new const CLASSES[MAXCLASSES][] = { "None", "VIPAR", "SPEEDMAN", "MEDIC", "COW" } new msgtext new const LEVELS[7] = { 50, 100, 200, 400, 800, 1600, 3200 } public plugin_precache() { blood_normal = precache_model("sprites/xu/normal_bl.spr") blood_bleed = precache_model("sprites/xu/blood_bleed.spr") } public plugin_init() { register_plugin("Xp xu", "0.2", "Hip_Hop_x") new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|M ENU_KEY_4 register_menucmd(register_menuid("Wich power?"),keys,"principal_menu"); register_cvar("sv_xumod", "1", 0) register_cvar("XP_per_kill", "6") register_cvar("XP_per_death", "1") register_cvar("sv_xu_ev", "1") register_clcmd("say /xp","infoXp") register_clcmd("say_team /xp","infoXp") register_clcmd("say /xum","showPowerMenu") register_event("DeathMsg", "DeathMsg", "a") register_event("DeathMsg","blood_efect","a") register_event("ResetHUD", "ResetHud", "b") gStatusText = get_user_msgid("StatusText") msgtext = get_user_msgid("StatusText") register_srvcmd("sv_evolution", "evolution") //sxnV = nvault_open("sx_nVault") to load using nvault } // public //************************ save/load users by ip ********************************* public SaveXP(id) { get_user_ip(id, ip, 31, 1) /*format(vaultkey,63,"Xu mod - %s - class",ip); format(vaultdata,63,"%d",PlayerClass[id]); set_vaultdata(vaultkey, vaultdata) format(vaultkey,63,"Xu mod - %s - xp",ip); format(vaultdata,63,"%d",PlayerXP[id]); set_vaultdata(vaultkey,vaultdata); format(vaultkey,63,"Xu mod - %s - level",ip); format(vaultdata,63,"%d",PlayerLevel[id]); set_vaultdata(vaultkey,vaultdata); */ format(vaultdata, 63, "%d - %d - %d", PlayerClass[id], PlayerXP[id], PlayerLevel[id]) format(vaultkey, 63, "Xu mod: %s", ip) set_vaultdata(vaultdata, vaultkey) } public LoadXP(id) { get_user_ip(id, ip, 31, 1) /* //format(vaultkey,63,"Xu mod - %s - class",ip); get_vaultdata(vaultkey,vaultdata,63); PlayerClass[id] = str_to_num(vaultdata); //format(vaultkey,63,"Xu mod - %s - xp",ip); get_vaultdata(vaultkey,vaultdata,63); PlayerXP[id] = str_to_num(vaultdata); //format(vaultkey,63,"Xu mod - %s -level",ip); get_vaultdata(vaultkey,vaultdata,63); PlayerLevel[id] = str_to_num(vaultdata); */ get_vaultdata(vaultkey,vaultdata,63) PlayerClass[id] = str_to_num(vaultdata) PlayerXP[id] = str_to_num(vaultdata) PlayerLevel[id] = str_to_num(vaultdata) } public client_connect(id) { if(get_cvar_num("sv_xumod") == 0) { return PLUGIN_HANDLED } else { ShowHUD(id) set_hudmessage(200, 100, 0, -1.0, 0.15, 0, 1.0, 21.0, 0.1, 0.2, -1) show_hudmessage(0, "User connected") LoadXP(id) client_print(id, print_chat, "[Xu message] XP Loaded!") client_print(id, print_chat, "[Xu message] You are using power %s with level %s and %s XP", PlayerClass[id], PlayerLevel[id], PlayerXP[id]) } return PLUGIN_HANDLED } public client_disconnect(id) { { set_hudmessage(200, 100, 40, -1.0, 0.15, 0, 1.0, 5.0, 0.1, 0.2, 2) show_hudmessage(0,"User disconnected") } if(get_cvar_num("sv_xumod") == 0) { return PLUGIN_HANDLED } if(get_cvar_num("sv_xumod") == 1) { SaveXP(id) } return PLUGIN_CONTINUE } public showPowerMenu(id) { new menu[192] new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|M ENU_KEY_4 format(menu, 191, "Chose power?^n^n1. Subject 47^n2. Bleash^n3. Xu Creature^n4. Project Co^n^n0. Exit") show_menu(id, keys, menu, 20, "principal_menu") return PLUGIN_CONTINUE } public principal_menu(id, key) { if(key == 0) { return PLUGIN_HANDLED } if(key == 1) { if(PlayerClass[id] == CLASS_VIPAR) { client_print(id, print_chat, "[Xu message] You are allready Subject 47! Choose something else!") showPowerMenu(id) return PLUGIN_HANDLED } PlayerClass[id] = CLASS_VIPAR client_print(id, print_chat, "[Xu message] You are now Subject 47!") set_user_armor(id,150) } else if(key == 2) { if(PlayerClass[id] == CLASS_SPEEDMAN) { client_print(id, print_chat, "[Xu message] You are allready Bleash! Choose something else!") showPowerMenu(id) return PLUGIN_HANDLED } PlayerClass[id] = CLASS_SPEEDMAN client_print(id, print_chat, "[Xu message] You are now Bleash!") set_user_maxspeed(id,390) } else if(key == 3) { if(PlayerClass[id] == CLASS_MEDIC) { client_print(id, print_chat, "[Xu message] You are allready Xu Creature! Choose something else!") showPowerMenu(id) return PLUGIN_HANDLED } PlayerClass[id] = CLASS_MEDIC client_print(id, print_chat, "[Xu message] You are now Xu Creature!") set_user_health(id,125) } else if(key == 4) { if(PlayerClass[id] == CLASS_COW) { client_print(id, print_chat, "[Xu message] You are allready Project Co! Choose something else!") showPowerMenu(id) } PlayerClass[id] = CLASS_COW client_print(id, print_chat, "[Xu message] You are now Project Co!") } /**ShowHUD(id) */ return PLUGIN_HANDLED } public ResetHud(id) { if(PlayerClass[id] == CLASS_NOTHING) { showPowerMenu(id) //return PLUGIN_HANDLED } return PLUGIN_HANDLED } public DeathMsg() { new attacker = read_data(1) new attacker2 = read_data(2) if(get_cvar_num("sv_xumod") == 0) { return PLUGIN_HANDLED } else { if(PlayerClass[attacker] == CLASS_NOTHING || PlayerLevel[attacker] == 8) { return PLUGIN_HANDLED } if (is_user_connected(attacker) == 1 && is_user_connected(attacker2) == 1 && get_user_team(attacker) != get_user_team(attacker2)) { award_xp(attacker,attacker2) SaveXP(attacker) ShowHUD(attacker) } } return PLUGIN_HANDLED } // Show xp left side public write_hud(id) { if (PlayerLevel[id] == 0) PlayerLevel[id] = 1 if (PlayerClass[id] == CLASS_NOTHING ) { return PLUGIN_HANDLED } new msg2[256] if (PlayerClass[id] != CLASS_NOTHING) { format(msg2,255,"[Xu Mod: %i Xp - %i Level - %i Power %s]", PlayerXP[id], PlayerLevel[id], PlayerClass[id]) } message_begin(MSG_ONE, gStatusText,{0,0,0}, id) write_byte(0) write_string(msg2) message_end() } // Get xp.... public award_xp(killer_id,victim_id) { //if (is_user_connected(index) == 1) //{ PlayerXP[killer_id]+=get_cvar_num("XP_per_kill") if(PlayerXP[victim_id] >= 50) { PlayerXP[victim_id]-=get_cvar_num("XP_per_death") } //} write_hud(killer_id) } // Hud msg down left public ShowHUD(id) { new HUD[51] format(HUD, 50, "Power:[%s] Level: %i XP: %i", CLASSES[PlayerClass[id]], PlayerLevel[id], PlayerXP[id]) message_begin(MSG_ONE, msgtext, {0,0,0}, id) write_byte(0) write_string(HUD) message_end() return } // Evolutions public evolution(id) { if (PlayerXP[id] >= 50) { if (PlayerClass[id] == CLASS_VIPAR) { set_user_armor(id,130) } if (PlayerClass[id] == CLASS_SPEEDMAN) { set_user_maxspeed(id,380) } if (PlayerClass[id] == CLASS_MEDIC) { set_user_health(id,130) give_item(id,"item_longjump") } if (PlayerClass[id] == CLASS_COW) { set_user_gravity(id,740) } } // evolution 2 if (PlayerXP[id] >= 100) { if (PlayerClass[id] == CLASS_VIPAR) { set_user_armor(id,150) } if (PlayerClass[id] == CLASS_SPEEDMAN) { set_user_maxspeed(id, 390) } if (PlayerClass[id] == CLASS_MEDIC) { set_user_health(id,150) } if (PlayerClass[id] == CLASS_COW) { set_user_gravity(id,700) } } // evolution 3 if (PlayerXP[id] >= 200) { if (PlayerClass[id] == CLASS_VIPAR) { set_user_armor(id,175) } if (PlayerClass[id] == CLASS_SPEEDMAN) { set_user_maxspeed(id,400) //get_cvar_num("invisibleNade") } if (PlayerClass[id] == CLASS_MEDIC) { set_user_health(id,170) set_user_armor(id, 115) } if (PlayerClass[id] == CLASS_COW) { set_user_gravity(id, 700) set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,20) user_silentkill(id) } } } //The xp message public infoXp(id) { //show_motd(id,"/addons/amxmodx/plugins/xu/motd.txt","Xu mod help") client_print(id, print_chat, "[Xu message] You have %i xp",PlayerXP[id]) } // ************************************** The blood colors **************************** public headshot_color_red(origin[3]) { // Blood spray, 5 times for (new i = 0; i < 5; i++) { message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(101) write_coord(origin[0]) write_coord(origin[1]) write_coord(origin[2]+30) write_coord(random_num(-20,20)) write_coord(random_num(-20,20)) write_coord(random_num(50,300)) write_byte(70) // the color write_byte(random_num(100,200)) message_end() } } // small blood decal static blood_decal_small(origin[3],num) { static const blood_small[7] = {190,191,192,193,194,195,197} for (new j = 0; j < num; j++) { message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(116) write_coord(origin[0]+random_num(-100,100)) write_coord(origin[1]+random_num(-100,100)) write_coord(origin[2]-36) write_byte(blood_small[random_num(0,6)]) message_end() } } // Big blood decal static blood_decal_large(origin[3],num) { // Blood decals static const blood_large[2] = {204,205} // Large splash for (new i = 0; i < num; i++) { message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(116) //TE_WORLDDECAL from const.h write_coord(origin[0]+random_num(-50,50)) write_coord(origin[1]+random_num(-50,50)) write_coord(origin[2]-36) write_byte(blood_large[random_num(0,1)]) // index message_end() } } public blood_red(origin[3]) // stomach hitbox { message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(115) write_coord(origin[0]+random_num(-20,20)) write_coord(origin[1]+random_num(-20,20)) write_coord(origin[2]+random_num(-20,20)) write_short(blood_normal) // bleed write_short(blood_bleed) write_byte(248) write_byte(14) message_end() } // ******************* The blood efect for CLASS_MEDIC (xu creature) ********************* public blood_efect() { new origin[3] new sWeapon[32] new id = read_data(2) new Headshot = read_data(3) read_data(4,sWeapon,31) if (Headshot) { if(PlayerClass[id] == CLASS_MEDIC) { get_user_origin(id,origin) headshot_color_red(origin) blood_decal_large(origin,2) blood_decal_small(origin,5) } } if( is_user_alive(id) ) { blood_decal_small(origin,12) blood_decal_large(origin,6) } } |
Re: How to fix this code?
You need to change your LoadXP Fucntion to this:
Code:
To: Code:
Also keep in mind with that, that PlayerClass, PlayerXP, and PlayerLevel will all be the same value. You should use your commented code to retrive and store your data properly. |
Re: How to fix this code?
Thank you very much, but doesn't work :(. Menu still apears, and i don't get xp after i kill the enemy:(.
|
Re: How to fix this code?
Maybe you spellt something important wrong, I saw some unimportant spelling errors like wich instead of which and allready instead of already. With this I am supposing you just replaced key phrases in Xuntrics code and added extra stuff. One thing I'd suggest is wait for another XP mod tutorial to come out, this one simply doesnt work so well.
|
Re: How to fix this code?
[Xu message] You are .... Also i think this part of code isn't right. public DeathMsg() { if(get_cvar_num("sv_xumod") == 0) { server_print("[Xu message] Xu mod is disabled!") return PLUGIN_HANDLED } else if (get_cvar_num("sv_xumod") == 1) { new attacker = read_data(1) SaveXP(attacker) if(PlayerClass[attacker] == CLASS_NOTHING) { return PLUGIN_HANDLED } if(PlayerLevel[attacker] == 8) { return PLUGIN_HANDLED } PlayerXP[attacker] += get_cvar_num("XP_per_kill") if(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) { PlayerLevel[attacker] += 1 client_print(attacker, print_chat, "[Xu - LEVEL] Congratulations! You are now level %i!", PlayerLevel[attacker]) /*if(get_cvar_num("sv_xumod") == 1) { SaveXP(attacker) } ShowHUD(attacker) */ } ShowHUD(attacker) // return p_c } return PLUGIN_CONTINUE } |
Re: How to fix this code?
Look at these two lines:
Code:
Code:
The second one is redundant, and slightly wasteful. After any if() statement, else will always be the opposite of the if(). That means you can change the second one to: Code:
Also, these two lines can be combined into one: Code:
The one: Code:
The "||" symbol means OR in an if() statement, and "&&" means AND (No quotes) Now, your XP isn't being saved because you save the XP before you modify it. Move this line to: Code:
To after you modify it: Code:
Lastly, this line will spam the console with useless information, so comment it for now. Code:
So, use this: Code:
Keep in mind that your Saving and loading functions still need to be fixed as well. |
Re: How to fix this code?
Thank you for explains and for fixed code .
Could you give me an example how to save/load data using nVaul ? |
Re: How to fix this code?
I tried to improve the mod, but still xp doesn't laod/save :(.
Code:
|
Re: How to fix this code? Xp isn't loading/saving
This should work
Code:
xpSTEAM_ID: = XP HERE Loading: Code:
|
Re: How to fix this code? Xp isn't loading/saving
Thx, nowI think saving/loading xp problme is solved. Mod still doesn't work :(. If i kill somebody i still don't get xp. I think here is the last problem: Code:
|
| All times are GMT -4. The time now is 08:01. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.