Author Topic: Remake of the medic script  (Read 886 times)

0 Members and 1 Guest are viewing this topic.

Offline Bydlak

  • Major(1)
  • Posts: 34
Remake of the medic script
« on: November 23, 2013, 06:36:40 pm »
Hello  :)

I was looking for a new medic script and asked DorkeyDear to write it. He did very good job but doesn't have more time to complite the script. I would like to modify it, he gave me his permition to do that. So I'm asking sb to help me with some changes.

The changes are:
- A time period bewteen claiming medic by the same person to prevent using it all the time. The perion should be like 20-30 seconds ( if a player type !medic until the period pass he will be known how many seconds left )
- Add a command /medic to claim it from commands console to hide that some players are claiming medic at the moment
- The alpha medic messages at the chat can't be seen by bravo team and vica versa
- If a player types !med and the medic position is busy, he will see how many time left for being medic free to claim (it could be based on the healing speed)
- if a medic become free a player that tried to be a medic will get a message that it's finally free to claim



Below is the incomplete medic script. It's used on my server so everybody can test and see how it works:
IP: 46.29.23.162, Port: 23073




Code: [Select]
const
  Color = $EE30DDEE;
  MaxDist = 65;
  MaxHealth = 150;
  HealRate = 8;
AutoRelinquish = true; // once the medic heals completely or is dead, medic becomes unclaimed

var
  Medic: array[1..2] of byte;

procedure AppOnIdle(Ticks: integer);
var
Relinquish: boolean;
i,j: byte;
X,Y: single;
begin
for i := 1 to 2 do begin
GetPlayerXY(Medic[i],X,Y);
if Medic[i] <> 0 then begin
Relinquish := true;
if GetPlayerStat(Medic[i],'Alive') = true then
for j := 1 to 32 do
if (GetPlayerStat(j,'Active') = true) then
if (GetPlayerStat(j,'Alive') = true) and (GetPlayerStat(Medic[i],'Team') = GetPlayerStat(j,'Team')) and (Distance(X,Y,GetPlayerStat(j,'X'),GetPlayerStat(j,'Y')) <= MaxDist) and (GetPlayerStat(j,'Health') < MaxHealth) then begin
Relinquish := false;
if GetPlayerStat(j,'Health') + HealRate > MaxHealth then
DoDamage(j,GetPlayerStat(j,'Health') - MaxHealth)
else
DoDamage(j,-HealRate);
end;
if (Relinquish) then begin
Medic[i] := 0;
          end;
end;
end;
end;

procedure OnJoinGame(ID, Team: byte);
begin
  if Medic[Team] = 0 then WriteConsole(ID,'Medic is up for grabs on your team. Type !medic to claim it.',Color);
end;

procedure OnJoinTeam(ID, Team: byte);
var
  OTeam: byte;
begin
  if Team = 1 then OTeam := 2 else OTeam := 1;
  if Medic[OTeam] = ID then begin
    Medic[OTeam] := 0;
    WriteConsole(0,'Medic for team #' + InttoStr(OTeam) + ' is up for grabs. Type !medic to claim it.',Color);
  end;
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
begin
  if Medic[Team] = ID then begin
    Medic[Team] := 0;
  end;
end;

procedure OnMapChange(NewMap: string);
var
  i: byte;
begin
  for i := 1 to 2 do Medic[i] := 0;
  WriteConsole(0,'Medic is now up for grabs for both teams. Type !medic to claim it.',Color);
end;

procedure OnPlayerSpeak(ID: byte; Text: string);
var
Hurt: boolean;
  Team, i: byte;
X, Y: single;
begin
  if RegExpMatch('^!(medic|med|medi|Medic|Nurse|nurse)$',LowerCase(Text)) then begin
    Team := GetPlayerStat(ID,'Team');
    if Medic[Team] = 0 then begin
Hurt := not AutoRelinquish;
if (AutoRelinquish) then begin
GetPlayerXY(ID,X,Y);
for i := 1 to 32 do
if (GetPlayerStat(i, 'Active') = true) then
if (GetPlayerStat(i,'Alive') = true) and (Team = GetPlayerStat(i,'Team')) and (Distance(X,Y,GetPlayerStat(i,'X'),GetPlayerStat(i,'Y')) <= MaxDist) and (GetPlayerStat(i,'Health') < MaxHealth) then begin
Hurt := true;
break;
end;
end;
if (Hurt) then begin
    Medic[Team] := ID;
    WriteConsole(ID,GetPlayerStat(ID,'Name') + ' has claimed medic for team #' + InttoStr(Team) + '.',Color);
end else WriteConsole(ID,'You cannot claim medic because you and those near you are not hurt.',Color);
    end else WriteConsole(ID,'Medic has already been claimed by ' + GetPlayerStat(Medic[Team],'Name') + '.',Color);
  end;
end;

Offline dominikkk26

  • Camper
  • ***
  • Posts: 404
    • PMGsite
Re: Remake of the medic script
« Reply #1 on: November 24, 2013, 06:17:37 am »
I'm not sure that it meets all of your expectations but try my version.
Code: [Select]
const
  HpHealed= 6;
  HealForPoint= 65;
  HealDistance= 60;
  Color= $EE00FF00;   
  Red = $FF0000;
  Blue = $0000FF;

var
  Medic: array[1..2] of byte;
  Healed: array[1..2] of integer;
  MaxHP: byte;

procedure Reset;
begin
  if Command('/realistic') = 1 then MaxHP:= 65 else MaxHP:= 150;
  Medic[1]:= 0;
  Medic[2]:= 0;
  Healed[1]:= 0;
  Healed[2]:= 0;
end;

procedure ActivateServer();
begin
  Reset;
end;

procedure OnMapChange(NewMap: string);
var
i: byte;
begin
  Reset;
  WriteConsole(0,'Medic position is now free. Write !medic to apply.',Color);
end;

procedure MedicQuit(Team: byte);
begin
  WriteConsole(0,IDToName(Medic[Team])+' is no longer the '+iif(Team=1,'alpha','bravo')+' team''s medic!',iif(Team=1,Red,Blue));
  Medic[Team]:= 0;
  Healed[Team]:= 0;
end;

procedure Heal(Team: byte);
var
  HP: integer;
  i: byte;
begin
  for i:= 1 to 32 do if GetPlayerStat(i,'Active') = true then if GetPlayerStat(i,'Alive') = true then if GetPlayerStat(i,'Health') < MaxHP then
   if Team = GetPlayerStat(i,'Team') then if
    Distance(GetPlayerStat(Medic[Team],'X'),GetPlayerStat(Medic[Team],'Y'),GetPlayerStat(i,'X'),GetPlayerStat(i,'Y')) <= HealDistance then begin

    if GetPlayerStat(i,'Health') <= (MaxHP-HpHealed) then HP:= 5 else HP:= MaxHP-GetPlayerStat(i,'Health');
    DoDamage(i,-HP);
    if Medic[Team] <> i then begin
      inc(Healed[Team],HP);
      if Healed[Team] > HealForPoint then begin
        WriteConsole(Medic[Team],'You got 1 point for healing.',Color);
        SetScore(Medic[Team],GetPlayerStat(Medic[Team],'Kills')+1);
        Healed[Team]:= 0;
      end;
    end;
  end;
end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
var T: byte;
begin
  if RegExpMatch('^/(medic|med|medi)$',LowerCase(Text)) then if (GetPlayerStat(ID,'Team')=1) or (GetPlayerStat(ID,'Team')=2) then begin
    T:= GetPlayerStat(ID,'Team');
   if Medic[T]=0 then begin
      WriteConsole(0,IDToName(ID)+' is now the '+iif(T=1,'alpha','bravo')+' team''s medic!',iif(T=1,Red,Blue));
      Medic[T]:= ID;
    end else if Medic[T] = ID then begin
      MedicQuit(T);
    end else WriteConsole(ID,IDToName(Medic[T])+' is already your team''s medic!',Color);
end;
Result := false;
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
begin
  if (Team = 1) or (Team = 2) then if ID = Medic[Team] then MedicQuit(Team);
end;

procedure OnJoinTeam(ID, Team: byte);
begin
  if (Medic[1]=ID) or (Medic[2]=ID) then MedicQuit(iif(Medic[1]=ID,1,2));
  if (Team = 1) or (Team = 2) then if Medic[Team]=0 then WriteConsole(ID,'Medic position is free. Write !medic to apply.',Color) else
   WriteConsole(ID,IDToName(Medic[Team]) + ' is your team''s medic.',Color);
end;

procedure AppOnIdle(Ticks: integer);
var
i, T: byte;
begin
for i:= 1 to 32 do if GetPlayerStat(i,'Active') = true then begin
if (Medic[1]=i) or (Medic[2]=i) then if GetPlayerStat(i,'Health') > 0 then Heal(iif(Medic[1]=i,1,2));
end;
end;
« Last Edit: November 24, 2013, 06:22:03 am by dominikkk26 »

Offline dominikkk26

  • Camper
  • ***
  • Posts: 404
    • PMGsite
Re: Remake of the medic script
« Reply #2 on: November 24, 2013, 06:25:34 am »
Would you like to add to this that a player which write /medic him through 30 seconds?
Code: [Select]
const
  HpHealed= 6;
  HealForPoint= 65;
  HealDistance= 60;
  Color= $EE00FF00;   
  Red = $FF0000;
  Blue = $0000FF;

var
  Medic: array[1..2] of byte;
  Healed: array[1..2] of integer;
  MaxHP: byte;
  Timer: array [1..2] of integer;
  startTimer: array [1..2] of integer;

procedure Reset;
begin
  if Command('/realistic') = 1 then MaxHP:= 65 else MaxHP:= 150;
  Medic[1]:= 0;
  Medic[2]:= 0;
  Healed[1]:= 0;
  Healed[2]:= 0;
end;

procedure ActivateServer();
begin
  Reset;
end;

procedure OnMapChange(NewMap: string);
var
i: byte;
begin
  Reset;
  WriteConsole(0,'Medic position is now free. Write !medic to apply.',Color);
  for i:= 1 to 32 do begin
if GetPlayerStat(i,'Active') = true then begin
end;
  end;
end;

procedure MedicQuit(Team: byte);
begin
  WriteConsole(0,IDToName(Medic[Team])+' is no longer the '+iif(Team=1,'alpha','bravo')+' team''s medic!',iif(Team=1,Red,Blue));
  Medic[Team]:= 0;
  Healed[Team]:= 0;
end;

procedure Heal(Team: byte);
var
  HP: integer;
  i: byte;
begin
  for i:= 1 to 32 do if GetPlayerStat(i,'Active') = true then if GetPlayerStat(i,'Alive') = true then if GetPlayerStat(i,'Health') < MaxHP then
   if Team = GetPlayerStat(i,'Team') then if
    Distance(GetPlayerStat(Medic[Team],'X'),GetPlayerStat(Medic[Team],'Y'),GetPlayerStat(i,'X'),GetPlayerStat(i,'Y')) <= HealDistance then begin

    if GetPlayerStat(i,'Health') <= (MaxHP-HpHealed) then HP:= 5 else HP:= MaxHP-GetPlayerStat(i,'Health');
    DoDamage(i,-HP);
    if Medic[Team] <> i then begin
      inc(Healed[Team],HP);
      if Healed[Team] > HealForPoint then begin
        WriteConsole(Medic[Team],'You got 1 point for healing.',Color);
        SetScore(Medic[Team],GetPlayerStat(Medic[Team],'Kills')+1);
        Healed[Team]:= 0;
      end;
    end;
  end;
end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
var T: byte;
begin
  if RegExpMatch('^!(medic|med|medi)$',LowerCase(Text)) then if (GetPlayerStat(ID,'Team')=1) or (GetPlayerStat(ID,'Team')=2) then begin
    T:= GetPlayerStat(ID,'Team');
   if Medic[T]=0 then begin
      WriteConsole(0,IDToName(ID)+' is now the '+iif(T=1,'alpha','bravo')+' team''s medic!',iif(T=1,Red,Blue));
      Medic[T]:= ID;
  startTimer[ID] := 1;
  Timer[ID] := 30;
    end else if Medic[T] = ID then begin
      MedicQuit(T);
    end else WriteConsole(ID,IDToName(Medic[T])+' is already your team''s medic!',Color);
end else WriteConsole(ID,'You were already a medic on the map!',Color);
end;
Result := false;
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
begin
  if (Team = 1) or (Team = 2) then if ID = Medic[Team] then MedicQuit(Team);
end;

procedure OnJoinTeam(ID, Team: byte);
begin
  if (Medic[1]=ID) or (Medic[2]=ID) then MedicQuit(iif(Medic[1]=ID,1,2));
  if (Team = 1) or (Team = 2) then if Medic[Team]=0 then WriteConsole(ID,'Medic position is free. Write !medic to apply.',Color) else
   WriteConsole(ID,IDToName(Medic[Team]) + ' is your team''s medic.',Color);
end;

procedure AppOnIdle(Ticks: integer);
var
i, T: byte;
begin
for i:= 1 to 2 do begin
if startTimer[i] = 1 then begin
Timer[i] := Timer[i] - 1;
if Timer[i] = 0 then begin
if(GetPlayerStat(i,'Active')=true) then begin
T:= GetPlayerStat(i,'Team');
MedicQuit(T);
startTimer[i] := 0;
end;
end;
end;
end;
for i:= 1 to 32 do if GetPlayerStat(i,'Active') = true then begin
if (Medic[1]=i) or (Medic[2]=i) then if GetPlayerStat(i,'Health') > 0 then Heal(iif(Medic[1]=i,1,2));
end;
end;

« Last Edit: November 24, 2013, 06:32:47 am by dominikkk26 »