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

Set Player's max HP on spawn (TF2)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 02-25-2008 , 06:35   Set Player's max HP on spawn (TF2)
Reply With Quote #1

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?
CrimsonGT is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 02-25-2008 , 10:38   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #2

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 ).
bl4nk is offline
Durandal
New Member
Join Date: Feb 2008
Old 02-27-2008 , 12:26   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #3

n00b question:
Why do you need to create a timer in event_PlayerSpawn to make a delayed call to timer_PlayerSpawn?
Durandal is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 02-27-2008 , 14:22   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #4

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.
bl4nk is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-27-2008 , 14:27   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #5

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
Greyscale is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 02-27-2008 , 14:50   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #6

You try it. I didn't even compile my version.
bl4nk is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-27-2008 , 14:57   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #7

I don't even have a TF2 server lol, CrimsonGT, wanna give a delay of 0.0 a try?
Greyscale is offline
Stinkyfax
BANNED
Join Date: Aug 2007
Old 09-12-2009 , 18:31   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #8

This way doesn't work anymore to set higher max health. I do really need that thing, any fresh ideas?
Stinkyfax is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-12-2009 , 20:24   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #9

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.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Stinkyfax
BANNED
Join Date: Aug 2007
Old 09-13-2009 , 06:03   Re: Set Player's max HP on spawn (TF2)
Reply With Quote #10

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..
Stinkyfax 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 11:27.


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