#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define GLOWSTICK_CLASSNAME "glowstick"
#define Maximum "Elértétek a maximális Fénypálca számot!"
#define Nincs "Nincs egy Fénypálcád sem!"
const PEV_FLARE_COLOR = pev_punchangle
new const sound_grenade_flare_explode[] = { "items/nvg_on.wav" }
new g_radius_light = 6, g_frequency = 15, g_duration = 60, g_round_sticks = 4, g_limit = 64
new cv_radius_light, cv_frequency, cv_duration, cv_round_sticks, cv_limit
new active_sticks
///// ///// ///// /////
new i_glowsticks[33]
new bool:g_is_alive[33]
new user_weapon[33]
///// ///// ///// ///// ///// ///// ///// ///// /////
new g_model_glowstick[][] =
{
"models/glowstick/glowstick01.mdl",
"models/glowstick/glowstick02.mdl",
"models/glowstick/glowstick03.mdl",
"models/glowstick/glowstick04.mdl"
}
public plugin_precache()
{
precache_model(g_model_glowstick[0])
precache_model(g_model_glowstick[1])
precache_model(g_model_glowstick[2])
precache_model(g_model_glowstick[3])
precache_sound(sound_grenade_flare_explode)
}
///// ///// ///// ///// ///// ///// ///// ///// /////
public plugin_init()
{
register_plugin("Glowsticks", "1.02", "Leo_[BH]")
register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
register_event("CurWeapon","CurWeapon","be","1=1")
register_forward(FM_PlayerPreThink, "fw_clientPreThink", 0)
RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
cv_radius_light = register_cvar("glowsticks_radius_light", "6")
cv_frequency = register_cvar("glowsticks_frequency", "15")
cv_duration = register_cvar("glowsticks_duration", "60")
cv_round_sticks = register_cvar("glowsticks_round_limit", "4")
cv_limit = register_cvar("glowsticks_map_limit", "64")
}
public plugin_cfg()
{
server_cmd("exec addons/amxmodx/configs/glowsticks.cfg")
reload_cvars()
}
public reload_cvars()
{
g_radius_light = get_pcvar_num(cv_radius_light)
g_frequency = get_pcvar_num(cv_frequency)
g_duration = get_pcvar_num(cv_duration)
g_round_sticks = get_pcvar_num(cv_round_sticks)
g_limit = get_pcvar_num(cv_limit)
if(g_duration < g_frequency * 2)
{
g_duration = g_frequency * 2
}
}
public fw_clientPreThink(id)
{
if(!g_is_alive[id]) return;
if(user_weapon[id] != CSW_KNIFE) return;
if(pev(id, pev_button) & IN_RELOAD)
{
if(!(pev(id, pev_oldbuttons) & IN_RELOAD))
{
cmd_place_glowstick(id)
}
}
}
public cmd_place_glowstick(id)
{
if(active_sticks > g_limit)
{
client_print(id, print_center, "%s",Maximum)
}
else
{
if(i_glowsticks[id])
{
the_place_glowstick(id)
i_glowsticks[id]--
}
else
{
client_print(id, print_center, "%s",Nincs)
}
}
}
public the_place_glowstick(id)
{
place_glowstick(id, random_num(1, 4))
}
///// ///// ///// ///// ///// ///// ///// ///// /////
public place_glowstick(id, color)
{
static entity;
entity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
set_pev(entity, pev_classname, GLOWSTICK_CLASSNAME)
engfunc(EngFunc_SetModel, entity, g_model_glowstick[color-1])
set_pev(entity, pev_mins, Float:{ -0.660000, -0.660000, 0.000000 } )
set_pev(entity, pev_maxs, Float:{ 0.660000, 0.660000, 10.170000 } )
set_pev(entity, pev_size, Float:{ -0.660000, -0.660000, 0.000000, 0.660000, 0.660000, 10.170000 } )
set_pev(entity, pev_solid, SOLID_TRIGGER)
set_pev(entity, pev_movetype, MOVETYPE_TOSS)
// // // // //
static rgb[3]
switch(color)
{
case 1: // green
{
rgb[0] = 28
rgb[1] = 211
rgb[2] = 45
}
case 2: // red
{
rgb[0] = 204
rgb[1] = 27
rgb[2] = 26
}
case 3: // blue
{
rgb[0] = 25
rgb[1] = 71
rgb[2] = 200
}
case 4: // orange
{
rgb[0] = 195
rgb[1] = 108
rgb[2] = 25
}
}
set_pev(entity, PEV_FLARE_COLOR, rgb)
static Float:my_origin[3], Float:my_angles[3]
pev(id, pev_origin, my_origin)
pev(id, pev_angles, my_angles)
set_pev(entity, pev_origin, my_origin)
my_angles[0] = 0.0
set_pev(entity, pev_angles, my_angles)
set_task(1.5, "activate_stick", entity)
active_sticks++
}
public activate_stick(entity)
{
if(pev_valid(entity))
{
static Float:origin[3]
pev(entity, pev_origin, origin)
engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
write_byte(TE_SPARKS) // TE id
engfunc(EngFunc_WriteCoord, origin[0]) // x
engfunc(EngFunc_WriteCoord, origin[1]) // y
engfunc(EngFunc_WriteCoord, origin[2]) // z
message_end()
emit_sound(entity, CHAN_WEAPON, sound_grenade_flare_explode, 1.0, ATTN_NORM, 0, PITCH_NORM)
flare_lighting(entity)
set_task(float(g_frequency), "flare_lighting", entity, _, _, "a", g_duration / g_frequency - 1)
set_task(float(g_duration), "last_light", entity)
set_task(float(g_duration) + float(g_frequency / 3), "remove_glowstick", entity)
}
}
public flare_lighting(entity)
{
if(!pev_valid(entity)) return;
static Float:origin[3], color[3]
pev(entity, pev_origin, origin)
pev(entity, PEV_FLARE_COLOR, color)
engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, origin, 0)
write_byte(TE_DLIGHT) // TE id
engfunc(EngFunc_WriteCoord, origin[0]) // x
engfunc(EngFunc_WriteCoord, origin[1]) // y
engfunc(EngFunc_WriteCoord, origin[2]) // z
write_byte(g_radius_light) // radius
write_byte(color[0]) // r
write_byte(color[1]) // g
write_byte(color[2]) // b
write_byte(g_frequency * 10) // life //
write_byte(0) // decay rate
message_end()
}
public last_light(entity)
{
if(!pev_valid(entity)) return;
static Float:origin[3], color[3]
pev(entity, pev_origin, origin)
pev(entity, PEV_FLARE_COLOR, color)
engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, origin, 0)
write_byte(TE_DLIGHT) // TE id
engfunc(EngFunc_WriteCoord, origin[0]) // x
engfunc(EngFunc_WriteCoord, origin[1]) // y
engfunc(EngFunc_WriteCoord, origin[2]) // z
write_byte(g_radius_light) // radius
write_byte(color[0]) // r
write_byte(color[1]) // g
write_byte(color[2]) // b
write_byte(g_frequency) // life
write_byte(3) // decay rate
message_end()
}
public remove_glowstick(entity)
{
if(!pev_valid(entity)) return;
engfunc(EngFunc_RemoveEntity, entity)
active_sticks--
}
///// ///// ///// ///// ///// ///// ///// ///// /////
public event_round_start(id)
{
reload_cvars()
arrayset(i_glowsticks, g_round_sticks, 33)
}
public client_puinserver(id)
{
i_glowsticks[id] = g_round_sticks
}
public client_disconnect(id)
{
i_glowsticks[id] = 0
user_weapon[id] = 0
g_is_alive[id] = false
}
public CurWeapon(id)
{
user_weapon[id] = read_data(2)
}
public fw_PlayerSpawn_Post(id)
{
if(is_user_alive(id))
{
g_is_alive[id] = true
}
}
public fw_PlayerKilled(id)
{
g_is_alive[id] = false
}
///// ///// ///// ///// ///// ///// ///// ///// /////
public plugin_natives()
{
register_native("glowstick", "native_glowstick", 1)
}
public native_glowstick(id)
{
if(active_sticks > g_limit) return 0
if(!g_is_alive[id]) return 0
the_place_glowstick(id)
return 1
}