Raised This Month: $ Target: $400
 0% 

Best way to Detect Hit/Miss with Awp.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Paulster1022
Member
Join Date: Apr 2006
Old 04-24-2011 , 11:42   Best way to Detect Hit/Miss with Awp.
Reply With Quote #1

This function seems to do exactly what I need. However, I am not entirely sure how this function works and or how to register the function properly. Also to detect if Hit/Miss I was using get_user_aiming. Not sure if thats the most accurate way.

/**
* Description: Called when the main attack of a weapon is triggered.
* Forward params: function(this)
* Return type: None.
* Execute params: ExecuteHam(Ham_Weapon_PrimaryAttack, this);
*/
Ham_Weapon_PrimaryAttack,
Paulster1022 is offline
Send a message via AIM to Paulster1022
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 04-24-2011 , 11:49   Re: Best way to Detect Hit/Miss with Awp.
Reply With Quote #2

Paulster1022
Quote:
using get_user_aiming
This will not detect a hit through the wall or grenade hit.
You can use Ham_Takedamage to detect hit and Ham_Weapon_PrimaryAttack to detect shots count. Ham_Weapon_PrimaryAttack count - Ham_Takedamage count = miss count.

RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_awp" "ham_Weapon_PrimaryAttack")
RegisterHam(Ham_TakeDamage, "player", "ham_TakeDamage")

public ham_Weapon_PrimaryAttack(weapon_entity)
{
}

public ham_TakeDamage(victim, inflictor, attacker, Float:damage) // inflictor will probably be weapon_entity from function above
{
}
__________________


Last edited by SonicSonedit; 04-24-2011 at 11:56.
SonicSonedit is offline
Paulster1022
Member
Join Date: Apr 2006
Old 04-24-2011 , 12:23   Re: Best way to Detect Hit/Miss with Awp.
Reply With Quote #3

Quote:
Originally Posted by SonicSonedit View Post
Paulster1022
This will not detect a hit through the wall or grenade hit.
You can use Ham_Takedamage to detect hit and Ham_Weapon_PrimaryAttack to detect shots count. Ham_Weapon_PrimaryAttack count - Ham_Takedamage count = miss count.

RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_awp" "ham_Weapon_PrimaryAttack")
RegisterHam(Ham_TakeDamage, "player", "ham_TakeDamage")

public ham_Weapon_PrimaryAttack(weapon_entity)
{
}

public ham_TakeDamage(victim, inflictor, attacker, Float:damage) // inflictor will probably be weapon_entity from function above
{
}
To detect a hit I would use Takedamage, but to detect a miss.... I need to detect the bullet shot and no damage occurred.
Code:
new bool: did_damage[33]

public ham_TakeDamage(victim, inflictor, attacker, Float:damage)
{
    if(inflictor == CSW_AWP)
        did_damage[attacker] = true
}

public ham_Weapon_PrimaryAttack(weapon_entity)
{
	for(new i = 0; i < g_maxplayers; i++)
	{
		if(is_user_alive(i))
		{
                        if(did_damage[i])
                        {
                              client_print(i, print_chat, "Hit with Awp!")
                              did_damage[i] = false
                        }
                  
                       else
                       {
                              client_print(i, print_chat, "Missed with Awp!")
                       }
                 }
        }
}
Ya there is no way this is working out correctly. Still unsure on detecting the shot missed.
Paulster1022 is offline
Send a message via AIM to Paulster1022
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 04-24-2011 , 12:38   Re: Best way to Detect Hit/Miss with Awp.
Reply With Quote #4

Paulster1022
If I remember correctly, ham_primary attack goes before ham_takedamage. You can use a "post" version of the function to detect missed player or not.
Also inflictor is weapon_entity, not weapon id! Weapon is not a part of player, it's a separate entity that lives it's own life.

PHP Code:
  /* Plugin generated by AMXX-Studio */
    
#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

const OFFSET_LINUX_WEAPONS 4
const OFFSET_WEAPONOWNER 41

new g_maxplayers

new hits[33]
new 
shots[33]


public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_awp""ham_Weapon_PrimaryAttack")
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_awp""ham_Weapon_PrimaryAttack_Post"1)
    
RegisterHam(Ham_TakeDamage"player""ham_TakeDamage")
    
    
g_maxplayers=get_maxplayers()
}

public 
ham_TakeDamage(victiminflictorattackerFloat:damage)
{
    if (
get_user_weapon(attacker)!=CSW_AWP)
        return 
HAM_IGNORED

    hits
[attacker]++
    
    
client_print(0print_chat"player %d hit %d with awp!"attackervictim)
    
    return 
HAM_IGNORED
}

public 
ham_Weapon_PrimaryAttack(weapon_entity)
{
    static 
attacker
    
    attacker 
get_pdata_cbase(weapon_entityOFFSET_WEAPONOWNEROFFSET_LINUX_WEAPONS);
    
    if (
attacker<1||attacker>g_maxplayers)
        return 
HAM_IGNORED
    
    shots
[attacker]++
    
    
client_print(0print_chat"player %d fires awp!"attacker)
    
    return 
HAM_IGNORED
}

public 
ham_Weapon_PrimaryAttack_Post(weapon_entity)
{
    static 
attacker
    
    attacker 
get_pdata_cbase(weapon_entityOFFSET_WEAPONOWNEROFFSET_LINUX_WEAPONS);
    
    if (
attacker<1||attacker>g_maxplayers)
        return 
HAM_IGNORED
    
    client_print
(0print_chat"player %d  missed %d times!"attackershots[attacker]-hits[attacker])
    
    return 
HAM_IGNORED

You can find some interesting information here: http://forums.alliedmods.net/showthread.php?t=93229
__________________


Last edited by SonicSonedit; 04-24-2011 at 12:53.
SonicSonedit is offline
Paulster1022
Member
Join Date: Apr 2006
Old 04-24-2011 , 13:28   Re: Best way to Detect Hit/Miss with Awp.
Reply With Quote #5

Thank you, I'll try it out today. I am just hoping the "post" version of Ham_Weapon_PrimaryAttack does in fact happen after the TakeDamage function. By the way, Happy Easter =D.
Paulster1022 is offline
Send a message via AIM to Paulster1022
Old 04-24-2011, 16:43
Hunter-Digital
This message has been deleted by Hunter-Digital. Reason: meh nvm it's unefficient.
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 20:09.


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