Author Topic: 1v1 With Voted Weapon (Survival)  (Read 1840 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
1v1 With Voted Weapon (Survival)
« on: August 13, 2007, 07:13:06 pm »
Script Name: 1v1 With Voted Weapon (Survival)
Script Description: When server has survival enabled, the script checks if there is only 1 player alive on alpha and bravo team, and when there is, both players may type '/ready _' where as _ is a weapon number from 1 to 14 (1 - 10 primaries, 11 - 14 secondaries). Players are prevented to pick up weapons. This is done by just re-forcing their weapon back when they change weapons. This means that if a player throws a knife, yes, they get a new one.
Original Author: Curt (DorkeyDear)
Core Version: 2.6.2
Code:
Code: [Select]
const
  Color = $FFFFFFFF;
  Health = 65;

var
  Player,Choice: array[1..2] of byte;
  AfterKillMsg: string;
  Start,Once: boolean;

function FixType(Value: integer): integer;
begin
  Result := StrtoInt(InttoStr(Value));
end;

function AlivePlayers(Team: shortint): byte;
var
  i: byte;
begin
  for i := 1 to 32 do if (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Alive') = true) and ((Team = -1) or (GetPlayerStat(i,'Team') = Team)) then Result := Result + 1;
end;

function WeapNumtoRealWeapNum(Num: byte): byte;
begin
  if Num <= 10 then Result := Num else if Num = 11 then Result := 0 else Result := Num + 2;
end;

procedure AppOnIdle(Ticks: integer);
begin
  if AfterKillMsg <> '' then begin
    DrawText(0,AfterKillMsg,300,$FFDF3CA8,3.5 / Length(AfterKillMsg),8,400);
    AfterKillMsg := '';
  end;
end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
var
  i,Weap,PlayerNum: byte;
begin
  Result := false;
  if (GetPiece(Text,' ',0) = '/ready') and ((ID = Player[1]) or (ID = Player[2])) and (Start = false) and (GetPlayerStat(Player[1],'Alive') = true) and (GetPlayerStat(Player[2],'Alive') = true) then begin
    for i := 1 to 2 do if ID = Player[i] then PlayerNum := i;
    try
      Weap := StrtoInt(GetPiece(Text,' ',1));
    except
      WriteConsole(ID,'Invalid input.',Color);
    end;
    if (Weap >= 1) and (Weap <= 14) then begin
      Choice[PlayerNum] := Weap;
      if Choice[FixType(iif(PlayerNum = 1,2,1))] = Weap then begin
        WriteConsole(0,'Both players have agreed to choose weapon #' + InttoStr(Weap) + '.',Color);
        for i := 1 to 2 do begin
          DoDamage(Player[i],GetPlayerStat(Player[i],'Health') - Health);
          ForceWeapon(Player[i],WeapNumtoRealWeapNum(Weap),255,0);
        end;
        Start := true;
      end else WriteConsole(0,GetPlayerStat(ID,'Name') + ' has selected weapon #' + InttoStr(Weap) + '.',Color);
    end else WriteConsole(ID,'Invalid weapon number.',Color);
  end;
end;

procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
var
  i,j: byte;
begin
  if (NumPlayers >= 2) and (((GetPlayerStat(Killer,'Team') <> GetPlayerStat(Victim,'Team')) and (AlivePlayers(GetPlayerStat(Victim,'Team')) = 2) and (AlivePlayers(GetPlayerStat(Killer,'Team')) = 1))) or ((GetPlayerStat(Killer,'Team') = GetPlayerStat(Victim,'Team')) and (AlivePlayers(GetPlayerStat(Killer,'Team')) = 2) and (AlivePlayers(iif(GetPlayerStat(Killer,'Team') = 1,2,1)) = 1)) then begin
    WriteConsole(0,'1 vs 1! If you want to fight with the same weapon, type',Color);
    WriteConsole(0,'''/ready _'' where as _ is the weapon number (1-14).',Color);
    for i := 1 to 32 do if (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Alive') = true) and (i <> Victim) then begin
      for j := 1 to 2 do if Player[j] = 0 then begin
        Player[j] := i;
        Break;
      end;
      if Player[2] <> 0 then Break;
    end;
  end;
  if Start then begin
    if Killer <> Victim then AfterKillMsg := GetPlayerStat(Killer,'Name') + ' has won the 1 vs 1!';
    Start := false;
  end;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer): integer;
begin
  Result := Damage;
end;

procedure OnPlayerRespawn(ID: byte);
var
  i,j: byte;
begin
  for i := 1 to 2 do begin
    Player[i] := 0;
    Choice[i] := 0;
  end;
  if (NumPlayers = 2) then begin
    if Once then begin
      WriteConsole(0,'1 vs 1! If you want to fight with the same weapon, type',Color);
      WriteConsole(0,'''/ready _'' where as _ is the weapon number (1-14).',Color);
      Once := false;
    end else Once := true;
    for i := 1 to 32 do if (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Alive') = true) then begin
      for j := 1 to 2 do if Player[j] = 0 then begin
        Player[j] := i;
        Break;
      end;
      if Player[2] <> 0 then Break;
    end;
  end;
end;

procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);
begin
  if (Start) and (PrimaryNum <> Choice[1]) then ForceWeapon(ID,WeapNumtoRealWeapNum(Choice[1]),255,0);
end;
Bugs:
  • When the map restarts or changes, the message saying to do the /ready thing comes up two times if there is only one alpha and bravo players.
In request from Zigosity

Offline dasilverguy

  • Major(1)
  • Posts: 40
    • |BTK| Forum
Re: 1v1 With Voted Weapon (Survival)
« Reply #1 on: July 14, 2008, 03:25:33 am »
and when you throw a weapon, the weapon is automatically reloaded? I haven't tested it yet, just wondering.