Hello!
I have this plugin that when somebody write /freexp it gives XP to the player, it should work only by nickname. By that i mean for example player: Test1 joins the servers and writes /freexp, then he gets the XP. Then he quit and join the server with name Test2 writes /freexp and to be able to get XP again. Currently something is stopping it to work properly because i have players that play in gaming club so 15 players with same IP and when one of them write /freexp others cannot use it.Can anyone tell me where is my mistake? Thanks!
I have this plugin that when somebody write /freexp it gives XP to the player, it should work only by nickname. By that i mean for example player: Test1 joins the servers and writes /freexp, then he gets the XP. Then he quit and join the server with name Test2 writes /freexp and to be able to get XP again. Currently something is stopping it to work properly because i have players that play in gaming club so 15 players with same IP and when one of them write /freexp others cannot use it.Can anyone tell me where is my mistake? Thanks!
Код:
#include <amxmodx>
#include <cromchat>
#include <fvault>
#define PLUGIN "Give XP - Command"
#define VERSION "1.0"
#define AUTHOR "AMXXBG Team - Invius"
#if !defined MAX_PLAYERS
#define MAX_PLAYERS 32
#endif
#if !defined MAX_NAME_LENGTH
#define MAX_NAME_LENGTH 32
#endif
new const g_szVault[] = "FreeXp_VaultNames"
new bool:g_bUsedCommand[MAX_PLAYERS + 1], g_szUserName[MAX_PLAYERS + 1][MAX_NAME_LENGTH]
new g_pCvarXPAmount
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /freexp", "cmdfreexp")
register_clcmd("say_team /freexp", "cmdfreexp")
register_clcmd("say /clearfreexp", "cmd_clear_freexp")
register_clcmd("say_team /clearfreexp", "cmd_clear_freexp")
g_pCvarXPAmount = register_cvar("hnsxp_free_xp", "250000")
CC_SetPrefix("&x01[&x04Free&x03XP&x01]")
}
public cmdfreexp(id)
{
if (g_bUsedCommand[id])
{
CC_SendMessage(id, "Vie veche ste vzeli bezplatno XP")
}
else
{
g_bUsedCommand[id] = true
hnsxp_add_user_xp(id, get_pcvar_num(g_pCvarXPAmount))
CC_SendMessage(id, "You succesfully received &x03%i &x04XP&x01.", get_pcvar_num(g_pCvarXPAmount))
}
return PLUGIN_HANDLED
}
public cmd_clear_freexp(id)
{
if (get_user_flags(id) & ADMIN_RCON)
{
fvault_clear(g_szVault)
CC_SendMessage(id, "Succesfully cleared all XP information.")
static iPlayers[MAX_PLAYERS], iNum, iPlayerId
get_players(iPlayers, iNum, "c")
for (--iNum; iNum >= 0; iNum--)
{
iPlayerId = iPlayers[iNum]
get_user_name(iPlayerId, g_szUserName[iPlayerId], charsmax(g_szUserName[]))
Load_Data(g_szUserName[iPlayerId], iPlayerId)
}
}
return PLUGIN_HANDLED
}
public client_putinserver(id)
{
get_user_name(id, g_szUserName[id], charsmax(g_szUserName[]))
set_task(0.1, "Load_Data", id, g_szUserName[id], sizeof(g_szUserName[]))
}
public client_disconnected(id)
{
Save_Data(id, g_szUserName[id])
g_bUsedCommand[id] = false;
}
public client_infochanged(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED
static szNames[2][MAX_NAME_LENGTH]
get_user_name(id, szNames[0], charsmax(szNames[]))
get_user_info(id, "name", szNames[1], charsmax(szNames[]))
if (!equali(szNames[1], szNames[0]))
{
Save_Data(id, szNames[0])
set_task(0.1, "Load_Data", id, szNames[1], sizeof(szNames[]))
g_szUserName[id] = szNames[1]
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public Load_Data(szName[], id)
{
if(!is_user_connected(id))
return
new szData[64]
if(fvault_get_data(g_szVault, szName, szData, charsmax(szData)))
{
g_bUsedCommand[id] = true
}
else
{
g_bUsedCommand[id] = false
}
}
public Save_Data(id, szName[])
{
new szData[64]
formatex(szData, charsmax(szData), "Free XP has been taken!")
fvault_set_data(g_szVault, szName, szData)
}
/*
* Returns a players XP points
*
* @param client - The player index to get points of
*
* @return The XP points of client
*
*/
native hnsxp_get_user_xp(client);
/*
* Sets <xp> points to client
*
* @param client - The player index to set points to
* @param xp - The amount of XP points to set to client
*
* @return The XP points of client
*
*/
native hnsxp_set_user_xp(client, xp);
/*
* Adds <xp> points to client
*
* @param client - The player index to add points to
* @param xp - The amount of XP points to add to client
*
* @return The XP points of client
*
*/
stock hnsxp_add_user_xp(client, xp)
{
return hnsxp_set_user_xp(client, hnsxp_get_user_xp(client) + xp);
}
/*
* Subtracts <xp> points from client
*
* @param client - The player index to subtract points from
* @param xp - The amount of XP points to subtract from client
*
* @return The XP points of client
*
*/
stock hnsxp_sub_user_xp(client, xp)
{
return hnsxp_set_user_xp(client, hnsxp_get_user_xp(client) - xp);
}