Raised This Month: $ Target: $400
 0% 

[Correction] XP Mod


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
preetham
Member
Join Date: Sep 2012
Location: India
Old 02-28-2014 , 03:11   [Correction] XP Mod
Reply With Quote #1

Hey Modders! Im a beginner in scripting... i tried to create XP mod of my own by seeing TUT(its author is flyeni6). Im getting an error when compiling.. Help me :\


PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>

#define MAXCLASSES 5

new PlayerXP[33],PlayerLevel[33],PlayerClass[33]
 
//these are for special kills 
new XP_Kill,XP_Knife,XP_Hs,SaveXP
 
//this is for Nvault. so that We can save XP
 
new g_vault  
 
 
new const CLASSES[MAXCLASSES][] = {
    
"None",
    
"Newbie",
    
"Average",
    
"Hardcore",
    
"Professional"
}  

new const 
LEVELS[7] = {
0,
500,//this means you need 100 xp
1100,//this means you need 200 xp
2100,//this means you need 400 xp
3500,//so on
4100,//so on
5000 //so on
}  

public 
plugin_init()
{
    
register_plugin("XPMod""1.0""Preetham")
    
register_event("DeathMsg""eDeath""a")
    
//is saving on?
    
SaveXP register_cvar("SaveXP","1")
    
//how many xp are u gonna get per kill?
    
XP_Kill=register_cvar("XP_per_kill""10")
    
//if you get a hs you get bonus xp
    
XP_Hs=register_cvar("XP_hs_bonus","10")
    
//if you make a knife kill you get bounus xp
    
XP_Knife=register_cvar("XP_knife_bonus","20")
    
//we just opened a new connection NVAULT connection
    // we will call it animod
    
g_vault nvault_open("animod")
    
// register a say command to change class
    
register_clcmd("say /class""ChangeClass")
    
register_clcmd("say_team /class""ChangeClass")
    
//show how much xp you have
    
register_clcmd("say /xp""ShowHud")
    
register_clcmd("say_team /xp""ShowHud")
}  

public 
eDeath( )

    
// If the player's Class is  nothing, then dont bother to do any of the below
    
if(PlayerClass[attacker] == 0)
         return 
PLUGIN_CONTINUE

    
// Create a variable to store the attacker's id
    
new attacker read_data)
    
// We create the victim variable, so that this function can check 
    // if a player was killed 
    
new iVictim read_data)
    
// If a player was killed by a HeadShot, this will be used for the cvar Xp_Hs
    
new headshot read_data)
 
    
//which weapon was used
    
new clipammoweapon get_user_weapon(attacker,clip,ammo);
    
PlayerXP[attacker] += get_pcvar_num(XP_Kill
    
// used for the xp_hs cvar 
    // it checks if the victim was killed by a headshot 
    
if(headshot
    
// give him/her bonus xp 
    
PlayerXP[attacker] += get_pcvar_num(XP_Hs
    
// checks if the victim was killed by a knife 
    
if(weapon == CSW_KNIFE
        
//give him/her bonus xp 
    
PlayerXP[attacker] += get_pcvar_num(XP_Knife
    
// this checks if the player has enough xp to advance to a new level
 
     
while(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) 
    { 
// this will create the Congratulations message. 
        
client_print(attackerprint_chat"[XP] You're on level %i %s!"PlayerLevel[attacker],CLASSES[PlayerClass[attacker]]) 
        
// Add his/her level 
        
PlayerLevel[attacker] += 
    

    
// shows his level on a hud message 
    
ShowHud(attacker)
 
}  

public 
ShowHud(id

    
set_hudmessage(1921921920.00.2406.015.0
    
show_hudmessage(id"Level: %i^nXP: %i^nClass: %s",PlayerLevel[id],PlayerXP[id],CLASSES[PlayerClass[id]]) 
}  

public 
ChangeClass(id
{
    new 
menu menu_create("Class Menu" "Class_Handle");
    
menu_additem(menu ,"Newbie""1" 0); 
    
menu_additem(menu ,"Average""2" 0); 
    
menu_additem(menu ,"Hardcore""3" 0); 
    
menu_additem(menu ,"Professional""4" 0);
    
menu_setprop(menu MPROP_EXIT MEXIT_ALL);
    
menu_display(id menu 0); 
    return 
PLUGIN_CONTINUE

 
public 
Class_Handle(id menu item

    if(
item == MENU_EXIT
    { 
        
menu_destroy(menu); 
    } 
    new 
szCommand[6] , szName[64]; new access callback
    
menu_item_getinfo(menu item access szCommand szName 63 callback); 
    new 
str_to_num(szCommand
    if(
PlayerClass[id] != i
    { 
        
PlayerClass[id] = i client_print(id,print_chat,"[LEVEL ANNOUNCER] You're on level _%s_",CLASSES[i]) 
    }
    else 
    { 
        
client_print(id,print_chat,"[LEVEL ANNOUNCER] You're alredy on _%s_",CLASSES[i]) 
    } 
    
menu_destroy(menu); 
    return 
PLUGIN_CONTINUE 
}  

public 
client_connect(id
{
    
// Only does it if xp saving is on 
    
if(get_pcvar_num(SaveXP) == 1
    { 
        
// load your player data 
        
LoadData(id
    } 
}  

public 
client_disconnect(id

// Only does it if xp saving is on 
     
if(get_pcvar_num(SaveXP) == 1
     { 
          
// lets save the data 
          
SaveData(id
     } 
}  

public 
SaveData(id

    
// get the players steam id. We need this because we are saving by steam id 
    
new AuthID[35get_user_authid(id,AuthID,34
    new 
vaultkey[64],vaultdata[256
    
// format wat is going to be in the animal mod vault file 
    
format(vaultkey,63,"%s-Mod",AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
// save the data 
    
nvault_set(g_vault,vaultkey,vaultdata
    return 
PLUGIN_CONTINUE 
}  

public 
LoadData(id

    new 
AuthID[35get_user_authid(id,AuthID,34
    new 
vaultkey[64],vaultdata[256
    
// search 
    
format(vaultkey,63,"%s-Mod",AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
// load the data 
    
nvault_get(g_vault,vaultkey,vaultdata,255
    
replace_all(vaultdata255"#"" "
    new 
playerxp[32], playerlevel[32
    
parse(vaultdataplayerxp31playerlevel31
    
PlayerXP[id] = str_to_num(playerxp
    
PlayerLevel[id] = str_to_num(playerlevel
    return 
PLUGIN_CONTINUE 

__________________

Last edited by preetham; 02-28-2014 at 03:14.
preetham is offline
skazime
New Member
Join Date: Aug 2011
Location: Brazil
Old 02-28-2014 , 13:26   Re: [Correction] XP Mod
Reply With Quote #2

Try :
Code:
#include <amxmodx> 
#include <amxmisc> 
#include <nvault> 

#define MAXCLASSES 5 

new PlayerXP[33],PlayerLevel[33],PlayerClass[33] 
//these are for special kills  
new XP_Kill,XP_Knife,XP_Hs,SaveXP 
//this is for Nvault. so that We can save XP 
new g_vault   

new const CLASSES[MAXCLASSES][] = { 
	"None", 
	"Newbie", 
	"Average", 
	"Hardcore", 
	"Professional" 
}   

new const LEVELS[7] = { 
	0, 
	500,//this means you need 100 xp 
	1100,//this means you need 200 xp 
	2100,//this means you need 400 xp 
	3500,//so on 
	4100,//so on 
	5000 //so on 
}   

public plugin_init() 
{ 
	register_plugin("XPMod", "1.0", "Preetham") 
	register_event("DeathMsg", "eDeath", "a") 
	//is saving on? 
	SaveXP = register_cvar("SaveXP","1") 
	//how many xp are u gonna get per kill? 
	XP_Kill=register_cvar("XP_per_kill", "10") 
	//if you get a hs you get bonus xp 
	XP_Hs=register_cvar("XP_hs_bonus","10") 
	//if you make a knife kill you get bounus xp 
	XP_Knife=register_cvar("XP_knife_bonus","20") 
	//we just opened a new connection NVAULT connection 
	// we will call it animod 
	g_vault = nvault_open("animod") 
	// register a say command to change class 
	register_clcmd("say /class", "ChangeClass") 
	register_clcmd("say_team /class", "ChangeClass") 
	//show how much xp you have 
	register_clcmd("say /xp", "ShowHud") 
	register_clcmd("say_team /xp", "ShowHud") 
}   

public eDeath( ) 
{  
	// Create a variable to store the attacker's id 
	new attacker = read_data( 1 ) 
	// We create the victim variable, so that this function can check  
	// if a player was killed  
	new iVictim = read_data( 2 ) 
	// If a player was killed by a HeadShot, this will be used for the cvar Xp_Hs 
	new headshot = read_data( 3 ) 
	
	if(attacker == iVictim)
		return PLUGIN_HANDLED;
	//which weapon was used
	
	if(PlayerClass[attacker] == 0) 
		return PLUGIN_CONTINUE
	
	new clip, ammo, weapon = get_user_weapon(attacker,clip,ammo); 
	PlayerXP[attacker] += get_pcvar_num(XP_Kill)  
	// used for the xp_hs cvar  
	// it checks if the victim was killed by a headshot  
	if(headshot)  
		// give him/her bonus xp  
	PlayerXP[attacker] += get_pcvar_num(XP_Hs)  
	// checks if the victim was killed by a knife  
	if(weapon == CSW_KNIFE)  
		//give him/her bonus xp  
	PlayerXP[attacker] += get_pcvar_num(XP_Knife)  
	// this checks if the player has enough xp to advance to a new level 
	
	while(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]])  
	{ // this will create the Congratulations message.  
		client_print(attacker, print_chat, "[XP] You're on level %i %s!", PlayerLevel[attacker],CLASSES[PlayerClass[attacker]])  
		// Add his/her level  
		PlayerLevel[attacker] += 1  
	}  
	// shows his level on a hud message  
	ShowHud(attacker) 
	return PLUGIN_CONTINUE;
	
}   

public ShowHud(id)  
{  
	set_hudmessage(192, 192, 192, 0.0, 0.24, 0, 6.0, 15.0)  
	show_hudmessage(id, "Level: %i^nXP: %i^nClass: %s",PlayerLevel[id],PlayerXP[id],CLASSES[PlayerClass[id]])  
}   

public ChangeClass(id)  
{ 
	new menu = menu_create("Class Menu" , "Class_Handle"); 
	menu_additem(menu ,"Newbie", "1" , 0);  
	menu_additem(menu ,"Average", "2" , 0);  
	menu_additem(menu ,"Hardcore", "3" , 0);  
	menu_additem(menu ,"Professional", "4" , 0); 
	menu_setprop(menu , MPROP_EXIT , MEXIT_ALL); 
	menu_display(id , menu , 0);  
	return PLUGIN_CONTINUE;  
}  

public Class_Handle(id , menu , item)  
{  
	if(item == MENU_EXIT)  
	{  
		menu_destroy(menu);  
	}  
	new szCommand[6] , szName[64]; new access , callback;  
	menu_item_getinfo(menu , item , access , szCommand , 5 , szName , 63 , callback);  
	new i = str_to_num(szCommand)  
	if(PlayerClass[id] != i)  
	{  
		PlayerClass[id] = i 
		client_print(id,print_chat,"[LEVEL ANNOUNCER] You're on level %s",CLASSES[i])  
	} 
	else  
	{  
		client_print(id,print_chat,"[LEVEL ANNOUNCER] You're alredy on %s",CLASSES[i])  
	}  
	menu_destroy(menu);  
	return PLUGIN_CONTINUE  
}   

public client_connect(id)  
{ 
	// Only does it if xp saving is on  
	if(get_pcvar_num(SaveXP) == 1)  
	{  
		// load your player data  
		LoadData(id)  
	}  
}   

public client_disconnect(id)  
{  
	// Only does it if xp saving is on  
	if(get_pcvar_num(SaveXP) == 1)  
	{  
		// lets save the data  
		SaveData(id)  
	}  
}   

public SaveData(id)  
{  
	// get the players steam id. We need this because we are saving by steam id  
	new AuthID[35] 
	get_user_authid(id,AuthID,34)  
	new vaultkey[64],vaultdata[256]  
	// format wat is going to be in the animal mod vault file  
	format(vaultkey,63,"%s-Mod",AuthID)  
	format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])  
	// save the data  
	nvault_set(g_vault,vaultkey,vaultdata)  
	return PLUGIN_CONTINUE  
}   

public LoadData(id)  
{  
	new AuthID[35] 
	get_user_authid(id,AuthID,34)  
	new vaultkey[64],vaultdata[256]  
	// search  
	format(vaultkey,63,"%s-Mod",AuthID)  
	format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])  
	// load the data  
	nvault_get(g_vault,vaultkey,vaultdata,255)  
	replace_all(vaultdata, 255, "#", " ")  
	new playerxp[32], playerlevel[32]  
	parse(vaultdata, playerxp, 31, playerlevel, 31)  
	PlayerXP[id] = str_to_num(playerxp)  
	PlayerLevel[id] = str_to_num(playerlevel)  
	return PLUGIN_CONTINUE  
}
skazime is offline
Send a message via MSN to skazime Send a message via Skype™ to skazime
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 02:47.


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