I got a bit of a problem with this simple rocket launcher plugin that i made.
PHP Code:
/* [CSO Zombie Scenario 2.7] - AT4 Rocket Launcher Extra Item */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fakemeta_util>
#include <fun>
#include <hamsandwich>
#include <cstrike>
#include <engine>
#define TASK_HUDAMMO 1337
#define ID_HUDAMMO (taskid - TASK_HUDAMMO)
#define fm_find_ent_by_class(%1,%2) engfunc(EngFunc_FindEntityByString, %1, "classname", %2)
new const PLUGIN[] = "CSO ZBS WPN AT4 Launcher";
new const VERSION[] = "1.0";
new const AUTH[] = "jc980,tuty";
new const P_AT4_MODEL[] = "models/cso/p_at4.mdl"
new const V_AT4_MODEL[] = "models/cso/v_at4.mdl"
new const W_AT4_MODEL[] = "models/cso/w_at4.mdl"
new ROCKET_MODEL[] = "models/cso/s_at4.mdl";
new ROCKET_SOUND[] = "weapon/at4_fire.wav";
new ROCKET_EXP_SOUND[] = "weapon/at4_explode.wav";
new rocket_trail[] = "sprites/smoke.spr";
new rocket_explode[] = "sprites/cso/at4_exp.spr";
new rocket_smokesZ[] = "sprites/steam1.spr";
new rocket_classname[] = "at4_launcher";
new Float:was_rocket[33];
new trail2, explode2, smokesZ2;
new g_toggle_enable, g_toggle_speed, g_toggle_delay, g_toggle_trail_width;
new g_toggle_damageradius, g_toggle_rocket_damage, g_maxplayers;
new gMsgID, gDmsgID
new g_hasAT4[33] // whether player has AT4
new g_FireAT4[33] // player is shooting
new g_canShoot[33] // player can shoot
new rocket_count[33] // current grenade count
new Float:g_last_shot_time[33] // last shot time
new g_restarted // whether game was restarted
new rocket_cost
new rockets_cost
new SayText
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTH);
register_forward(FM_Touch, "pfn_touch" );
register_forward(FM_Touch, "fw_Touch")
register_forward(FM_SetModel, "fw_SetModel");
register_forward(FM_StartFrame, "server_frame");
register_forward(FM_CmdStart, "fw_CmdStart")
register_forward(FM_PlayerPostThink, "fw_PlayerPostThink")
register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
register_event("CurWeapon", "Event_CurrentWeapon", "be", "1=1")
register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0");
register_event("TextMsg", "Event_GameRestart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in");
register_logevent("logevent_round_end", 2, "1=Round_End");
register_clcmd("say /csozbswpn_at4", "CmdBuyIt")
register_clcmd("cso_zbs_wpn_at4", "CmdBuyIt")
register_clcmd("say /csozbswpn_rockets","CmdBuyAmmo")
register_clcmd("cso_zbs_wpn_rockets","CmdBuyAmmo")
g_toggle_enable = register_cvar("cso_zbs_at4_enable", "1");// 1-enabled/2-disabled
g_toggle_speed = register_cvar("cso_zbs_at4_speed","5000");// rocket speed
g_toggle_delay = register_cvar("cso_zbs_at4_delay","3.0"); // rocket delay
g_toggle_damageradius = register_cvar("cso_zbs_at4_dmg_radius", "500");// rocket explode radius damage
g_toggle_rocket_damage = register_cvar("cso_zbs_at4_dmg", "250");// rocket damage when hit someone
g_toggle_trail_width = register_cvar("cso_zbs_at4_trail_width", "5");// trail width
rocket_cost = register_cvar("cso_zbs_at4_cost","1000");//Cost Price
rockets_cost = register_cvar("cso_zbs_rockets_cost","500")//Rockets Cost price
gMsgID = get_user_msgid("Damage");
gDmsgID = get_user_msgid("DeathMsg");
g_maxplayers = get_maxplayers();
SayText = get_user_msgid("SayText")
set_task(10.0, "hud_init", TASK_HUDAMMO, _, _, "b")
}
public Event_NewRound(id)
{
if (g_restarted)
{
for (new i = 1; i <= get_maxplayers(); i++)
{
g_hasAT4[i] = false
remove_task(i+TASK_HUDAMMO)
}
g_restarted = false
}
}
public Event_GameRestart()
{
g_restarted = true
}
public Event_CurrentWeapon(id)
{
// Read weapon ID
new weaponID = read_data(2)
if (weaponID == CSW_P90)
{
if (g_hasAT4[id])
{
// View model
entity_set_string(id, EV_SZ_viewmodel, V_AT4_MODEL)
// Player model
entity_set_string(id, EV_SZ_weaponmodel, P_AT4_MODEL)
}
}
}
// Set model
public fw_SetModel(ent, const model[])
{
// Invalid entity
if (!pev_valid(ent))
return FMRES_IGNORED
// Not needed model
if(!equali(model, "models/w_p90.mdl"))
return FMRES_IGNORED
// Get owner and classname
new owner = pev(ent, pev_owner)
new classname[33]; pev(ent, pev_classname, classname, charsmax(classname))
// Entity classname is a weaponbox
if(equal(classname, "weaponbox"))
{
if(g_hasAT4[owner])
{
g_hasAT4[owner] = false
// Set world model
engfunc(EngFunc_SetModel, ent, W_AT4_MODEL)
// Touch fix
set_task(0.1, "touch_fix", owner)
// Remove HUD
remove_task(owner+TASK_HUDAMMO)
return FMRES_SUPERCEDE
}
}
return FMRES_IGNORED
}
public touch_fix(id)
{
if (g_hasAT4[id])
g_hasAT4[id] = false
}
public client_connect(id)
{
// Reset all
g_hasAT4[id] = false
g_canShoot[id] = false
g_last_shot_time[id] = 0.0
rocket_count[id] = 0
}
public client_disconnect(id)
{
// Reset all
g_hasAT4[id] = false
g_canShoot[id] = false
g_last_shot_time[id] = 0.0
rocket_count[id] = 0
}
public CmdBuyIt(id)
{
// Plugin not enabled
if (get_pcvar_num(g_toggle_enable) == 0)
return PLUGIN_CONTINUE
// Ignore dead
if (!is_user_alive(id))
return PLUGIN_CONTINUE
// Already own
if (g_hasAT4[id] || user_has_weapon(id, CSW_P90))
{
cso_zbs_colorprint(id, "^4[^3CSO ZBS 2.7 WPN^4] -^1 You already own this weapon")
return PLUGIN_CONTINUE
}
// Not enough money
if (cs_get_user_money(id) < get_pcvar_num(rocket_cost))
{
cso_zbs_colorprint(id,"^4[^3CSO ZBS 2.7 WPN^4] -^1 You don't have enough money.")
return PLUGIN_CONTINUE
}
// Otherwise all is OK
cso_zbs_colorprint(id, "^4[^3CSO ZBS 2.7 WPN^4] -^1 You bought ^3AT4 Rocket Launcher")
give_item(id, "weapon_p90")
cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(rocket_cost))
g_hasAT4[id] = true
g_canShoot[id] = true
rocket_count[id] = 10
set_task(10.0, "hud_init", id+TASK_HUDAMMO, _, _, "b")
return PLUGIN_CONTINUE
}
public CmdBuyAmmo(id)
{
// Plugin not enabled
if (get_pcvar_num(g_toggle_enable) == 0)
return PLUGIN_CONTINUE
// Ignore dead
if (!is_user_alive(id))
return PLUGIN_CONTINUE
// Already own
if (g_hasAT4[id] || user_has_weapon(id, CSW_P90))
{
// Not enough money
if (cs_get_user_money(id) < get_pcvar_num(rockets_cost))
{
cso_zbs_colorprint(id,"^4[CSO ZBS^3 2.7 ^4WPN] -^1 You don't have enough money.")
return PLUGIN_CONTINUE
}
else
{
// Otherwise all is OK
cso_zbs_colorprint(id, "^4[CSO ZBS^3 2.7 ^4WPN] -^1 You bought ^3AT4 Rocket Launcher Ammo")
cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(rockets_cost))
g_hasAT4[id] = true
rocket_count[id] = 10
}
}
return PLUGIN_CONTINUE
}
public fw_Touch(ent, toucher)
{
// Invalid ent/toucher
if(!pev_valid(ent) || !pev_valid(toucher))
return FMRES_IGNORED;
// Get model, toucherclass, entityclass
new model[33], toucherclass[33], entityclass[33]
pev(ent, pev_model, model, charsmax(model))
pev(ent, pev_classname, entityclass, charsmax(entityclass))
pev(toucher, pev_classname, toucherclass, charsmax(toucherclass))
// TOucher isn't player and entity isn't weapon
if (!equali(toucherclass, "player") || !equali(entityclass, "weaponbox"))
return FMRES_IGNORED
// Our world model
if(equali(model, W_AT4_MODEL))
{
// If allowed to touch
if(allowed_toucher(toucher))
{
// Pick up weapon
g_hasAT4[toucher] = true
g_canShoot[toucher] = true
g_FireAT4[toucher] = false
}
}
return FMRES_IGNORED;
}
public server_frame()
{
if(get_pcvar_num(g_toggle_enable) == 0)
return FMRES_IGNORED;
return FMRES_IGNORED;
}
public plugin_precache()
{
engfunc(EngFunc_PrecacheModel, ROCKET_MODEL);
engfunc(EngFunc_PrecacheModel, V_AT4_MODEL);
engfunc(EngFunc_PrecacheModel, P_AT4_MODEL);
engfunc(EngFunc_PrecacheModel, W_AT4_MODEL);
engfunc(EngFunc_PrecacheSound, ROCKET_SOUND);
engfunc(EngFunc_PrecacheSound, ROCKET_EXP_SOUND);
trail2 = engfunc(EngFunc_PrecacheModel, rocket_trail);
explode2 = engfunc(EngFunc_PrecacheModel, rocket_explode);
smokesZ2 = engfunc(EngFunc_PrecacheModel, rocket_smokesZ);
}
public fw_CmdStart(id, uc_handle, seed)
{
if(get_pcvar_num(g_toggle_enable) == 0)
return PLUGIN_HANDLED;
// Ignore dead
if (!is_user_alive(id))
return FMRES_IGNORED
// Don't have our weapon
if (!g_hasAT4[id])
return FMRES_IGNORED
// Get ammo, clip, weapon
new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
// Not replaced weapon
if (weapon != 30)
return FMRES_IGNORED
new button = pev(id, pev_button);
new buttons = get_uc(uc_handle, UC_Buttons)
if(button & IN_ATTACK)
{
g_FireAT4[id] = true
buttons &= ~IN_ATTACK
set_uc(uc_handle, UC_Buttons, buttons)
}
else
g_FireAT4[id] = false
return FMRES_HANDLED
}
public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
// Dead
if (!is_user_alive(id))
return FMRES_IGNORED
// Don't have our weapon
if (!g_hasAT4[id])
return FMRES_IGNORED
// Get ammo, clip, weapon
new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
// Not replaced weapon
if (weapon != 30)
return FMRES_IGNORED
// Block default sounds
set_cd(cd_handle, CD_ID, 0)
return FMRES_HANDLED
}
public fw_PlayerPostThink(id)
{
// ignore dead
if (!is_user_alive(id))
return FMRES_IGNORED
// Don't have our weapon
if (!g_hasAT4[id])
return FMRES_IGNORED
// Get ammo, clip, and weapon
new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
// Not our replaced weapon
if (weapon != 30)
return FMRES_IGNORED
// If player is firing
if (g_FireAT4[id])
{
// Grenades are more or equal to 1
if (rocket_count[id] >= 1)
{
// Player can shoot
if (get_gametime() - g_last_shot_time[id] > 1.0)
{
// Fire!!!
launch_rocket(id)
// Decrease nade count
rocket_count[id]--
// Remember last shot time
g_last_shot_time[id] = get_gametime()
}
}
else
{
// Don't have nades
cso_zbs_colorprint(id, "^4[CSO ZBS^3 2.7 ^4WPN] -^1 Out of Rockets!")
}
}
return FMRES_IGNORED
}
// HUD init
public hud_init(taskid)
{
new HudAmmo[65]
if (g_hasAT4[ID_HUDAMMO])
{
format(HudAmmo, 64, "^4[^3CSO ZBS 2.7 WPN^4] -^1 Rockets Remaining: ^3%d", rocket_count[ID_HUDAMMO])
cso_zbs_colorprint(ID_HUDAMMO,HudAmmo)
}
}
public fw_PlayerKilled(victim, attacker, shouldgib)
{
if (g_hasAT4[victim])
{
// Reset all
g_hasAT4[victim] = false
g_canShoot[victim] = false
g_FireAT4[victim] = false
rocket_count[victim] = 0
// Remove HUD
remove_task(victim+TASK_HUDAMMO)
}
}
public launch_rocket(id)
{
new Float:nexTime = get_gametime();
if(was_rocket[id] > nexTime)
{
return PLUGIN_CONTINUE;
}
else
{
new rocket = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
if(rocket == 0)
return PLUGIN_CONTINUE;
set_pev(id, pev_weaponanim, 4)
set_pev(rocket, pev_classname, rocket_classname);
engfunc(EngFunc_SetModel, rocket, ROCKET_MODEL);
set_pev(rocket, pev_size, Float:{0.0, 0.0, 0.0}, Float:{0.0, 0.0, 0.0});
set_pev(rocket, pev_movetype, MOVETYPE_FLY);
set_pev(rocket, pev_solid, SOLID_BBOX);
new Float:vSrc[3];
pev(id, pev_origin, vSrc);
new Float:Aim[3], Float:origin[3];
velocity_by_aim(id, 64, Aim);
pev(id,pev_origin,origin);
vSrc[0] += Aim[0];
vSrc[1] += Aim[1];
engfunc(EngFunc_SetOrigin, rocket, vSrc);
new Float:velocity[3], Float:angles[3];
velocity_by_aim(id, get_pcvar_num(g_toggle_speed), velocity);
set_pev(rocket, pev_velocity, velocity);
vector_to_angle(velocity, angles);
set_pev(rocket, pev_angles, angles);
set_pev(rocket, pev_owner,id);
set_pev(rocket, pev_takedamage, 1.0);
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_BEAMFOLLOW);
write_short(rocket);
write_short(trail2);
write_byte(25);
write_byte(get_pcvar_num(g_toggle_trail_width));
write_byte(200);
write_byte(200);
write_byte(200);
write_byte(255);
message_end();
emit_sound(rocket, CHAN_WEAPON, ROCKET_SOUND, 1.0, ATTN_NORM, 0, PITCH_NORM);
was_rocket[id] = nexTime + get_pcvar_float(g_toggle_delay);
}
return PLUGIN_CONTINUE;
}
public pfn_touch(ptr, ptd)
{
if(get_pcvar_num(g_toggle_enable) == 1)
{
if(pev_valid(ptr))
{
new classname[32];
pev(ptr, pev_classname, classname, 31);
if(equal(classname, rocket_classname))
{
new Float:fOrigin[3];
new iOrigin[3];
pev(ptr, pev_origin, fOrigin);
FVecIVec(fOrigin,iOrigin);
nade_radius_damage(ptr);
emit_sound(ptr, CHAN_WEAPON, ROCKET_EXP_SOUND, 1.0, ATTN_NORM, 0, PITCH_NORM);
message_begin(MSG_BROADCAST,SVC_TEMPENTITY,iOrigin);
write_byte(TE_EXPLOSION);
write_coord(iOrigin[0]);
write_coord(iOrigin[1]);
write_coord(iOrigin[2]);
write_short(explode2);
write_byte(60);
write_byte(15);
write_byte(0);
message_end();
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_SMOKE);
write_coord(iOrigin[0]);
write_coord(iOrigin[1]);
write_coord(iOrigin[2]);
write_short(smokesZ2);
write_byte(40);
write_byte(5);
message_end();
engfunc(EngFunc_RemoveEntity, ptr);
}
}
}
}
public logevent_round_end()
{
if(get_pcvar_num(g_toggle_enable) == 1)
{
new ent = -1;
while((ent = fm_find_ent_by_class(ent, rocket_classname)))
engfunc(EngFunc_RemoveEntity, ent);
}
}
stock nade_radius_damage(entity)
{
new id = pev(entity, pev_owner);
new i;
for(i = 1; i <= g_maxplayers; i++)
{
if(is_user_alive(i))
{
new dist = floatround(fm_entity_range(entity,i));
if(dist <= get_pcvar_num(g_toggle_damageradius))
{
new hp = get_user_health(i);
new Float:damage = get_pcvar_float(g_toggle_rocket_damage)-(get_pcvar_float(g_toggle_rocket_damage) / get_pcvar_float(g_toggle_damageradius))*float(dist);
new Origin[3];
get_user_origin(i,Origin);
if(!get_cvar_num("mp_friendlyfire"))
{
if(get_user_team(id) != get_user_team(i))
{
if(hp > damage)
{
nade_take_damage(i, floatround(damage), Origin, DMG_BLAST);
}
else
{
nade_kill(id, i, "** CSO ZBS WPN AT4-Launcher **", 0);
}
}
}
}
}
}
}
stock nade_take_damage(victim,damage,origin[3],bit)
{
message_begin(MSG_ONE_UNRELIABLE, gMsgID,{0,0,0}, victim);
write_byte(21);
write_byte(20);
write_long(bit);
write_coord(origin[0]);
write_coord(origin[1]);
write_coord(origin[2]);
message_end();
fm_set_user_health(victim, get_user_health(victim) - damage);
}
stock nade_kill(killer, victim, weapon[],headshot)
{
set_msg_block(gDmsgID , BLOCK_ONCE);
user_kill(victim, 1);
set_msg_block(gDmsgID, BLOCK_NOT);
message_begin(MSG_ALL, gDmsgID, {0,0,0}, 0);
write_byte(killer);
write_byte(victim);
write_byte(headshot);
write_string(weapon);
message_end();
return 1;
}
stock allowed_toucher(player)
{
// Already has it
if (g_hasAT4[player] || cs_get_user_team(player) == CS_TEAM_T)
return false
return true
}
stock cso_zbs_colorprint(const id, const input[], any:...)
{
new count = 1, players[32];
static msg[191];
vformat(msg, 190, input, 3);
replace_all(msg, 190, "!g", "^4"); // Green Color
replace_all(msg, 190, "!y", "^1"); // Default Color (?©° ??«??©)
replace_all(msg, 190, "!t", "^3"); // Team Color
if (id) players[0] = id; else get_players(players, count, "ch");
{
for ( new i = 0; i < count; i++ )
{
if ( is_user_connected(players[i]) )
{
message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
}
i dont know whats causing it.