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

Solved Creating Wall Shot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-03-2017 , 16:54   Creating Wall Shot
Reply With Quote #1

I'm sorry I've tried 3 methods already that I found here in the forums and it's either none of them works on my system or I'm just too stupid to properly use them.

I'm making a custom sniper rifle with no scope (no crosshair either) and with 100% accuracy, meaning the bullet goes exactly where you point. To do this I've blocked primary attack written the whole shooting function. What I can't give it is the ability to shoot through walls (or other users for that matter).

Here is the trigger function I've done:
PHP Code:
public Fw_Weapon_PrimaryAttack(weapon)
{
    static 
id;
    
id pev(weaponpev_owner);
    
pev(idpev_punchangleg_recoil[id]);
    
    if(!
is_user_connected(id) || !is_user_alive(id))
        return 
HAM_IGNORED
        
    
if(!Get_BitVar(g_has_weaponid))
        return 
HAM_IGNORED
    
    
new iclip cs_get_weapon_ammo(weapon)
    
get_pdata_int(idm_iClip4);
    new 
Float:get_gametime();
    
    if(
iclip && get_pdata_int(idm_iShotsFired4) <= && (get_gametime() - g_gametime) > RATEOFIRE)
    {
        
set_weapon_anim(idSHOOT_ANIM);
        
emit_sound(idCHAN_WEAPONFIRE_SOUNDVOL_NORMATTN_NORM0PITCH_NORM);
        
make_shells(id);
        
        new 
targetbody;
        
get_user_aiming(idtargetbody9999);
        
        if(
target)
        {
            new 
iOrigin[3];
            
get_origin_int(targetiOrigin);
        
            
ExecuteHam(Ham_TakeDamagetargetweaponidDAMAGE hitgroups[body], bodyDMG_BULLET);
            
make_blood(iOriginbody);
        }
        else
        {
            new 
bullet_origin[3];
            
get_user_origin(idbullet_origin3);
            
make_bullet_hole(idbullet_origin);
        }
            
        
cs_set_weapon_ammo(weaponiclip 1);
        
g_gametime get_gametime()
    }
    else
        return 
HAM_IGNORED
    
    
return HAM_SUPERCEDE

And I've tried incorporating 3 different stuff I could find: Alka's, Emp's and GHW_Chronic's.

I was thinking if once the weapon is fired, a traceline is made for x number of distance. Any player hit by that line is stored in an array, then all of them damaged using this:
HTML Code:
ExecuteHam(Ham_TakeDamage, target, weapon, id, DAMAGE * hitgroups[body], body, DMG_BULLET);
But it's a lot easier said than done.

I hope you guys could help me. The weapon is coming along really great but it's weird for it not having any wall penetration...

EDIT:
I've attached the .sma in case you need to see the full code. It's still a mess so pardon for that...
Attached Files
File Type: sma Get Plugin or Get Source (csws_awpns.sma - 415 views - 32.4 KB)
__________________

Last edited by hellmonja; 06-25-2017 at 05:08. Reason: Solved...
hellmonja is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-03-2017 , 16:59   Re: [HELP] Creating Wall Shot
Reply With Quote #2

Have you tried correcting the traceattack of the bullet?
__________________
@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
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-04-2017 , 01:06   Re: [HELP] Creating Wall Shot
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
Have you tried correcting the traceattack of the bullet?
I'm not sure what that is, I'm sorry. Traces and coordinates are so new to me it's really confusing. Thanks, at least I have a lead now. I'll google traceattack later and see what I could come up with...
__________________
hellmonja is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-25-2017 , 04:01   Re: [HELP] Creating Wall Shot
Reply With Quote #4

Sorry I only got back now but I finally figured it out. I'm using GHW_Chronic's code. The reason ExecuteHam(Ham_TakeDamage) wasn't working on it was just a simple thing I overlooked.

Chronic's shoot thru walls code uses weapon indexes (CSW_AWP) while as Ham_TakeDamage uses weapon classnames (weapon_awp). I simply changed Chronic's code to accept weapon classnames so I can use Ham_TakeDamage inside it. It eliminated half of Chronic's code.

The only weird thing is there are two codes handling both damage, but one for shooting thru walls and one when the target is out in the open. I guess it's okay since the plugin works now.

Here's some snippets of what I've done so far. Thanks again for the help!
PHP Code:
public Fw_Weapon_PrimaryAttack(weapon)
{
    static 
id;
    
id pev(weaponpev_owner);
    
pev(idpev_punchangleg_recoil[id]);
    
    if(!
is_user_connected(id) || !is_user_alive(id))
        return 
HAM_IGNORED
        
    
if(!Get_BitVar(g_has_weaponid))
        return 
HAM_IGNORED
    
    
new iclip cs_get_weapon_ammo(weapon)
    
get_pdata_int(idm_iClip4);
    
    if(
iclip && (get_gametime() - g_gametime[id]) > RATEOFIRE)
    {
        
set_weapon_anim(idSHOOT_ANIM);
        
emit_sound(idCHAN_WEAPONFIRE_SOUNDVOL_NORMATTN_NORM0PITCH_NORM);
        
make_shells(id);
        
cs_set_weapon_ammo(weaponiclip 1);
        
g_gametime[id] = get_gametime()
        
        new 
targetbody;
        
get_user_aiming(idtargetbody9999);
        
        if(
target 33)
        {
            
g_killmsg "awpns";
            
            
ExecuteHam(Ham_TakeDamagetargetweaponidDAMAGE hitgroups[body], bodyDMG_BULLET);
            
            static 
CsArmorType:armortype
            
static armor
            armor 
cs_get_user_armor(targetarmortype)
            
            if(
cs_get_user_shield(target) && body == 8)
            {
                
cs_set_user_armor(targetarmor random_num(4550), armortype)
                return 
HAM_SUPERCEDE
            
}
            else 
                
cs_set_user_armor(target0CS_ARMOR_NONE)
            
            new 
body_origin[3];
            
get_user_origin(targetbody_origin);
                        
            if(
cs_get_user_team(id)==cs_get_user_team(target) && !get_pcvar_num(cvar_friendly_fire))
                return 
HAM_SUPERCEDE
            
            make_blood
(body_origin2);
        }
        else
        {
            new 
bullet_origin[3];
            
get_user_origin(idbullet_origin3);
            
make_bullet_hole(idbullet_origin);
        }
    }
    
    
Wall_Shot(idweapon);
    
    return 
HAM_SUPERCEDE

PHP Code:
public Wall_Shot(idwpn//by GHW_Chronic
{
    if(!
is_user_connected(id) || !is_user_alive(id))
        return 
PLUGIN_CONTINUE
        
    
if(!Get_BitVar(g_has_weaponid))
        return 
PLUGIN_CONTINUE
    
    
static Porigin[3]
    static 
Borigin[3]
    
get_user_origin(id,Porigin,1)
    
get_user_origin(id,Borigin,4)
    static 
Float:Delta1[3]
    
Delta1[0]=float(Borigin[0]) - float(Porigin[0])
    
Delta1[1]=float(Borigin[1]) - float(Porigin[1])
    
Delta1[2]=float(Borigin[2]) - float(Porigin[2])
    static 
Float:XYSlope
    XYSlope 
Delta1[1] / Delta1[0]
    static 
Float:YZSlope
    YZSlope 
Delta1[2] / Delta1[1]

    
//Let's check all players to see if we hit anyone.
    
static players[32], numi2i
    get_players
(players,num,"ah")
    for(
i2=0;i2<num;i2++)
    {
        
//We don't want any DEBUG errors in console, we don't want to hit a spec, and we dont want to hurt ourselves either.
        
if(players[i2]!=id)
        {
            
i=players[i2]
            
//Need to know if the player is now within the max distance.
            
static Iorigin[3]
            
get_user_origin(i,Iorigin)
            static 
disti
            disti 
get_distance(Iorigin,Borigin)

            
//Checking...
            
if(disti<=2000)
            {
                
//If they are infront of the person. Added to fix bug reported by that one guy whos name escapes me.
                
static deltaIB[3]
                
deltaIB[0] = Iorigin[0] - Borigin[0]
                
deltaIB[1] = Iorigin[1] - Borigin[1]
                
deltaIB[2] = Iorigin[2] - Borigin[2]

                
//Checking...
                
if((deltaIB[0]>=&& Delta1[0]>=0.0) || (deltaIB[0]<=&& Delta1[0]<=0.0) && ((deltaIB[1]>=&& Delta1[1]>=0) || (deltaIB[1]<=&& Delta1[1]<=0)))
                {
                    
//If they're ducking, their height is changed.
                    
static Float:mp
                    mp 
74.0
                    
if(get_user_button(i) & IN_DUCK)(mp=32.0)
    
                    
//Calculate where their origin would be if they were DIRECTLY in the path of the bullet.
                    
static Float:on_line[3]
                    
on_line[0] = (((Borigin[1] - Iorigin[1]) / XYSlope) - Borigin[0]) * (-1)
                    
on_line[1] = (-1) * ((XYSlope Borigin[0]) - (XYSlope Iorigin[0]) - Borigin[1])
                    
on_line[2] = (-1) * ((YZSlope Borigin[1]) - (YZSlope Iorigin[1]) - Borigin[2])
    
                    
//Check if we hit them anywhere on the body.
                    
if(Iorigin[0]<on_line[0]+32 && Iorigin[0]>on_line[0]-32 && Iorigin[1]<on_line[1]+32 && Iorigin[1]>on_line[1]-32 && Iorigin[2]<on_line[2]+mp && Iorigin[2]>on_line[2]-mp)
                    {
                        
//"I" is now reffered to as "ent". This is because this section of script was made AND THEN placed into a for sequence.
                        
static ent
                        ent 
i
    
                        
//Let's Obey Friendly Fire.
                        
static bool:continue3=false
                        
if(cs_get_user_team(id)==cs_get_user_team(ent) && get_pcvar_num(cvar_friendly_fire))
                            
continue3=true
                        
if(cs_get_user_team(id)!=cs_get_user_team(ent))
                            
continue3=true
                        
if(cs_get_user_shield(ent))
                            
continue3=false

                        
if(continue3)
                        {
                            
//Here are tHe hitplaces that I uUsed below for refference.
                            //1=head +20z
                            //2=torso >=8 side, >=20z, <=0z
                            //4=arm <8 side, 0<z
                            //5=foot -z
    
                            //Calculate what hitbox we will register the hit as hitting.
                            
static hitplacebody;
                            
hitplace=7
                            
static Float:endyoffset
                            endyoffset 
on_line[1] - Iorigin[1]
                            static 
Float:endzoffset
                            endzoffset 
on_line[2] - Iorigin[2]
                            if(
endzoffset>=15)//8 && endyoffset<5 && endyoffset>-5)
                            
{
                                
hitplace //HeadShot!
                                
body 1;
                            }
                            else if(
endzoffset<=-5)
                            {
                                
hitplace=//Foot
                                
body random_num(67);
                            }
                            else if(
endzoffset>-&& endzoffset<15)
                            {
                                
hitplace=//Torso
                                
if(endyoffset<-13 || endyoffset>13)
                                {
                                    
hitplace=//arm
                                    
body random_num(25);
                                }
                            }
                            else if(
endzoffset>25 || endzoffset<-39)
                            {
                                
hitplace=//Error, mistake, didn't actually hit them X_X
                            
}
    
                            
//Since there is this height error, we're gonna stop here.
                            
if(hitplace!=7)
                            {
                                
//Find out what weapon player is using so we can calculate how much damage the player will do (IE: Pistols do less than rifles)
                                
static weapon
                                weapon 
get_user_weapon(id);

                                if(
weapon==CSW_AWP && Get_BitVar(g_has_weapon,id))
                                {
    
                                    
//Find armor.
                                    
static CsArmorType:armortype
                                    
static armor
                                    armor 
cs_get_user_armor(entarmortype)
                                    
                                    
g_killmsg "awpns_thru_the_wall";
                                    
                                    new 
Float:dmg = (DAMAGE hitgroups[body]) * 0.50;
                                    
ExecuteHam(Ham_TakeDamageentwpniddmgbodyDMG_BULLET);
                                    
                                    if(
cs_get_user_shield(ent))
                                        
cs_set_user_armor(entarmor random_num(4045), armortype)
                                    else 
                                        
cs_set_user_armor(ent0CS_ARMOR_NONE)
                                                                        
                                    new 
targ_origin[3];
                                    
get_user_origin(enttarg_origin);
                        
                                    if(
cs_get_user_team(id) == cs_get_user_team(ent) && !get_pcvar_num(cvar_friendly_fire))
                                        return 
PLUGIN_CONTINUE
            
                                    make_blood
(targ_originbody);
                                    return 
PLUGIN_HANDLED
                                
}
                            }
                        }
                    }
                }
            }
        }
    }
    return 
PLUGIN_HANDLED

__________________
hellmonja is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 06-25-2017 , 11:57   Re: Creating Wall Shot
Reply With Quote #5

Wtf is this lol. You can just use multiple TraceLine.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-25-2017 , 18:30   Re: Creating Wall Shot
Reply With Quote #6

Quote:
Originally Posted by PRoSToTeM@ View Post
Wtf is this lol. You can just use multiple TraceLine.
Not familiar with TraceLine. Please teach me...

https://forums.alliedmods.net/showthread.php?t=66076
Would this suffice?...
__________________

Last edited by hellmonja; 06-25-2017 at 18:34. Reason: Update
hellmonja is offline
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 21:48.


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