Raised This Month: $ Target: $400
 0% 

Check if it is a player (aiming)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 11-13-2010 , 18:00   Check if it is a player (aiming)
Reply With Quote #1

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;


Last edited by bibu; 11-13-2010 at 19:06.
bibu is offline
Old 11-14-2010, 07:26
bibu
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
Old 11-14-2010, 08:57
nnajko
This message has been deleted by nnajko.
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-14-2010 , 13:00   Re: Check if it is a player (aiming)
Reply With Quote #4

Quote:
Originally Posted by bibu View Post
bump
Don't bump until 2 weeks have passed since last post.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 11-14-2010 , 09:18   Re: Check if it is a player (aiming)
Reply With Quote #5

Getting
Quote:
Invalid player id x
...
bibu is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-14-2010 , 09:44   Re: Check if it is a player (aiming)
Reply With Quote #6

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;

__________________

Last edited by Bugsy; 11-14-2010 at 09:50.
Bugsy is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 11-14-2010 , 13:42   Re: Check if it is a player (aiming)
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
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.
__________________
Hunter-Digital is offline
Old 11-14-2010, 14:02
Bugsy
This message has been deleted by Bugsy.
bibu
Veteran Member
Join Date: Sep 2010
Old 11-14-2010 , 17:03   Re: Check if it is a player (aiming)
Reply With Quote #9

Quote:
Originally Posted by Hunter-Digital View Post
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.
bibu is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 11-14-2010 , 11:12   Re: Check if it is a player (aiming)
Reply With Quote #10

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;

bibu 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 11:28.


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