Raised This Month: $66 Target: $400
 16% 

Solved [L4D] How to force mission lost


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 10-19-2018 , 01:43   [L4D] How to force mission lost
Reply With Quote #1

Hi,
how to force mission lost without having killing all team?

I tried:
Code:
	int oldFlags = GetCommandFlags("scenario_end");
	SetCommandFlags("scenario_end", oldFlags & ~(FCVAR_CHEAT | FCVAR_LAUNCHER));
	ServerCommand("scenario_end");
	ServerExecute();
	SetCommandFlags("scenario_end", oldFlags);
(the code from No Death Check Until Dead plugin.)
But calling it just in arbitrary place has no effect.

Also:
Code:
	Event hEvent = CreateEvent("mission_lost");
	if (hEvent != null)
	{
		hEvent.Fire(true);
	}
with no luck. Of course, it's just post-event, but I had to try it.

Ideas? Thanks.
__________________
Expert of CMD/VBS/VB6. Malware analyst.

Last edited by Dragokas; 10-23-2018 at 12:08.
Dragokas is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-23-2018 , 07:17   Re: [L4D] How to force mission lost
Reply With Quote #2

Try "endround"
__________________


Accepting private work. Contact me if you're interested.
eyal282 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-23-2018 , 08:53   Re: [L4D] How to force mission lost
Reply With Quote #3

What if create game_end entity ?
https://developer.valvesoftware.com/wiki/Game_end
Bacardi is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 10-23-2018 , 11:15   Re: [L4D] How to force mission lost
Reply With Quote #4

Thank you, Bacardi and eyal282.

Here is my code:
Code:
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
	RegAdminCmd("sm_game_end", ForceGameEnd, ADMFLAG_BAN, "");
	RegAdminCmd("sm_round_end", ForceRoundEnd, ADMFLAG_BAN, "");
	RegAdminCmd("sm_round_end_2", ForceRoundEnd_2, ADMFLAG_BAN, "");
}

public Action ForceGameEnd(int client, int args)
{
	SpawnEntity(client, "game_end", "EndGame");
	return Plugin_Handled;
}

public Action ForceRoundEnd(int client, int args)
{
	SpawnEntity(client, "game_round_end", "EndRound_Draw");
	SpawnEntity(client, "game_round_end", "EndRound_TerroristsWin");
	SpawnEntity(client, "game_round_end", "EndRound_CounterTerroristsWin");
	return Plugin_Handled;
}

public Action ForceRoundEnd_2(int client, int args)
{
	ServerExecuteCmd("endround");
	ReplyToCommand(client, "Executing server command 'endround'");
	return Plugin_Handled;
}

void SpawnEntity(int client, char[] sEntity, char[] sMethod)
{
	int iEnt = FindEntityByClassname(iEnt, sEntity);
	if (iEnt == -1)
	{
		ReplyToCommand(client, "%s entity is not exist, trying create it...", sEntity);
		iEnt = CreateEntityByName(sEntity);
	}
	if (iEnt == -1)
	{
		ReplyToCommand(client, "Failed to create %s entity!", sEntity);
	}
	else {
		if (!IsValidEntity(iEnt)) {
			ReplyToCommand(client, "Entity %i is not valid!", iEnt);
		}
		else {
			int bRet = DispatchSpawn(iEnt);
			ReplyToCommand(client, "%s entity is spawned with result: %b", sEntity, bRet);

			bRet = AcceptEntityInput(iEnt, sMethod);
			ReplyToCommand(client, "%s input is executed with result: %b", sMethod, bRet);
			
			AcceptEntityInput(iEnt, "Kill");
		}
	}
}

void ServerExecuteCmd(char[] sCmd)
{
	int oldFlags = GetCommandFlags(sCmd);
	SetCommandFlags(sCmd, oldFlags & ~(FCVAR_CHEAT | FCVAR_LAUNCHER));
	ServerCommand(sCmd);
	ServerExecute();
	SetCommandFlags(sCmd, oldFlags);
}
1) When I use "game_end" all players are freeze, TAB window is opened, and round is not end (like "pause"), game raise "round_freeze_end" event.
Quote:
game_end entity is not exist, trying create it...
game_end entity is spawned with result: 1
EndGame input is executed with result: 1
Also, when I use it second time (after my diconnect/connect to server) plugin raise an exception:
Quote:
L 10/23/2018 - 17:09:18: [SM] Exception reported: Entity 878 is not valid
L 10/23/2018 - 17:09:18: [SM] Blaming: sm_end_game.smx
L 10/23/2018 - 17:09:18: [SM] Call stack trace:
L 10/23/2018 - 17:09:18: [SM] [0] FindEntityByClassname
L 10/23/2018 - 17:09:18: [SM] [1] Line 34, H:\_To_games\Left4Dead_2\My_mods\Events\sm_en d_game.sp::SpawnEntity
L 10/23/2018 - 17:09:18: [SM] [2] Line 13, H:\_To_games\Left4Dead_2\My_mods\Events\sm_en d_game.sp::ForceGameEnd
2) Checked "game_round_end" just in case. In L4d it doesn't exist.

EDIT.
3) Checked endround command. It work very-very fast. Suspiciously, too fast. But it really restart the round.

There is slightly difference between fake round end events sequence:
Quote:
L 10/23/2018 - 172:41: [say_event.smx] 2018-10-23, 172:41 - EVENT_HAPPENED :::: "round_end"
and real round end:

Quote:
L 10/23/2018 - 176:16: [say_event.smx] 2018-10-23, 176:16 - EVENT_HAPPENED ---> "award_earned"
L 10/23/2018 - 176:16: [say_event.smx] 2018-10-23, 176:16 - EVENT_HAPPENED ---> "mission_lost"
L 10/23/2018 - 176:16: [say_event.smx] 2018-10-23, 176:16 - EVENT_HAPPENED :::: "round_end"
and player dosn't see screen fogging before restarting the round. New round begins instantly.
__________________
Expert of CMD/VBS/VB6. Malware analyst.

Last edited by Dragokas; 10-23-2018 at 11:41.
Dragokas is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-23-2018 , 11:52   Re: [L4D] How to force mission lost
Reply With Quote #5

Try log events (or look from console).

con_logfile myevents.log
sm_cvar net_showevents 2
Bacardi is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 10-23-2018 , 12:13   Re: [L4D] How to force mission lost
Reply With Quote #6

Quote:
Unknown command "con_logfile"
__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-23-2018 , 13:46   Re: [L4D] How to force mission lost
Reply With Quote #7

look:
help con_logfile

try:
sm_cvar con_logfile logfile.log
Bacardi is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 10-23-2018 , 17:58   Re: [L4D] How to force mission lost
Reply With Quote #8

ahh, of course. Thank you. After changing that var, file is created in the root of left4dead/ server folder.
__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-23-2018 , 18:32   Re: [L4D] How to force mission lost
Reply With Quote #9

Have you tried lying to the game? Try setting netprop m_bIsAlive or whatever it's called on all survivors, use "endround" and restore it. Check if the events are solved.
__________________


Accepting private work. Contact me if you're interested.
eyal282 is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 10-24-2018 , 10:55   Re: [L4D] How to force mission lost
Reply With Quote #10

eyal282, interesting idea.

Human player is CTerrorPlayer in L4D. I didn't found *Alive properties in map.

To be sure:
Quote:
L 10/24/2018 - 143:46: [SM] Exception reported: Property "m_bIsAlive" not found (entity 1/player)
L 10/24/2018 - 145:16: [SM] Exception reported: Property "m_isAlive" not found (entity 1/player)
L 10/24/2018 - 148:08: [SM] Exception reported: Property "m_bAlive" not found (entity 1/player)
However, I found several related properties.

The differeces are:
Alive state:
Quote:
deadflag = 0
m_lifeState = 0
m_iPlayerState = 0
m_isGoingToDie = 0
m_isCalm = 0
m_isGhost = 0
m_fFlags = 129
m_flDeathTime = 0.000000
m_flStamina = 0.000000
Dead state:

Quote:
deadflag = 1
m_lifeState = 1
m_iPlayerState = 4
m_isGoingToDie = 0
m_isCalm = 0
m_isGhost = 0
m_fFlags = 128
m_flDeathTime = 4403.697265
m_flStamina = 0.000000
On round start I ran code:

Code:
public OnPluginStart()
{
	RegAdminCmd("sm_dead", ForceDead, ADMFLAG_BAN, "");
}

public Action ForceDead(int client, int args)
{
	for (int i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && GetClientTeam(i) == 2)
		{
			SetEntProp(i, Prop_Send, "m_lifeState", 1); // like ghost (model become invisible)
			//SetEntData(client, FindDataMapInfo(client, "m_lifeState"), 1, 4, true);

			SetEntProp(i, Prop_Send, "deadflag", 1); // unknown (m_bIsAlive analogue?)
			SetEntProp(i, Prop_Send, "m_fFlags", 128); // unknown (hands up animation)
			SetEntProp(i, Prop_Send, "m_iPlayerState", 4); // freeze
		}
	}

	ShowStateInt(client, "deadflag");
	ShowStateInt(client, "m_lifeState");
	ShowStateInt(client, "m_iPlayerState");
	ShowStateInt(client, "m_isGoingToDie");
	ShowStateInt(client, "m_isCalm");
	ShowStateInt(client, "m_isGhost");
	ShowStateInt(client, "m_fFlags");
	ShowStateFloat(client, "m_flDeathTime");
	ShowStateFloat(client, "m_flStamina");
	
	PrintToChat(client, "Player alive? %b", IsPlayerAlive(client));
	
	CreateTimer(5.0, Timer_Stage_3, client);
	
	return Plugin_Handled;
}

public Action Timer_Stage_3(Handle timer, int client)
{
	ServerExecuteCmd("endround");
}

void ShowStateInt(int client, char[] sProp)
{
	int iValue = GetEntProp(client, Prop_Send, sProp);
	PrintToChat(client, "%s = %i", sProp, iValue);
}
void ShowStateFloat(int client, char[] sProp)
{
	float fValue = GetEntPropFloat(client, Prop_Send, sProp);
	PrintToChat(client, "%s = %f", sProp, fValue);
}
and we are almost there: even without ServerExecuteCmd("endround"); screen is fading, "award_earned" and "mission_lost" are fired and round ends in ~ 4-6 sec.

Unfortunately, that is not always happen. Randomly, after executing above code (without "endround" cmd) round is not end automatically. Dunno why. I checked: we only need these two prop: m_lifeState + deadflag. It's enough. I tried set these prop in vice versa order and with 0.5 sec. delay between each other, but no luck. Game randomly ends the round or not.

Adding "endround" cmd not help to recover correct events sequence. It's just a signal for instant round_end.
__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
Reply


Thread Tools
Display Modes

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:00.


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