Assuming there are collisions between players in the game you want this for, you could do it by checking the client property m_hGroundEntity if it is a client, and the previous ent is not the same. Either checking OnGameFrame() or by 0.1 repeating timer, here is an example:
Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma semicolon 1;
#pragma newdecls required;
int lastground[MAXPLAYERS+1];
char g_SoundPath[128];
bool PlaySound = true;
public void OnPluginStart()
{
CreateTimer(0.1,repeater,_,TIMER_REPEAT);
Handle cvar = FindConVar("sm_jumponhead_sound");
if (cvar == INVALID_HANDLE) cvar = CreateConVar("sm_jumponhead_sound", "", "Sound to play when landing on players head.");
if (cvar != INVALID_HANDLE)
{
GetConVarString(cvar,g_SoundPath,sizeof(g_SoundPath));
HookConVarChange(cvar,soundpathch);
}
CloseHandle(cvar);
}
public void OnMapStart()
{
if (strlen(g_SoundPath) > 0)
{
char fullpath[128];
Format(fullpath,sizeof(fullpath),"sound/%s",g_SoundPath);
if (FileExists(fullpath,true,NULL_STRING))
{
PrecacheSound(g_SoundPath,true);
PlaySound = true;
}
else
{
PrintToServer("Sound \"%s\" does not exist",g_SoundPath);
PlaySound = false;
}
}
else PlaySound = false;
}
public Action repeater(Handle timer)
{
for (int i = 1;i<MaxClients+1;i++)
{
if ((IsValidEntity(i)) && (i != 0))
{
if (IsClientConnected(i))
{
if (IsClientInGame(i))
{
if (IsPlayerAlive(i))
{
if (HasEntProp(i,Prop_Data,"m_hGroundEntity"))
{
int groundent = GetEntPropEnt(i,Prop_Data,"m_hGroundEntity");
if ((groundent > 0) && (groundent < MaxClients+1) && (groundent != lastground[i]))
{
lastground[i] = groundent;
PrintToChatAll("Player %N jumped on %N's head", i, groundent);
if (PlaySound) EmitSoundToAll(g_SoundPath, i, SNDCHAN_AUTO, SNDLEVEL_NORMAL);
}
else lastground[i] = groundent;
}
}
}
}
}
}
}
public void OnClientDisconnect(int client)
{
lastground[client] = 0;
}
public void soundpathch(Handle convar, const char[] oldValue, const char[] newValue)
{
Format(g_SoundPath,sizeof(g_SoundPath),"%s",newValue);
if (strlen(g_SoundPath) > 0)
{
char fullpath[128];
Format(fullpath,sizeof(fullpath),"sound/%s",g_SoundPath);
if (FileExists(fullpath,true,NULL_STRING))
{
PrecacheSound(g_SoundPath,true);
PlaySound = true;
}
else
{
PrintToServer("Sound \"%s\" does not exist",g_SoundPath);
PlaySound = false;
}
}
else PlaySound = false;
}