AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player should evade all bullets (https://forums.alliedmods.net/showthread.php?t=95343)

DA 06-22-2009 14:38

Player should evade all bullets
 
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

SnoW 06-22-2009 14:47

Re: Player should evade all bullets
 
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;



SchlumPF* 06-22-2009 14:49

Re: Player should evade all bullets
 
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];

ConnorMcLeod 06-22-2009 15:05

Re: Player should evade all bullets
 
Better to hook TraceAttack.

Sylwester 06-22-2009 15:29

Re: Player should evade all bullets
 
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;



SchlumPF* 06-22-2009 15:42

Re: Player should evade all bullets
 
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.

ConnorMcLeod 06-22-2009 16:03

Re: Player should evade all bullets
 
Quote:

Originally Posted by SchlumPF* (Post 854438)
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 );
    }



DA 06-22-2009 17:01

Re: Player should evade all bullets
 
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?

ConnorMcLeod 06-22-2009 17:18

Re: Player should evade all bullets
 
You can retrieve it from the trace handle in TraceAttack, or by player offset m_LastHitGroup (= 75 in cs and cz) in TraceAttack.

SchlumPF* 06-23-2009 05:24

Re: Player should evade all bullets
 
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 ^^)


All times are GMT -4. The time now is 15:32.

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