Raised This Month: $106 Target: $400
 26% 

[INFO] Fakemeta & Ham detailed function descriptions and examples


Post New Thread Reply   
 
Thread Tools Display Modes
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 08-25-2009 , 12:03   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #41

Oi but you need a name on that. The thread's name is too long i guess.
SnoW is offline
Send a message via MSN to SnoW
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 08-26-2009 , 09:44   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #42

HamSandWich function:
PHP Code:
Ham_TraceAttack 
Description:
Forward: This function is called when an entity is shot by another player (weapon, not grenade.)
Function: This function simulates a weapon attack on an entity.
You should use this function when you want to simulate an attack by a weapon from a player (like a gunshot!)

Parameters:
(ent, attacker, float:damage, Float:direction[3], trace, bits)
- ent is the entity that has been shot
- attacker is the entity that shoot the victim
- damage - this is the damage done by the shot but it does not have the hitgroup multiplication done (that is done before TakeDamage Call)
- direction - this parameter has a very important roll, it is a normalized vector that shows the direction of the bullets path
- trace - the trace handle that offers lots of useful information
- bits - the damage bits

Forward usage:
PHP Code:
#define SHOT_DISTANCE_POSSIBLE 2048.0

// plugin_init()
Register_Ham(Ham_TraceAttack"func_breakable""fw_traceatt_break")

public 
fw_traceatt_break(entattackerfloat:damageFloat:direction[3], tracebits)
{
    new 
Float:start[3], end[3], fractionmulti
    get_tr2
(traceTR_vecEndPosend)
    
get_tr2(traceTR_flFractionfraction)
    
    
multi fraction SHOT_DISTANCE_POSSIBLE
    
    xs_vec_mul_scalar
(directionmultistart)
    
    
// This is how to correctly get the start origin!
    
xs_vec_add(startendstart)
    

Function true usage:
PHP Code:
#define SHOT_DISTANCE_POSSIBLE 2048.0

public Ham_Shoot(attackerdamagebitsbool:can_penetrate)
{
    new 
Float:angles[3], Float:start[3], Float:end[3], Float:direction[3], Float:fakeend[3]
    
    
// Turn the angles in a true vector
    
pev(attackerpev_anglesangles)
    
angle_vector(anglesANGLEVECTOR_FORWARDdirection)
    
    
// We make this as a normal shot!
    
xs_vec_mul_scalar(directionSHOT_DISTANCE_POSSIBLEfakeend)
    
    
// Start origin
    
pev(attackerpev_originstart)
    
pev(attackerpev_view_ofsend)
    
xs_vec_add(endstartstart)
    
    
// Obtain the end shot origin
    
xs_vec_add(startfakeendend)
    
    
// From now this is how these variables will be used
    // origin - start place (will remain constant!)
    // end - end place (will remain constant!)
    // angles - no use
    // fakeend - dynamic start origin
    // direction - will be used in the forwards (will remain constant!)
    
    
new ptr create_tr2()
    
    
// Trace to the first entity
    
engfunc(EngFunc_TraceLinestartendDONT_IGNORE_MONSTERSattackerptr)
    
    new 
Float:fractionhit get_tr2(ptrTR_pHit)
    
get_tr2(ptrTR_flFractionfraction)
    
    
// Update the fake start origin
    
get_tr2(ptrTR_vecEndPosfakeend)
    
    
// This means that we hited sky!
    
if (fraction != 1.0 && engfunc(EngFunc_PointContentsfakeend) == CONTENTS_SKY && hit == -1)
    {
        
// Prepare the trace handle
        
set_tr2(ptrTR_pHit0)
        
        
// Bullet trace!
        
ExecuteHamB(Ham_TraceAttack0attackerdamagedirectionptrDMG_NEVERGIB DMG_BULLET)
        
        
free_tr2(ptr)
        return -
1
    
}
    
    if (
hit == -1)
    {
        
hit 0
        set_tr2
(ptrTR_pHithit)
    }
    
    
ExecuteHamB(Ham_TraceAttackhitattackerdamagedirectionptrDMG_NEVERGIB DMG_BULLET)
    
    if (!
can_penetrate)
    {
        
free_tr2(ptr)
        return 
1
    
}
    
    
// Trace to the next entity
    
engfunc(EngFunc_TraceLinefakeendendDONT_IGNORE_MONSTERShitptr)
    
    
hit get_tr2(ptrTR_pHit)
    
get_tr2(ptrTR_flFractionfraction)
    
    
// Update the fake start origin
    
get_tr2(ptrTR_vecEndPosfakeend)
    
    if (
hit == -1)
    {
        
hit 0
        set_tr2
(ptrTR_pHithit)
    }
    
    
set_tr2(ptrTR_flFractionget_distance_f(startfakeend) / SHOT_DISTANCE_POSSIBLE)
    
    
ExecuteHamB(Ham_TraceAttackhitattackerdamagedirectionptrDMG_NEVERGIB DMG_BULLET)
    
        
    
free_tr2(ptr)
    return 
1

__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 09-16-2010 at 20:03.
ot_207 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-26-2009 , 18:51   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #43

Quote:
- direction - this parameter has a very important roll, it is the tangent of the line that the bullet goes
I don't understand this. Is it the direction vector from the attacker to the victim?
__________________
fysiks is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 08-26-2009 , 18:54   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #44

Quote:
Originally Posted by fysiks View Post
I don't understand this. Is it the direction vector from the attacker to the victim?
Let me explain in vectors.
We have the endposition of the bullet.
ENDPOS
We have the gun tube from where the bullet was fired.
STARTPOS
Direction is xs_vec_normalize(ENDPOS-STARTPOS), it shows the angles.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-26-2009 , 19:04   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #45

Ok that's what I thought. Tangent is not a good word to use there in this case. The tangent of the bullet's path is constantly changing throughout it's parabolic path (I don't know if they consider gravity for bullets in these games ).
__________________
fysiks is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 08-26-2009 , 19:07   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #46

Quote:
Originally Posted by fysiks View Post
Ok that's what I thought. Tangent is not a good word to use there in this case. The tangent of the bullet's path is constantly changing throughout it's parabolic path (I don't know if they consider gravity for bullets in these games ).
Gravity does not influence bullets. So Tangent is the best term (I think) to describe it.
If you have a better suggestion please let me know .
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-27-2009 , 00:12   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #47

Quote:
Originally Posted by ot_207 View Post
Gravity does not influence bullets. So Tangent is the best term (I think) to describe it.
If you have a better suggestion please let me know .
"[Unit] vector in the direction of the bullets path."

[unit] only if it's normalized.

The tangent of a straight line is the line itself. When I first read it I was thinking perpendicular for some reason which would mean it was a plane lol .
__________________

Last edited by fysiks; 08-27-2009 at 00:16.
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-27-2009 , 00:39   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #48

It's called normal vector i guess.
__________________
- tired and retired -
ConnorMcLeod is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-03-2009 , 12:23   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #49

Quote:
NOTE The terms "perpendicular," "orthogonal," and "normal" all mean essentially the same thing - meeting at right angles. However, it is common to say that two vectors are orthogonal, two lines or planes are perpendicular, and a vector is normal to a given line or plane.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-03-2009 , 17:12   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #50

Normalize => convert to vector of length 1 (aka unit vector).

!=

normal vector (Emp explains above)
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 20:40.


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