Untitled diff

Created Diff never expires
43 removals
386 lines
43 additions
389 lines
#pragma semicolon 1
#pragma semicolon 1


#include <cstrike>
#include <sourcemod>
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#undef REQUIRE_PLUGIN


#define cDefault 0x01
#define cDefault 0x01
#define cLightGreen 0x03
#define cLightGreen 0x03
#define cGreen 0x04
#define cGreen 0x04
#define cDarkGreen 0x05
#define cDarkGreen 0x05

#define PLUGIN_VERSION "1.4.2"


// Uncomment for debugging
// Uncomment for debugging
// #define DEBUG 1
// #define DEBUG 1


public Plugin:myinfo =
#define PLUGIN_VERSION "1.4.3"
#define PLUGIN_NAME "[CS:GO] Noblock"
#define PLUGIN_AUTHOR "altex & Modded by Chaya_"
#define PLUGIN_DESCRIPTION "NoBlock plugin removes player vs. player collisions."

public Plugin myinfo =
{
{
name = "NoBlock",
name = PLUGIN_NAME,
author = "Otstrel.ru Team",
author = PLUGIN_AUTHOR,
description = "Removes player collisions.",
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
version = PLUGIN_VERSION,
url = "http://otstrel.ru"
url = "http://otstrel.ru"
};
}


// ===========================================================================
// ===========================================================================
// GLOBALS
// GLOBALS
// ===========================================================================
// ===========================================================================


new g_offsCollisionGroup;
new g_offsCollisionGroup;
new bool:g_enabled;
new bool:g_enabled;
new bool:g_enabled_nades;
new bool:g_enabled_nades;
new bool:g_enabled_hostages;
new bool:g_enabled_hostages;
new bool:g_noblock_allow_block;
new bool:g_noblock_allow_block;
new Float:g_noblock_allow_block_time;
new Float:g_noblock_allow_block_time;


new Handle:sm_noblock;
new Handle:sm_noblock;
new Handle:sm_noblock_nades;
new Handle:sm_noblock_nades;
new Handle:sm_noblock_hostages;
new Handle:sm_noblock_hostages;
new Handle:sm_noblock_allow_block;
new Handle:sm_noblock_allow_block;
new Handle:sm_noblock_allow_block_time;
new Handle:sm_noblock_allow_block_time;
new Handle:g_hTimer[MAXPLAYERS+1];
new Handle:g_hTimer[MAXPLAYERS+1];


new Handle:sm_noblock_blockafterspawn_time;
new Handle:sm_noblock_blockafterspawn_time;
new Float:g_blockTime;
new Float:g_blockTime;


// ===========================================================================
// ===========================================================================
// LOAD & UNLOAD
// LOAD & UNLOAD
// ===========================================================================
// ===========================================================================


public OnPluginStart()
public void OnPluginStart()
{
{
LoadTranslations("common.phrases");

#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Plugin started.");
LogError("[DEBUG] Plugin started.");
#endif
#endif
new Handle:Cvar_Version = CreateConVar("sm_noblock_version", PLUGIN_VERSION, "NoBlock Version", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
new Handle:Cvar_Version = CreateConVar("sm_noblock_version", PLUGIN_VERSION, "NoBlock Version", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
/* Just to make sure they it updates the convar version if they just had the plugin reload on map change */

SetConVarString(Cvar_Version, PLUGIN_VERSION);
SetConVarString(Cvar_Version, PLUGIN_VERSION);
g_offsCollisionGroup = FindSendPropOffs("CBaseEntity", "m_CollisionGroup");
g_offsCollisionGroup = FindSendPropInfo("CBaseEntity", "m_CollisionGroup");
if (g_offsCollisionGroup == -1)
if (g_offsCollisionGroup == -1)
{
{
SetFailState("[NoBlock] Failed to get offset for CBaseEntity::m_CollisionGroup.");
SetFailState("[NoBlock] Failed to get offset for CBaseEntity::m_CollisionGroup.");
}
}
sm_noblock = CreateConVar("sm_noblock", "1", "Removes player vs. player collisions");
sm_noblock = CreateConVar("sm_noblock", "1", "Removes player vs. player collisions");
g_enabled = GetConVarBool(sm_noblock);
HookConVarChange(sm_noblock, OnConVarChange);

sm_noblock_nades = CreateConVar("sm_noblock_nades", "1", "Removes player vs. nade collisions");
sm_noblock_nades = CreateConVar("sm_noblock_nades", "1", "Removes player vs. nade collisions");
g_enabled_nades = GetConVarBool(sm_noblock_nades);
HookConVarChange(sm_noblock_nades, OnConVarChange);

sm_noblock_hostages = CreateConVar("sm_noblock_hostages", "0", "Removes player vs. hostage collisions");
sm_noblock_hostages = CreateConVar("sm_noblock_hostages", "0", "Removes player vs. hostage collisions");
g_enabled_hostages = GetConVarBool(sm_noblock_hostages);
HookConVarChange(sm_noblock_hostages, OnConVarChange);

sm_noblock_allow_block = CreateConVar("sm_noblock_allow_block", "1.0", "Allow players to use say !block", _, true, 0.0, true, 1.0);
sm_noblock_allow_block = CreateConVar("sm_noblock_allow_block", "1.0", "Allow players to use say !block", _, true, 0.0, true, 1.0);
g_noblock_allow_block = GetConVarBool(sm_noblock_allow_block);
HookConVarChange(sm_noblock_allow_block, OnConVarChange);

sm_noblock_allow_block_time = CreateConVar("sm_noblock_allow_block_time", "20.0", "Time limit to say !block command", _, true, 0.0, true, 600.0);
sm_noblock_allow_block_time = CreateConVar("sm_noblock_allow_block_time", "20.0", "Time limit to say !block command", _, true, 0.0, true, 600.0);
g_noblock_allow_block_time = GetConVarFloat(sm_noblock_allow_block_time);
HookConVarChange(sm_noblock_allow_block_time, OnConVarChange);

sm_noblock_blockafterspawn_time = CreateConVar("sm_noblock_blockafterspawn_time", "0.0", "Disable blocking only for that time from spawn.", _, true, 0.0, true, 600.0);
sm_noblock_blockafterspawn_time = CreateConVar("sm_noblock_blockafterspawn_time", "0.0", "Disable blocking only for that time from spawn.", _, true, 0.0, true, 600.0);
g_enabled = GetConVarBool(sm_noblock);
g_enabled_nades = GetConVarBool(sm_noblock_nades);
g_enabled_hostages = GetConVarBool(sm_noblock_hostages);
g_noblock_allow_block = GetConVarBool(sm_noblock_allow_block);
g_noblock_allow_block_time = GetConVarFloat(sm_noblock_allow_block_time);
g_blockTime = GetConVarFloat(sm_noblock_blockafterspawn_time);
g_blockTime = GetConVarFloat(sm_noblock_blockafterspawn_time);
HookConVarChange(sm_noblock_blockafterspawn_time, OnConVarChange);
HookConVarChange(sm_noblock, OnConVarChange);
HookConVarChange(sm_noblock_nades, OnConVarChange);
HookConVarChange(sm_noblock_hostages, OnConVarChange);
HookConVarChange(sm_noblock_allow_block, OnConVarChange);
HookConVarChange(sm_noblock_allow_block_time, OnConVarChange);
HookConVarChange(sm_noblock_blockafterspawn_time, OnConVarChange);


if ( g_enabled ) {
if ( g_enabled ) {
StartHook();
StartHook();
}
}
AutoExecConfig(true, "noblock");
RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say_team", Command_Say);
RegConsoleCmd("say_team", Command_Say);
if(GetEngineVersion() != Engine_CSGO)
{
SetFailState("ERROR: This plugin is designed only for CS:GO.");
}
}
}


// ===========================================================================
// ===========================================================================
// EVENTS
// EVENTS
// ===========================================================================
// ===========================================================================


public OnConVarChange(Handle:hCvar, const String:oldValue[], const String:newValue[])
public OnConVarChange(Handle:hCvar, const String:oldValue[], const String:newValue[])
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Cvar changed.");
LogError("[DEBUG] Cvar changed.");
#endif
#endif
if ( hCvar == sm_noblock ) {
if ( hCvar == sm_noblock ) {
g_enabled = GetConVarBool(sm_noblock);
g_enabled = GetConVarBool(sm_noblock);
if ( g_enabled ) {
if ( g_enabled ) {
UnblockClientAll();
UnblockClientAll();
if ( sm_noblock_hostages ) {
if ( sm_noblock_hostages ) {
UnblockHostages();
UnblockHostages();
}
}
StartHook();
StartHook();
} else {
} else {
StopHook();
StopHook();
BlockClientAll();
BlockClientAll();
if ( sm_noblock_hostages ) {
if ( sm_noblock_hostages ) {
BlockHostages();
BlockHostages();
}
}
}
}
return;
return;
}
}
if ( hCvar == sm_noblock_nades ) {
if ( hCvar == sm_noblock_nades ) {
g_enabled_nades = GetConVarBool(sm_noblock_nades);
g_enabled_nades = GetConVarBool(sm_noblock_nades);
return;
return;
}
}
if ( hCvar == sm_noblock_hostages ) {
if ( hCvar == sm_noblock_hostages ) {
g_enabled_hostages = GetConVarBool(sm_noblock_hostages);
g_enabled_hostages = GetConVarBool(sm_noblock_hostages);
if ( g_enabled ) {
if ( g_enabled ) {
if ( g_enabled_hostages ) {
if ( g_enabled_hostages ) {
UnblockHostages();
UnblockHostages();
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
} else {
} else {
UnhookEvent("round_start", OnRoundStart, EventHookMode_Post);
UnhookEvent("round_start", OnRoundStart, EventHookMode_Post);
BlockHostages();
BlockHostages();
}
}
}
}
return;
return;
}
}
if ( hCvar == sm_noblock_blockafterspawn_time ) {
if ( hCvar == sm_noblock_blockafterspawn_time ) {
g_blockTime = GetConVarFloat(sm_noblock_blockafterspawn_time);
g_blockTime = GetConVarFloat(sm_noblock_blockafterspawn_time);
return;
return;
}
}
if ( hCvar == sm_noblock_allow_block ) {
if ( hCvar == sm_noblock_allow_block ) {
g_noblock_allow_block = GetConVarBool(sm_noblock_allow_block);
g_noblock_allow_block = GetConVarBool(sm_noblock_allow_block);
return;
return;
}
}
if ( hCvar == sm_noblock_allow_block_time ) {
if ( hCvar == sm_noblock_allow_block_time ) {
g_noblock_allow_block_time = GetConVarFloat(sm_noblock_allow_block_time);
g_noblock_allow_block_time = GetConVarFloat(sm_noblock_allow_block_time);
return;
return;
}
}
}
}


public OnSpawn(Handle:event, const String:name[], bool:dontBroadcast)
public OnSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Player spawned.");
LogError("[DEBUG] Player spawned.");
#endif
#endif


new userid = GetEventInt(event, "userid");
new userid = GetEventInt(event, "userid");
new client = GetClientOfUserId(userid);
new client = GetClientOfUserId(userid);
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] ... player %i.", client);
LogError("[DEBUG] ... player %i.", client);
#endif
#endif
if ( g_hTimer[client] != INVALID_HANDLE )
if ( g_hTimer[client] != INVALID_HANDLE )
{
{
CloseHandle(g_hTimer[client]);
CloseHandle(g_hTimer[client]);
g_hTimer[client] = INVALID_HANDLE;
g_hTimer[client] = INVALID_HANDLE;
PrintToChat(client, "%c[NoBlock] %cBlocking has been Disabled because of respawn", cLightGreen, cDefault);
PrintToChat(client, "%c[NoBlock] %cBlocking has been Disabled because of respawn", cLightGreen, cDefault);
}
}


UnblockEntity(client);
UnblockEntity(client);
if ( g_blockTime )
if ( g_blockTime )
{
{
CreateTimer(g_blockTime, Timer_PlayerBlock, client);
CreateTimer(g_blockTime, Timer_PlayerBlock, client);
}
}
}
}


//Enable NoBlock on hostages on roundstart
//Enable NoBlock on hostages on roundstart
public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Round started.");
LogError("[DEBUG] Round started.");
#endif
#endif
UnblockHostages();
UnblockHostages();
}
}


public Action:Command_Say(client, args)
public Action:Command_Say(client, args)
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Player %i sayd something.", client);
LogError("[DEBUG] Player %i sayd something.", client);
#endif
#endif
if ( !g_enabled || !client || !g_noblock_allow_block )
if ( !g_enabled || !client || !g_noblock_allow_block )
{
{
return Plugin_Continue;
return Plugin_Continue;
}
}


decl String:text[192], String:command[64];
decl String:text[192], String:command[64];
new startidx = 0;
new startidx = 0;
if (GetCmdArgString(text, sizeof(text)) < 1)
if (GetCmdArgString(text, sizeof(text)) < 1)
{
{
return Plugin_Continue;
return Plugin_Continue;
}
}
if (text[strlen(text)-1] == '"')
if (text[strlen(text)-1] == '"')
{
{
text[strlen(text)-1] = '\0';
text[strlen(text)-1] = '\0';
startidx = 1;
startidx = 1;
}
}


if (strcmp(command, "say2", false) == 0)
if (strcmp(command, "say2", false) == 0)
{
{
startidx += 4;
startidx += 4;
}
}


if ( (strcmp(text[startidx], "!block", false) == 0) && !g_blockTime )
if ( (strcmp(text[startidx], "!block", false) == 0) && !g_blockTime )
{
{
if ( g_hTimer[client] != INVALID_HANDLE )
if ( g_hTimer[client] != INVALID_HANDLE )
{
{
CloseHandle(g_hTimer[client]);
CloseHandle(g_hTimer[client]);
g_hTimer[client] = INVALID_HANDLE;
g_hTimer[client] = INVALID_HANDLE;
PrintToChat(client, "%c[NoBlock] %cBlocking has been Disabled by the client", cLightGreen, cDefault);
PrintToChat(client, "%c[NoBlock] %cBlocking has been Disabled by the client", cLightGreen, cDefault);
UnblockEntity(client);
UnblockEntity(client);
return Plugin_Continue;
return Plugin_Continue;
}
}
g_hTimer[client] = CreateTimer(g_noblock_allow_block_time, Timer_PlayerUnblock, client);
g_hTimer[client] = CreateTimer(g_noblock_allow_block_time, Timer_PlayerUnblock, client);
PrintToChat(client, "%c[NoBlock] %cBlocking has been Enabled for %.0f seconds", cLightGreen, cDefault, g_noblock_allow_block_time);
PrintToChat(client, "%c[NoBlock] %cBlocking has been Enabled for %.0f seconds", cLightGreen, cDefault, g_noblock_allow_block_time);
BlockEntity(client);
BlockEntity(client);
}
}
return Plugin_Continue;
return Plugin_Continue;
}
}


//Player Blocking Expires
//Player Blocking Expires
public Action:Timer_PlayerUnblock(Handle:timer, any:client)
public Action:Timer_PlayerUnblock(Handle:timer, any:client)
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Timer unblocks client %i.", client);
LogError("[DEBUG] Timer unblocks client %i.", client);
#endif
#endif
//Disable Blocking on the Client
//Disable Blocking on the Client
g_hTimer[client] = INVALID_HANDLE;
g_hTimer[client] = INVALID_HANDLE;
if ( !g_enabled || !client || !IsClientInGame(client) || !IsPlayerAlive(client) )
if ( !g_enabled || !client || !IsClientInGame(client) || !IsPlayerAlive(client) )
{
{
return Plugin_Continue;
return Plugin_Continue;
}
}
PrintToChat(client, "%c[NoBlock] %cBlocking is now Disabled", cLightGreen, cDefault);
PrintToChat(client, "%c[NoBlock] %cBlocking is now Disabled", cLightGreen, cDefault);
UnblockEntity(client);
UnblockEntity(client);
return Plugin_Continue;
return Plugin_Continue;
}
}


public Action:Timer_PlayerBlock(Handle:timer, any:client)
public Action:Timer_PlayerBlock(Handle:timer, any:client)
{
{
//Enable Blocking on the Client
//Enable Blocking on the Client
if ( !g_enabled || !client || !IsClientInGame(client) || !IsPlayerAlive(client) )
if ( !g_enabled || !client || !IsClientInGame(client) || !IsPlayerAlive(client) )
{
{
return Plugin_Continue;
return Plugin_Continue;
}
}
BlockEntity(client);
BlockEntity(client);
return Plugin_Continue;
return Plugin_Continue;
}
}


public OnEntityCreated(entity, const String:classname[])
public OnEntityCreated(entity, const String:classname[])
{
{
if ( g_enabled_nades )
if ( g_enabled_nades )
{
{
//Enable NoBlock on Nades
//Enable NoBlock on Nades
if (StrEqual(classname, "hegrenade_projectile")) {
if (StrEqual(classname, "hegrenade_projectile")) {
UnblockEntity(entity);
UnblockEntity(entity);
} else if (StrEqual(classname, "flashbang_projectile")) {
} else if (StrEqual(classname, "flashbang_projectile")) {
UnblockEntity(entity);
UnblockEntity(entity);
} else if (StrEqual(classname, "smokegrenade_projectile")) {
} else if (StrEqual(classname, "smokegrenade_projectile")) {
UnblockEntity(entity);
UnblockEntity(entity);
}
}
}
}
}
}


// ===========================================================================
// ===========================================================================
// HELPERS
// HELPERS
// ===========================================================================
// ===========================================================================


StartHook() {
StartHook() {
HookEvent("player_spawn", OnSpawn, EventHookMode_Post);
HookEvent("player_spawn", OnSpawn, EventHookMode_Post);
if ( g_enabled_hostages ) {
if ( g_enabled_hostages ) {
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
}
}
}
}


StopHook() {
StopHook() {
UnhookEvent("player_spawn", OnSpawn, EventHookMode_Post);
UnhookEvent("player_spawn", OnSpawn, EventHookMode_Post);
if ( g_enabled_hostages ) {
if ( g_enabled_hostages ) {
UnhookEvent("round_start", OnRoundStart, EventHookMode_Post);
UnhookEvent("round_start", OnRoundStart, EventHookMode_Post);
}
}
}
}


UnblockHostages() {
UnblockHostages() {
new String:sClassName[32];
new String:sClassName[32];
new iMaxEntities = GetMaxEntities();
new iMaxEntities = GetMaxEntities();
/* Apparently the clients are always at the start of the entity list,
so we can skip them in hopes of reducing roundstart lag */
for ( new iEntity = MaxClients + 1; iEntity < iMaxEntities; iEntity++ )
for ( new iEntity = MaxClients + 1; iEntity < iMaxEntities; iEntity++ )
{
{
if ( !IsValidEntity(iEntity) || !IsValidEdict(iEntity) ) {
if ( !IsValidEntity(iEntity) || !IsValidEdict(iEntity) ) {
continue;
continue;
}
}
GetEdictClassname(iEntity, sClassName, sizeof(sClassName));
GetEdictClassname(iEntity, sClassName, sizeof(sClassName));
if ( StrEqual("hostage_entity", sClassName) ) {
if ( StrEqual("hostage_entity", sClassName) ) {
UnblockEntity(iEntity);
UnblockEntity(iEntity);
}
}
}
}
}
}


BlockHostages() {
BlockHostages() {
new String:sClassName[32];
new String:sClassName[32];
new iMaxEntities = GetMaxEntities();
new iMaxEntities = GetMaxEntities();
/* Apparently the clients are always at the start of the entity list,
so we can skip them in hopes of reducing roundstart lag */
for ( new iEntity = MaxClients + 1; iEntity < iMaxEntities; iEntity++ )
for ( new iEntity = MaxClients + 1; iEntity < iMaxEntities; iEntity++ )
{
{
if ( !IsValidEntity(iEntity) || !IsValidEdict(iEntity) ) {
if ( !IsValidEntity(iEntity) || !IsValidEdict(iEntity) ) {
continue;
continue;
}
}
GetEdictClassname(iEntity, sClassName, sizeof(sClassName));
GetEdictClassname(iEntity, sClassName, sizeof(sClassName));
if ( StrEqual("hostage_entity", sClassName) ) {
if ( StrEqual("hostage_entity", sClassName) ) {
BlockEntity(iEntity);
BlockEntity(iEntity);
}
}
}
}
}
}


BlockEntity(client)
BlockEntity(client)
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] BLOCK client %i.", client);
LogError("[DEBUG] BLOCK client %i.", client);
#endif
#endif
SetEntData(client, g_offsCollisionGroup, 5, 4, true);
SetEntData(client, g_offsCollisionGroup, 5, 4, true);
}
}


UnblockEntity(client)
UnblockEntity(client)
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] UNBLOCK client %i.", client);
LogError("[DEBUG] UNBLOCK client %i.", client);
#endif
#endif
SetEntData(client, g_offsCollisionGroup, 2, 4, true);
SetEntData(client, g_offsCollisionGroup, 2, 4, true);
}
}


BlockClientAll()
BlockClientAll()
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Block all.");
LogError("[DEBUG] Block all.");
#endif
#endif
for (new i = 1; i <= MaxClients; i++)
for (new i = 1; i <= MaxClients; i++)
{
{
if ( IsClientInGame(i) && IsPlayerAlive(i) )
if ( IsClientInGame(i) && IsPlayerAlive(i) )
{
{
BlockEntity(i);
BlockEntity(i);
}
}
}
}
}
}


UnblockClientAll()
UnblockClientAll()
{
{
#if defined DEBUG
#if defined DEBUG
LogError("[DEBUG] Unblock all.");
LogError("[DEBUG] Unblock all.");
#endif
#endif
for (new i = 1; i <= MaxClients; i++)
for (new i = 1; i <= MaxClients; i++)
{
{
if ( IsClientInGame(i) && IsPlayerAlive(i) )
if ( IsClientInGame(i) && IsPlayerAlive(i) )
{
{
UnblockEntity(i);
UnblockEntity(i);
}
}
}
}
}
}