AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Best way to Detect Hit/Miss with Awp. (https://forums.alliedmods.net/showthread.php?t=155614)

Paulster1022 04-24-2011 11:42

Best way to Detect Hit/Miss with Awp.
 
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,

SonicSonedit 04-24-2011 11:49

Re: Best way to Detect Hit/Miss with Awp.
 
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
{
}

Paulster1022 04-24-2011 12:23

Re: Best way to Detect Hit/Miss with Awp.
 
Quote:

Originally Posted by SonicSonedit (Post 1456773)
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.

SonicSonedit 04-24-2011 12:38

Re: Best way to Detect Hit/Miss with Awp.
 
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

Paulster1022 04-24-2011 13:28

Re: Best way to Detect Hit/Miss with Awp.
 
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.


All times are GMT -4. The time now is 20:09.

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