Raised This Month: $ Target: $400
 0% 

Player should evade all bullets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DA
Veteran Member
Join Date: Nov 2005
Location: Germany/Münster
Old 06-22-2009 , 14:38   Player should evade all bullets
Reply With Quote #1

Hello guys,

I'm currently working on a function where a player can evade bullets.
First, my simple example.

Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #include <engine> #define PLUGIN "Godmodetest" #define VERSION "1.0" #define AUTHOR "DA" new fLastShotFired[32]; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_forward ( FM_TraceLine, "TRIGGER_TraceLine" );     register_event ( "CurWeapon", "on_CurWeapon", "be", "1=1" ); } public on_CurWeapon( id ) {     fLastShotFired[id] = halflife_time(); } // Called when a user looks somewhere public TRIGGER_TraceLine( Float:v1[3], Float:v2[3], noMonsters, pentToSkip ) {     new iAttacker = pentToSkip;     new iVictim = get_tr(TR_pHit);         // Make sure we have a valid victim     if ( is_user_alive( iVictim ) )     {         // We need to have a valid player!         if ( is_user_alive( iAttacker ) )         {             new Float:fTime = halflife_time();             new Float:fDifference = fTime - fLastShotFired[iAttacker];                         if ( fDifference < 0.1 && fDifference > 0.0 )             {                 client_print( 0, print_chat, "He is the god!" );                                 set_tr( TR_flFraction, 1.0 );                 return FMRES_SUPERCEDE;             }         }     }         return FMRES_IGNORED; }

How you see that I make it with Trigger_TraceLine. Why?
Because in my real plugin the player should have only a chance to evade a bullet.

Well. I've tested this function on my localmachine but it's not working. Maybe you have an idea why or better - a better way to do it.

Thanks in advance for any help.
DA
__________________
DA is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 06-22-2009 , 14:47   Re: Player should evade all bullets
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <hamsandwich>
public plugin_init()
     
RegisterHamHam_TakeDamage"player""ham_TakeDamage" );
public 
ham_TakeDamageidinflictorattackerFloat:damagedamagebits )
{
     if( 
damagebits == DMG_BULLET )
          return 
random_num0) ? HAM_IGNORED HAM_SUPERCEDE;
     return 
HAM_IGNORED;


Last edited by SnoW; 06-22-2009 at 14:50.
SnoW is offline
Send a message via MSN to SnoW
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 06-22-2009 , 14:49   Re: Player should evade all bullets
Reply With Quote #3

ham_takedmg -> dmgtype == DMG_BULLET -> if( random_num(0,100) < PERCETNAGE_CHANCE ) return HAM_SUPERCEDE

edit: snow was faster -.-

edit2:
new fLastShotFired[32]; ->
new fLastShotFired[33];
__________________

Last edited by SchlumPF*; 06-22-2009 at 14:54.
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-22-2009 , 15:05   Re: Player should evade all bullets
Reply With Quote #4

Better to hook TraceAttack.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-22-2009 , 15:29   Re: Player should evade all bullets
Reply With Quote #5

You can use traceline if you want...
PHP Code:
public TRIGGER_TraceLine(Float:v1[3], Float:v2[3], noMonsterspentToSkip){
    new 
iAttacker pentToSkip;
    new 
iVictim get_tr(TR_pHit);
    if ( 
iVictim >= && iVictim <= 32 && iAttacker >= && iAttacker <= 32){
        new 
Float:rand random_float(0.0,1.0)
        new 
Float:chance 0.3
        
if (is_user_alive(iVictim) && (rand <= chance)){
            
set_tr(TR_flFraction1.0);
            return 
FMRES_SUPERCEDE;
        }
    }
    return 
FMRES_IGNORED;

__________________
Impossible is Nothing
Sylwester is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 06-22-2009 , 15:42   Re: Player should evade all bullets
Reply With Quote #6

you can traceline but its inefficient, also traceattack and takedmg shouldnt make any difference since you have to check the dmgtype and supercede the hook if the player evaded.
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-22-2009 , 16:03   Re: Player should evade all bullets
Reply With Quote #7

Quote:
Originally Posted by SchlumPF* View Post
you can traceline but its inefficient, also traceattack and takedmg shouldnt make any difference since you have to check the dmgtype and supercede the hook if the player evaded.
But TakeDamage and TraceBleed are called from TraceAttack.

PHP Code:
//=========================================================
// TraceAttack
//=========================================================
void CBasePlayer :: TraceAttackentvars_t *pevAttackerfloat flDamageVector vecDirTraceResult *ptrint bitsDamageType)
{
    if ( 
pev->takedamage )
    {
        
m_LastHitGroup ptr->iHitgroup;

        switch ( 
ptr->iHitgroup )
        {
        case 
HITGROUP_GENERIC:
            break;
        case 
HITGROUP_HEAD:
            
flDamage *= gSkillData.plrHead;
            break;
        case 
HITGROUP_CHEST:
            
flDamage *= gSkillData.plrChest;
            break;
        case 
HITGROUP_STOMACH:
            
flDamage *= gSkillData.plrStomach;
            break;
        case 
HITGROUP_LEFTARM:
        case 
HITGROUP_RIGHTARM:
            
flDamage *= gSkillData.plrArm;
            break;
        case 
HITGROUP_LEFTLEG:
        case 
HITGROUP_RIGHTLEG:
            
flDamage *= gSkillData.plrLeg;
            break;
        default:
            break;
        }

        
SpawnBlood(ptr->vecEndPosBloodColor(), flDamage);// a little surface blood.
        
TraceBleedflDamagevecDirptrbitsDamageType );
        
AddMultiDamagepevAttackerthisflDamagebitsDamageType );
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
DA
Veteran Member
Join Date: Nov 2005
Location: Germany/Münster
Old 06-22-2009 , 17:01   Re: Player should evade all bullets
Reply With Quote #8

Thank you all for your response. But I have a little problem.
I have forgot to say that I need the Hitzone.
Is it maybe possible to get the Hitzone with TraceAttack or the TakeDamage event? (with hamsandwich)

I found this in the ham_const.inc
Code:
/**
	 * Description:		Usually called whenever an entity gets attacked by a hitscan (such as a gun) weapon.
	 *					Use the get/set tr2 natives in fakemeta to handle the traceresult data.
	 *					Do not use a handle of 0 as a traceresult in execution, use create_tr2() from Fakemeta
	 *					to pass a custom handle instead.  (Don't forget to free the handle when you're done.)
	 * Forward params:	function(this, idattacker, Float:damage, Float:direction[3], traceresult, damagebits)
	 * Return type:		None.
	 * Execute params:	ExecuteHam(Ham_TraceAttack, this, idattacker, Float:damage, Float:direction[3], tracehandle, damagebits);
	 */
	Ham_TraceAttack,
	
	/**
	 * Description:		Usually called whenever an entity takes any kind of damage.
	 *					Inflictor is the entity that caused the damage (such as a gun).
	 *					Attacker is the entity that tirggered the damage (such as the gun's owner).
	 * Forward params:	function(this, idinflictor, idattacker, Float:damage, damagebits);
	 * Return type:		Integer.
	 * Execute params:	ExecuteHam(Ham_TakeDamage, this, idinflictor, idattacker, Float:damage, damagebits);
	 */
	Ham_TakeDamage,
So it's not possible?
__________________
DA is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-22-2009 , 17:18   Re: Player should evade all bullets
Reply With Quote #9

You can retrieve it from the trace handle in TraceAttack, or by player offset m_LastHitGroup (= 75 in cs and cz) in TraceAttack.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 06-23-2009 , 05:24   Re: Player should evade all bullets
Reply With Quote #10

Ham_TraceAttack(plr, idattacker, Float:damage, Float:direction[3], tracehandle, damagebits) -> hitgroup = get_tr2( tracehandle, TR_iHitgroup ) (not sure whetehr there is a typo anywhere, my time runs out ^^)
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
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 15:32.


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