Author Topic: Health Regeneration Script  (Read 5462 times)

0 Members and 1 Guest are viewing this topic.

Offline Avkon

  • Soldier
  • **
  • Posts: 136
  • Ah, whatever.
Health Regeneration Script
« on: July 12, 2007, 11:48:36 am »
This is a really small script, with the basic functionality of increasing all the players' healths in specified 'drops' per second till the maximum value is reached.

Script:

Code: [Select]
// Health Regeneration Script v1.2 by Avkon
// This script automatically replenishes lost health of all players at a specified pace.

// Declare a couple of essential values:
const
  MAX_HEALTH = 150; // Set to 150 for non-realistic mode, else set to 65.
  DROP_VALUE = 5;   // Value of each 'drop' of health, def: 5.

// Incorporate main health regen code into AppOnIdle procedure:
procedure AppOnIdle(Ticks: integer);
var i: byte;
begin
  if Ticks mod (60 * 1) = 0 then begin
  for  i := 1 to 32 do
    if (GetPlayerStat(i,'Health') < (MAX_HEALTH - (DROP_VALUE - 1))) then begin
      DoDamage(i,-DROP_VALUE);
    end else begin
      DoDamage(i,-(MAX_HEALTH - (GetPlayerStat(i,'Health'))));
    end;
  end;
end;

// Inform players of health regen modification:
procedure OnJoinTeam(ID, Team: byte);
begin
  SayToPlayer(ID, 'This server runs the following mod:');
  SayToPlayer(ID, '! Health Regeneration Script v1.2 (by Avkon)');
end;

Script Configuration:

The only variables the user needs to edit are:

Code: [Select]
  MAX_HEALTH = 150; // Set to 150 for non-realistic mode, else set to 65.
  DROP_VALUE = 5;   // Value of each 'drop' of health, def: 5.

Change MAX_HEALTH to the maximum health the user can obtain (eg. MAX_HEALTH = 200;). If the health of the player is more than the limit, it will be automatically decreased.
Change DROP_VALUE to the amount of health to be added every second (eg. DROP_VALUE = 5;).

The AppOnIdle procedure will be found in Core.pas, and the OnJoinTeam one will be found in the NetworkCore.pas file by default.

And that's it, enjoy :) !
« Last Edit: July 14, 2007, 07:49:30 am by Avkon »

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Health Regeneration Script
« Reply #1 on: July 12, 2007, 12:06:42 pm »
useful for those that dunno any scritping - very simple...
gj for ur first script i guess :D

p.s.:  next to limit right // maxhealth = 150 for non-real, 65 for real
just to let them know*
Can't think of anything original to put here...

Offline Avarax

  • Veteran
  • *****
  • Posts: 1529
    • Official Hexer & MMod site
Re: Health Regeneration Script
« Reply #2 on: July 12, 2007, 03:09:33 pm »
declare drop and limit as global constants so they aren't recreated with every AppOnIdle. Also brings a bit more overviewability in the script if the constants are placed at the top of the .pas file.

I like to have one Martini
Two at the very most
Three I'm under the table
Four I'm under the host

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Health Regeneration Script
« Reply #3 on: July 13, 2007, 12:29:42 am »
maybe not constants if u wanna change it in-game, but definitely not in the AppOnIdle procedure's variable list...
Can't think of anything original to put here...

Offline Master Chief43

  • Soldier
  • **
  • Posts: 223
  • When life gives you lemons, eat them :D
Re: Health Regeneration Script
« Reply #4 on: July 13, 2007, 08:28:47 pm »
Hmm... Would this be good for an awesome Halo Mod? Say... SHIELD!?!?!
In-Game Name: "Master Chief43"
Favorite Map: ctf_Ash
Favorite Mods: Special Operation 2.0, Original Soldier 1.9
Favorite Guns: [MP5][AK74][socom][Barret]

Offline Avkon

  • Soldier
  • **
  • Posts: 136
  • Ah, whatever.
Re: Health Regeneration Script
« Reply #5 on: July 14, 2007, 12:00:15 am »
Thanks, zyxstand - and yeah, it is my first script for Soldat. I added the comments, and also a part which tells players about the mod after they join the game.

Also, now MAX_HEALTH and DROP_VALUE are constants, thanks for the tip @Avarax, and it's probably not going to be changed in-game.

Hmm... Would this be good for an awesome Halo Mod? Say... SHIELD!?!?!

A Halo mod? I don't really know what you mean...

Offline Master Chief43

  • Soldier
  • **
  • Posts: 223
  • When life gives you lemons, eat them :D
Re: Health Regeneration Script
« Reply #6 on: July 14, 2007, 12:23:16 am »
In Halo your shield regenerates after a few seconds, so you can imlement this script into a Halo mod or something so it would be more like Halo ya know?
In-Game Name: "Master Chief43"
Favorite Map: ctf_Ash
Favorite Mods: Special Operation 2.0, Original Soldier 1.9
Favorite Guns: [MP5][AK74][socom][Barret]

Offline Avkon

  • Soldier
  • **
  • Posts: 136
  • Ah, whatever.
Re: Health Regeneration Script
« Reply #7 on: July 14, 2007, 07:43:53 am »
Lol Soldat is a long call away from the Halo games... but yeah, you could combine this script with other ones to create Halo-like features, if that's what you want - it's your server, after all...
« Last Edit: July 14, 2007, 07:50:20 am by Avkon »

Offline ghg

  • Camper
  • ***
  • Posts: 411
  • Village Idiot
Re: Health Regeneration Script
« Reply #8 on: July 15, 2007, 05:25:54 am »
That inspires me to add a vampirism script to a script I've made. Very nice.
-=Gradius wuz you=-

Offline miketh2005

  • Soldat Beta Team
  • Flagrunner
  • ******
  • Posts: 668
  • What's the URL for www.microsoft.com?
Re: Health Regeneration Script
« Reply #9 on: July 26, 2007, 05:03:44 pm »
how can i get this to only regenerate health on 1 person, say like the !medic in leos ctf/inf
Quote from: 'Ando.' pid='12999178' dateline='1309046898'
My new password is secure as shit :)
Mate, I am not sure Shit is even secured nowadays.

Offline Avkon

  • Soldier
  • **
  • Posts: 136
  • Ah, whatever.
Re: Health Regeneration Script
« Reply #10 on: July 27, 2007, 03:39:58 pm »
Replace the main part of the code with this:

Code: [Select]
// Incorporate main health regen code into AppOnIdle procedure:
procedure AppOnIdle(Ticks: integer);
var i: byte;
begin
  if Ticks mod (60 * 1) = 0 then begin
  i := NameToID("Player Name");
  if (GetPlayerStat(i,'Health') < (MAX_HEALTH - (DROP_VALUE - 1))) then begin
    DoDamage(i,-DROP_VALUE);
  end else begin
    DoDamage(i,-(MAX_HEALTH - (GetPlayerStat(i,'Health'))));
  end;
end;

And then change 'Player Name' in this line:

Code: [Select]
  i := NameToID("Player Name");
To the name of the player who you want to regenerate health for. For e.g., if your player's name is 'miketh2005', you'll have to change the line to:

Code: [Select]
  i := NameToID("miketh2005");
That should do it.

Offline Master Chief43

  • Soldier
  • **
  • Posts: 223
  • When life gives you lemons, eat them :D
Re: Health Regeneration Script
« Reply #11 on: July 28, 2007, 03:09:50 pm »
How do you make it so that when someone says a command, that players can heal others and him/her self?
In-Game Name: "Master Chief43"
Favorite Map: ctf_Ash
Favorite Mods: Special Operation 2.0, Original Soldier 1.9
Favorite Guns: [MP5][AK74][socom][Barret]

Offline Avkon

  • Soldier
  • **
  • Posts: 136
  • Ah, whatever.
Re: Health Regeneration Script
« Reply #12 on: July 29, 2007, 12:30:23 am »
Use the 'OnCommand' procedure.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Health Regeneration Script
« Reply #13 on: July 29, 2007, 12:32:36 pm »
Or OnPlayerCommand procedure if u want it to work for non-admins too.

Offline Tosty

  • Soldier
  • **
  • Posts: 172
  • Ultimate TW Medic
    • Just Click it
Re: Health Regeneration Script
« Reply #14 on: August 05, 2007, 07:24:24 pm »
I cant get it to work

when i use it w the script combiner it said

error 21:1 unknown identifier 'i'

what do i do



Offline miketh2005

  • Soldat Beta Team
  • Flagrunner
  • ******
  • Posts: 668
  • What's the URL for www.microsoft.com?
Re: Health Regeneration Script
« Reply #15 on: August 13, 2007, 11:36:55 am »
How do I get it to work so only 1 player can say a command like !medic and only they can get this and if 1 person is already medic then it says $PLAYER_NAME is already your medic!
Quote from: 'Ando.' pid='12999178' dateline='1309046898'
My new password is secure as shit :)
Mate, I am not sure Shit is even secured nowadays.

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Health Regeneration Script
« Reply #16 on: August 13, 2007, 01:29:10 pm »
How do I get it to work so only 1 player can say a command like !medic and only they can get this and if 1 person is already medic then it says $PLAYER_NAME is already your medic!

First you have to know what the player's ID is - say it's player ID 3

Code: [Select]
AlphaMedicID := 3;  //somewhere in your code to establish who is medic (for alpha team)
BravoMedicID := 5;  //for bravo team*

procedure HealTeam(Team: byte);
var c: byte;
begin
  for c := 1 to 32 do if (GetPlayerStat(c,'Active') = 1) and (GetPlayerStat(c,'Team') = Team) then DoDamage(c, GetPlayerStat(c,'Health') - 150);  // use 65 instead of 150 for Realistic
end;

procedure OnPlayerCommand(ID, Text)
begin
  Ltext := LowerCase(Text);  //makes it so commands are not case sensitive
  if Ltext = '/heal' then
  begin
    if ID = AlphaMedicID then HealTeam(1);  //calls up HealTeam function - 1 means Alpha
    else if ID = BravoMedicID then HealTeam(2);  //same as above line for team 2 (bravo)
    else WriteConsole(ID, iif(GetPlayerStat(ID, 'Team') = 1, GetPlayerStat(AlphaMedicID,'Name'), GetPlayerStat(BravoMedicID,'Name')) + ' is your team-medic', $B0FF4000);
end;

There.
if someone types '/heal' then the server checks if he's either Alpha or Bravo Medic.  If the person is a medic the server will run the HealTeam procedure and heal the medic's teammate.  If the person isn't a medic then the procedure will tell the person who his team's medic is.
This script doesn't include a method for defining each team's medic is (it just picks player 3 and 5) so you'll have to do that yourself.
This script doesn't provide a limitation of any sort for a medic to heal his teammates.  Every time /heal is used by the medic all his team members get healed.
This script does not support multi-team medics.  It only works for alpha and bravo teams - otherwise it will mess up.
This script does not work with a spectator /heal command correctly.
This script has not been checked for any errors or functionality (though it should work correctly).
Can't think of anything original to put here...

Offline miketh2005

  • Soldat Beta Team
  • Flagrunner
  • ******
  • Posts: 668
  • What's the URL for www.microsoft.com?
Re: Health Regeneration Script
« Reply #17 on: August 13, 2007, 02:30:04 pm »
 hmm thanx but how will it tell the person that they are medic?
Quote from: 'Ando.' pid='12999178' dateline='1309046898'
My new password is secure as shit :)
Mate, I am not sure Shit is even secured nowadays.