sry second post.
Player is executing this function every cmd rate, which is very spammy.
What also handle buymenu, switch weapon by "use" and switch weapon to c4 when bomb target area.
Code:
void CBasePlayer::PlayerUse ( void )
Function check, is player pressed or holded "use" key, then take a action.
This function use native(?) called
Code:
CBaseEntity *pUseEntity = FindUseEntity();
...which find entity by using TraceRay.
I don't know way to block this, because it works some how by address and offset I guess ?
So here is, again, bad example.
When player press "use" key and PlayerUse is called, you can block it.
- I tried add RayTrace thingie but today I can't get it work right. Would be better use TR_TraceHullFilter for lager area.
Someone could fix that part.
It is now fixed.
Try this.
PHP Code:
#include <dhooks>
DynamicHook dPlayerUse;
public void OnPluginStart()
{
// Windows offset 462, Linux is... 463 or 461 ?
dPlayerUse = DHookCreate(463, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, PlayerUse);
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i)) OnClientPutInServer(i);
}
}
public void OnClientPutInServer(int client)
{
DHookEntity(dPlayerUse, false, client);
}
public MRESReturn PlayerUse(int pThis)
{
static timestamps[MAXPLAYERS];
if(!IsFakeClient(pThis) && GetClientButtons(pThis) & IN_USE && IsPlayerAlive(pThis))
{
int playerc4 = PlayerC4();
// no c4 carrier or player is human
if(playerc4 < 1 || !IsFakeClient(playerc4))
{
return MRES_Ignored;
}
// cooldown
int time = GetTime();
if(timestamps[pThis] > time)
return MRES_Supercede;
float pos[3], pos2[3], angle[3];
GetClientEyePosition(pThis, pos);
GetClientEyeAngles(pThis, angle);
// End position, where player aim + distance 210.0 unit
GetAngleVectors(angle, pos2, NULL_VECTOR, NULL_VECTOR);
ScaleVector(pos2, 210.0);
AddVectors(pos2, pos, pos2);
float mins[3] = {-5.0, -5.0, -5.0};
float maxs[3] = {5.0, 5.0, 5.0};
TR_TraceHullFilter(pos, pos2, mins, maxs, CONTENTS_HITBOX, filter, pThis);
int hit = TR_GetEntityIndex(null);
if(hit == playerc4)
{
timestamps[pThis] = time + 2;
PrintToChat(pThis, " [SM]\x03You can't drop bomb from bots");
return MRES_Supercede;
}
}
return MRES_Ignored;
}
public bool filter(int entity, int contentsMask, any data)
{
if(entity > 0 && entity <= MaxClients && entity != data && entity == PlayerC4())
return true;
return false;
}
int PlayerC4()
{
int entity = FindEntityByClassname(-1, "cs_player_manager");
if(entity != -1 && HasEntProp(entity, Prop_Send, "m_iPlayerC4"))
{
return GetEntProp(entity, Prop_Send, "m_iPlayerC4");
}
return -1;
}
__________________