Raised This Month: $ Target: $400
 0% 

Need Help with Save XP and Load XP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
desert
Junior Member
Join Date: Jan 2006
Location: Canada
Old 07-21-2007 , 21:33   Re: Need Help with Save XP and Load XP
Reply With Quote #1

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)
}
__________________
Predator Mod v1.0 - [==========] 80% done. need a suicide bomber script for predator skill only.
desert 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 21:26.


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