AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need Help with Save XP and Load XP (https://forums.alliedmods.net/showthread.php?t=58199)

desert 07-20-2007 21:09

Need Help with Save XP and Load XP
 
Hey, i've been trying to use nvault to create a load and save xp method for my mod but i can't seem to figure it out. mySQL is out of the question because i don't have a database to link it to and vault is just to laggy so i was thinking either nvault or vaultx. if anyones willing to help me set up those methods please pm me or post on this thread.


Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <engine> #include <fun> #include <nvault> new const PLUGIN[] = "AvP" new const VERSION[] = "1.0" new const AUTHOR[] = "Desert" #define CS_ARMOR_NONE 0 #define CS_ARMOR_KEVLAR 1 #define CS_ARMOR_VESTHELM 2 #define VAULTNAME "playerXPinfo" new enable_cvar, avp_hp,avp_ap new neededxp[33] new statusMsg new vault new bandage[33] new g_maxplayers public plugin_init() {  register_plugin(PLUGIN, VERSION, AUTHOR)  enable_cvar =    register_cvar("sv_avp", "1")  avp_hp    = register_cvar("sv_avphp", "500")  avp_ap    = register_cvar("sv_avpap", "500")    register_event("HLTV" , "new_round_start" , "a" , "1=0" , "2=0")    register_clcmd("say /bandage", "buyBandage")  //this stores the message id for sending StatusText messages  statusMsg = get_user_msgid("StatusText")  g_maxplayers = get_maxplayers()    vault = nvault_open(VAULTNAME) } public plugin_end(){  nvault_close(vault) } public plugin_precache(){  precache_model("models/player/predator_t/predator_t.mdl")  precache_model("models/player/predator_ct/predator_ct.mdl")  precache_model("models/player/gign/gign.mdl")  precache_model("models/player/terror/terror.mdl")   } public predator() {  if (get_pcvar_num(enable_cvar) == 1) {   for (new id = 1; id <= g_maxplayers; id++) {    new team = get_user_team(id)        new client_name[33]    get_user_name(id, client_name, 32)        if(is_user_alive(id)) {         if (team == 1) {      cs_set_user_model(id, "predator_t")     }         if (team == 2) {      cs_set_user_model(id, "predator_ct")     }         client_print(id, print_chat, "[AvP] Client: %s Has become a Predator.", client_name)         set_user_health(id, get_pcvar_num(avp_hp))         new CsArmorType:ArmorType     cs_set_user_armor(id, get_pcvar_num(avp_ap),ArmorType)        }         }  }  else {   for (new ids = 1; ids <= g_maxplayers; ids++) {    new team = get_user_team(ids)        if(is_user_alive(ids)) {         if (team == 1) {      cs_set_user_model(ids, "terror")     }         if (team == 2) {      cs_set_user_model(ids, "gign")     }    }   }  } } public new_round_start() {    if (get_pcvar_num(enable_cvar) == 1) {   set_task(1.0 , "predator")   set_task(1.0 , "avp_stats",_,_,_, "b")   set_task(1.0 , "health_loss",_,_,_, "b")   set_task(1.0, "SaveXP",_,_,_,"b")     for( new id = 1; id <= g_maxplayers; id++) {    bandage[id] = 0   }  } } public avp_stats () {  if (get_pcvar_num(enable_cvar) == 1) {   for (new id = 1; id <= g_maxplayers; id++){    if(is_user_alive(id) && !is_user_bot(id)) {     new client_name[33]     get_user_name(id, client_name, 32)         new health = get_user_health(id)         new CsArmorType:ArmorType     new armor = cs_get_user_armor(id, ArmorType)         new levelxp[33], level[33]         neededxp[id]  = (get_user_frags(id) * 20) - (get_user_deaths(id)*10);         if (neededxp[id] < 100) {      levelxp[id] = 100      level[id] = 1     }         if(neededxp[id] >= 100){      levelxp[id] = 200      level[id] = 2      set_user_gravity (id, 0.5)            if (neededxp[id] >= 200) {       levelxp[id] = 400       level[id] = 3       set_user_footsteps(id, 1)             if (neededxp[id] >= 400) {        levelxp[id] = 800        level[id] = 4        set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,20)                if (neededxp[id] >= 800) {         levelxp[id] = 1600         level[id] = 5         set_task(5.0, "health_regen",_,_,_,"b")                 if (neededxp[id] >= 1600) {          neededxp[id] = 1600         }        }       }      }     }         //need to make a place where we can save the message     new message[64];         //this basicly works like the second half of the client_print function (also other functions)     //only instead of sending the message, or doing something with it, it just stores it into your first argument     formatex(message, 64, "[AvP] Health:%d Armor:%d Level:%d XP:%d/%d",health, armor, level[id], neededxp[id], levelxp[id])     message_begin( MSG_ONE, statusMsg, {0,0,0}, id)     write_byte(0)     write_string(message)     message_end()        }   }  } } public buyBandage (id){  bandage[id] = 1 } public health_loss() {  for ( new id = 1; id <= g_maxplayers; id++) {   new health = get_user_health(id)   if(health <= 100) {    if(bandage[id] == 1) {     set_user_health(id, health)    }    else {     set_user_health(id, health - 1)    }   }  } } public health_regen() {  for ( new id = 1; id <= g_maxplayers; id++) {   neededxp[id]  = (get_user_frags(id) * 20) - (get_user_deaths(id)*10);   if (neededxp[id] >= 800) {    if(get_user_health(id) < get_pcvar_num(avp_hp)) {     set_user_health(id,get_user_health(id) + 1)    }    else {     break;    }    if(neededxp[id] >= 1600) {     if(get_user_health(id) < get_pcvar_num(avp_hp) + 500) {      set_user_health(id,get_user_health(id) + 1)     }     else {      break;     }    }   }  } } public SaveXP () {    if (vault == INVALID_HANDLE) {   client_print(0, print_console, "xp was not saved / loaded")  }    for ( new id = 1; id <= g_maxplayers; id++) {   new AuthID[33]   new XP[33]     get_user_authid(id, AuthID, 32)     format(XP,sizeof(XP),"%i",neededxp[id])     nvault_set(vault, AuthID, XP)  } } public client_authorized(id) {  new AuthID[33]  new XP[33]    format(XP,sizeof(XP),"%i",neededxp[id])  get_user_authid(id, AuthID, 32)  nvault_get(vault, AuthID,XP) }





---------------------------------------------------------------------------------------------
Predator Mod v1.0 - [==========] :nono:(80%) done. need save / load xp system

Rolnaaba 07-20-2007 22:59

Re: Need Help with Save XP and Load XP
 
Creating an AvP Mod?

desert 07-20-2007 23:26

Re: Need Help with Save XP and Load XP
 
its not really an AVP mod like urs im assumin because i don't have the alien model. ima switch the name to predator since theres nothing related to aliens in mine. but any chance u know how to work out a saving and loading xp feature?

---------------------------------------------------------------------------------------------
Predator Mod v1.0 - [==========] :nono:(80%) done. need save / load xp system

Rolnaaba 07-21-2007 12:40

Re: Need Help with Save XP and Load XP
 
well my plugin uses SQL methodology that I stole from War3FT so if you want SQL look there. For Vault saving I am using nVault, but it is my first time, so I am not sure if I got the syntax right...

I am asking here: http://forums.alliedmods.net/showthread.php?t=58220

but if I am right something like this:

These are the vault XP saving/loading functions from my AvP Mod.

Code:
public vSaveXP(id) {     #if defined DEBUG         debug_log("Begining: vSaveXP(id), id=%i", id);     #endif     if(pdata[id][PCLASS] == CLASS_NOTHING || is_user_bot(id)     || !get_pcvar_num(pcvar[SAVEXP]) || pdata[id][PXP] == 0)         return PLUGIN_CONTINUE;             //make sure player has steam ID     new playerID[32];     get_user_authid(id, playerID, 31);         if(get_pcvar_num(pcvar[SAVEBY]) == SAVEBY_STEAMID     && equal(playerID, "STEAM_ID_PENDING"))         return PLUGIN_CONTINUE;         new playerIP[20], name[33];     get_user_name(id, name, 32);     get_user_ip(id, playerIP, 19);         new szKey[128], szData[512];             //actual data to be saved.     format(szData, 511, "%d %d %d %d %s", classxp[id][CLASS_PREDATOR],  classxp[id][CLASS_ALIEN], classxp[id][CLASS_MARINE], get_systime(), name);         //the key to the vault data.     if(get_pcvar_num(pcvar[SAVEBY]) == SAVEBY_STEAMID)         format(szKey, 127, "%s", playerID);     else if(get_pcvar_num(pcvar[SAVEBY]) == SAVEBY_IP)         format(szKey, 127, "%s", playerIP);     else         format(szKey, 127, "%s", name);         new vault = nvault_open(PLUGIN_VAULT);         if(vault == INVALID_HANDLE) {         avp_log("ERROR: Unable to open vault file %s", PLUGIN_VAULT);         return PLUGIN_CONTINUED;     }         //saves     nvault_set(vault, szKey, szData);         nvault_close(vault);         vSaveSkill(id);         return PLUGIN_CONTINUE; } public vLoadXP(id) {     #if defined DEBUG         debug_log("Begining: vLoadXP(id), id=%i", id);     #endif     if(!get_pcvar_num(pcvar[SAVEXP]) || !id)         return PLUGIN_CONTINUE;     //check SteamID     new playerID[32], name[33];     get_user_authid(id, playerID, 31);     get_user_name(id, name, 32);         if(get_pcvar_num(pcvar[SAVEBY]) == SAVEBY_STEAMID && equal(playerID, "STEAM_ID_PENDING")) {         client_print(id, print_chat, "%L", LANG_PLAYER, "STEAM_ID_PENDING_LOADING_ERROR", MOD);         avp_log("ERROR: player's(%i) exp could not be loaded. SteamID was: %s", id, playerID);                 return PLUGIN_CONTINUE;     }         new playerIP[20];     get_user_ip(id, playerIP, 19);         new szKey[128], szData[256], data;     //vault key, must unlock it :)     if(get_pcvar_num(pcvar[SAVEBY]) == SAVEBY_STEAMID)         format(szKey, 127, "%s", playerID);     else if(get_pcvar_num(pcvar[SAVEBY]) == SAVEBY_IP)         format(szKey, 127, "%s", playerIP);     else         format(szKey, 127, "%s", name);     new vault = nvault_open(PLUGIN_VAULT);         if(vault == INVALID_HANDLE) {         avp_log("ERROR: Unable to open vault file %s", PLUGIN_VAULT);         return PLUGIN_CONTINUED;     }     data = nvault_get(vault, szKey, szData, 255);             nvault_close(vault);             //ok there is something in vault lets check it out.     if(data) {         new datPredXP[8],  datAlienXP[8],  datMarinXP[8];         //break it up baby, break it up!!         parse(szData, datPredXP, 7, datAlienXP, 7, datMarinXP, 7);         //now I guess I can take this stored data from vault,         //store it in the a temporary storage bin, then store the         //data in that temporary storage bin into another storage bin         //that is a global storage bin and the stored data has been         //stored now in the bigger storage bin and everything is STORED!!         classxp[id][CLASS_PREDATOR]     = str_to_num(datPredXP);         classxp[id][CLASS_ALIEN]    = str_to_num(datAlienXP);         classxp[id][CLASS_MARINE]   = str_to_num(datMarinXP);     } else { //nothing there, so just restart them.         classxp[id][CLASS_PREDATOR]     = (get_pcvar_num(pcvar[STRTLVL]) == 0) ? 0 : LEVELS[get_pcvar_num(pcvar[STRTLVL])-1];         classxp[id][CLASS_ALIEN]    = (get_pcvar_num(pcvar[STRTLVL]) == 0) ? 0 : LEVELS[get_pcvar_num(pcvar[STRTLVL])-1];         classxp[id][CLASS_MARINE]   = (get_pcvar_num(pcvar[STRTLVL]) == 0) ? 0 : LEVELS[get_pcvar_num(pcvar[STRTLVL])-1];     }     ShowHUD(id);         pdata[id][PXP]      = (pdata[id][PCLASS] == CLASS_NOTHING) ? 0 : classxp[id][pdata[id][PCLASS]];     pdata[id][PLEVEL]   = Calc_Player_Level(id);         return PLUGIN_CONTINUE; }

Rolnaaba 07-21-2007 12:50

Re: Need Help with Save XP and Load XP
 
note I defined PLUGIN_VAULT like this:
Code:
#define PLUGIN_VAULT "avp_vault"
forgot to mention that, remember to check that link because I am probably wrong.

desert 07-21-2007 16:06

Re: Need Help with Save XP and Load XP
 
iight will do. is it ok if ur method works that i somewhat use the same method to create my saving and loading xp function?

Rolnaaba 07-21-2007 17:54

Re: Need Help with Save XP and Load XP
 
Open Source, you dont need my permission. But I really dont care lol.

desert 07-21-2007 21:33

Re: Need Help with Save XP and Load XP
 
This is my updated code:

Code:


#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <fun>
#include <nvault>
new const PLUGIN[] = "AvP"
new const VERSION[] = "1.0"
new const AUTHOR[] = "Desert"
#define CS_ARMOR_NONE 0
#define CS_ARMOR_KEVLAR 1
#define CS_ARMOR_VESTHELM 2
#define PLUGIN_VAULT "avp_vault"
new enable_cvar, avp_hp,avp_ap
new neededxp[33]
new statusMsg
new vault
new bandage[33]
new g_maxplayers
public plugin_init() {
 register_plugin(PLUGIN, VERSION, AUTHOR)
 enable_cvar =    register_cvar("sv_avp", "1")
 avp_hp    = register_cvar("sv_avphp", "500")
 avp_ap    = register_cvar("sv_avpap", "500")
 
 register_event("HLTV" , "new_round_start" , "a" , "1=0" , "2=0")
 
 register_clcmd("say /bandage", "buyBandage")
 //this stores the message id for sending StatusText messages
 statusMsg = get_user_msgid("StatusText")
 g_maxplayers = get_maxplayers()
 
}
public plugin_precache(){
 precache_model("models/player/predator_t/predator_t.mdl")
 precache_model("models/player/predator_ct/predator_ct.mdl")
 precache_model("models/player/gign/gign.mdl")
 precache_model("models/player/terror/terror.mdl")
}
public client_putinserver(id) {
 LoadXP(id)
}
public predator() {
 if (get_pcvar_num(enable_cvar) == 1) {
  for (new id = 1; id <= g_maxplayers; id++) {
  new team = get_user_team(id)
 
  new client_name[33]
  get_user_name(id, client_name, 32)
 
  if(is_user_alive(id)) {
   
    if (team == 1) {
    cs_set_user_model(id, "predator_t")
    }
   
    if (team == 2) {
    cs_set_user_model(id, "predator_ct")
    }
   
    client_print(id, print_chat, "[AvP] Client: %s Has become a Predator.", client_name)
   
    set_user_health(id, get_pcvar_num(avp_hp))
   
    new CsArmorType:ArmorType
    cs_set_user_armor(id, get_pcvar_num(avp_ap),ArmorType)
  }     
  }
 }
 else {
  for (new ids = 1; ids <= g_maxplayers; ids++) {
  new team = get_user_team(ids)
 
  if(is_user_alive(ids)) {
   
    if (team == 1) {
    cs_set_user_model(ids, "terror")
    }
   
    if (team == 2) {
    cs_set_user_model(ids, "gign")
    }
  }
  }
 }
}
public new_round_start() {
 
 if (get_pcvar_num(enable_cvar) == 1) {
  set_task(1.0 , "predator")
  set_task(1.0 , "avp_stats",_,_,_, "b")
  set_task(1.0 , "health_loss",_,_,_, "b")
  set_task(1.0, "SaveXP",_,_,_,"b")
 
  for( new id = 1; id <= g_maxplayers; id++) {
  bandage[id] = 0
  }
 }
}
public avp_stats () {
 if (get_pcvar_num(enable_cvar) == 1) {
  for (new id = 1; id <= g_maxplayers; id++){
  if(is_user_alive(id) && !is_user_bot(id)) {
    new client_name[33]
    get_user_name(id, client_name, 32)
   
    new health = get_user_health(id)
   
    new CsArmorType:ArmorType
    new armor = cs_get_user_armor(id, ArmorType)
   
    new levelxp[33], level[33]
   
    neededxp[id]  = (get_user_frags(id) * 20) - (get_user_deaths(id)*10);
   
    if (neededxp[id] < 100) {
    levelxp[id] = 100
    level[id] = 1
    }
   
    if(neededxp[id] >= 100){
    levelxp[id] = 200
    level[id] = 2
    set_user_gravity (id, 0.5)
   
    if (neededxp[id] >= 200) {
      levelxp[id] = 400
      level[id] = 3
      set_user_footsteps(id, 1)
     
      if (neededxp[id] >= 400) {
      levelxp[id] = 800
      level[id] = 4
      set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,20)
     
      if (neededxp[id] >= 800) {
        levelxp[id] = 1600
        level[id] = 5
        set_task(5.0, "health_regen",_,_,_,"b")
       
        if (neededxp[id] >= 1600) {
        neededxp[id] = 1600
        }
      }
      }
    }
    }
   
    //need to make a place where we can save the message
    new message[64];
   
    //this basicly works like the second half of the client_print function (also other functions)
    //only instead of sending the message, or doing something with it, it just stores it into your first argument
    formatex(message, 64, "[AvP] Health:%d Armor:%d Level:%d XP:%d/%d",health, armor, level[id], neededxp[id], levelxp[id])
    message_begin( MSG_ONE, statusMsg, {0,0,0}, id)
    write_byte(0)
    write_string(message)
    message_end()
  }
  }
 }
}
public buyBandage (id){
 bandage[id] = 1
}
public health_loss() {
 for ( new id = 1; id <= g_maxplayers; id++) {
  new health = get_user_health(id)
  if(health <= 100) {
  if(bandage[id] == 1) {
    set_user_health(id, health)
  }
  else {
    set_user_health(id, health - 1)
  }
  }
 }
}
public health_regen() {
 for ( new id = 1; id <= g_maxplayers; id++) {
  neededxp[id]  = (get_user_frags(id) * 20) - (get_user_deaths(id)*10);
  if (neededxp[id] >= 800) {
  if(get_user_health(id) < get_pcvar_num(avp_hp)) {
    set_user_health(id,get_user_health(id) + 1)
  }
  else {
    break;
  }
  if(neededxp[id] >= 1600) {
    if(get_user_health(id) < get_pcvar_num(avp_hp) + 500) {
    set_user_health(id,get_user_health(id) + 1)
    }
    else {
    break;
    }
  }
  }
 }
}
public SaveXP (id) {
 if(!is_user_bot(id)) {
  vault = nvault_open(PLUGIN_VAULT)
 
  if (vault == INVALID_HANDLE) {
  log_amx("Error: unable to open vault file: %s", PLUGIN_VAULT)
  }
  new key[62], value[10], authid[33]
 
  get_user_authid(id, authid, 32)
 
 
  format(key, 61,"%s-points", authid);
  format(value, 9,"%d", neededxp[id]);
  nvault_set(vault, key, value)
 
  nvault_close(vault)
 }
 return 0;
}
public LoadXP(id)
{
 if(!is_user_bot(id)) {
  new vault = nvault_open("PLUGIN_VAULT");
 
  if(vault == INVALID_HANDLE){
  log_amx("Error: unable to open vault file: %s", PLUGIN_VAULT)
  }
 
  new key[100], authid[33];
 
  get_user_authid(id, authid, 32);
 
  formatex(key, 99,"%s-points", authid);
 
  neededxp[id] = nvault_get(vault, key);
  nvault_close(vault);
 
 }
 return 0;
}
public client_disconnect(id) {
 SaveXP(id)
}


Rolnaaba 07-21-2007 22:06

Re: Need Help with Save XP and Load XP
 
looks fine to me, just change two things:
1) change your PLUGIN_VAULT to something other than avp_vault, so our plugins have different vaults.
2)instead of this:
Code:
format(key, 61,"%s-points", authid); format(value, 9,"%d", neededxp[id]); nvault_set(vault, key, value);
I think this would work:
Code:
format(key, 61,"%s-points", authid); nvault_set(vault, key, neededxp[id]);
do it like that because of your extraction of the data in loadXP :D


All times are GMT -4. The time now is 21:26.

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