Member
|
01-23-2018
, 19:20
[HELP] Custom Sniper Bullet
|
#1
|
Hi so i have tried to make bullet travel time a thing for The awp and it worked for me.
But i have this one problem with my code which is the bullet doesn't get shot from the the Gun Barel so it's not the center of screen, and i believe that's because the code i have right here sets it to be shot from my origin and the thing that i don't understand is why it doesn't count my current origin cuz it gets shot it a little bit to the left/right but never from my real origin :/ , so anyone have a idea/solution ?
Code:
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
//#include <xs>
#define Weapon CSW_AWP
const m_flNextPrimaryAttack = 46;
const EXTRAOFFSET_WEAPONS = 4;
new const BULLET_MODEL[] = { "models/Bullet.mdl" };
new const BULLET_SHOOT[] = { "weapons/awp1.wav" };
new cvar_damage, cvar_bullet_speed, cvar_shotwait_time, cvar_ammocost, cvar_buyammo, cvar_maxammo;
new Float:g_shooting_time[33];
new Ammo[33], g_ammo[33];
public plugin_init()
{
register_plugin("Sniper Bullet Travel Time", "0.1", "iTzMeHey");
register_cvar("SBTT_version", "0.1", FCVAR_SERVER);
cvar_bullet_speed = register_cvar("SniperBullet_Speed", "1000");
cvar_damage = register_cvar("SniperBullet_Damage", "110.0");
cvar_shotwait_time = register_cvar("SniperBullet_WaitTime", "2.0");
cvar_maxammo = register_cvar("SniperBullet_MaxAmmo", "30");
cvar_ammocost = register_cvar("SniperBullet_AmmoCost", "150");
cvar_buyammo = register_cvar("SniperBullet_AmmoCount", "10");
RegisterHam(Ham_Item_Deploy, "weapon_awp", "HamWeaponDeploy_Post", 1);
register_forward(FM_CmdStart, "fw_CmdStart");
register_clcmd("buyammo1", "buy_ammo");
register_clcmd("aw", "give");
}
public plugin_precache()
{
precache_model(BULLET_MODEL);
precache_sound(BULLET_SHOOT);
//server_cmd("sv_maxvelocity 9999");
}
public buy_ammo(id)
{
if(get_user_weapon(id) == Weapon)
{
if(cs_get_user_money(id) <= get_pcvar_num(cvar_ammocost))
return PLUGIN_CONTINUE;
if(Ammo[id] == get_pcvar_num(cvar_maxammo))
return PLUGIN_CONTINUE;
if(cs_get_user_buyzone(id))
{
give_ammo(id)
return PLUGIN_HANDLED
}
}
return PLUGIN_HANDLED
}
public give_ammo(id)
{
cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(cvar_ammocost));
Ammo[id] += get_pcvar_num(cvar_buyammo);
update_ammo(id);
return PLUGIN_CONTINUE
}
public HamWeaponDeploy_Post(iEnt)
{
set_pdata_float(iEnt, m_flNextPrimaryAttack, 9999.0, EXTRAOFFSET_WEAPONS);
}
public fw_CmdStart(id, uc_handle, seed)
{
if(get_user_weapon(id) != Weapon)
return FMRES_IGNORED
static CurButton, OldButton
CurButton = get_uc(uc_handle, UC_Buttons)
OldButton = (pev(id, pev_oldbuttons) & IN_ATTACK)
if(get_gametime() - g_shooting_time[id] > get_pcvar_float(cvar_shotwait_time))
{
// Attack1 button pressed
if(CurButton & IN_ATTACK && !OldButton)
{
if(get_user_weapon(id) != Weapon)
return FMRES_IGNORED;
FireBullet(id);
g_shooting_time[id] = get_gametime();
}
}
return FMRES_HANDLED
}
public give(id)
{
give_item(id, "weapon_awp");
}
// Code Taken From Atrocraz Code
public FireBullet(id)
{
// Set animation
playanim(id, random_num(1, 3));
// Create ent
new Bullet = create_entity("info_target")
// Not a Bullet
if (!Bullet) return PLUGIN_HANDLED
// Classname
entity_set_string(Bullet, EV_SZ_classname, "sniper_bullet")
// Model
entity_set_model(Bullet, BULLET_MODEL)
set_rendering(Bullet, kRenderFxGlowShell, 150, 250, 200, kRenderNormal, 25)
Ammo[id]--
// Get origin. angle and velocity
new Float:vOrigin[3], Float:vUp[3], Float:vOffset[3];
new Float:fAngle[3], Float:fVelocity[3];
pev(id, pev_v_angle, fAngle);
pev(id, pev_origin, vOrigin);
pev(id, pev_view_ofs, vOffset);
global_get(glb_v_up, vUp);
new up = 5;
vOrigin[0] = vOrigin[0] + vOffset[0] + vUp[0] * up;
vOrigin[1] = vOrigin[1] + vOffset[1] + vUp[1] * up;
vOrigin[2] = vOrigin[2] + vOffset[2] + vUp[2] * up;
/*new Float:vOrigin[3], Float:vAngle[3], Float:vOffset[3];
pev(id, pev_origin, vOrigin);
pev(id, pev_view_ofs, vOffset);
pev(id, pev_v_angle, vAngle)
xs_vec_add(vOrigin, vOffset, vOrigin);
angle_vector(vAngle, ANGLEVECTOR_FORWARD, vAngle)
xs_vec_mul_scalar(vAngle, 9999.0, vAngle)
xs_vec_add(vOrigin, vAngle, vOrigin)
entity_set_vector(Bullet, EV_VEC_velocity, vOrigin);*/
// Origin
entity_set_origin(Bullet, vOrigin)
// Angles
entity_set_vector(Bullet, EV_VEC_angles, fAngle)
// Size
new Float:MinBox[3] = {-1.0, -1.0, -1.0}
new Float:MaxBox[3] = {1.0, 1.0, 1.0}
entity_set_vector(Bullet, EV_VEC_mins, MinBox)
entity_set_vector(Bullet, EV_VEC_maxs, MaxBox)
// Interaction
entity_set_int(Bullet, EV_INT_solid, SOLID_SLIDEBOX)
// Movetype
entity_set_int(Bullet, EV_INT_movetype, MOVETYPE_TOSS)
// Owner
entity_set_edict(Bullet, EV_ENT_owner, id);
// Velocity
new Float: BulletVc[33];
BulletVc[id] = float(get_pcvar_num(cvar_bullet_speed) * 6);
VelocityByAim(id, floatround(BulletVc[id]), fVelocity);
entity_set_vector(Bullet, EV_VEC_velocity, fVelocity);
emit_sound(Bullet, CHAN_WEAPON, BULLET_SHOOT, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
return PLUGIN_CONTINUE
}
// We hit something!!!
public pfn_touch(ptr, ptd)
{
// If ent is valid
if (pev_valid(ptr))
{
// Get classnames and owner id
static classname[32], classnameptd[32]
new owner = pev(ptr, pev_owner)
pev(ptr, pev_classname, classname, charsmax(classname));
// Our ent
if(equal(classname, "sniper_bullet"))
{
// Get it's origin
new Float:Origin[3]
pev(ptr, pev_origin, Origin)
if(is_user_alive(ptd))
{
if(cs_get_user_team(ptd) != cs_get_user_team(owner))
{
ExecuteHamB(Ham_TakeDamage, ptd, ptr, owner, get_pcvar_float(cvar_damage), DMG_BULLET)
}
}
// We hit breakable
if(pev_valid(ptd))
{
pev(ptd, pev_classname, classnameptd, 31)
if (equali(classnameptd, "func_breakable"))
{
// Destroy it
force_use(ptr,ptd)
}
}
set_pev(ptr, pev_flags, FL_KILLME)
}
}
}
public update_ammo(id)
{
g_ammo[id] = Ammo[id];
cs_set_user_bpammo(id, Weapon, g_ammo[id])
engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), {0, 0, 0}, id)
write_byte(1)
write_byte(Weapon)
write_byte(-1)
message_end()
set_task(0.1, "hud_debug", id)
}
public hud_debug(id)
{
engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), {0, 0, 0}, id)
write_byte(1)
write_byte(Weapon)
write_byte(-1)
message_end()
}
//play anim
public playanim(player, anim)
{
set_pev(player, pev_weaponanim, anim)
message_begin(MSG_ONE, SVC_WEAPONANIM, {0, 0, 0}, player)
write_byte(anim)
write_byte(pev(player, pev_body))
message_end()
}
P.S: Solved by changing sv_maxvelocity to 9999
Last edited by Hey; 01-31-2018 at 16:11.
Reason: Solved, Code Updated
|
|