AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if it is a player (aiming) (https://forums.alliedmods.net/showthread.php?t=143054)

bibu 11-13-2010 18:00

Check if it is a player (aiming)
 
I am hooking a knife attack with ham:

PHP Code:

RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""BlockKnife")
 
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""BlockKnife"

This is what I have:

PHP Code:

public BlockKnife(id)
{
    if(
cached_status && !get_user_aiming (id) == PLAYER)
        return 
HAM_SUPERCEDE;
        
    return 
HAM_IGNORED;


So I want to enable knife attacks only on players, this can be a friend or an enemy.

I tested it like that now but I am getting weird errors:

PHP Code:

public BlockKnife(id)
{
    if(
cached_status)
        if(!
is_aiming_at_player(id))
            return 
HAM_SUPERCEDE;
        
    return 
HAM_IGNORED;
}

stock bool:is_aiming_at_player(index)
{
    new 
targettempclassname[32];
    
    
get_user_aiming(indextargettemp);
    
    
pev(targetpev_classnameclassname31);
    
    if ( 
equal(classname"player") ) 
        return 
true;
        
    return 
false;



bibu 11-14-2010 09:18

Re: Check if it is a player (aiming)
 
Getting
Quote:

Invalid player id x
...

Bugsy 11-14-2010 09:44

Re: Check if it is a player (aiming)
 
The weapon entity is passed to the ham forward, not player id. Use pev( iEntity , pev_owner ) to get the player id. You will still get the knife attack animation though no attack is actually occurring.

Untested
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new g_iMaxPlayers;

#define IsPlayer(%1)    (1<=%1<=g_iMaxPlayers)

public plugin_init() 
{
    
RegisterHamHam_Weapon_PrimaryAttack "weapon_knife" "BlockKnife" );
    
RegisterHamHam_Weapon_SecondaryAttack "weapon_knife" "BlockKnife" );
    
    
g_iMaxPlayers get_maxplayers();
}
public 
BlockKnifeiEntity )
{
    new 
iEnemy iBody iPlayer peviEntity pev_owner );
    
    if ( !
IsPlayeriPlayer ) )
        return 
HAM_IGNORED;
        
    
get_user_aimingiPlayer iEnemy iBody );
     
    return 
IsPlayeriEnemy ) ? HAM_IGNORED HAM_SUPERCEDE;



bibu 11-14-2010 11:12

Re: Check if it is a player (aiming)
 
Wow, works perfect. Can you show me an example with that please? So that I can check also other entities easily.

PHP Code:

stock bool:is_aiming_at_player(index)
{
    new 
targettempclassname[32];
    
    
get_user_aiming(indextargettemp);
    
    
pev(targetpev_classnameclassname31);
    
    if ( 
equal(classname"player") ) 
        return 
true;
        
    return 
false;



Bugsy 11-14-2010 12:53

Re: Check if it is a player (aiming)
 
PHP Code:

public BlockKnifeiEntity )
{
    new 
iPlayer peviEntity pev_owner );
    
    if ( !
IsPlayeriPlayer ) )
        return 
HAM_IGNORED;
        
    return 
is_aiming_at_entityiPlayer "player" ) ? HAM_IGNORED HAM_SUPERCEDE;
}  

bool:is_aiming_at_entityiPlayer , const szEntityClassname[] )
{
    new 
iTarget iTmp szClassname32 ];
    
    
get_user_aimingiPlayer iTarget iTmp );
    
peviTarget pev_classname szClassname charsmaxszClassname ) );
    
    return 
bool:equalszEntityClassname szClassname );



Exolent[jNr] 11-14-2010 13:00

Re: Check if it is a player (aiming)
 
Quote:

Originally Posted by bibu (Post 1349133)
bump

Don't bump until 2 weeks have passed since last post.

Hunter-Digital 11-14-2010 13:42

Re: Check if it is a player (aiming)
 
Quote:

Originally Posted by Bugsy (Post 1349214)
You will still get the knife attack animation though no attack is actually occurring.

You could just hook attack in pre and set next attack to 0.1s or so and then it shouldn't play the animation and shouldn't attack either.

bibu 11-14-2010 17:03

Re: Check if it is a player (aiming)
 
Quote:

Originally Posted by Hunter-Digital (Post 1349378)
You could just hook attack in pre and set next attack to 0.1s or so and then it shouldn't play the animation and shouldn't attack either.

I don't get a knife animation at all. Works perfectly, thanks bugsy. :wink:

ARES[ro] 11-15-2010 19:12

Re: Check if it is a player (aiming)
 
Uhhh sory but if u dont aim at the person and ur near him u may still hit him... therefore use trace_forward. :P
Hope this helps if when u want to fix that bug.


All times are GMT -4. The time now is 11:28.

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