I'm trying to transfer XP between player. The "id" passed to the function transfer_xp is the user's ID who is calling it. Two parameters are passed: <name of receiver> <amount of XP>. Then, it creates the XP to be TAKEN from the giver, and creates the XP to be GIVEN to the receiver (which is a simple formula).
Example: Sleeper gives 100,000 XP to Johnny, the plugin will TAKE 100,000 XP from Sleeper, BUT give Johnny only 25,000 because the amount of XP given is multiplied by the PCVAR xp_percent. The plugin does not give or take XP at all which is my dilemma.
Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Transfer XP (WC3FT)"
#define VERSION ".3a"
#define AUTHOR "slmclarengt"
new xp_percent;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /transferxp", "transfer_xp", 0, "<name> <XP to transfer> - transfers xp between players/races")
register_clcmd("say_team /transferxp", "transfer_xp", 0, "<name> <XP to transfer> - transfers xp between players/races")
xp_percent = register_cvar("amx_xp_percent", "25")// XP actually used, other xp trashed (default: 25)
}
public transfer_xp(id)
{
if (read_argc() == 1) // only 1 parameter (nothing passed)
{
client_print(id, print_chat, "/transferxp <name> <Amount XP to transfer> - only %d% will be transferred!", get_pcvar_num(xp_percent));
}
new target[32], amt[10];
read_argv(1, target, 31) // receiver of xp
read_argv(2, amt, 9) // amount of xp
new xp = str_to_num(amt) // make string to number for multiplication
client_print(0, print_chat, "%s wants to give a player %d XP", target, amt) //debug
new target_id = get_user_index(target); //Index for target
client_print(0, print_chat,"%d is the receivers ID", target_id) //debug
new negative_xp = 0 - xp // negative xp to take from giver
new t_xp = (xp * (get_pcvar_num(xp_percent) / 100));// ACTUAL transfer xp amount (amt * keep xp amt)
client_print(0, print_chat, "%d XP will be taken from giver & %d XP will be given to receiver", negative_xp, t_xp)
new receive_name[32];
get_user_name(target_id, receive_name, 31);
new give_name[32];
get_user_name(id, give_name, 31);
client_print(id, print_chat, "You are giving %d XP but losing %d XP to %s - what a nice person!", t_xp, xp, receive_name)
client_print(target_id, print_chat, "%s is giving you %d XP for the current race - be thankful!", give_name, t_xp)
server_cmd("amx_givexp %s %d", receive_name, t_xp) // give t_xp XP to receiver
server_cmd("amx_givexp %s %d", give_name, negative_xp); // take XP away from giver
}