Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: Avkon on July 12, 2007, 11:48:36 am

Title: Health Regeneration Script
Post by: Avkon 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 :) !
Title: Re: Health Regeneration Script
Post by: zyxstand 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*
Title: Re: Health Regeneration Script
Post by: Avarax 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.

Title: Re: Health Regeneration Script
Post by: zyxstand 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...
Title: Re: Health Regeneration Script
Post by: Master Chief43 on July 13, 2007, 08:28:47 pm
Hmm... Would this be good for an awesome Halo Mod? Say... SHIELD!?!?!
Title: Re: Health Regeneration Script
Post by: Avkon 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...
Title: Re: Health Regeneration Script
Post by: Master Chief43 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?
Title: Re: Health Regeneration Script
Post by: Avkon 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...
Title: Re: Health Regeneration Script
Post by: ghg on July 15, 2007, 05:25:54 am
That inspires me to add a vampirism script to a script I've made. Very nice.
Title: Re: Health Regeneration Script
Post by: miketh2005 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
Title: Re: Health Regeneration Script
Post by: Avkon 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.
Title: Re: Health Regeneration Script
Post by: Master Chief43 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?
Title: Re: Health Regeneration Script
Post by: Avkon on July 29, 2007, 12:30:23 am
Use the 'OnCommand' procedure.
Title: Re: Health Regeneration Script
Post by: DorkeyDear on July 29, 2007, 12:32:36 pm
Or OnPlayerCommand procedure if u want it to work for non-admins too.
Title: Re: Health Regeneration Script
Post by: Tosty 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
Title: Re: Health Regeneration Script
Post by: miketh2005 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!
Title: Re: Health Regeneration Script
Post by: zyxstand 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).
Title: Re: Health Regeneration Script
Post by: miketh2005 on August 13, 2007, 02:30:04 pm
 hmm thanx but how will it tell the person that they are medic?