View Single Post
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-19-2018 , 13:34   Re: [L4D2] Survivor healed
Reply With Quote #9

Quote:
Originally Posted by midnight9 View Post
I dont think i can rely on that.
Lets say Player A plays as Ellis, another player heals player A (Ellis) so the bool will be true for player A, but then player A leaves the game and player B joins and takes over Ellis, so then bool will be false because its been set to true for player A that has left correct?
Look what I did on another plugin:

Code:
#include <sourcemod>
#include <sdktools>

public Plugin:myinfo = 
{
	name = "Fun Shit For Admins",
	author = "Eyal282 ( FuckTheSchool )",
	description = "Allows you to do shit with your poor players",
	version = "1.1",
	url = "<- URL ->"
}

new bool:bShouldFreeze[MAXPLAYERS];

new const String:const_GameDataFile[] = "FunShitForAdmins";
new const String:const_LinuxOnStartCarrying[] = "_ZN13CTerrorPlayer21OnStartCarryingVictimEPS_";

new spCollisionGroup;

new Handle:hFreezeTimer[MAXPLAYERS] = INVALID_HANDLE;
new bool:bFrozen[MAXPLAYERS];
new Duration[MAXPLAYERS];

new Handle:SDKStartCarrying = INVALID_HANDLE;

new bool:RoundStarted;

public OnPluginStart()
{	
	RegAdminCmd("sm_freeze", Command_Freeze, ADMFLAG_SLAY);
	RegAdminCmd("sm_unfreeze", Command_Unfreeze, ADMFLAG_SLAY);
	
	new String:FileName[300], Handle:hGameConf;

	BuildPath(Path_SM, FileName, sizeof(FileName), "gamedata/%s.txt", const_GameDataFile);
	if( !FileExists(FileName) )
	{
		
		new Handle:FileHandle = OpenFile(FileName, "a+");
		
		if(FileHandle == INVALID_HANDLE)
			SetFailState("Could not create gamedata file.");
		
		
		WriteFileLine(FileHandle, "\"Games\""); 
		WriteFileLine(FileHandle, "{");
		WriteFileLine(FileHandle, "	\"left4dead2\"");
		WriteFileLine(FileHandle, "	{");
		WriteFileLine(FileHandle, "		\"Signatures\"");
		WriteFileLine(FileHandle, "		{");
		WriteFileLine(FileHandle, "			\"OnStartCarryingVictim\"");
		WriteFileLine(FileHandle, "			{");
		WriteFileLine(FileHandle, "				\"library\" \"server\"");
		WriteFileLine(FileHandle, "				\"linux\" \"@%s\"", const_LinuxOnStartCarrying);
		WriteFileLine(FileHandle, "			}");
		WriteFileLine(FileHandle, "		}");
		WriteFileLine(FileHandle, "	}");
		WriteFileLine(FileHandle, "}");

		CloseHandle(FileHandle);

		hGameConf = LoadGameConfigFile(const_GameDataFile);
	}
	else
		hGameConf = LoadGameConfigFile(const_GameDataFile);
	
	StartPrepSDKCall(SDKCall_Player);
	PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "OnStartCarryingVictim");
	PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
	
	SDKStartCarrying = EndPrepSDKCall();

	if(SDKStartCarrying == INVALID_HANDLE)
	{
		SetFailState("Could not find signature OnStartCarryingVictim.");
		return;
	}
	spCollisionGroup = FindSendPropInfo("CBaseEntity", "m_CollisionGroup");
	HookEvent("player_bot_replace", Event_PlayerBotReplace_Pre, EventHookMode_Pre); // Bot replaced a player.
	HookEvent("player_bot_replace", Event_PlayerBotReplace_Post, EventHookMode_Post);	// Bot replaced a player.
	HookEvent("bot_player_replace", Event_BotPlayerReplace_Pre, EventHookMode_Pre); // Player replaced a bot.
	HookEvent("bot_player_replace", Event_BotPlayerReplace_Post, EventHookMode_Post);	// Player replaced a bot.
	HookEvent("charger_carry_start", Event_ChargerCarryStart, EventHookMode_Pre);
	HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
	HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
	
}

public Action:Event_RoundEnd(Handle:hEvent, const String:Name[], bool:dontBroadcast)
{
	RoundStarted = false;
	for(new i=1;i <= MaxClients;i++)
	{
		if(!IsClientInGame(i))
			continue;
			
		else if(GetClientTeam(i) != 2)
			continue;
			
		else if(!IsPlayerAlive(i))
			continue;
		
		else if(hFreezeTimer[i] == INVALID_HANDLE)
			continue;
		
		Duration[i] = 0;
		TriggerTimer(hFreezeTimer[i], true);
	}
}

public Action:Event_RoundStart(Handle:hEvent, const String:Name[], bool:dontBroadcast)
{
	RoundStarted = true;
}

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
	CreateNative("FunCharger_freeze", FunCharger_freeze);
}

// native FunCharger_freeze(client, bool:freeze);

public FunCharger_freeze(Handle:plugin, numParams)
{
	if(!RoundStarted)	
		return;
		
	new client, bool:freeze;
	
	client = GetNativeCell(1);
	freeze = bool:GetNativeCell(2);
	if(freeze)
		performFreeze(client);
		
	else	
		performUnfreeze(client);
}
public OnClientConnected(client)
{
	bShouldFreeze[client] = false;
}	

public Action:Event_PlayerBotReplace_Pre(Handle:hEvent, const String:Name[], bool:dontBroadcast) // A bot replaces a player.
{
	new client = GetClientOfUserId(GetEventInt(hEvent, "player"));
	
	if(!bFrozen[client])
		return;
	
	new bot = GetClientOfUserId(GetEventInt(hEvent, "bot"));
	Duration[bot] = Duration[client];
	performUnfreeze(client);
	bShouldFreeze[bot] = true;
	if(hFreezeTimer[client] != INVALID_HANDLE)
	{
		CloseHandle(hFreezeTimer[client]);
		hFreezeTimer[client] = INVALID_HANDLE;
	}	
}

public Action:Event_PlayerBotReplace_Post(Handle:hEvent, const String:Name[], bool:dontBroadcast) // A bot replaces a player.
{
	new bot = GetClientOfUserId(GetEventInt(hEvent, "bot"));
	
	if(!bShouldFreeze[bot])
		return;
	
	hFreezeTimer[bot] = CreateTimer(1.0, UnfreezePlayer, bot, TIMER_REPEAT);
	performFreeze(bot);
	bShouldFreeze[bot] = false;
}

public Action:Event_BotPlayerReplace_Pre(Handle:hEvent, const String:Name[], bool:dontBroadcast) // A player replaces a bot.
{
	new bot = GetClientOfUserId(GetEventInt(hEvent, "bot"));
	
	if(!bFrozen[bot])
		return;
	
	new client = GetClientOfUserId(GetEventInt(hEvent, "player"));
	Duration[client] = Duration[bot];
	performUnfreeze(bot);
	bShouldFreeze[client] = true;
	if(hFreezeTimer[bot] != INVALID_HANDLE)
	{
		CloseHandle(hFreezeTimer[bot]);
		hFreezeTimer[bot] = INVALID_HANDLE;
	}	
}

public Action:Event_BotPlayerReplace_Post(Handle:hEvent, const String:Name[], bool:dontBroadcast) // A player replaces a bot.
{
	new client = GetClientOfUserId(GetEventInt(hEvent, "player"));
	
	if(!bShouldFreeze[client])
		return;
	
	hFreezeTimer[client] = CreateTimer(1.0, UnfreezePlayer, client, TIMER_REPEAT);
	performFreeze(client);
	bShouldFreeze[client] = false;
}

public Action:Event_ChargerCarryStart(Handle:hEvent, const String:Name[], bool:dontBroadcast) // A player replaces a bot.
{
	new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
	new victim = GetClientOfUserId(GetEventInt(hEvent, "victim"));
	
	if(client == victim)
		return;

	else if(bFrozen[victim])
	{
		performUnfreeze(victim);
		if(hFreezeTimer[victim] != INVALID_HANDLE)
		{
			CloseHandle(hFreezeTimer[victim]);
			hFreezeTimer[victim] = INVALID_HANDLE;
		}	
	}
}
public Action:Command_Freeze(client, args)
{
	if(!RoundStarted)
	{
		ReplyToCommand(client, "[SM] Error: Round has not started.");
		return Plugin_Handled;
	}
	if (args == 0)
	{
		ReplyToCommand(client, "[SM] Usage: sm_freeze <target> [duration]");
		return Plugin_Handled;
	}
	else if (args > 2)
	{
		ReplyToCommand(client, "[SM] Usage: sm_freeze <target> [duration]");
		return Plugin_Handled;
	}
	
	
	decl String:arg[65], String:arg2[65];
	GetCmdArg(1, arg, sizeof(arg));
	
	new Time;
	if(args == 2)
	{
		GetCmdArg(2, arg2, sizeof(arg2));
		Time = StringToInt(arg2);
	}
	else
		Time = 7;
	
	if(Time < 0)
	{
		ReplyToCommand(client, "[SM] Error: Invalid freeze duration!");
		return Plugin_Handled;
	}

	decl String:target_name[MAX_TARGET_LENGTH];
	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
	if ((target_count = ProcessTargetString(
			arg,
			client,
			target_list,
			MAXPLAYERS,
			COMMAND_FILTER_ALIVE,
			target_name,
			sizeof(target_name),
			tn_is_ml)) <= 0)
	{
		ReplyToTargetError(client, target_count);
		return Plugin_Handled;
	}
	new target;
	for (new i = 0; i < target_count; i++)
	{
		target = target_list[i];
		if(!IsClientInGame(target))
			continue;
			
		else if(GetClientTeam(target) != 2)
			continue;
			
		else if(!IsPlayerAlive(target))
			continue;
		
		else if(GetEntProp(target, Prop_Send, "m_isHangingFromLedge") > 0 || GetEntProp(target, Prop_Send, "m_isFallingFromLedge") > 0 || GetEntProp(target, Prop_Send, "m_isIncapacitated") > 0)
			continue;
		
		else if(IsClientTrappedBySI(target))
			continue;
			
		if(hFreezeTimer[target] != INVALID_HANDLE)
		{
			Duration[target] = 0;
			TriggerTimer(hFreezeTimer[target], true);
		}
		
		hFreezeTimer[target] = CreateTimer(1.0, UnfreezePlayer, target, TIMER_REPEAT);
		Duration[target] = Time;
		performFreeze(target);
	}
	
	return Plugin_Handled;
}

public Action:UnfreezePlayer(Handle:hTimer, target)
{
	if(Duration[target] == 0)
	{
		performUnfreeze(target);
			
		hFreezeTimer[target] = INVALID_HANDLE;
		
		return Plugin_Stop;
	}
	
	PrintHintText(target, "You are FROZEN!\nYou will be released in %i second%s!", Duration[target], Duration[target] == 1 ? "" : "s");
	Duration[target]--;
	return Plugin_Continue;
	
}

public Action:Command_Unfreeze(client, args)
{
	if (args == 0 || args > 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_unfreeze <target>");
		return Plugin_Handled;
	}
	
	
	decl String:arg[65];
	GetCmdArg(1, arg, sizeof(arg));
	

	decl String:target_name[MAX_TARGET_LENGTH];
	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
	if ((target_count = ProcessTargetString(
			arg,
			client,
			target_list,
			MAXPLAYERS,
			COMMAND_FILTER_ALIVE,
			target_name,
			sizeof(target_name),
			tn_is_ml)) <= 0)
	{
		ReplyToTargetError(client, target_count);
		return Plugin_Handled;
	}
	new target;
	for (new i = 0; i < target_count; i++)
	{
		target = target_list[i];
		if(!IsClientInGame(target))
			continue;
			
		else if(GetClientTeam(target) != 2)
			continue;
			
		else if(!IsPlayerAlive(target))
			continue;
		
		else if(hFreezeTimer[target] == INVALID_HANDLE)
			continue;
		
		Duration[target] = 0;
		TriggerTimer(hFreezeTimer[target], true);
	}
	
	return Plugin_Handled;
}

performUnfreeze(target)
{
	bFrozen[target] = false;
	
	SetEntPropEnt(target, Prop_Send, "m_carryAttacker", -1);
	SetEntPropEnt(target, Prop_Send, "m_carryVictim", -1);
	
	SetEntityMoveType(target, MOVETYPE_WALK);
	SetEntData(target, spCollisionGroup, 5, 1, true);
	SetEntPropFloat(target, Prop_Send, "m_healthBuffer", 0.0);
}

performFreeze(target)
{
	SDKCall(SDKStartCarrying, target, target);
	bFrozen[target] = true;
	SetEntData(target, spCollisionGroup, 2, 1, true); // This blocks the target from being touched. If it's not done and a charger grabs the self-charged victim, the server will crash.
}


stock bool IsClientTrappedBySI(client) // Not incap by a Special Infected
{	
	return ( ( GetEntPropEnt(client, Prop_Send, "m_pummelAttacker") != -1 ) || (GetEntPropEnt(client, Prop_Send, "m_pounceAttacker") != -1) || (GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker") != -1) || GetEntPropEnt(client, Prop_Send, "m_tongueOwner") != -1 || GetEntPropEnt(client, Prop_Send, "m_carryAttacker") != -1 ) ? true : false;
}
Refer to the four events of bot_player_replace and player_bot_replace
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline