AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Set Player's max HP on spawn (TF2) (https://forums.alliedmods.net/showthread.php?t=67502)

CrimsonGT 02-25-2008 06:35

Set Player's max HP on spawn (TF2)
 
I have seen several plugins on servers running sourcemod that do this, but everytime I have messed with it in the past, it would up their health, and then it would decrease like it was overhealing.

I am looking for a way to set their max health on spawn. Anyone have this code block laying around or care to explain to me what I need to do?

bl4nk 02-25-2008 10:38

Re: Set Player's max HP on spawn (TF2)
 
Code:

/**
 * MaxHealth Changer by bl4nk
 *
 * Description:
 *  Change the max health of players at spawn.
 *
 * CVars:
 *  sm_maxhealthchanger_amount
 *    - 500 = Change players' health to 500 upon spawning (default)
 *    - 1000 = Change players' health to 1000 upon spawning
 */

#pragma semicolon 1

#include <sourcemod>

// Global Definitions
#define PLUGIN_VERSION "1.0.0"

new Handle:cvarAmount;

public Plugin:myinfo =
{
    name = "MaxHealth Changer",
    author = "bl4nk",
    description = "Change the max health of players at spawn",
    version = PLUGIN_VERSION,
    url = "http://forums.alliedmods.net"
};

public OnPluginStart()
{
    CreateConVar("sm_maxhealthchanger_version", PLUGIN_VERSION, "MaxHealth Changer Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    cvarAmount = CreateConVar("sm_maxhealthchanger_amount", "500", "Amount of life to change health to upon spawn", FCVAR_PLUGIN, true, 1.0, false, _);

    HookEvent("player_spawn", event_PlayerSpawn);
}

public event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    CreateTimer(0.1, timer_PlayerSpawn, client);
}

public Action:timer_PlayerSpawn(Handle:timer, any:client)
{
    new MaxHealth = GetConVarInt(cvarAmount);
    SetEntData(client, FindDataMapOffs(client, "m_iMaxHealth"), MaxHealth, 4, true);
    SetEntData(client, FindDataMapOffs(client, "m_iHealth"), MaxHealth, 4, true);
}

That should do it. I can make it work for individual classes later on, but that would either create a lot of cvars or take a bit of tricky coding (which I can just copy from another plugin of mine :D).

Durandal 02-27-2008 12:26

Re: Set Player's max HP on spawn (TF2)
 
n00b question:
Why do you need to create a timer in event_PlayerSpawn to make a delayed call to timer_PlayerSpawn?

bl4nk 02-27-2008 14:22

Re: Set Player's max HP on spawn (TF2)
 
A bug with the way Valve handles player's Max Health. When they spawn, they have 100 health, and then a split second later (less than 0.1s), it's bumped up to the appropriate number. Having the delay is the only real way to change it, otherwise Valve's stuff will bump it back to what they want.

Greyscale 02-27-2008 14:27

Re: Set Player's max HP on spawn (TF2)
 
bl4nk you can try making the delay 0.0, which would fire the next frame, this way player's won't notice it being changed and it should bypass the weird way Valve handle's HP in TF2

bl4nk 02-27-2008 14:50

Re: Set Player's max HP on spawn (TF2)
 
You try it. I didn't even compile my version. :P

Greyscale 02-27-2008 14:57

Re: Set Player's max HP on spawn (TF2)
 
I don't even have a TF2 server lol, CrimsonGT, wanna give a delay of 0.0 a try?

Stinkyfax 09-12-2009 18:31

Re: Set Player's max HP on spawn (TF2)
 
This way doesn't work anymore to set higher max health. I do really need that thing, any fresh ideas?

Flynn 09-12-2009 20:24

Re: Set Player's max HP on spawn (TF2)
 
Well, I have system I use for a different mod entirely to incap player's HP due to super-regeneration of health.

It basically modifies the HP on every game frame (there is no obvious incap for health the mod I am working with) to lower it.

In the case of TF2, only minor tweaks are required - an array to store all the client's maximum possible HP, another for their current HP (modifying it via the hurt_event manually getting the damage), and setting their HP to match the 'current HP' stored in an array in OnGameFrame (killing them when they fall below 1HP).

Absolutely nightmarish way of doing it, but it's pretty much guaranteed to work.

Or, if someone knows how; disable the degeneration element of the HP.

Stinkyfax 09-13-2009 06:03

Re: Set Player's max HP on spawn (TF2)
 
Well, there are those nasty workarounds but the reason i want to increase max health:
In my mod health is dynamic, some have 321 max health, somebody else have 432 max health. In CSS it wasn't a problem.
In TF2 there is a really good hud of hp and all those workarounds will make that pretty hud be useless for health - I do really want to use it instead of writing in the mid of screen or somewhere else the mod health.
If remove degeneration then there will be a visual bug with "outer crest" in hp hud and problems with medic's healing and medcits..


All times are GMT -4. The time now is 13:56.

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