View Single Post
r3v
Senior Member
Join Date: Feb 2016
Location: Lithuania, Vilnius
Old 02-13-2022 , 06:02   Re: [CS:S] C4 Autoplanter
Reply With Quote #2

No error logs.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#pragma newdecls required
#pragma semicolon 1

int bomber;
int bombsite;
bool hasBombBeenDeleted;
float bombPosition[3];
Handle bombTimer;
int bombTicking;

ConVar isPluginEnabled;
ConVar freezeTime;

enum //Bombsites
{
    
BOMBSITE_INVALID = -1,
    
BOMBSITE_A 0,
    
BOMBSITE_B 1
}

public 
Plugin myinfo =
{
    
name "[Retakes] Autoplant",
    
author "B3none",
    
description "Automatically plant the bomb at the start of the round. This will work with all versions of the retakes plugin.",
    
version "2.1.1",
    
url "https://github.com/b3none"
};

public 
void OnPluginStart()
{
    
isPluginEnabled CreateConVar("sm_autoplant_enabled""1""Should the autoplant plugin be enabled"_true0.0true1.0);

    
freezeTime FindConVar("mp_freezetime");

    
bombTicking FindSendPropInfo("CPlantedC4""m_bBombTicking");

    
HookEvent("round_start"OnRoundStartEventHookMode_PostNoCopy);
    
HookEvent("round_end"OnRoundEndEventHookMode_PostNoCopy);
}

public 
Action OnRoundStart(Event eEvent, const char[] sNamebool bDontBroadcast)
{
    
hasBombBeenDeleted false;
    
    if (!
isPluginEnabled.BoolValue)
    {
        return 
Plugin_Continue;
    }
    
    
bomber GetBomber();
    
    if (
IsValidClient(bomber))
    {
        
bombsite GetNearestBombsite(bomber);
        
        
int bomb GetPlayerWeaponSlot(bomber4);
        
        
hasBombBeenDeleted SafeRemoveWeapon(bomberbomb);
        
        
GetClientAbsOrigin(bomberbombPosition);
        
        
delete bombTimer;
        
        
bombTimer CreateTimer(freezeTime.FloatValuePlantBombbomber);
    }
    
    return 
Plugin_Continue;
}

public 
void OnRoundEnd(Event event, const char[] sNamebool bDontBroadcast)
{
    
delete bombTimer;
}

public 
Action PlantBomb(Handle timerint client)
{
    
bombTimer INVALID_HANDLE;

    if (
IsValidClient(client) || !hasBombBeenDeleted)
    {
        if (
hasBombBeenDeleted)
        {
            
int bombEntity CreateEntityByName("planted_c4");

            
SetEntData(bombEntitybombTicking11true);
            
SendBombPlanted(client);

            if (
DispatchSpawn(bombEntity))
            {
                
ActivateEntity(bombEntity);
                
TeleportEntity(bombEntitybombPositionNULL_VECTORNULL_VECTOR);

                if (!(
GetEntityFlags(bombEntity) & FL_ONGROUND))
                {
                    
float direction[3];
                    
float floor[3];

                    
Handle trace;

                    
direction[0] = 89.0;

                    
TR_TraceRay(bombPositiondirectionMASK_PLAYERSOLID_BRUSHONLYRayType_Infinite);

                    if (
TR_DidHit(trace))
                    {
                        
TR_GetEndPosition(floortrace);
                        
TeleportEntity(bombEntityfloorNULL_VECTORNULL_VECTOR);
                    }
                }
            }
        }
    } 
    else
    {
        
CS_TerminateRound(1.0CSRoundEnd_Draw);
    }
}

public 
void SendBombPlanted(int client)
{
    
Event event CreateEvent("bomb_planted");

    if (
event != null)
    {
        
event.SetInt("userid"GetClientUserId(client));
        
event.SetInt("site"bombsite);
        
event.Fire();
    }
}

stock bool SafeRemoveWeapon(int clientint weapon)
{
    if (!
IsValidEntity(weapon) || !IsValidEdict(weapon) || !HasEntProp(weaponProp_Send"m_hOwnerEntity"))
    {
        return 
false;
    }

    
int ownerEntity GetEntPropEnt(weaponProp_Send"m_hOwnerEntity");

    if (
ownerEntity != client)
    {
        
SetEntPropEnt(weaponProp_Send"m_hOwnerEntity"client);
    }

    
CS_DropWeapon(clientweaponfalse);

    if (
HasEntProp(weaponProp_Send"m_hWeaponWorldModel"))
    {
        
int worldModel GetEntPropEnt(weaponProp_Send"m_hWeaponWorldModel");

        if (
IsValidEdict(worldModel) && IsValidEntity(worldModel))
        {
            if (!
AcceptEntityInput(worldModel"Kill"))
            {
                return 
false;
            }
        }
    }

    return 
AcceptEntityInput(weapon"Kill");
}

stock int GetBomber()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsValidClient(i) && HasBomb(i))
        {
            return 
i;
        }
    }
    
    return -
1;
}

stock bool HasBomb(int client)
{
    return 
GetPlayerWeaponSlot(client4) != -1;
}

stock int GetNearestBombsite(int client)
{
    
float pos[3];
    
GetClientAbsOrigin(clientpos);
    
    
int playerResource GetPlayerResourceEntity();
    if (
playerResource == -1)
    {
        return 
BOMBSITE_INVALID;
    }
    
    
float aCenter[3], bCenter[3];
    
GetEntPropVector(playerResourceProp_Send"m_bombsiteCenterA"aCenter);
    
GetEntPropVector(playerResourceProp_Send"m_bombsiteCenterB"bCenter);
    
    
float aDist GetVectorDistance(aCenterpostrue);
    
float bDist GetVectorDistance(bCenterpostrue);
    
    if (
aDist bDist)
    {
        return 
BOMBSITE_A;
    }
    
    return 
BOMBSITE_B;
}

stock bool IsValidClient(int client)
{
    return 
client && client <= MaxClients && IsClientInGame(client);

r3v is offline