View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-16-2012 , 23:49   Re: SDK Hooks 2.1 - Updated 2011-9-10
#1824

Quote:
Originally Posted by Ambit View Post
OnTakeDamagePost is crashing the server when I use it.

The values in OnTakeDamagePost are all wrong and Visual Studio says the server crash is due to an access violation.

This is the relevant code:

Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage)
    SDKHook(client, SDKHook_OnTakeDamagePost, OnTakeDamagePost)
}


public Action:OnTakeDamagePost(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    LogMessage("OnTakeDamagePost start")
    //LogMessage("Victim: %d", victim)
    LogMessage("Attacker: %d", attacker)
    LogMessage("Damage: %f", damage)
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{		
    LogMessage("OnTakeDamage start")
    LogMessage("Victim: %d", victim)
    LogMessage("Attacker: %d", attacker)
    LogMessage("Damage: %f", damage)

    if (victim > 1)
    {
        damage = 0.0
        return Plugin_Changed
    }
    return Plugin_Continue
}
And the log output:

Code:
L 05/16/2012 - 19:47:10: [freezetag.smx] OnTakeDamage start
L 05/16/2012 - 19:47:10: [freezetag.smx] Victim: 4
L 05/16/2012 - 19:47:10: [freezetag.smx] Attacker: 3
L 05/16/2012 - 19:47:10: [freezetag.smx] Damage: 12.000000
L 05/16/2012 - 19:47:10: [freezetag.smx] OnTakeDamagePost start
L 05/16/2012 - 19:47:10: [freezetag.smx] Attacker: 12846
L 05/16/2012 - 19:47:10: [freezetag.smx] Damage: 0.000000
L 05/16/2012 - 19:47:10: [freezetag.smx] OnTakeDamage start
L 05/16/2012 - 19:47:10: [freezetag.smx] Victim: 1
L 05/16/2012 - 19:47:10: [freezetag.smx] Attacker: 5
L 05/16/2012 - 19:47:10: [freezetag.smx] Damage: 30.000000
L 05/16/2012 - 19:47:10: [freezetag.smx] OnTakeDamagePost start
L 05/16/2012 - 19:47:10: [freezetag.smx] Attacker: 805306368
The server had friendly fire on and all of the other players were bots on the opposite team from me. Trying to access the victim id from OnTakeDamage post always resulted in a crash, so I had to comment it out. I'm not sure why reading damage worked the first time but crashed the second, but you can clearly see that the attacker id in OnTakeDamagePost is garbage.
According to sdkhooks.inc, you have the wrong signature for OnTakeDamagePost:

PHP Code:
    // OnTakeDamagePost
    
public(victimattackerinflictorFloat:damagedamagetype), 
Note the lack of Action return code and lack of ampersands (to indicate references). Strangely, victim is the only one that appears to have the correct argument, yet it's the one that's erroring...
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-16-2012 at 23:51.
Powerlord is offline