Raised This Month: $32 Target: $400
 8% 

Solved [HELP] Custom Sniper Bullet


Post New Thread Reply   
 
Thread Tools Display Modes
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
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-24-2018 , 03:15   Re: [HELP] Custom Sniper Bullet
Reply With Quote #2

Add pev_view_ofs.
__________________
HamletEagle is offline
Hey
Member
Join Date: Dec 2017
Old 01-24-2018 , 17:08   Re: [HELP] Custom Sniper Bullet
Reply With Quote #3

i did a try this code but when i did test it, it didn't work it still goes a bit to the left/right:

PHP Code:
    new Float:vOrigin[3], Float:vUp[3], Float:vOffset[3];
    
pev(idpev_originvOrigin);
    
pev(idpev_view_ofsvOffset);
    
    
global_get(glb_v_upvUp);
    new 
up 12;
    
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;
    
    
// Origin
    
entity_set_origin(BulletvOrigin

Last edited by Hey; 01-24-2018 at 17:30.
Hey is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-24-2018 , 18:25   Re: [HELP] Custom Sniper Bullet
Reply With Quote #4

Try this
, include xs
PHP Code:
    new Float:vOrigin[3], Float:vAngle[3], Float:vOffset[3];
    
pev(idpev_originvOrigin);
    
pev(idpev_view_ofsvOffset);
    
pev(idpev_v_anglevAngle)
    
xs_vec_add(vOriginvOffsetvOrigin);
    
entity_set_origin(BulletvOrigin);
    
angle_to_vector(vAngleANGLEVECTOR_FORWARDvAngle)
    
xs_vec_mul_scalar(vAngle9999.0vAngle)
    
xs_vec_add(vOriginvAnglevOrigin)
    
entity_set_vector(BulletEV_VEC_velocityvOrigin); 

disallow the dmg for the owner..
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-31-2018 at 05:59.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Hey
Member
Join Date: Dec 2017
Old 01-24-2018 , 19:11   Re: [HELP] Custom Sniper Bullet
Reply With Quote #5

won't work at all now the bullet(entity) doesn't get shot/created cuz there is no sound of the shooting which you can see in the code when the entity gets created and shot the sound plays from the bullet itself.

Thanks for trying tho.

Last edited by Hey; 01-24-2018 at 19:13.
Hey is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-24-2018 , 19:19   Re: [HELP] Custom Sniper Bullet
Reply With Quote #6

Quote:
Originally Posted by Hey View Post
won't work at all now the bullet(entity) doesn't get shot/created cuz there is no sound of the shooting which you can see in the code when the entity gets created and shot the sound plays from the bullet itself.

Thanks for trying tho.

I told you to check if the bullet is hitting the owner then ignore ... Why you dont listen?

And im not trying ik what im saying..
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-24-2018 at 19:28.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Hey
Member
Join Date: Dec 2017
Old 01-24-2018 , 19:29   Re: [HELP] Custom Sniper Bullet
Reply With Quote #7

how do i do such a check ?
PHP Code:
      if(ptd == owner)
      return 
FMRES_IGNORED
Hey is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-24-2018 , 19:35   Re: [HELP] Custom Sniper Bullet
Reply With Quote #8

Quote:
Originally Posted by Hey View Post
how do i do such a check ?
PHP Code:
      if(ptd == owner)
      return 
FMRES_IGNORED
PHP Code:
// We hit something!!!
public pfn_touch(ptrptd)
{
    
// If ent is valid
    
if (pev_valid(ptr))
    {    
        
// Get classnames
        
static classname[32], classnameptd[32]
        
pev(ptrpev_classnameclassname31)
        
        
// Our ent
        
if(equal(classname"sniper_bullet"))
        {
            
// Get it's origin
            
new Float:Origin[3]
            
pev(ptrpev_originOrigin)

            new 
owner pev(ptrpev_owner)

            
// hope so its not the shooter that we hit!
            
if(ptd == owner) return FMRES_IGNORED;

            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)
        }
    }

nothing complex!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-24-2018 at 19:36.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Hey
Member
Join Date: Dec 2017
Old 01-24-2018 , 19:48   Re: [HELP] Custom Sniper Bullet
Reply With Quote #9

i did the same thing but still didn't work, in fact this did for some weird reason block the buyzone, the original code was working but the problem was only the left/right thingy, is there anyway to just fix that original code ?

NOTE: you can test the code for yourself, idk.

Last edited by Hey; 01-24-2018 at 19:48.
Hey is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-24-2018 , 19:55   Re: [HELP] Custom Sniper Bullet
Reply With Quote #10

Quote:
Originally Posted by Hey View Post
i did the same thing but still didn't work, in fact this did for some weird reason block the buyzone, the original code was working but the problem was only the left/right thingy, is there anyway to just fix that original code ?

NOTE: you can test the code for yourself, idk.
can you post what have you done?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



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 16:28.


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