/*
---------------------------------------------------------
# # # #=== ### ## #
# ## #=== # # # #
# # #=== ### ## #
---------------------------------------------------------
<VeCo>'s Bazooka 1.2
Plugin made by <VeCo>
Special thanks to:
- bambuca : for the idea of the plugin.
---------------------------------------------------------
If you modify the code, please DO NOT change the author!
---------------------------------------------------------
Contacts:
e-mail:
veco.kn@gmail.com skype: veco_kn
---------------------------------------------------------
Changes log:
-> v 1.0 = First release!
-> v 1.1 = Fixed bug with the drop.
Fixed bug with center messages.
Fixed 'drop, get and shoot again' bug.
Fixed bug with rocket entity.
Fixed bug with removing the bazooka on death.
-> v 1.2 = Fixed bug with removing the bazooka on death.
---------------------------------------------------------
---------------------------------------------------------
*/
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <engine>
#include <cstrike>
new sprite_explosion,sprite_beamcylinder,
cvar_cost,cvar_damage,cvar_speed,cvar_reload_time,cvar_radius,cvar_can_drop,cvar_one_round,
maxplayers, has_bazooka[33],can_shoot[33]
public plugin_precache()
{
precache_model("models/v_rpg.mdl")
precache_model("models/p_rpg.mdl")
precache_model("models/w_rpg.mdl")
precache_model("models/rpgrocket.mdl")
sprite_explosion = precache_model("sprites/zerogxplode.spr")
sprite_beamcylinder = precache_model("sprites/white.spr")
precache_sound("weapons/rocketfire1.wav")
precache_sound("common/bodydrop2.wav")
precache_sound("items/gunpickup2.wav")
}
public plugin_init() {
register_plugin("<VeCo>'s Bazooka", "1.2", "<VeCo>")
cvar_cost = register_cvar("vecbz_cost","1000")
cvar_speed = register_cvar("vecbz_rocket_speed","800")
cvar_damage = register_cvar("vecbz_damage","150")
cvar_reload_time = register_cvar("vecbz_reload_time","10.0")
cvar_radius = register_cvar("vecbz_radius","200")
cvar_can_drop = register_cvar("vecbz_can_drop","1")
cvar_one_round = register_cvar("vecbz_one_round","0")
register_clcmd("say /bazooka","buy_bazooka",BAZOOKA_ACCESS)
register_clcmd("say_team /bazooka","buy_bazooka",BAZOOKA_ACCESS)
register_clcmd("drop","drop_bazooka")
RegisterHam(Ham_Weapon_PrimaryAttack,"weapon_knife","shoot_bazooka")
register_touch("weapon_bazooka","player","get_bazooka")
register_touch("","info_bazooka_rocket","touch_bazooka")
register_event("DeathMsg","hook_death","a")
register_event("CurWeapon","event_curweapon","be","1=1","2=29")
register_logevent("round_end",2,"1=Round_End")
maxplayers = get_maxplayers()
}
public buy_bazooka(id,level,cid)
{
if(!cmd_access(id,level,cid,1)) return
if(!is_user_alive(id))
{
client_print(id,print_chat," [VECBZ]You must be alive to buy a bazooka.")
return
}
if(cs_get_user_money(id) < get_pcvar_num(cvar_cost))
{
client_print(id,print_chat," [VECBZ]You don't have enogh money to buy a bazooka.")
return
}
if(has_bazooka[id])
{
client_print(id,print_chat," [VECBZ]You have already own a bazooka.")
return
}
cs_set_user_money(id,cs_get_user_money(id) - get_pcvar_num(cvar_cost), 1)
has_bazooka [id]= true
can_shoot [id]= true
emit_sound(id,CHAN_AUTO,"items/gunpickup2.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM)
client_cmd(id,"weapon_knife")
entity_set_string(id,EV_SZ_viewmodel,"models/v_rpg.mdl")
entity_set_string(id,EV_SZ_weaponmodel,"models/p_rpg.mdl")
}
public drop_bazooka(id) if(get_pcvar_num(cvar_can_drop) && get_user_weapon(id) == CSW_KNIFE && has_bazooka[id]) action_drop_user_bazooka(id)
public shoot_bazooka(ent)
{
new id = entity_get_edict(ent,EV_ENT_owner)
if(!has_bazooka[id]) return HAM_IGNORED
if(!can_shoot[id])
{
client_print(id,print_center," [VECBZ]You can't use the bazooka right now. Please wait...")
return HAM_IGNORED
}
action_shoot_user_bazooka(id)
return HAM_IGNORED
}
public action_drop_user_bazooka(id)
{
remove_task(id)
has_bazooka [id]= false
can_shoot [id]= false
emit_sound(id,CHAN_AUTO,"common/bodydrop2.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM)
new ent = create_entity("info_target")
if(ent)
{
new Float:origin[3],Float:velocity[3]
entity_get_vector(id,EV_VEC_origin,origin)
velocity_by_aim(id,60,velocity)
origin[0] += velocity[0]
origin[1] += velocity[1]
entity_set_string(ent,EV_SZ_classname,"weapon_bazooka")
entity_set_model(ent,"models/w_rpg.mdl")
entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER)
entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS)
entity_set_float(ent,EV_FL_gravity,1.0)
entity_set_origin(ent,origin)
}
entity_set_string(id,EV_SZ_viewmodel,"models/v_knife.mdl")
entity_set_string(id,EV_SZ_weaponmodel,"models/p_knife.mdl")
}
public action_shoot_user_bazooka(id)
{
can_shoot [id]= false
emit_sound(id,CHAN_AUTO,"weapons/rocketfire1.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM)
new ent = create_entity("info_target")
if(ent)
{
new Float:origin[3],Float:velocity[3],Float:angles[3]
entity_get_vector(id,EV_VEC_origin,origin)
velocity_by_aim(id,60,velocity)
origin[0] += velocity[0]
origin[1] += velocity[1]
velocity[0] = 0.0
velocity[1] = 0.0
velocity_by_aim(id,get_pcvar_num(cvar_speed),velocity)
entity_set_string(ent,EV_SZ_classname,"info_bazooka_rocket")
entity_set_model(ent,"models/rpgrocket.mdl")
entity_set_int(ent,EV_INT_solid,SOLID_BBOX)
entity_set_int(ent,EV_INT_movetype,MOVETYPE_FLY)
entity_set_size(ent,Float:{-0.5,-0.5,-0.5},Float:{0.5,0.5,0.5})
entity_set_vector(ent,EV_VEC_velocity,velocity)
vector_to_angle(velocity,angles)
entity_set_vector(ent,EV_VEC_angles,angles)
entity_set_edict(ent,EV_ENT_owner,id)
entity_set_int(ent,EV_INT_effects,entity_get_int(ent,EV_INT_effects) | EF_LIGHT)
entity_set_origin(ent,origin)
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte(TE_BEAMFOLLOW)
write_short(ent)
write_short(sprite_beamcylinder)
write_byte(30)
write_byte(5)
write_byte(255)
write_byte(255)
write_byte(255)
write_byte(140)
message_end()
}
set_task(get_pcvar_float(cvar_reload_time),"action_reload_user_bazooka",id)
}
public action_reload_user_bazooka(id)
{
if(!is_user_connected(id) || !has_bazooka[id]) return
can_shoot [id]= true
client_print(id,print_center," [VECBZ]Your bazooka has been reloaded. Now you can shoot again!")
}
public get_bazooka(ent,id)
{
if(has_bazooka[id]) return
remove_task(id)
has_bazooka [id]= true
can_shoot [id]= false
emit_sound(id,CHAN_AUTO,"items/gunpickup2.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM)
client_cmd(id,"weapon_knife")
entity_set_string(id,EV_SZ_viewmodel,"models/v_rpg.mdl")
entity_set_string(id,EV_SZ_weaponmodel,"models/p_rpg.mdl")
set_task(get_pcvar_float(cvar_reload_time),"action_reload_user_bazooka",id)
remove_entity(ent)
}
public touch_bazooka(world,ent)
{
if(!is_valid_ent(ent)) return
new Float:origin[3], origin_int[3], owner = entity_get_edict(ent,EV_ENT_owner)
entity_get_vector(ent,EV_VEC_origin,origin)
FVecIVec(origin,origin_int)
new id = -1
while((id = find_ent_in_sphere(id,origin,float(get_pcvar_num(cvar_radius)))) != 0)
{
if(!is_user_connected(owner)) break
if(1 <= id <= maxplayers)
{
if(get_user_team(id) == get_user_team(owner)) continue
ExecuteHamB(Ham_TakeDamage,id, owner,owner, float(get_pcvar_num(cvar_damage)), DMG_ALWAYSGIB)
}
}
message_begin(MSG_BROADCAST,SVC_TEMPENTITY,origin_int)
write_byte(TE_EXPLOSION)
write_coord(origin_int[0])
write_coord(origin_int[1])
write_coord(origin_int[2])
write_short(sprite_explosion)
write_byte(floatround(get_pcvar_num(cvar_radius) * 0.5))
write_byte(10)
write_byte(0)
message_end()
message_begin(MSG_BROADCAST,SVC_TEMPENTITY,origin_int)
write_byte(TE_DLIGHT)
write_coord(origin_int[0])
write_coord(origin_int[1])
write_coord(origin_int[2])
write_byte(floatround(get_pcvar_num(cvar_radius) * 0.25))
write_byte(200)
write_byte(145)
write_byte(0)
write_byte(16)
write_byte(32)
message_end()
message_begin(MSG_BROADCAST,SVC_TEMPENTITY,origin_int)
write_byte(TE_BEAMCYLINDER)
write_coord(origin_int[0])
write_coord(origin_int[1])
write_coord(origin_int[2])
write_coord(origin_int[0])
write_coord(origin_int[1])
write_coord(origin_int[2] + get_pcvar_num(cvar_radius))
write_short(sprite_beamcylinder)
write_byte(0)
write_byte(0)
write_byte(10)
write_byte(50)
write_byte(0)
write_byte(255)
write_byte(255)
write_byte(255)
write_byte(160)
write_byte(0)
message_end()
remove_entity(ent)
}
public hook_death()
{
new id = read_data(2)
if(get_pcvar_num(cvar_can_drop))
{
if(has_bazooka [id]&& get_user_weapon(id) == CSW_KNIFE) action_drop_user_bazooka(id)
has_bazooka [id]= false
can_shoot [id]= false
} else {
has_bazooka [id]= false
can_shoot [id]= false
}
}
public event_curweapon(id)
{
if(has_bazooka[id])
{
entity_set_string(id,EV_SZ_viewmodel,"models/v_rpg.mdl")
entity_set_string(id,EV_SZ_weaponmodel,"models/p_rpg.mdl")
}
}
public round_end()
{
remove_entity_name("weapon_bazooka")
if(get_pcvar_num(cvar_one_round))
{
for(new i=1;i<maxplayers;i++)
{
if(is_user_connected(i))
{
has_bazooka [i]= false
can_shoot [i]= false
if(get_user_weapon(i) == CSW_KNIFE)
{
entity_set_string(i,EV_SZ_viewmodel,"models/v_knife.mdl")
entity_set_string(i,EV_SZ_weaponmodel,"models/p_knife.mdl")
}
}
}
}
}
public client_connect(id) has_bazooka [id]= false
public client_disconnect(id) has_bazooka [id]= false