PDA

View Full Version : Help porting this from mm to sm


Austinbots
01-31-2012, 23:36
I have the following one function mms plugin.
Can some help get me get a start on porting to a sm plugin instead?
I can compile plugins and have the example compiling.

// ----------------------------------------------------------
// TraceLine()
// Disallow headshot damage to human players
// Disallow every 3rd bullet hit to human players
// ---------------------------------------------------------
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
static int skipHit = 0;

TRACE_LINE(v1, v2, fNoMonsters, pentToSkip, ptr);

// is a human taking damage?
if ( (ptr->pHit->v.flags & FL_CLIENT) && !(ptr->pHit->v.flags & FL_FAKECLIENT) )
{
// is it a head shot?
if( (1<<HITGROUP_HEAD) & (1<<ptr->iHitgroup) )
{
// disallow head shots to humans, return no damage
ptr->flFraction = 1.0;
RETURN_META(MRES_SUPERCEDE);
}
else if
(
((1<<HITGROUP_HEAD) & (1<<ptr->iHitgroup)) ||
((1<<HITGROUP_CHEST) & (1<<ptr->iHitgroup)) ||
((1<<HITGROUP_STOMACH) & (1<<ptr->iHitgroup)) ||
((1<<HITGROUP_LEFTARM) & (1<<ptr->iHitgroup)) ||
((1<<HITGROUP_RIGHTARM) & (1<<ptr->iHitgroup)) ||
((1<<HITGROUP_LEFTLEG) & (1<<ptr->iHitgroup)) ||
((1<<HITGROUP_RIGHTLEG) & (1<<ptr->iHitgroup)) )
{
if(skipHit >= 3)
{
// skip some damage
skipHit = 0;
ptr->flFraction = 1.0;
RETURN_META(MRES_SUPERCEDE);
}
else
{
skipHit++;
}
}
}// not a human
RETURN_META(MRES_IGNORED);
}

Austinbots
02-03-2012, 04:22
Austin, here you go...

#include <sourcemod>
#include <sdkhooks>

new skipHit = 0;

public Plugin:myinfo =
{
name = "No Head Shot",
author = "Austinbots",
description = "No Head Shot to Humans, and skip every 3rd damage hit.",
version = "1.0",
url = ""
}

public OnPluginStart()
{
}

public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_TraceAttack, HookTraceAttack);
}

public Action:HookTraceAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotype, hitbox, HitGroup)
{
if (!attacker || attacker > MaxClients)
return Plugin_Continue;

if(IsFakeClient(attacker))
{
if(HitGroup == 1)
{
// Don't let bots get a head shot
damage = 0.0;
return Plugin_Changed;
}
else if(skipHit >=3)
{
// skip every third damage
skipHit = 0;
damage = 0.0;
return Plugin_Changed;
}
else
{
skipHit++;
return Plugin_Continue;
}
}

return Plugin_Continue;
}

Powerlord
02-03-2012, 10:16
Austin, here you go...

You probably should have mentioned that it requires the SDKHooks extension.