Raised This Month: $ Target: $400
 0% 

Solved [HELP] Custom Sniper Bullet


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Hey
Member
Join Date: Dec 2017
Old 01-23-2018 , 19:20   [HELP] Custom Sniper Bullet
Reply With Quote #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_damagecvar_bullet_speedcvar_shotwait_timecvar_ammocostcvar_buyammocvar_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(idcs_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(iEntm_flNextPrimaryAttack9999.0EXTRAOFFSET_WEAPONS);
}
public 
fw_CmdStart(iduc_handleseed
{
    if(
get_user_weapon(id) != Weapon)
        return 
FMRES_IGNORED

    
static CurButtonOldButton
    
    CurButton 
get_uc(uc_handleUC_Buttons)
    
OldButton = (pev(idpev_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(idrandom_num(13));
    
    
// Create ent
    
new Bullet create_entity("info_target")
    
    
// Not a Bullet
    
if (!Bullet) return PLUGIN_HANDLED

    
// Classname
    
entity_set_string(BulletEV_SZ_classname"sniper_bullet")
    
    
// Model
    
entity_set_model(BulletBULLET_MODEL)

    
set_rendering(BulletkRenderFxGlowShell150250200kRenderNormal25)
    
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(idpev_v_anglefAngle);
    
pev(idpev_originvOrigin);
    
pev(idpev_view_ofsvOffset);
    
    
global_get(glb_v_upvUp);
    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(BulletvOrigin)
    
    
// Angles
    
entity_set_vector(BulletEV_VEC_anglesfAngle)
    
    
// Size
    
new Float:MinBox[3] = {-1.0, -1.0, -1.0}
    new 
Float:MaxBox[3] = {1.01.01.0}
    
entity_set_vector(BulletEV_VEC_minsMinBox)
    
entity_set_vector(BulletEV_VEC_maxsMaxBox)
    
    
// Interaction
    
entity_set_int(BulletEV_INT_solidSOLID_SLIDEBOX)
    
    
// Movetype
    
entity_set_int(BulletEV_INT_movetypeMOVETYPE_TOSS)
    
    
// Owner
    
entity_set_edict(BulletEV_ENT_ownerid);
    
    
// Velocity
    
new FloatBulletVc[33];

    
BulletVc[id] = float(get_pcvar_num(cvar_bullet_speed) * 6);
    
VelocityByAim(idfloatround(BulletVc[id]), fVelocity);
    
    
entity_set_vector(BulletEV_VEC_velocityfVelocity);
    
    
emit_sound(BulletCHAN_WEAPONBULLET_SHOOTVOL_NORMATTN_NORM0PITCH_NORM)

    return 
PLUGIN_CONTINUE
}    

// We hit something!!!
public pfn_touch(ptrptd)
{
    
// If ent is valid
    
if (pev_valid(ptr))
    {    
        
// Get classnames and owner id
        
static classname[32], classnameptd[32]
        new 
owner pev(ptrpev_owner)
        
pev(ptrpev_classnameclassnamecharsmax(classname));
        
        
// Our ent
        
if(equal(classname"sniper_bullet"))
        {
            
// Get it's origin
            
new Float:Origin[3]
            
pev(ptrpev_originOrigin)
            
            if(
is_user_alive(ptd))
            {
                if(
cs_get_user_team(ptd) != cs_get_user_team(owner))
                {
                    
ExecuteHamB(Ham_TakeDamageptdptrownerget_pcvar_float(cvar_damage), DMG_BULLET)
                }
            }
            
// We hit breakable
            
if(pev_valid(ptd))
            {
                
pev(ptdpev_classnameclassnameptd31)
                if (
equali(classnameptd"func_breakable"))
                {
                    
// Destroy it
                    
force_use(ptr,ptd)
                }
            }
            
set_pev(ptrpev_flagsFL_KILLME)
        }
    }
}
public 
update_ammo(id)
{
    
g_ammo[id] = Ammo[id];
    
cs_set_user_bpammo(idWeapong_ammo[id])
    
    
engfunc(EngFunc_MessageBeginMSG_ONE_UNRELIABLEget_user_msgid("CurWeapon"), {000}, 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_MessageBeginMSG_ONE_UNRELIABLEget_user_msgid("CurWeapon"), {000}, id)
    
write_byte(1)
    
write_byte(Weapon)
    
write_byte(-1)
    
message_end()
}
//play anim
public playanim(playeranim)
{
    
set_pev(playerpev_weaponanimanim)
    
message_begin(MSG_ONESVC_WEAPONANIM, {000}, player)
    
write_byte(anim)
    
write_byte(pev(playerpev_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
Hey is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode