This would be a very simple plugin to make.
Here's a fully commented copy so you can see how it's done.
Code:
#include <sourcemod>
#include <tf2>
public OnPluginStart()
{
// Hook players taking damage
HookEvent("player_hurt", OnPlayerHurtEvent);
}
public OnPlayerHurtEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
// Check that attacker is valid
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if (attacker == 0 || !IsClientInGame(attacker))
return;
// Check that attacker has access to stun with wrench.
// Default 'p' flag, use admin_overrides to override. Command is "wrench_stun".
if (!CheckCommandAccess(attacker, "wrench_stun", ADMFLAG_CUSTOM2))
return;
// Now let's make sure the victim is valid
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
if (victim == 0 || !IsClientInGame(victim))
return;
// Let's also make sure the damage wasn't enough to kill them
if (GetClientHealth(victim) <= 0)
return;
decl String:weapon[64];
GetEventString(event, "weapon_logclassname", weapon, sizeof(weapon));
// Check that the weapon is a wrench.
// We'll look at the log name as it will be different for SH or Golden Wrench
if (!StrEqual(weapon, "wrench"))
return;
// If we made it through all of the checks, set phasers to STUN
TF2_StunPlayer(victim, 1.0, _, TF_STUNFLAGS_BIGBONK, attacker);
}