Raised This Month: $ Target: $400
 0% 

PLEASE HELP MISTAKE WITH pLUGINn x:P BaseD


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xXxOpOpxXx
Senior Member
Join Date: Aug 2007
Old 10-14-2007 , 04:17   PLEASE HELP MISTAKE WITH pLUGINn x:P BaseD
Reply With Quote #1

Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <vault> 

#define PLUGIN "ELEMENT"
#define VERSION "1.0"
#define AUTHOR "Pr3da7oR"


#define CLASS_NOTHING
#define CLASS_WATER 1
#define CLASS_AIR 2
#define CLASS_FIRE 3
#define CLASS_EARTH 4
#define CLASS_WIND 5
#define CLASS_DARK 6
#define CLASS_LIGHT 7
#define CLASS_ELEMENT 8

#define MAXCLASSES 9
// I set MAXCLASSES to 9, since we have 9 classes 

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

new const CLASSES[MAXCLASSES][] = 
{
    "None",
    "Water",
    "Air",
    "Fire",
    "Earth"
    "Wind",
    "Dark",
    "Light",
    "Element"
}

new msgtext

//Lets say we have 40 levels now..
new const LEVELS[40] = {
    700, //700 XP for level 1
    1200, //200 XP for level 2
    2000, //Etc..
    3500,
    5000,
    8500,
    11000,
    15000,
    18000,
    23000,
    27000,
    30000,
    34000,
    37000,
    41000,
    45000,
    48000,
    52000,
    56000,
    57000,
    60000,
    64000,
    71000,
    73000,
    76000,
    78000,
    81000,
    83000,
    85000,
    89000,
    95000,
    100000,
    105000,
    110000,
    115000,
    120000,
    125000,
    130000,
    135000,
    140000    
}


public plugin_init()
{    
    //I'll create a on/off cvar for the mod... You dont have to add this.
    register_cvar("sv_element", "1")
    
    //Now we register the DeathMsg event. This is where we can add XP when you kill somebody.
    register_event("DeathMsg", "DeathMsg", "a") 
    //Note that i registered it as "a"; global event
    
    //Now we register a "XP Per Kill" cvar...
    //Now I made 20 xp per kill.
    register_cvar("xp_element", "20")

    //Lets register a SaveXP toggle cvar.
    register_cvar("SaveXP", "1")
    
    //Lets register a menu to choose ELEMENT with...
    register_menucmd(register_menuid("menu_choose_element"),1023,"DoChooseELEMENT"); 
    
    //ResetHUD event... (Check if user has no class)
    register_event("ResetHUD", "ResetHud", "b")
    
    //Something for ShowHUD... Will explain later.
    msgtext = get_user_msgid("StatusText") 

    //Lets make a "Change ELEMENT" cmd for players.
    //I just lead it to the change ELEMENT menu.
    //Ill get back to the menu later.
    register_clcmd("say /changemental", "ChangeELEMENT")
    register_clcmd("say_team /changemental", "ChangeELEMENT")
}

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

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

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

    //Save their level
    format(vaultkey,63,"ELEMENT-%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,"ELEMENT-%s-class",authid); 
    get_vaultdata(vaultkey,vaultdata,63); 
    PlayerClass[id] = str_to_num(vaultdata); 

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

    //Load their level
    format(vaultkey,63,"ELEMENT-%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, "[ELEMENT MOD] XP Loaded!")
         client_print(id, print_chat, "[ELEMENT 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)
    }
}

//Call it whatever you want...
stock ChooseELEMENT(id)
{
    new menu[192] 
    
    //Add keys for how many classes you have + exit key.
    new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|

    
    //Here we write the menu options..
    format(menu, 191, "ELEMENT MOD: Choose ELEMENT^n^n1. WATER^n2. AIR^n3. FIRE^n4. EARTH^n5. WIND^n6. DARK^n7. LIGHT^n8. ELEMENT^n9. Exit^n^n0. Exit") 
    
    //We created a menu in plugin_init() and now we make the plugin know that its this menu it has to show.
    show_menu(id, keys, menu, -1, "menu_ChooseELEMENT") 
    
    return PLUGIN_CONTINUE
}


public DoChooseELEMENT(id, key)
{
    // Remeber that the keys starts on 0...
    if(key == 0) {
       
         //Lets check if the player allready has WATER...
         if(PlayerClass[id] == CLASS_WATER) {
         
              //Make a message here if you want...
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the Element of WATER! Choose another")
              
              //Open the menu again...
              ChooseELEMENT(id)
              
              //Exit...
              return PLUGIN_HANDLED
         }        

         //Now, if the player didnt have dog allready, we'll set his class to dog.
         PlayerClass[id] = CLASS_WATER
         
         //Make a message if you want...
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of WATER!")
    }        
    
    //Im doing the same on all other buttons...
         
    if(key == 1) {
         
         if(PlayerClass[id] == CLASS_WATER) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of WATER!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_AIR
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of WATER!")
    }
    
    if(key == 2) {
         
         if(PlayerClass[id] == CLASS_AIR) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of AIR!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_AIR
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of AIR!")
    }    

    if(key == 3) {
         
         if(PlayerClass[id] == CLASS_FIRE) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of FIRE!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_FIRE
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of FIRE!")
    }
      
      
      if(key == 5) {
         
         if(PlayerClass[id] == CLASS_EARTH) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of EARTH!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_EARTH
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of EARTH!")
    }
      
      
      
      if(key == 6) {
         
         if(PlayerClass[id] == CLASS_WIND) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of WIND!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_WIND
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of WIND!")
    }
      
      
      if(key == 7) {
         
         if(PlayerClass[id] == CLASS_DARK) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of DARK!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_DARK
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of DARK!")
    }
      
      
      if(key == 8) {
         
         if(PlayerClass[id] == CLASS_LIGHT) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the element of LIGHT!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_LIGHT
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the element of LIGHT!")
    }
      
      
      
      if(key == 9) {
         
         if(PlayerClass[id] == CLASS_ELEMENT) {
              
              client_print(id, print_chat, "[ELEMENT MOD] You are already with the V ELEMENT!")
              ChooseELEMENT(id)
              return PLUGIN_HANDLED
         }
                   
         PlayerClass[id] = CLASS_ELEMENT
         client_print(id, print_chat, "[ELEMENT MOD] You are now with the V ELEMENT!")
    }
      
      
    //Show new HUD after picking class.
    //Ill get back to this later...
    ShowHUD(id)
    
    return PLUGIN_HANDLED
}



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

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




public DeathMsg() //Note that i only had (), and not (id)
{
    //Lets check if "sv_element" is on. If its off, we'll stop the function.
    if(get_cvar_num("sv_element") == 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, "[ELEMENT 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
}
Could you tell me were I mistake ?
xXxOpOpxXx is offline
Send a message via Skype™ to xXxOpOpxXx
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 10-14-2007 , 09:23   Re: PLEASE HELP MISTAKE WITH pLUGINn x:P BaseD
Reply With Quote #2

Next time post in the correct section
__________________
|<-- Retired from everything Small/Pawn related -->|
You know when you've been Rango'd
Orangutanz is offline
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 10-14-2007 , 09:51   Re: PLEASE HELP MISTAKE WITH pLUGINn x:P BaseD
Reply With Quote #3

line 38 error:

Code:
new const CLASSES[MAXCLASSES][] = {     "None",     "Water",     "Air",     "Fire",     "Earth", // comma was missing here     "Wind",     "Dark",     "Light",     "Element" }

line 369 error (fix on line 14):

Code:
#define CLASS_NOTHING 0 // 0 was missing here #define CLASS_WATER 1 #define CLASS_AIR 2 #define CLASS_FIRE 3 #define CLASS_EARTH 4 #define CLASS_WIND 5 #define CLASS_DARK 6 #define CLASS_LIGHT 7 #define CLASS_ELEMENT 8

Compiles fine.
__________________
alien is offline
Send a message via ICQ to alien
xXxOpOpxXx
Senior Member
Join Date: Aug 2007
Old 11-22-2007 , 00:11   Re: PLEASE HELP MISTAKE WITH pLUGINn x:P BaseD
Reply With Quote #4

ty
xXxOpOpxXx is offline
Send a message via Skype™ to xXxOpOpxXx
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 01:22.


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