AlliedModders
XFactor Servers

[EXTENSION] SDK Hooks 1.1 (Updated 11/03/09)


Post New Thread Reply   
 
Thread Tools Display Modes
devil21
Junior Member
Karma: Neutral
Old 11-02-2009 , 14:23   Re: [EXTENSION] SDK Hooks
Reply With Quote #51

can some1 teach how to use it??
devil21 is offline
psychonic
Veteran Member
Karma: Neutral
Old 11-02-2009 , 15:25   Re: [EXTENSION] SDK Hooks
Reply With Quote #52

Quote:
Originally Posted by devil21 View Post
can some1 teach how to use it??
There is an example in the second post and plenty of info in the first. What specifically are you trying to do?
__________________
HLstatsX Community Edition - http://www.hlxcommunity.com - Free stats package supporting many HL1/HL2 games and mods
psychonic is offline
Sammy-ROCK!
Senior Member
Karma: Neutral
Old 11-02-2009 , 15:34   Re: [EXTENSION] SDK Hooks
Reply With Quote #53

Psychonic thank you but there is a compression error on ob version.
Code:
Winrar:
C:\sdkhooks_ob.zip: CRC failed in extensions\sdkhooks.ext.so. The file is corrupt
[EDIT]
This also seems to happen on the other version. I'd say your zip manager is broken or using a unknown format.

Last edited by Sammy-ROCK!; 11-02-2009 at 15:38..
Sammy-ROCK! is offline
Sammy-ROCK!
Senior Member
Karma: Neutral
Old 11-02-2009 , 15:44   Re: [EXTENSION] SDK Hooks
Reply With Quote #54

Thank you it worked now.

Last edited by Sammy-ROCK!; 11-02-2009 at 15:49..
Sammy-ROCK! is offline
Sammy-ROCK!
Senior Member
Karma: Neutral
Old 11-03-2009 , 17:13   Re: [EXTENSION] SDK Hooks
Reply With Quote #55

There is a issue I'm having with the linux version. (OB)
If I return Plugin_Stop at OnTakeDamage the server crashes. And if I return Plugin_Changed the OnTakeDamage is recalled with the new values. When I tried damage changes it ended up with instant kill after getting called 6 times and increasing damage on each one.
Sammy-ROCK! is offline
exvel
SourceMod Donor
Karma: Positive
Location: Russia
Old 11-03-2009 , 17:15   Re: [EXTENSION] SDK Hooks
Reply With Quote #56

Try using return Plugin_Handled.
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
Mecha the Slag
Member
Karma: Terrible
Old 11-03-2009 , 17:17   Re: [EXTENSION] SDK Hooks
Reply With Quote #57

Hi. This sounds very interesting and might be what I need. Would this allow me (in it's current or a modified state) to call the versus survivor victory event in Left 4 Dead?
(Related to this: http://forums.alliedmods.net/showthr...999#post979999)

Thanks in advance
Mecha the Slag is offline
stachi
Junior Member
Karma: Neutral
Old 11-03-2009 , 19:20   Re: [EXTENSION] SDK Hooks 1.1 (Updated 11/03/09)
Reply With Quote #58

I try to rewrite the Healthkit On Death to use SDK Hooks instead of Hacks Extension. But with my code you are unable to pick up a healthkit. Nothing happend if you running over an healthkit.

Original
Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <hacks>

#define PLUGIN_VERSION "1.3.0"

#define HEALTHKIT_SOUND    "items/medshot4.wav"
#define HEALTHKIT_MODEL    "models/items/healthkit.mdl"

#define MOVETYPE_VPHYSICS        6
#define MOVECOLLIDE_DEFAULT        0

#define SOLID_BBOX    2

#define    FSOLID_TRIGGER                0x0008
#define FSOLID_NOT_STANDABLE        0x0010
#define FSOLID_USE_TRIGGER_BOUNDS    0x0080

#define COLLISION_GROUP_DEBRIS    1

#define LIFE_ALIVE    0

// ConVars
new Handle:hod_enabled        = INVALID_HANDLE;
new Handle:hod_health        = INVALID_HANDLE;
new Handle:hod_max_health    = INVALID_HANDLE;
new Handle:hod_lifetime        = INVALID_HANDLE;
new Handle:hod_dissolve        = INVALID_HANDLE;

// SendProp Offsets
new g_iCollision        = -1;
new g_iCollisionGroup    = -1;
new g_iHealth            = -1;
new g_iLifeState        = -1;
new g_iMoveCollide        = -1;
new g_iMoveType            = -1;
new g_iSolidFlags        = -1;

// SDKTools Stuff
new Handle:g_hGameConf                = INVALID_HANDLE;
//new Handle:g_hCreateEntityByName    = INVALID_HANDLE;
//new Handle:g_hDispatchSpawn            = INVALID_HANDLE;
new Handle:g_hDissolve                = INVALID_HANDLE;
new Handle:g_hSetModel                = INVALID_HANDLE;
new Handle:g_hUtilRemove            = INVALID_HANDLE;

// Healthkit
new g_iHealthkits[MAXPLAYERS + 1]    = {-1,...};

// Hooks
new g_iHooks_StartTouch[MAXPLAYERS + 1]        = {-1,...};
new g_iHooks_UpdateOnRemove[MAXPLAYERS + 1]    = {-1,...};

// Timers
new Handle:g_hTimers_Dissolve[MAXPLAYERS + 1]    = {INVALID_HANDLE,...};
new Handle:g_hTimers_Remove[MAXPLAYERS + 1]    = {INVALID_HANDLE,...};

// MaxClients
new g_iMaxClients;

public Plugin:myinfo =
{
    name = "Healthkit On Death",
    author = "Knagg0",
    description = "",
    version = PLUGIN_VERSION,
    url = "http://www.mfzb.de"
};

public OnPluginStart()
{
    AutoExecConfig();
    
    // Create ConVars
    CreateConVar("hod_version", PLUGIN_VERSION, "", FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
    hod_enabled     = CreateConVar("hod_enabled", "1", "", FCVAR_PLUGIN);
    hod_health        = CreateConVar("hod_health", "25", "", FCVAR_PLUGIN);
    hod_max_health    = CreateConVar("hod_max_health", "150", "", FCVAR_PLUGIN);
    hod_lifetime    = CreateConVar("hod_lifetime", "5", "", FCVAR_PLUGIN);
    hod_dissolve    = CreateConVar("hod_dissolve", "1", "", FCVAR_PLUGIN);
    
    // Find SendProp Offsets
    if((g_iCollision = FindSendPropOffs("CBaseEntity", "m_Collision")) == -1)
        LogError("Could not find offset for CBaseEntity::m_Collision");
        
    if((g_iCollisionGroup = FindSendPropOffs("CBaseEntity", "m_CollisionGroup")) == -1)
        LogError("Could not find offset for CBaseEntity::m_CollisionGroup");
        
    if((g_iHealth = FindSendPropOffs("CBasePlayer", "m_iHealth")) == -1)
        LogError("Could not find offset for CBasePlayer::m_iHealth");

    if((g_iLifeState = FindSendPropOffs("CBasePlayer", "m_lifeState")) == -1)
        LogError("Could not find offset for CBasePlayer::m_lifeState");
    
    if((g_iMoveCollide = FindSendPropOffs("CBaseEntity", "movecollide")) == -1)
        LogError("Could not find offset for CBaseEntity::movecollide");
    
    if((g_iMoveType = FindSendPropOffs("CBaseEntity", "movetype")) == -1)
        LogError("Could not find offset for CBaseEntity::movetype");
    
    if((g_iSolidFlags = FindSendPropOffs("CBaseEntity", "m_usSolidFlags")) == -1)
        LogError("Could not find offset for CBaseEntity::m_usSolidFlags");
    
    // SDKTool Stuff
    if((g_hGameConf = LoadGameConfigFile("plugin.healthkit_on_death")) != INVALID_HANDLE)
    {
        StartPrepSDKCall(SDKCall_Static);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "CreateEntityByName");
        PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
        PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
        PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
//        g_hCreateEntityByName = EndPrepSDKCall();
        
        StartPrepSDKCall(SDKCall_Static);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "DispatchSpawn");
        PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
//        g_hDispatchSpawn = EndPrepSDKCall();
        
        StartPrepSDKCall(SDKCall_Entity);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "Dissolve");
        PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
        PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByValue);
        PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
        g_hDissolve = EndPrepSDKCall();
        
        StartPrepSDKCall(SDKCall_Entity);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Virtual, "SetModel");
        PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
        g_hSetModel = EndPrepSDKCall();
        
        StartPrepSDKCall(SDKCall_Static);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "UTIL_Remove");
        PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
        g_hUtilRemove = EndPrepSDKCall();
    }
    
    // Hook Events
    HookEvent("player_death", EventPlayerDeath);
}

public OnMapStart()
{
    g_iMaxClients = GetMaxClients();
    PrecacheSound(HEALTHKIT_SOUND, true);
    PrecacheModel(HEALTHKIT_MODEL, true);
}

public EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!GetConVarBool(hod_enabled))
        return;
    
    new iClient = GetClientOfUserId(GetEventInt(event, "userid"));
    new iAttacker = GetClientOfUserId(GetEventInt(event, "attacker"));
    
    if(iClient != 0 && iAttacker != 0 && GetClientTeam(iClient) != GetClientTeam(iAttacker))
    {
        new Float:vecPos[3];
        GetClientAbsOrigin(iClient, vecPos);
        
        if(g_iHealthkits[iClient] != -1)
            UtilRemove(g_iHealthkits[iClient]);
        
        if((g_iHealthkits[iClient] = CreateEntityByName("prop_physics", -1)) == -1)
            return;
        
        TeleportEntity(g_iHealthkits[iClient], vecPos, NULL_VECTOR, NULL_VECTOR);
        SetModel(g_iHealthkits[iClient], HEALTHKIT_MODEL);
        DispatchSpawn(g_iHealthkits[iClient]);
        SetCollisionGroup(g_iHealthkits[iClient], COLLISION_GROUP_DEBRIS);
        SetSolidFlags(g_iHealthkits[iClient], FSOLID_USE_TRIGGER_BOUNDS | FSOLID_NOT_STANDABLE | FSOLID_TRIGGER);
        SetMoveType(g_iHealthkits[iClient], MOVETYPE_VPHYSICS, MOVECOLLIDE_DEFAULT);
        
        new Float:vecVel[3];
        
        vecVel[0] = GetRandomFloat(-200.0, 200.0);
        vecVel[1] = GetRandomFloat(-200.0, 200.0);
        vecVel[2] = GetRandomFloat(1.0, 200.0);
        
        TeleportEntity(g_iHealthkits[iClient], NULL_VECTOR, NULL_VECTOR, vecVel);
        
        g_iHooks_StartTouch[iClient]        = Hacks_Hook(g_iHealthkits[iClient], HACKS_HTYPE_STARTTOUCH, StartTouch, false);
        g_iHooks_UpdateOnRemove[iClient]    = Hacks_Hook(g_iHealthkits[iClient], HACKS_HTYPE_UPDATEONREMOVE, UpdateOnRemove, false);

        new Float:fLifeTime = GetConVarFloat(hod_lifetime);
        
        if(GetConVarBool(hod_dissolve))
        {
            new Float:fDissolve = fLifeTime - 2.5;
            g_hTimers_Dissolve[iClient] = CreateTimer((fDissolve < 0.0) ? 0.0 : fDissolve, TimerDissolve, iClient);
        }

        g_hTimers_Remove[iClient] = CreateTimer(fLifeTime, TimerRemove, iClient);
    }
}

// Hook Handlers
public StartTouch(entity, other, dummy1, dummy2, dummy3, dummy4)
{
    if(other < 1 || other > g_iMaxClients || !IsClientInGame(other) || !IsClientAlive(other))
        return Hacks_Continue;
    
    new iHealth            = GetConVarInt(hod_health);
    new iMaxHealth        = GetConVarInt(hod_max_health);
    new iClientHealth    = GetClientHealth(other);
    
    if(iClientHealth < iMaxHealth)
    {
        iClientHealth += iHealth;
        if(iClientHealth > iMaxHealth) iClientHealth = iMaxHealth;
        SetClientHealth(other, iClientHealth);
        
        new Float:vecPos[3];
        GetClientAbsOrigin(other, vecPos);
        
        EmitSoundToAll(HEALTHKIT_SOUND, other, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, 1.0, SNDPITCH_NORMAL, -1, vecPos, NULL_VECTOR, true, 0.0);
    
        UtilRemove(entity);
    }
        
    return Hacks_Continue;    
}

public UpdateOnRemove(entity, dummy1, dummy2, dummy3, dummy4, dummy5)
{
    new iIndex = GetHealthkitIndex(entity);
    if(iIndex == -1) return Hacks_Continue;
    
    if(g_hTimers_Dissolve[iIndex] != INVALID_HANDLE)
    {
        KillTimer(g_hTimers_Dissolve[iIndex]);
        g_hTimers_Dissolve[iIndex] = INVALID_HANDLE;
    }
    
    if(g_hTimers_Remove[iIndex] != INVALID_HANDLE)
    {
        KillTimer(g_hTimers_Remove[iIndex]);
        g_hTimers_Remove[iIndex] = INVALID_HANDLE;
    }
    
    g_iHealthkits[iIndex] = -1;
    
    Hacks_Unhook(g_iHooks_StartTouch[iIndex]);
    Hacks_Unhook(g_iHooks_UpdateOnRemove[iIndex]);
    
    g_iHooks_StartTouch[iIndex]        = -1;
    g_iHooks_UpdateOnRemove[iIndex]    = -1;
    
    return Hacks_Continue;
}

// Timers
public Action:TimerDissolve(Handle:timer, any:index)
{
    g_hTimers_Dissolve[index] = INVALID_HANDLE;

    if(g_iHealthkits[index] != -1)
        Dissolve(g_iHealthkits[index], 0);
}

public Action:TimerRemove(Handle:timer, any:index)
{
    g_hTimers_Remove[index] = INVALID_HANDLE;

    if(g_iHealthkits[index] != -1)
        UtilRemove(g_iHealthkits[index]);
}

// ...
GetHealthkitIndex(entity)
{
    for(new i = 1; i <= g_iMaxClients; i++)
    {
        if(g_iHealthkits[i] == entity)
            return i;
    }
    
    return -1;
}

// SendProps
bool:IsClientAlive(client)
{
    if(g_iLifeState != -1 && GetEntData(client, g_iLifeState, 1) == LIFE_ALIVE)
        return true;

    return false;
}

SetClientHealth(client, health)
{
    if(g_iHealth == -1) return;
    SetEntData(client, g_iHealth, health);    
}

SetCollisionGroup(entity, group)
{
    if(g_iCollisionGroup == -1) return;
    SetEntData(entity, g_iCollisionGroup, group, 4, true);
}

SetMoveType(client, movetype, movecollide)
{
    if(g_iMoveType == -1) return;
    SetEntData(client, g_iMoveType, movetype);
    if(g_iMoveCollide == -1) return;
    SetEntData(client, g_iMoveCollide, movecollide);
}

SetSolidFlags(entity, flags)
{
    if(g_iCollision == -1 || g_iSolidFlags == -1) return;
    SetEntData(entity, g_iCollision + g_iSolidFlags, flags, 2, true);
}

// SDKTools Calls
//CreateEntityByName(const String:name[], forceindex)
//{
//    if(g_hCreateEntityByName == INVALID_HANDLE) return -1;
//    return SDKCall(g_hCreateEntityByName, name, forceindex);
//}

//DispatchSpawn(entity)
//{
//    if(g_hDispatchSpawn == INVALID_HANDLE) return -1;
//    return SDKCall(g_hDispatchSpawn, entity);
//}

Dissolve(entity, type)
{
    if(g_hDissolve == INVALID_HANDLE) return -1;
    return SDKCall(g_hDissolve, entity, NULL_STRING, GetGameTime(), false, type, Float:{0.0,0.0,0.0}, 0);
}

SetModel(entity, const String:model[])
{
    if(g_hSetModel == INVALID_HANDLE) return;
    SDKCall(g_hSetModel, entity, model);
}

UtilRemove(entity)
{
    if(g_hUtilRemove == INVALID_HANDLE) return;
    SDKCall(g_hUtilRemove, entity);
}
Rewrite
Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define PLUGIN_VERSION "1.3.0-stachi"

#define HEALTHKIT_SOUND    "items/medshot4.wav"
#define HEALTHKIT_MODEL    "models/items/healthkit.mdl"

#define MOVETYPE_VPHYSICS        6
#define MOVECOLLIDE_DEFAULT        0

#define SOLID_BBOX    2

#define    FSOLID_TRIGGER                0x0008
#define FSOLID_NOT_STANDABLE        0x0010
#define FSOLID_USE_TRIGGER_BOUNDS    0x0080

#define COLLISION_GROUP_DEBRIS    1

#define LIFE_ALIVE    0

// ConVars
new Handle:hod_enabled        = INVALID_HANDLE;
new Handle:hod_health        = INVALID_HANDLE;
new Handle:hod_max_health    = INVALID_HANDLE;
new Handle:hod_lifetime        = INVALID_HANDLE;
new Handle:hod_dissolve        = INVALID_HANDLE;

// SendProp Offsets
new g_iCollision        = -1;
new g_iCollisionGroup    = -1;
new g_iHealth            = -1;
new g_iLifeState        = -1;
new g_iMoveCollide        = -1;
new g_iMoveType            = -1;
new g_iSolidFlags        = -1;

// SDKTools Stuff
new Handle:g_hGameConf                = INVALID_HANDLE;
new Handle:g_hDissolve                = INVALID_HANDLE;
new Handle:g_hSetModel                = INVALID_HANDLE;
new Handle:g_hUtilRemove            = INVALID_HANDLE;

// Healthkit
new g_iHealthkits[MAXPLAYERS + 1]    = {-1,...};

// Hooks
new g_iHooks_StartTouch[MAXPLAYERS + 1]        = {-1,...};
new g_iHooks_UpdateOnRemove[MAXPLAYERS + 1]    = {-1,...};

// Timers
new Handle:g_hTimers_Dissolve[MAXPLAYERS + 1]    = {INVALID_HANDLE,...};
new Handle:g_hTimers_Remove[MAXPLAYERS + 1]    = {INVALID_HANDLE,...};

// MaxClients
new g_iMaxClients;

public Plugin:myinfo =
{
    name = "Healthkit On Death",
    author = "Knagg0",
    description = "",
    version = PLUGIN_VERSION,
    url = "http://www.mfzb.de"
};

public OnPluginStart()
{
    AutoExecConfig();
    
    // Create ConVars
    CreateConVar("hod_version", PLUGIN_VERSION, "", FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
    hod_enabled     = CreateConVar("hod_enabled", "1", "", FCVAR_PLUGIN);
    hod_health        = CreateConVar("hod_health", "25", "", FCVAR_PLUGIN);
    hod_max_health    = CreateConVar("hod_max_health", "150", "", FCVAR_PLUGIN);
    hod_lifetime    = CreateConVar("hod_lifetime", "5", "", FCVAR_PLUGIN);
    hod_dissolve    = CreateConVar("hod_dissolve", "1", "", FCVAR_PLUGIN);
    
    // Find SendProp Offsets
    if((g_iCollision = FindSendPropOffs("CBaseEntity", "m_Collision")) == -1)
        LogError("Could not find offset for CBaseEntity::m_Collision");
        
    if((g_iCollisionGroup = FindSendPropOffs("CBaseEntity", "m_CollisionGroup")) == -1)
        LogError("Could not find offset for CBaseEntity::m_CollisionGroup");
        
    if((g_iHealth = FindSendPropOffs("CBasePlayer", "m_iHealth")) == -1)
        LogError("Could not find offset for CBasePlayer::m_iHealth");

    if((g_iLifeState = FindSendPropOffs("CBasePlayer", "m_lifeState")) == -1)
        LogError("Could not find offset for CBasePlayer::m_lifeState");
    
    if((g_iMoveCollide = FindSendPropOffs("CBaseEntity", "movecollide")) == -1)
        LogError("Could not find offset for CBaseEntity::movecollide");
    
    if((g_iMoveType = FindSendPropOffs("CBaseEntity", "movetype")) == -1)
        LogError("Could not find offset for CBaseEntity::movetype");
    
    if((g_iSolidFlags = FindSendPropOffs("CBaseEntity", "m_usSolidFlags")) == -1)
        LogError("Could not find offset for CBaseEntity::m_usSolidFlags");
    
    // SDKTool Stuff
    if((g_hGameConf = LoadGameConfigFile("plugin.healthkit_on_death")) != INVALID_HANDLE)
    {
        StartPrepSDKCall(SDKCall_Static);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "CreateEntityByName");
        PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
        PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
        PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
        
        StartPrepSDKCall(SDKCall_Static);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "DispatchSpawn");
        PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
        
        StartPrepSDKCall(SDKCall_Entity);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "Dissolve");
        PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
        PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
        PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByValue);
        PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
        g_hDissolve = EndPrepSDKCall();
        
        StartPrepSDKCall(SDKCall_Entity);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Virtual, "SetModel");
        PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
        g_hSetModel = EndPrepSDKCall();
        
        StartPrepSDKCall(SDKCall_Static);
        PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "UTIL_Remove");
        PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
        g_hUtilRemove = EndPrepSDKCall();
    }
    
    // Hook Events
    HookEvent("player_death", EventPlayerDeath);
}

public OnMapStart()
{
    g_iMaxClients = GetMaxClients();
    PrecacheSound(HEALTHKIT_SOUND, true);
    PrecacheModel(HEALTHKIT_MODEL, true);
}

public EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!GetConVarBool(hod_enabled))
        return;
    
    new iClient = GetClientOfUserId(GetEventInt(event, "userid"));
    new iAttacker = GetClientOfUserId(GetEventInt(event, "attacker"));
    
    if(iClient != 0 && iAttacker != 0 && GetClientTeam(iClient) != GetClientTeam(iAttacker))
    {
        new Float:vecPos[3];
        GetClientAbsOrigin(iClient, vecPos);
        
        if(g_iHealthkits[iClient] != -1)
            UtilRemove(g_iHealthkits[iClient]);
        
        if((g_iHealthkits[iClient] = CreateEntityByName("prop_physics", -1)) == -1)
            return;
        
        TeleportEntity(g_iHealthkits[iClient], vecPos, NULL_VECTOR, NULL_VECTOR);
        SetModel(g_iHealthkits[iClient], HEALTHKIT_MODEL);
        DispatchSpawn(g_iHealthkits[iClient]);
        SetCollisionGroup(g_iHealthkits[iClient], COLLISION_GROUP_DEBRIS);
        SetSolidFlags(g_iHealthkits[iClient], FSOLID_USE_TRIGGER_BOUNDS | FSOLID_NOT_STANDABLE | FSOLID_TRIGGER);
        SetMoveType(g_iHealthkits[iClient], MOVETYPE_VPHYSICS, MOVECOLLIDE_DEFAULT);
        
        new Float:vecVel[3];
        
        vecVel[0] = GetRandomFloat(-200.0, 200.0);
        vecVel[1] = GetRandomFloat(-200.0, 200.0);
        vecVel[2] = GetRandomFloat(1.0, 200.0);
        
        TeleportEntity(g_iHealthkits[iClient], NULL_VECTOR, NULL_VECTOR, vecVel);
        
        g_iHooks_StartTouch[iClient]        = SDKHook(g_iHealthkits[iClient], SDKHook_StartTouch, StartTouch);
        g_iHooks_UpdateOnRemove[iClient]    = SDKHook(g_iHealthkits[iClient], SDKHook_UpdateOnRemove, UpdateOnRemove);

        new Float:fLifeTime = GetConVarFloat(hod_lifetime);
        
        if(GetConVarBool(hod_dissolve))
        {
            new Float:fDissolve = fLifeTime - 2.5;
            g_hTimers_Dissolve[iClient] = CreateTimer((fDissolve < 0.0) ? 0.0 : fDissolve, TimerDissolve, iClient);
        }

        g_hTimers_Remove[iClient] = CreateTimer(fLifeTime, TimerRemove, iClient);
    }
}

// Hook Handlers
public StartTouch(entity, other)
{
    if(other > 0 || other <= g_iMaxClients || IsClientInGame(other) || IsClientAlive(other))
    {
        new iHealth            = GetConVarInt(hod_health);
        new iMaxHealth        = GetConVarInt(hod_max_health);
        new iClientHealth    = GetClientHealth(other);
    
        if(iClientHealth < iMaxHealth)
        {
            iClientHealth += iHealth;
            if(iClientHealth > iMaxHealth) iClientHealth = iMaxHealth;
            SetClientHealth(other, iClientHealth);
        
            new Float:vecPos[3];
            GetClientAbsOrigin(other, vecPos);
        
            EmitSoundToAll(HEALTHKIT_SOUND, other, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, 1.0, SNDPITCH_NORMAL, -1, vecPos, NULL_VECTOR, true, 0.0);
    
            UtilRemove(entity);
        }
    }    
}

public UpdateOnRemove(entity)
{
    new iIndex = GetHealthkitIndex(entity);
    if(iIndex != -1)
    {
        if(g_hTimers_Dissolve[iIndex] != INVALID_HANDLE)
        {
            KillTimer(g_hTimers_Dissolve[iIndex]);
            g_hTimers_Dissolve[iIndex] = INVALID_HANDLE;
        }
    
        if(g_hTimers_Remove[iIndex] != INVALID_HANDLE)
        {
            KillTimer(g_hTimers_Remove[iIndex]);
            g_hTimers_Remove[iIndex] = INVALID_HANDLE;
        }
    
        g_iHealthkits[iIndex] = -1;
    
        //SDKUnhook(g_iHooks_StartTouch[iIndex]);
        //SDKUnhook(g_iHooks_UpdateOnRemove[iIndex]);
    
        g_iHooks_StartTouch[iIndex]        = -1;
        g_iHooks_UpdateOnRemove[iIndex]    = -1;
    }
}

// Timers
public Action:TimerDissolve(Handle:timer, any:index)
{
    g_hTimers_Dissolve[index] = INVALID_HANDLE;

    if(g_iHealthkits[index] != -1)
        Dissolve(g_iHealthkits[index], 0);
}

public Action:TimerRemove(Handle:timer, any:index)
{
    g_hTimers_Remove[index] = INVALID_HANDLE;

    if(g_iHealthkits[index] != -1)
        UtilRemove(g_iHealthkits[index]);
}

// ...
GetHealthkitIndex(entity)
{
    for(new i = 1; i <= g_iMaxClients; i++)
    {
        if(g_iHealthkits[i] == entity)
            return i;
    }
    
    return -1;
}

// SendProps
bool:IsClientAlive(client)
{
    if(g_iLifeState != -1 && GetEntData(client, g_iLifeState, 1) == LIFE_ALIVE)
        return true;

    return false;
}

SetClientHealth(client, health)
{
    if(g_iHealth == -1) return;
    SetEntData(client, g_iHealth, health);    
}

SetCollisionGroup(entity, group)
{
    if(g_iCollisionGroup == -1) return;
    SetEntData(entity, g_iCollisionGroup, group, 4, true);
}

SetMoveType(client, movetype, movecollide)
{
    if(g_iMoveType == -1) return;
    SetEntData(client, g_iMoveType, movetype);
    if(g_iMoveCollide == -1) return;
    SetEntData(client, g_iMoveCollide, movecollide);
}

SetSolidFlags(entity, flags)
{
    if(g_iCollision == -1 || g_iSolidFlags == -1) return;
    SetEntData(entity, g_iCollision + g_iSolidFlags, flags, 2, true);
}

// SDKTools Calls
Dissolve(entity, type)
{
    if(g_hDissolve == INVALID_HANDLE) return -1;
    return SDKCall(g_hDissolve, entity, NULL_STRING, GetGameTime(), false, type, Float:{0.0,0.0,0.0}, 0);
}

SetModel(entity, const String:model[])
{
    if(g_hSetModel == INVALID_HANDLE) return;
    SDKCall(g_hSetModel, entity, model);
}

UtilRemove(entity)
{
    if(g_hUtilRemove == INVALID_HANDLE) return;
    SDKCall(g_hUtilRemove, entity);
}
__________________
Sorry for my bad English, I'am German.
stachi is offline
DJ Tsunami
DJ Post Spammer
Karma: Good
Location: Netherlands
Old 11-03-2009 , 19:52   Re: [EXTENSION] SDK Hooks 1.1 (Updated 11/03/09)
Reply With Quote #59

SDKHook doesn't return anything, and there is no SDKHook_UpdateOnRemove, use OnEntityDestroyed for that. Antithasys just made a plugin where touch works fine, maybe try restarting your server.
__________________
My Plugins
Don't PM me asking for support, post in the plugin's topic.
DJ Tsunami is online now
stachi
Junior Member
Karma: Neutral
Old 11-03-2009 , 22:50   Re: [EXTENSION] SDK Hooks 1.1 (Updated 11/03/09)
Reply With Quote #60

Quote:
Originally Posted by DJ Tsunami View Post
SDKHook doesn't return anything, and there is no SDKHook_UpdateOnRemove, use OnEntityDestroyed for that. Antithasys just made a plugin where touch works fine, maybe try restarting your server.
Return is already removed. UpdateOnRemove exist in gamedata file and sourcecode, but not in the inc file. OnEntityDestroyed is a forward not a hook, how can I use that in my case?
__________________
Sorry for my bad English, I'am German.

Last edited by stachi; 11-03-2009 at 23:11..
stachi is offline
Reply


Thread Tools
Display Modes

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 05:21.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Theme made by Freecode Sponsored by Layered Technologies