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

Koshy 09-13-2009 06:40

Re: Set Player's max HP on spawn (TF2)
 
Yes please need uber solution to this problem is is a matter of life or death for me!!!

Thanks,
- Koshy

Stinkyfax 09-14-2009 07:58

Re: Set Player's max HP on spawn (TF2)
 
Come on guys, I need fresh ideas :-/

Peoples Army 09-14-2009 11:54

Re: Set Player's max HP on spawn (TF2)
 
Well the question is how often does it reset itself? If its only ever few seconds or longer then instead of using a on game frame , which is highly intense and will surely lag your server, try setting it at every weapon event, or every other player event.

Flynn 09-14-2009 12:50

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

Originally Posted by Peoples Army (Post 932552)
If its only ever few seconds or longer then instead of using a on game frame , which is highly intense and will surely lag your server

:nono:

I cannot say usage of OnGameFrame to modify HP lags the server. To be honest, I wouldn't use it if it did otherwise. Who would?

To the contrary, compared to the lack of alternatives it can be quite viable so long as operations are simple, short mathematic calculations. Heck, your game wouldn't even be running if it couldn't do that every frame (think of the amount of CPU and GPU required to parse graphics and player locations per frame (200 * a second)).

TF2's modification would just require additional checking to ensure HP is consistent throughout (as opposed to simply incapped below a certain amount). The hacky part would be ensuring the damages work.

Besides, I had hinted another way; disable the degeneration, or failing that, force whatever event stops it from running to run continuously, or even better, make it so when the degeneration of the HP occurs, give back the amount it drains.

The above is pseudo-ideas for people actually willing to hunt through the code-base for something that could match that. If you aren't desperate enough to try and experiment to get an idea working, you aren't desperate enough to need the code.

Peoples Army 09-14-2009 15:22

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

Originally Posted by Flynn (Post 932654)
:nono:

I cannot say usage of OnGameFrame to modify HP lags the server. To be honest, I wouldn't use it if it did otherwise. Who would?

To the contrary, compared to the lack of alternatives it can be quite viable so long as operations are simple, short mathematic calculations. Heck, your game wouldn't even be running if it couldn't do that every frame (think of the amount of CPU and GPU required to parse graphics and player locations per frame (200 * a second)).

TF2's modification would just require additional checking to ensure HP is consistent throughout (as opposed to simply incapped below a certain amount). The hacky part would be ensuring the damages work.

Besides, I had hinted another way; disable the degeneration, or failing that, force whatever event stops it from running to run continuously, or even better, make it so when the degeneration of the HP occurs, give back the amount it drains.

The above is pseudo-ideas for people actually willing to hunt through the code-base for something that could match that. If you aren't desperate enough to try and experiment to get an idea working, you aren't desperate enough to need the code.

If you don't care about how efficient the plugin is then by all means listen to Flynn, but optimizing code is part of your responsibility as a developer, why run a command 100,000 times if you only need to, key word NEED to, run it every once in awhile.

Just because it might not lag the server to un-usability does that make it a good idea to add 100,000 functions if their not necessary?

Flynn 09-14-2009 15:52

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

Originally Posted by Peoples Army (Post 932858)
If you don't care about how efficient the plugin is then by all means listen to Flynn

Oh oh! Personal attack! Poisoning the well, and Ad Hominem.

Personal attacks on credibility only work if you know the person. Which you don't... :nono:

2 years studying a Degree in Computer Games Programming (into my third year, nicely set for a first). The engineering AI lecturer (who happens to be a psychologist) said to me when going over my code that I was 'obsessed with efficiency'. I still disagree with his comment of making code less efficient simply to make it more readable.

Wrote a functional 2D game from scratch within 2 days (visuals, sounds, etc), wrote another one within 2 days also from scratch (visuals, sounds, animation, etc), and finally, pulling another's arse out of a fire, built a basic one in under half a day with no notice whatsoever.

Now that I have extinguished your little credibility flame (I'm used to that, used to moderate forums), allow me to retort;

You misread, so allow me to lay out the points;
One, the server performs far more taxing operations per frame than simple mathematic calculations
Two, if it couldn't handle the OTHER more taxing operations per frame (player position, areabox/hit-detection, physics etc), it wouldn't run
Three, It runs, ergo it can handle simple mathematics per frame
Four, it would only lag if you were stupid enough to put in REALLY complex OR slow access functions (like read/writing to disk etc)
Five, I've already used it for HP operations (where no OTHER alternative exists) and it does not lag
Six, it cannot logically lag, has not lagged during usage, ergo, your argument of it being laggy is flawed
Seven, people are desperate enough for functional ideas, this idea is already functional, ergo, it's still a useful suggestion

The point is, the other practical ideas have seemingly run out. You need an every frame check as the HP degeneration (if you have even played TF2) is pretty much 'every second'. Skip a beat and the HP will oddly change making it look weird to the user.

Besides, I had highlighted other suggestions BESIDES OnGameFrame on the bottom (all three far better than a 'simple shaving' of a frame or two). Pessimists versus Optimists I guess.

And finally, don't... DON'T ever exaggerate. It's not '100,000' operations. At worst it would be 64*X (assuming setclienthealth only does 5 operations, 64*5). Don't play to the 'public panic' simply because it says 'avoid costly executions' - it's meant to run some; if it can't even run some simple mathematics calculation then what is the point?

Sheesh. :down:

NeoDement 09-14-2009 15:56

Re: Set Player's max HP on spawn (TF2)
 
Well thanks Flynn, I always wondered if doing stuff every frame was safe, and now I know ;)

Peoples Army 09-14-2009 16:04

Re: Set Player's max HP on spawn (TF2)
 
You still avoided the point, it's unnecessary, which therefore makes it inefficient.

Flynn 09-14-2009 16:12

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

Originally Posted by Peoples Army (Post 932897)
You still avoided the point, it's unnecessary, which therefore makes it inefficient.

Actually, that's a nice strawman.
Quote:

Originally Posted by Flynn (Post 932885)
Seven, people are desperate enough for functional ideas, this idea is already functional, ergo, it's still a useful suggestion

Besides, I've dealt with more 'political' and 'slippery' people than simple mis-leading arguments. They'd bend you over like a memory metal spoon.

Besides, YOU missed the point; you unfairly attacked my credibility without basis, which is more a question of ethics than simple 'get the best code'. Just because I supply code that appears impractical (which if you read - I state that it is) does not mean I am not capable of better or more efficient code. But there isn't 'more efficient' code per se unless we can grab whatever functions modify the health.

EDIT: I imagined this forum as more of a teamwork element rather than a backstab/ignore people's post battle.

Peoples Army 09-14-2009 16:14

Re: Set Player's max HP on spawn (TF2)
 
Please display where I attacked your credability?

Flynn 09-14-2009 16:15

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

Originally Posted by Peoples Army (Post 932910)
Please display where I attacked your credability?

Quoted in the original post. You don't need me to point out.

EDIT: By original I mean the one with the lengthy statements.

Peoples Army 09-14-2009 16:16

Re: Set Player's max HP on spawn (TF2)
 
By simply mentioning you by name that is a creditability attack?

Flynn 09-14-2009 16:22

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

Originally Posted by Peoples Army (Post 932912)
By simply mentioning you by name that is a creditability attack?

Especially when you imply all code I supply is inefficient 'if you want inefficient code'. It's not exactly a very ethical thing to do, especially with little actual evidence to prove that point.

Additionally, we don't exactly have manoeuvring room to debate efficiency due to the limited (or lack of) options we have.

Presume I take away my idea; you'd have nothing to 'suggest' 'improvements' on, because we wouldn't even have anything functional. Most of the ideas I supply are pseudo-design ideas anyway; something to make use of to BUILD UPON.

You're not building upon, you're just taking my suggestion, improving it then stabbing me in the back for suggesting it by implying it's inefficient.

Peoples Army 09-14-2009 16:29

Re: Set Player's max HP on spawn (TF2)
 
This forum is for scripting plugins not debate, if you want to debate feel free to send me a private message.

Flynn 09-14-2009 16:32

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

Originally Posted by Peoples Army (Post 932919)
This forum is for scripting plugins not debate, if you want to debate feel free to send me a private message.

Isn't that ironic. Sure. If you want to debate the efficiency of my code, feel free to send a PM to me in future.

Peoples Army 09-14-2009 16:37

Re: Set Player's max HP on spawn (TF2)
 
Actually your inefficient code IS Scripting genius, therefore its perfectly acceptable to debate here.

Flynn 09-14-2009 16:41

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

Originally Posted by Peoples Army (Post 932926)
Actually your inefficient code IS Scripting genius, therefore its perfectly acceptable to debate here.

Seeing as we both agreed to PM over the debate, and you're just taking to douchebagginess in replies, I'm just going to ignore additional comments unless they come in the form of PM.

Peoples Army 09-14-2009 16:45

Re: Set Player's max HP on spawn (TF2)
 
I win.

naris 09-14-2009 16:46

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

Originally Posted by Flynn (Post 932885)
I still disagree with his comment of making code less efficient simply to make it more readable.

Try maintaining a piece of code someone wrote 10 years ago and has since been modified by 20 different people, all "optimizing" their code to "save" 1 or 2 instructions here or there (that does database access that takes much longer), with variable names like i, and no comments. Bonus points for getting called at 3AM because the code broke in a critical production batch job and having to figure it all out.

Then see is you still disagree with him.

//I have over 25 Years in IT and am currently a Senior Software Engineer doing Production Support for VWoA.

Flynn 09-14-2009 16:59

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

Touche on given point. :)

However (trying not to go off-topic too much, but that's not going to work :wink:), game code has to be pretty efficient to run on most machines (the bigger the machine base, bigger potential income). No game would seriously be maintained after 20 years (although I've seen this county's finances running on DoS and a copy of excel for backup - not cool). And typically, said game would be worked upon by a team who have their own specific 'modules' to construct.

Once released it'd either be patched up for faults or a new one written. Games have a different requirement of code to say, a spreadsheet or database program. They don't have to render full blown graphics, they can afford some loss of efficiency.

Readability is a must yes, but you do not need to sacrifice efficiency to make it readable. Only 'idiomatic C' that is supposed to be the most efficient way is the most unreadable. But I consider that shaving off a hair in order to lose weight.

Ever had to write a well named, but super-lengthy g_pPlayerRemainingHealth[player] over a dozen times and you'll see why it gets shortened to 'i' or 'arr'.

Additional Edit: When you have a stupidly short deadline, suddenly comments take a lot less priority. I'd imagine if I did work on a team I'd change my approach to match.

Dragonshadow 09-14-2009 19:17

Re: Set Player's max HP on spawn (TF2)
 
Can someone give me one example of where making code readable reduces efficiency? >.>

Flynn 09-14-2009 20:43

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

Originally Posted by Dragonshadow (Post 933060)
Can someone give me one example of where making code readable reduces efficiency? >.>

In the case of idiomatic C (C that uses syntax abuse in order to function correctly)

Code:

while(*(string1++) = *(string2++));
Would be re-written to be readable as
Code:

//Iterators for strings
int Iterator1 = 0;
int Iterator2 = 0;
//Copy from Source string to Destination String
while(Destination[Iterator1] != '\0')
{
  Destination[Iterator1] = Source[Iterator2];
  Iterator1++;
  Iterator2++;
}
//This code takes longer to write over-all, requires ints and a larger memory footprint, but is more readable

Pointer and bitwise logic will make things more unreadable. SM thankfully shields people from pointers.

Code:

int G, J;
int *L, *X; //Pointers; * is not 'multiply' but 'dereferencing'

L = G, X = J;

*L = *X = 2;

*L = (*L| (2 == (*L | *X))); //Fairly useless code, but some code can be written as confusingly

L = L ^ X;
X = L ^ X;
L = L ^ X;
//This is a swapping operation... but what has it swapped? The addresses or the variables?

If I was to simplify the code to make it readable I'd need to declare separate variables (as well named bools), instead of using bitwise operations, using standard C ops that are better recognised (or explaining each operation process throughout). If you have trouble following this code then you got problems; this is the basics.

Dragonshadow 09-14-2009 21:27

Re: Set Player's max HP on spawn (TF2)
 
Brain, it hurts

Stinkyfax 09-15-2009 09:24

Re: Set Player's max HP on spawn (TF2)
 
Guys, don't fight.
I tried modifying m_iMaxHealth in map props and in netprops -> CTFPlayerResource -> m_iMaxHealth
neither of them seemed to work.
The last method has weired effect:
Like for 1 frame each 5 seconds I see my max HP being modified but then it instantly goes to normal...

Flynn 09-15-2009 10:06

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

Originally Posted by Stinkyfax (Post 933582)
Like for 1 frame each 5 seconds I see my max HP being modified but then it instantly goes to normal...

That sounds like it implies TF2 has a maximum for how high you can heal a class up to, a threshold for where the HP starts to degenerate, and (keypoint) the 'current' HP.

Surely there must be a way we can find the other two variables...

bl4nk 09-15-2009 10:49

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

Originally Posted by Flynn (Post 933619)
a maximum for how high you can heal a class up to

Possibly 2147483647.

Quote:

Originally Posted by Flynn (Post 933619)
a threshold for where the HP starts to degenerate

Default class max health +1?

Quote:

Originally Posted by Flynn (Post 933619)
and (keypoint) the 'current' HP.

m_iHealth

Stinkyfax 09-15-2009 11:48

Re: Set Player's max HP on spawn (TF2)
 
bl4nk You've got the point :)
I can freely set the hp to 500 and it will degenerate.
As I said, all my methods complitely failed, does smbody know any new ideas? :)
By the way All the plugins I found which manipulate max health are not working as well. I guess it is new TF2 update since I honestly disrespect the way TF2 support modifications. I feel like they don't care about others who try to make their game more popular.

retsam 09-15-2009 12:37

Re: Set Player's max HP on spawn (TF2)
 
Theres a plugin around that keeps health from degenerating. It just uses repeating timers and keeps setting it back. Not sure how resource friendly it was but, it did work.

Flynn 09-15-2009 13:30

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

Originally Posted by bl4nk (Post 933672)
Default class max health +1?

But where is that default? If you can modify that, you can stop the degeneration.

Or maybe, like, a continuous 'healing' on the target player that doesn't give them health; just stops the degeneration?

Perhaps something like that. An always firing heal event on the given target that adds no health. Theoretically that could stop it, as if they had an invisible medic following them with a useless medigun.

pheadxdll 09-15-2009 14:44

Re: Set Player's max HP on spawn (TF2)
 
You could play around with these couple cvars:

tf_boost_drain_time
tf_max_health_boost


All times are GMT -4. The time now is 20:49.

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