Author Topic: SetVest  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

Offline J-Factor

  • Major(1)
  • Posts: 27
SetVest
« on: November 17, 2007, 11:11:12 am »
Script Name: SetVest
Script Description: Sets the amount of vest a player has (0 = No vest, 100 = Full vest).
Original Author(s): J-Factor
Core Version: 2.6.3

Code:
Code: [Select]
var
    NoDamage: boolean;

(* Gives a player a certain amount of vest *)
procedure SetVest(ID: Byte; VestAmount: integer);
begin
    GiveBonus(ID, 3);
       
    NoDamage := true;
    DoDamage(ID, 302 - VestAmount*302/100);
    NoDamage := false;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer): integer;
begin
    if (NoDamage) then begin
        Result := 0;
    end else begin
        Result := Damage;
    end;
end;
Colour formatted version: http://nopaste.com/p/aXHJayH9mb
Zip archive attached.

Notes: You can change the code involving the variable NoDamage but make sure that when DoDamage() is called in SetVest it does no actual damage to the player!. This is because we only want the vest amount to be decreased (which happens no matter what the result of OnPlayerDamage is).

When SetVest is called "Bulletproof Vest!" is drawn on the player's screen. You might want to call DrawText() to replace this text with your own after setting someone's vest amount.
« Last Edit: November 17, 2007, 11:04:43 pm by J-Factor »

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: SetVest
« Reply #1 on: November 17, 2007, 02:22:55 pm »
Nice :)
Is VestAmount like a % or the same intervals as normal for vest (whatever that is)?

Offline J-Factor

  • Major(1)
  • Posts: 27
Re: SetVest
« Reply #2 on: November 17, 2007, 03:29:58 pm »
Is VestAmount like a % or the same intervals as normal for vest (whatever that is)?
Same intervals. Vest goes from 0 to 100 normally, while health goes from 0 to 150. I haven't tested this with realistic mode yet (which has health from 0 to 65) but it should work.

Just so you know, when you have any amount of vest (between 1 and 100) you only take a quarter of any damage you receive while you vest amount takes a third of whatever damage you receive.

E.g. You have 100 health and 50 vest. If you were hit with 12 damage you would be left with 97 health (100 - 12/4) and 46 vest (50 - 12/3).


Offline A Zombie

  • Major(1)
  • Posts: 25
  • BRAINS!!!
Re: SetVest
« Reply #4 on: March 11, 2008, 10:43:07 am »
What is the command im suppose to type in? ???

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: SetVest
« Reply #5 on: March 11, 2008, 11:09:22 am »
What is the command im suppose to type in? ???
There is none.

If you want a command for this, put this at the bottom of the code, then you can do /setvest player amount (/setvest 1 50)
Code: [Select]
function OnCommand(ID: byte; Text: string): boolean;
begin
  if lowercase(GetPiece(Text, ' ', 0)) = '/setvest' then
    SetVest(StrToInt(GetPiece(Text, ' ', 1)), StrToInt(GetPiece(Text, ' ', 2)));
end;


Offline A Zombie

  • Major(1)
  • Posts: 25
  • BRAINS!!!
Re: SetVest
« Reply #6 on: March 15, 2008, 09:26:02 am »
Thx Bob ;D

Offline mikembm

  • Soldier
  • **
  • Posts: 210
Re: SetVest
« Reply #7 on: March 17, 2008, 03:10:24 pm »
For Those of you that don't like unneeded global variables and like less lines of code, here is an alternative way to do this:

Code: [Select]
procedure SetVest(ID: Byte; VestAmount: integer);
begin
    GiveBonus(ID, 3);
    While GetPlayerStat(ID, 'Vest') < VestAmount do DoDamage(ID, 2);
end;

How does this work?
A damage of 2 is just enough to decrease the vest amount by 1 but not enough to do damage to the player.


I typed this out without testing but it should work.