#include <amxmodx>
#include <nvault>
// Defining numbers , for better read ability
#define NORMAL_KILL 2
#define HEADSHOT_KILL 4
#define KNIFE_KILL 6
#define KNIFE_HEADSHOT 10
#define BOMB_PLANTED 15
#define BOMB_DEFUSED 20
#define CT_WIN 7
#define TR_WIN 4
//our uniq task id
#define TASK_ID 1000
// Max players that a server can have
#define MAX_PLAYERS 32
// Hud X position
const Float: HUD_POSITION_X = -0.2
// Hud Y position
const Float: HUD_POSITION_Y = 0.03
// Hud display time
const Float:HOLD_TIME = 1.0
const HUD_CHANNEL = 1
new const VERSION[] = "1.0"
//Our main array for Point_System
new Points[MAX_PLAYERS + 1]
// Saving users authid here
new szAuthid[MAX_PLAYERS + 1][35]
// nVault
new g_save
public plugin_init()
{
register_plugin("Point System" , VERSION , "LearninG")
// Logevents , (For increasing points)
register_logevent("bomb_planted", 3, "2=Planted_The_Bomb")
register_logevent("bomb_defused", 3, "2=Defused_The_Bomb")
register_logevent("on_CTWin", 6, "3=CTs_Win", "3=All_Hostages_Rescued")
register_logevent("on_TerroristWin" , 6, "3=Terrorists_Win", "3=Target_Bombed")
// called whenever a cliend dies/killed
register_event ("DeathMsg", "Event_Death", "a")
}
// Opening Our nVault (All of our data related to points , authids are saved in an nVault file)
public plugin_cfg()
{
g_save = nvault_open("FR-Points")
if ( g_save == INVALID_HANDLE )
{
set_fail_state( "Error opening nVault" )
}
}
// close nVault
public plugin_end()
{
nvault_close(g_save)
}
// Our natives (They are so useful whe you want to make sub-plugins)
public plugin_natives()
{
register_library("point_sytem")
register_native("get_user_point" , "native_get_user_point")
register_native("set_user_point" , "native_set_user_point")
}
// get_user_point
public native_get_user_point(index)
{
return Points[get_param(1)]
}
// set_user_point
public native_set_user_point(index , amount)
{
Points[get_param(1)] = get_param(2)
}
// get user authid , and load point whenever a client joins server + start a task for showing player point in hud
public client_putinserver(id)
{
get_user_authid(id , szAuthid[id] , charsmax(szAuthid))
LoadData(id)
set_task (1.0, "show_points",id + TASK_ID,_,_,"b")
}
// Save data (points) and remove task
public client_disconnect(id)
{
remove_task(id + TASK_ID)
SaveData(id)
}
// increasing points
public Event_Death()
{
static Attacker , Victim , Headshot , wpn
Attacker = read_data(1)
Victim = read_data(2)
Headshot = read_data(3)
wpn = get_user_weapon(Attacker)
if (Attacker == Victim) return PLUGIN_HANDLED
if(Headshot && wpn != CSW_KNIFE)
{
Points[Attacker] += HEADSHOT_KILL
}
if (wpn == CSW_KNIFE && !Headshot)
{
Points[Attacker] += KNIFE_KILL
}
if (wpn == CSW_KNIFE && Headshot)
{
Points[Attacker] += KNIFE_HEADSHOT
}
if (!Headshot && wpn != CSW_KNIFE)
{
Points[Attacker] += NORMAL_KILL
}
return PLUGIN_CONTINUE
}
// give points to planter
public bomb_planted(id)
{
Points[id] += BOMB_PLANTED
}
// give points to defuser
public bomb_defused(id)
{
Points[id] += BOMB_DEFUSED
}
// give point to all terrorist's
public on_TerroristWin()
{
new players[32], num
get_players(players, num, "ceh" , "TERRORIST")
for( --num; num >= 0; num-- )
{
Points[players[num]] += TR_WIN
}
}
// give point to all CT's
public on_CTWin()
{
new players[32], num
get_players(players, num, "ceh" , "CT")
for( --num; num >= 0; num-- )
{
Points[players[num]] += CT_WIN
}
}
// show hud message
public show_points(TASK)
{
new id = TASK - TASK_ID
set_hudmessage(255 , 255 , 255 , HUD_POSITION_X , HUD_POSITION_Y , 0, 8.0, HOLD_TIME, 0.3, 0.3, HUD_CHANNEL)
show_hudmessage(id , "FR-Points : %i" , Points[id])
}
// Saving Data to nVault file
SaveData(id)
{
new vaultkey[64], vaultdata[256]
formatex(vaultkey, charsmax(vaultkey), "%s-/", szAuthid[id])
formatex(vaultdata, charsmax(vaultdata), "%i#", Points[id])
nvault_set(g_save, vaultkey, vaultdata)
}
// Loading Data from nVault file
LoadData(id)
{
new vaultkey[64], vaultdata[256]
formatex(vaultkey, charsmax(vaultkey), "%s-/", szAuthid[id])
formatex(vaultdata, charsmax(vaultdata), "%i#", Points[id])
nvault_get(g_save, vaultkey, vaultdata, charsmax(vaultdata))
replace_all(vaultdata, charsmax(vaultdata), "#", " ")
new get_points[MAX_PLAYERS]
parse(vaultdata, get_points , charsmax(get_points))
Points[id] = str_to_num(get_points)
}