View Single Post
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 10-18-2009 , 11:15   Re: [EXTENSION] SDK Hooks
#2

Examples

Adding a simple spawn hook:
Code:
public OnEntityCreated(entity, const String:classname[])
{
    SDKHook(entity, SDKHook_Spawn, OnEntitySpawned);
}

public OnEntitySpawned(entity)
{
    // Stuff here
}
Blocking switching to a specific weapon:
Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}

public Action:OnWeaponSwitch(client, weapon)
{
    decl String:sWeapon[32];
    GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
    
    if(StrEqual(sWeapon, "tf_weapon_rocketlauncher"))
        return Plugin_Handled;
    
    return Plugin_Continue;
}
Changing damage done by a specific weapon:
Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    decl String:sWeapon[32];
    GetEdictClassname(inflictor, sWeapon, sizeof(sWeapon));
    
    if(StrEqual(sWeapon, "tf_weapon_flamethrower"))
    {
        damage *= 2.0;
        return Plugin_Changed;
    }
    
    return Plugin_Continue;
}
Note, you don't have to worry about unhooking every hook before the entity is destroyed, or before your plugin is unloaded, the extension automatically does that for you.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by psychonic; 12-07-2011 at 10:07.
DJ Tsunami is offline