Raised This Month: $ Target: $400
 0% 

something with classes


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
st0rmstan
Member
Join Date: May 2007
Old 05-21-2007 , 17:54   something with classes
Reply With Quote #1

I am starting to code, and I want to have a basic Player Class Chooser plugin for my first modification.
The code so far for this is:
Code:
#include <amxmodx> 
#include <amxmisc> 
#include <cstrike> 
#include <fun> 
#include <vault>

#define CLASS_NOTHING 0
#define CLASS_DOG 1
#define CLASS_CAT 2
#define CLASS_HORSE 3
#define CLASS_COW 4

#define MAXCLASSES 5

new PlayerClass[33] new PlayerXP[33] new PlayerLevel[33]

new const CLASSES[MAXCLASSES][] = {     
    "None",     
    "Dog",     
    "Cat",     
    "Horse",     
    "Cow" 
}

new msgtext

//Lets say we have 6 levels now.. 
new const LEVELS[6] = {     
    100, //100 XP for level 1     
    200, //200 XP for level 2     
    400, //Etc..     
    800,     
    1600,     
    3200 
}

public plugin_init()
{
    register_plugin("Animal Mod", "1.0", "XunTric")

    register_cvar("sv_animalmod", "1")

    register_event("DeathMsg", "DeathMsg", "a")

    register_cvar("xp_per_kill", "20")

    register_cvar("SaveXP", "1")
    
    register_menucmd(register_menuid("menu_ChooseAnimal"),1023,"DoChooseAnimal"); 

    register_event("ResetHUD", "ResetHud", "b")

    msgtext = get_user_msgid("StatusText")

    register_clcmd("say /changeanimal", "ChangeAnimal")

    register_clcmd("say_team /changeanimal", "ChangeAnimal")
}

public SaveXP(id)
{
    new authid[32]; 
    get_user_authid(id,authid,31); 

    new vaultkey[64], vaultdata[64]; 

    //Save their class
    format(vaultkey,63,"ANIMAL-%s-class",authid); 
    format(vaultdata,63,"%d",PlayerClass[id]); 
    set_vaultdata(vaultkey,vaultdata); 

    //Save their XP
    format(vaultkey,63,"ANIMAL-%s-xp",authid); 
    format(vaultdata,63,"%d",PlayerXP[id]); 
    set_vaultdata(vaultkey,vaultdata); 

    //Save their level
    format(vaultkey,63,"ANIMAL-%s-level",authid); 
    format(vaultdata,63,"%d",PlayerLevel[id]); 
    set_vaultdata(vaultkey,vaultdata);
}

public LoadXP(id)
{
    new authid[32]; 
    get_user_authid(id,authid,31); 

    new vaultkey[64], vaultdata[64]; 

    //Load their class
    format(vaultkey,63,"ANIMAL-%s-class",authid); 
    get_vaultdata(vaultkey,vaultdata,63); 
    PlayerClass[id] = str_to_num(vaultdata); 

     //Load their XP
    format(vaultkey,63,"ANIMAL-%s-xp",authid); 
    get_vaultdata(vaultkey,vaultdata,63); 
    PlayerXP[id] = str_to_num(vaultdata); 

    //Load their level
    format(vaultkey,63,"ANIMAL-%s-level",authid); 
    get_vaultdata(vaultkey,vaultdata,63);
    PlayerLevel[id] = str_to_num(vaultdata);  
} 

public client_connect(id)
{
    //Only load their XP if our SaveXP cvar is 1.
    if(get_cvar_num("SaveXP") == 1) {
       
         LoadXP(id)

         //Add a message if you want....
         client_print(id, print_chat, "[Animal Mod] XP Loaded!")
         client_print(id, print_chat, "[Animal Mod] You are a %s with level %s and %s XP", PlayerClass[id], PlayerLevel[id], PlayerXP[id])
    }
}

public client_disconnect(id)
{
    //Only save their XP if our SaveXP cvar is 1.
    if(get_cvar_num("SaveXP") == 1) {
       
        SaveXP(id)
    }
}

//menu-Call it whatever you want...
stock ChooseAnimal(id)
{
    new menu[192] 

    new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3 

    format(menu, 191, "Animal Mod: Choose Animal^n^n1. Dog^n2. Cat^n3. Horse^n4. Cow^n^n0. Exit")

    show_menu(id, keys, menu, -1, "menu_ChooseAnimal") 

    return PLUGIN_CONTINUE
}

public DoChooseAnimal(id, key)
{
    // Remeber that the keys starts on 0...
    if(key == 0) {
       
         //Lets check if the player allready has Dog...
         if(PlayerClass[id] == CLASS_DOG) {
         
              //Make a message here if you want...
              client_print(id, print_chat, "[Animal Mod] You are allready a Dog! Choose something else!")
              
              //Open the menu again...
              ChooseAnimal(id)
              
              //Exit...
              return PLUGIN_HANDLED
         }        

         //Now, if the player didnt have dog allready, we'll set his class to dog.
         PlayerClass[id] = CLASS_DOG
         
         //Make a message if you want...
         client_print(id, print_chat, "[Animal Mod] You are now a Dog!")
    }        
    
    //Im doing the same on all other buttons...
         
    if(key == 1) {
         
         if(PlayerClass[id] == CLASS_CAT) {
              
              client_print(id, print_chat, "[Animal Mod] You are allready a Cat! Choose something else!")
              ChooseAnimal(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_CAT
         client_print(id, print_chat, "[Animal Mod] You are now a Cat!")
    }
    
    if(key == 2) {
         
         if(PlayerClass[id] == CLASS_HORSE) {
              
              client_print(id, print_chat, "[Animal Mod] You are allready a Horse! Choose something else!")
              ChooseAnimal(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_HORSE
         client_print(id, print_chat, "[Animal Mod] You are now a Horse!")
    }    

    if(key == 3) {
         
         if(PlayerClass[id] == CLASS_COW) {
              
              client_print(id, print_chat, "[Animal Mod] You are allready a Cow! Choose something else!")
              ChooseAnimal(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_COW
         client_print(id, print_chat, "[Animal Mod] You are now a Cow!")
    }
      
    //Show new HUD after picking class.
    //Ill get back to this later...
    ShowHUD(id)
    
    return PLUGIN_HANDLED
}

public ResetHUD(id)
{
    //Lets check if "sv_animalmod" is on. If its off, we'll stop the function.
    if(get_cvar_num("sv_animalmod") == 0) {
         return PLUGIN_HANDLED
    }

//Lets check if the player has no animal.
    if(PlayerClass[id] == CLASS_NOTHING) {
    
         //If the player doesnt have a animal;
         //Open the choose animal menu for him.
         ChooseAnimal(id)
         return PLUGIN_HANDLED
    }
    
    return PLUGIN_HANDLED
}

public DeathMsg() //Note that i only had (), and not (id)
{
    //Lets check if "sv_animalmod" is on. If its off, we'll stop the function.
    if(get_cvar_num("sv_animalmod") == 0) {
         return PLUGIN_HANDLED
    }
    
    //Now we create a "attacker" varriable. So the XP will be given to the killer, and not all players on the server.
    new attacker = read_data(1)
    
    //Now the plugin will check if the attacker doesnt have a class, and if he doesnt, the function will stop.
    if(PlayerClass[attacker] == CLASS_NOTHING) {
         return PLUGIN_HANDLED
    }
    
    //Now lets see if the attacker allready has level 6, and doesnt need more XP, and if he is, stop the function.
    //You can remove this if you want, and let the player get as much XP he want. But we wont get more than level 6 anyway.
    if(PlayerLevel[attacker] == 6) {
         return PLUGIN_HANDLED
    }
    
    //Now we can add XP to the attacker.        
    PlayerXP[attacker] += get_cvar_num("XP_per_kill") //Add the amout of XP you have on the "XP_per_kill" cvar.
    
    //Now we check if the attacker has enough XP for a new level. And if he has, we add it.
    if(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) {
     
         //Add his level...
         PlayerLevel[attacker] += 1
         
         //Now you can make a "congratualtions" message if you want...
         client_print(attacker, print_chat, "[Animal Mod] Congratulations! You are now level %i!", PlayerLevel[attacker])
         
         //Lets save his XP every time he gets a level incase the server crashes or something. So they wont loose it all.
         if(get_cvar_num("SaveXP") == 1) {
 
              SaveXP(attacker)
         }


         //Show His New Level on the HUD message.
         //Ill get back to this later...
         ShowHUD(attacker)
    }   
    
    //Show new HUD if you didnt get level too. (To show the new XP)
    //Ill get back to this later...
    ShowHUD(attacker)
    
    return PLUGIN_CONTINUE
}

public ShowHUD(id)    
{ 
    new HUD[51] 
    
    //This is the stuff that will actually show in game.
    format(HUD, 50, "[%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
}
But now, I want to make them all start with 200 HP. Can anybody give me the edited code for that, so that I can examine it and tell what you did? Thanks a ton
st0rmstan is offline
 



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 10:31.


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