View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-07-2022 , 11:57   Re: [CS:GO]Preventing Bots from Taking Bombs
Reply With Quote #5

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(463HookType_EntityReturnType_VoidThisPointer_CBaseEntityPlayerUse);

    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i)) OnClientPutInServer(i);
    }
}



public 
void OnClientPutInServer(int client)
{
    
DHookEntity(dPlayerUsefalseclient);
}

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 || !IsFakeClient(playerc4))
        {
            return 
MRES_Ignored;
        }

        
// cooldown
        
int time GetTime();

        if(
timestamps[pThis] > time)
            return 
MRES_Supercede;



        
float pos[3], pos2[3], angle[3];
        
GetClientEyePosition(pThispos);
        
GetClientEyeAngles(pThisangle);

        
// End position, where player aim + distance 210.0 unit
        
GetAngleVectors(anglepos2NULL_VECTORNULL_VECTOR);
        
ScaleVector(pos2210.0);
        
AddVectors(pos2pospos2);

        
float mins[3] = {-5.0, -5.0, -5.0};
        
float maxs[3] = {5.05.05.0};

        
TR_TraceHullFilter(pospos2minsmaxsCONTENTS_HITBOXfilterpThis);

        
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 entityint contentsMaskany data)
{
    if(
entity && entity <= MaxClients && entity != data && entity == PlayerC4())
        return 
true;

    return 
false;
}

int PlayerC4()
{
    
int entity FindEntityByClassname(-1"cs_player_manager");
    
    if(
entity != -&& HasEntProp(entityProp_Send"m_iPlayerC4"))
    {
        return 
GetEntProp(entityProp_Send"m_iPlayerC4");
    }

    return -
1;

__________________
Do not Private Message @me

Last edited by Bacardi; 11-08-2022 at 08:33. Reason: fix
Bacardi is offline