Raised This Month: $51 Target: $400
 12% 

plugin modification


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MrGarfield
Senior Member
Join Date: Feb 2013
Old 09-05-2020 , 05:39   plugin modification
Reply With Quote #1

Hello everyone, I would like to make a small modification on this semiclip plugin. The plugin works well but I would just like to go through my teammates without there being any degradation on the player.



thank you

Code:
#define SHOW_NAMES_WHEN_AIM
#define ENABLE_SHOTS_DAMAGE

#define SEMICLIP_RENDERING_RADIUS 180.0

// #define CHATCOLOR // if you are runing plugin : http://forums.alliedmods.net/showthread.php?p=851160

// /* DON'T EDIT BELOW */

#include < amxmodx >
#include < engine >
#include < fakemeta >
#include < hamsandwich >

// #if defined CHATCOLOR
// #include < chatcolor >
// #endif

#pragma semicolon 1

#define PLUGIN "Team SemiClip"
new const VERSION[] = "0.3.5b1";

#define cm(%0)	( sizeof(%0) - 1 )

const Float:SEMICLIP_RADIUS = SEMICLIP_RENDERING_RADIUS;

const m_iTeam = 114;

const GROUP_OP_NAND = 1;
#define ENGINE_SETGROUPMASK(%0,%1)	engfunc(EngFunc_SetGroupMask, %0, %1)

const groupNone = 0;

new const CLASS_PLAYER[] = "player";

new g_iMaxPlayers;
#define IsPlayer(%0)	( 1 <= (%0) <= g_iMaxPlayers )

#define MaskEnt(%0)	( 1<<(%0 & 31) )

new g_bitIsPlayerInSphere;
#define MarkPlayerInSphere(%0)	g_bitIsPlayerInSphere |= MaskEnt(%0)
#define IsPlayerInSphere(%0)	( g_bitIsPlayerInSphere & MaskEnt(%0) )

new g_bitIsPlayerInTeam;
#define MarkPlayerInTeam(%0)	g_bitIsPlayerInTeam |= MaskEnt(%0)
#define IsPlayerInTeam(%0)	( g_bitIsPlayerInTeam & MaskEnt(%0) )

new g_bitIsPlayerAlive;
#define MarkPlayerAlive(%0)	g_bitIsPlayerAlive |= MaskEnt(%0)
#define IsPlayerAlive(%0)	( g_bitIsPlayerAlive & MaskEnt(%0) )

new g_bitBots;
#define MarkPlayerBot(%0)	g_bitBots |= MaskEnt(%0)
#define ClearPlayerBot(%0)	g_bitBots &= ~MaskEnt(%0)
#define IsUserBot(%0)		( g_bitBots & MaskEnt(%0) )

// new g_bitSeeingPlayers = 0xFFFFFFFF;
// #define MarkPlayerSee(%0)		g_bitSeeingPlayers |= MaskEnt(%0)
// #define ClearPlayerSee(%0)		g_bitSeeingPlayers &= ~MaskEnt(%0)
// #define IsPlayerSeeing(%0)		( g_bitSeeingPlayers & MaskEnt(%0) )
// #define TogglePlayerSeeing(%0)	g_bitSeeingPlayers ^= MaskEnt(%0)

new g_iPlayers[32], g_iNum;

new g_iLastPlayerIndex;

new g_iFhAddToFullPackPost;

new bool:g_bReadPackets;
new bool:g_bClientMessages;

#if defined SHOW_NAMES_WHEN_AIM
	new HamHook:g_iHhPreThink, HamHook:g_iHhPreThinkPost, bool:g_bPreThinkHooked;
#endif

#if defined ENABLE_SHOTS_DAMAGE
	new HamHook:g_iHhPostThink, HamHook:g_iHhPostThinkPost, bool:g_bPostThinkHooked;
	new HamHook:g_iHhPostThinkCSBOT, HamHook:g_iHhPostThinkPostCSBOT;
#endif

public plugin_init()
{
	register_plugin( PLUGIN, VERSION, "ConnorMcLeod" );
	set_pcvar_string
	(
		register_cvar("team_semiclip_version", VERSION, FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY), 
		VERSION
	);

	register_forward(FM_CmdStart, "OnCmdStart_P", true);

	state Not_Registered;

	new modname[7];
	get_modname(modname, cm(modname));
	if( equal(modname, "czero") )
	{
		register_event("TextMsg", "Event_TextMsg_Game_connected", "a", "1=1", "2=#Game_connected");
	}

#if defined SHOW_NAMES_WHEN_AIM
	DisableHamForward( g_iHhPreThink = RegisterHam(Ham_Player_PreThink, CLASS_PLAYER, "OnCBasePlayer_PreThink", false) );
	DisableHamForward( g_iHhPreThinkPost = RegisterHam(Ham_Player_PreThink, CLASS_PLAYER, "OnCBasePlayer_PreThink_P", true) );
#endif
	
#if defined ENABLE_SHOTS_DAMAGE
	DisableHamForward( g_iHhPostThink = RegisterHam(Ham_Player_PostThink, CLASS_PLAYER, "OnCBasePlayer_PostThink", false) );
	DisableHamForward( g_iHhPostThinkPost = RegisterHam(Ham_Player_PostThink, CLASS_PLAYER, "OnCBasePlayer_PostThink_P", true) );
#endif

	RegisterHam(Ham_Spawn, CLASS_PLAYER, "OnCBasePlayer_Spawn_P", true);
	RegisterHam(Ham_Killed, CLASS_PLAYER, "OnCBasePlayer_Killed_P", true);

	register_forward(FM_UpdateClientData, "OnUpdateClientData_P", true);

	g_iMaxPlayers = get_maxplayers();

	// register_clcmd("say /invis", "ClCmd_Players");
	// register_clcmd("say /players", "ClCmd_Players");
}

HandleCzBotsHamForwards(id)
{
	RegisterHamFromEntity(Ham_Spawn, id, "OnCBasePlayer_Spawn_P", true);
	RegisterHamFromEntity(Ham_Killed, id, "OnCBasePlayer_Killed_P", true);

#if defined ENABLE_SHOTS_DAMAGE
	DisableHamForward( g_iHhPostThinkCSBOT = RegisterHamFromEntity(Ham_Player_PostThink, id, "OnCBasePlayer_PostThink", false) );
	DisableHamForward( g_iHhPostThinkPostCSBOT = RegisterHamFromEntity(Ham_Player_PostThink, id, "OnCBasePlayer_PostThink_P", true) );
#endif
}

public Event_TextMsg_Game_connected() <Registered> {}
public Event_TextMsg_Game_connected() <Not_Registered>
{
	new szName[32];
	read_data(3, szName, cm(szName));
	new id = find_player("ai", szName);
	if( id && IsCzBot( id ) )
	{
		HandleCzBotsHamForwards(id);
		state Registered;
	}
}

IsCzBot( id )
{
#if defined Ham_CS_Player_IsBot
	static valid = -1;
	if( valid == -1 )
	{
		valid = IsHamValid( Ham_CS_Player_IsBot );
	}
	if( valid )
	{
		return ExecuteHam(Ham_CS_Player_IsBot, id);
	}
	return ExecuteHam(Ham_Weapon_ExtractClipAmmo, id, 0);
#else
	return ExecuteHam(Ham_Weapon_ExtractClipAmmo, id, 0);
#endif
}

public client_putinserver(id)
{
	if( is_user_bot(id) )
	{
		MarkPlayerBot(id);
	}
	else
	{
		ClearPlayerBot(id);
	}
	// MarkPlayerSee(id);
}

public OnCmdStart_P(id)
{
	if( !g_bReadPackets )
	{
		g_bReadPackets = true;

		static plr;
		get_players g_iPlayers, g_iNum, "a" ;
		for(--g_iNum; g_iNum>=0; g_iNum--)
		{
			plr = g_iPlayers[ g_iNum ];
			entity_set_int plr, EV_INT_groupinfo, get_pdata_int(plr, m_iTeam) ;
		}
		g_iLastPlayerIndex = 0;
	}

	if( g_iLastPlayerIndex && is_user_alive(g_iLastPlayerIndex) )
	{
		entity_set_int g_iLastPlayerIndex, EV_INT_groupinfo, get_pdata_int(g_iLastPlayerIndex, m_iTeam) ;
	}

	if( is_user_alive(id) )
	{
		static group;
		group = get_pdata_int(id, m_iTeam);
		entity_set_int id, EV_INT_groupinfo, group ;
		ENGINE_SETGROUPMASK(group, GROUP_OP_NAND);
		// if( IsPlayerSeeing(id) )
		// {
#if defined SHOW_NAMES_WHEN_AIM
		if( !g_bPreThinkHooked && !IsUserBot(id) )
		{
			EnableHamForward g_iHhPreThink ;
			EnableHamForward g_iHhPreThinkPost ;
			g_bPreThinkHooked = true;
		}
#endif
#if defined ENABLE_SHOTS_DAMAGE
		if( !g_bPostThinkHooked )
		{
			EnableHamForward g_iHhPostThink ;
			EnableHamForward g_iHhPostThinkPost ;
			if( g_iHhPostThinkCSBOT )
			{
				EnableHamForward g_iHhPostThinkCSBOT ;
				EnableHamForward g_iHhPostThinkPostCSBOT ;
			}
			g_bPostThinkHooked = true;
		}
#endif
		// }
		// else // empty statement when nothing is defined ?
		// {
// #if defined SHOW_NAMES_WHEN_AIM
			// if( g_bPreThinkHooked )
			// {
				// DisableHamForward g_iHhPreThink ;
				// DisableHamForward g_iHhPreThinkPost ;
				// g_bPreThinkHooked = false;
			// }
// #endif
// #if defined ENABLE_SHOTS_DAMAGE
			// if( g_bPostThinkHooked )
			// {
				// DisableHamForward g_iHhPostThink ;
				// DisableHamForward g_iHhPostThinkPost ;
				// if( g_iHhPostThinkCSBOT )
				// {
					// DisableHamForward g_iHhPostThinkCSBOT ;
					// DisableHamForward g_iHhPostThinkPostCSBOT ;
				// }
				// g_bPostThinkHooked = false;
			// }
// #endif
		// }
	}
	else
	{
		entity_set_int id, EV_INT_groupinfo, groupNone ;
		g_iLastPlayerIndex = id;
#if defined SHOW_NAMES_WHEN_AIM
		if( g_bPreThinkHooked )
		{
			DisableHamForward g_iHhPreThink ;
			DisableHamForward g_iHhPreThinkPost ;
			g_bPreThinkHooked = false;
		}
#endif
#if defined ENABLE_SHOTS_DAMAGE
		if( g_bPostThinkHooked )
		{
			DisableHamForward g_iHhPostThink ;
			DisableHamForward g_iHhPostThinkPost ;
			if( g_iHhPostThinkCSBOT )
			{
				DisableHamForward g_iHhPostThinkCSBOT ;
				DisableHamForward g_iHhPostThinkPostCSBOT ;
			}
			g_bPostThinkHooked = false;
		}
#endif
	}
}

public OnCBasePlayer_PreThink(id)
{
	entity_set_int id, EV_INT_groupinfo, groupNone ;
}

public OnCBasePlayer_PreThink_P(id)
{
	entity_set_int id, EV_INT_groupinfo, get_pdata_int(id, m_iTeam) ;
}

public OnCBasePlayer_PostThink(id)
{
	entity_set_int id, EV_INT_groupinfo, groupNone ;
}

public OnCBasePlayer_PostThink_P(id)
{
	entity_set_int id, EV_INT_groupinfo, get_pdata_int(id, m_iTeam) ;
}

public OnCBasePlayer_Spawn_P(id)
{
	if( is_user_alive(id) )
	{
		entity_set_int id, EV_INT_groupinfo, get_pdata_int(id, m_iTeam) ;
	}
}

public OnCBasePlayer_Killed_P(id)
{
	if( !is_user_alive(id) )
	{
		entity_set_int id, EV_INT_groupinfo, groupNone ;
	}
}

// maybe this could be moved to first UpdateClientData ??
// in any ways, SV_Physics gonna be executed with clipping players
public server_frame()
{
	g_iLastPlayerIndex = 0;
	g_bReadPackets = false;
	g_bClientMessages = false;

	// seems to be too early for cz bots oO
	get_players g_iPlayers, g_iNum, "a" ;
	for(--g_iNum; g_iNum>=0; g_iNum--)
	{
		entity_set_int g_iPlayers[ g_iNum ], EV_INT_groupinfo, groupNone ;
	}
}

public OnUpdateClientData_P(id, sendweapons, cd)
{
	// if( IsUserBot(id) )
	// {
		// return;
	// }

	static player;

	if( !g_bClientMessages )
	{
		g_bClientMessages = true;

		g_bitIsPlayerAlive = 0;
		get_players g_iPlayers, g_iNum, "a" ;
		for(--g_iNum; g_iNum>=0; g_iNum--)
		{
			player = g_iPlayers[ g_iNum ];
			MarkPlayerAlive( player ); // safe to cache alive players here because nobody can die/spawn during rendering
			entity_set_int player, EV_INT_groupinfo, groupNone ; // CZ BOTS fix
		}
	}

	if( IsPlayerAlive(id) )
	{
		// if( IsPlayerSeeing(id) )
		// {
		g_bitIsPlayerInTeam = 0;
		g_bitIsPlayerInSphere = 0;

		get_players g_iPlayers, g_iNum, "ae", get_pdata_int(id, m_iTeam) == 1 ? "TERRORIST" : "CT" ;

		if( g_iNum > 1 )
		{
			for(--g_iNum; g_iNum>=0; g_iNum--)
			{
				player = g_iPlayers[ g_iNum ];
				if( player != id )
				{
					MarkPlayerInTeam( player );
				}
			}
			g_iNum = find_sphere_class(id, CLASS_PLAYER, SEMICLIP_RADIUS, g_iPlayers, g_iMaxPlayers);
			
			
			for(--g_iNum; g_iNum>=0; g_iNum--)
			{
				player = g_iPlayers[ g_iNum ];
				if( player != id && IsPlayerInTeam( player ) )
				{
					MarkPlayerInSphere( player );
				}
			}
		}
		if( g_bitIsPlayerInSphere )
		{
			if( !g_iFhAddToFullPackPost )
			{
				g_iFhAddToFullPackPost = register_forward(FM_AddToFullPack, "OnAddToFullPack_P", true);
			}
		}
		else if( g_iFhAddToFullPackPost )
		{
			unregister_forward FM_AddToFullPack, g_iFhAddToFullPackPost, true ;
			g_iFhAddToFullPackPost = 0;
		}
		// }
		// else if( g_iFhAddToFullPackPost )
		// {
			// unregister_forward FM_AddToFullPack, g_iFhAddToFullPackPost, true ;
			// g_iFhAddToFullPackPost = 0;
		// }
	}
}

public OnAddToFullPack_P(es, e, ent, id, hostflags, player, pSet)
{
	if( player )
	{
		if( IsPlayerAlive(ent) && IsPlayerInSphere(ent) )
		{
			set_es es, ES_Solid, SOLID_NOT ;
			set_es es, ES_RenderMode, kRenderTransAlpha ;
			set_es es, ES_RenderAmt, floatround(entity_range(id, ent) * 255.0 / SEMICLIP_RADIUS, floatround_floor) ;
		}
	}
	else
	{
		unregister_forward FM_AddToFullPack, g_iFhAddToFullPackPost, true ;
		g_iFhAddToFullPackPost = 0;
	}
}

// public ClCmd_Players(id)
// {
	// TogglePlayerSeeing(id);
// #if defined CHATCOLOR
	// client_print_color(id, Red, "^4[Invis] ^1Players are now %sisible.", IsPlayerSeeing(id) ? "^4V" :"^3Inv");
// #else
	// client_print(id, print_chat, "[Invis] Players are now %sisible.", IsPlayerSeeing(id) ? "V" :"Inv");
// #endif
// }
MrGarfield is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode