Raised This Month: $32 Target: $400
 8% 

[L4D2] Starting Health


Post New Thread Reply   
 
Thread Tools Display Modes
Hawkins
Senior Member
Join Date: Jul 2021
Old 10-22-2021 , 15:48   Re: [L4D2] Starting Health
Reply With Quote #11

Quote:
Originally Posted by Austin View Post
Post your source code and I will take a look at it.
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

float g_roundStartedTime;
ConVar	abs_l4d2_StartingHealth;

// ------------------------------------------------------------------------------
// OnPluginStart()
// ------------------------------------------------------------------------------
public OnPluginStart()
{
	abs_l4d2_StartingHealth = CreateConVar("abs_l4d2_StartingHealth", "130", "Sets starting health at map start and in safe rooms.");
	HookEvent("player_spawn", PlayerSpawnEvent);
	HookEvent("round_start", Event_RoundStart);

	PrintToServer("L4D2_HealthSet` Loaded.");
}

public Action Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
  g_roundStartedTime = GetEngineTime();
}

//---------------------------------------------------------------------------
//	PlayerSpawnEvent()
//---------------------------------------------------------------------------
public Action:PlayerSpawnEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
	new clientID = GetClientOfUserId(GetEventInt(event,"userid"));
	if(IsClientInGame(clientID) && IsPlayerAlive(clientID) && GetClientTeam(clientID) == 2)
		CreateTimer(1.0, Timer_PlayerSpawn, clientID);
}

// ------------------------------------------------------------------------------
// Timer_PlayerSpawn()
// ------------------------------------------------------------------------------
public Action:Timer_PlayerSpawn(Handle:timer, any:client)
{
	if(IsClientInGame(client) && IsPlayerAlive(client))
	{
		//PrintToServer("%f - %f - diff=%f",GetEngineTime(), g_roundStartedTime, GetEngineTime() - g_roundStartedTime);
		if ((GetEngineTime() - g_roundStartedTime) < 101)
		{
			// reset incap count,
			SetEntProp(client, Prop_Send, "m_currentReviveCount", 0);

			// turn off isGoingToDie mode
			SetEntProp(client, Prop_Send, "m_isGoingToDie", 0);

			// turn off IsOnThirdStrike - this resets B+W
			SetEntProp(client, Prop_Send, "m_bIsOnThirdStrike", 0);

			// (try) to turn off the heart beat sound
			ClientCommand(client, "music_dynamic_stop_playing Player.Heartbeat");

			// reset their temp health.
			SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", GetGameTime());
			SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);

			// set their permanent health,
			SetEntProp(client, Prop_Send, "m_iHealth", abs_l4d2_StartingHealth.IntValue);
		}
	}
}
Hawkins is offline
Austinbots
Member
Join Date: Jan 2010
Old 10-23-2021 , 14:43   Re: [L4D2] Starting Health
Reply With Quote #12

Quote:
Originally Posted by Hawkins View Post
Code:
		if ((GetEngineTime() - g_roundStartedTime) < 101)
I just trested on my server again with only this one plugin running and it is working 100% as expected and the way that you want.

I think the reason it isn't working on your server is that line above.
You changed it from 40 seconds to 101 seconds to wait and allow for the health boost after round_start.

1) Re test it with your plugin but wait 101 seconds after the map loads to do you testing.
or
2) Set the time to allow for the health boost back down to 40 seconds and wait about 20-30 second safter you join the server to test.

Again on my server this plugin:
1) sets the health on the start of a map/campagin
2) sets the health when you spawn into the safe room
3) does not set the healt when you use sb_takecontrol after something like 20-30 seconds after the round starts.
Austinbots is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 10-23-2021 , 17:33   Re: [L4D2] Starting Health
Reply With Quote #13

You can simply use the L4D_HasAnySurvivorLeftSafeArea() native from Left 4 DHooks Direct on "player_spawn" event to check whether survivors are still in the starting point or not and if so, apply the new max health for all of them while also avoiding the usage of hack-ish workarounds then hook "player_bot_replace" and "bot_player_replace" events just in case to re-apply the last health values they had should they reset to the original values since "player_spawn" gets called almost all the time.

Last edited by cravenge; 10-23-2021 at 17:33.
cravenge is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-23-2021 , 18:47   Re: [L4D2] Starting Health
Reply With Quote #14

Quote:
Originally Posted by cravenge View Post
You can simply use the L4D_HasAnySurvivorLeftSafeArea() native from Left 4 DHooks Direct on "player_spawn" event to check whether survivors are still in the starting point or not...
Can also check from entity terror_player_manager
PHP Code:
public Action test(int clientint args)
{

    
int terror_player_manager FindEntityByClassname(-1"terror_player_manager");
    
    if(
terror_player_manager != -&& HasEntProp(terror_player_managerProp_Send"m_hasAnySurvivorLeftSafeArea"))
    {
        
PrintToServer("terror_player_manager %i - m_hasAnySurvivorLeftSafeArea %i",
                        
terror_player_manager,
                        
GetEntProp(terror_player_managerProp_Send"m_hasAnySurvivorLeftSafeArea"));
    }

    return 
Plugin_Handled;

Bacardi is offline
Hawkins
Senior Member
Join Date: Jul 2021
Old 10-24-2021 , 07:28   Re: [L4D2] Starting Health
Reply With Quote #15

Tested it without changing timer. Works as intended. Thanks!
Is it possible to let the plugin create a .cfg file to edit timer and starting health CVARS from cfg rather than re-compiling it?

Last edited by Hawkins; 10-24-2021 at 07:32.
Hawkins is offline
Austin
Senior Member
Join Date: Oct 2005
Old 10-24-2021 , 15:44   Re: [L4D2] Starting Health
Reply With Quote #16

Quote:
Originally Posted by Hawkins View Post
Is it possible to let the plugin create a .cfg file to edit timer and starting health CVARS from cfg rather than re-compiling it?
Attached is a new version with a cvar to set the time.
You already had a cvar to set the health amount.

Add lines to your server config like this:

// Sets the health of the survivors at map start
abs_l4d2_StartingHealth 130

// Set the time period in seconds after map start
// to set survivors health when you take over a bot
abs_l4d2_StartingHealthTimePeriod 60

cravenge + Bacardi
I am going to stick with the timer since our client (Hawkins) understands the plugin as is and has it working.
Plus I like to keep things as simple as possible and avoid code BLOAT!

cravenge
Thanks for the infor. I need to get serious and learn how to use DHooks.

Bacardi ?= Genius, No : Yes!

Valve has zero infor on this entity.
terror_player_manager
https://developer.valvesoftware.com/..._L4D2_Entities

It is obviously an entity but I don’t see it in any stripper dumps so it must be created automatically!
I never knew about auto created entities.
Wow!

What other auto created entities are there, where can I get a list and at least some information on how to use them?

It is a law of the universe,
You can’t give help to someone without getting help back!
Attached Files
File Type: sp Get Plugin or Get Source (ABS_L4D2_HealthSet.sp - 114 views - 2.6 KB)

Last edited by Austin; 10-24-2021 at 15:46.
Austin 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:10.


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