Hello guys, I need help testing the efficiency of two functions that do the same thing but in different ways. I would do it, but i have never gotten formatdate to behave and i know some of you have working time calculation functions.
The function is SetPlayerHealth. From the name you can tell it sets the players health and vest to a specific number. One strips the vest off, does the health and fixes the vest to the required amount. The other does both at the same time. Which is better?
Method One
procedure SetPlayerHealth(ID: byte; Health,Vest: integer; RecalcHealth: boolean);
var chealth,cvest: integer;
begin
chealth := getplayerstat(ID,'health');
cvest := getplayerstat(ID,'vest');
if (chealth=health) AND (cvest=vest) then exit;
if chealth = 0 then dodamage(ID,1000);
while(cvest > 0) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1; Mod specific use
dodamage(ID,2);
cvest := cvest - 1;
end;
if recalchealth then sbot[ID].health := round(health*(inttofloat(sbot[ID].maxhealth+player[ID].extrahp)/150));
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1; Mod specific use
dodamage(ID,chealth-health);
if vest = 0 then exit;
givebonus(ID,3);
cvest := 100;
while(cvest > vest) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1; Mod specific use
dodamage(ID,2);
cvest := cvest - 1;
end;
end;
Method Two
procedure SetPlayerHealth(ID: byte; Health,Vest: integer; RecalcHealth: boolean);
var chealth,cvest,delta: integer;
begin
chealth := getplayerstat(ID,'health');
cvest := getplayerstat(ID,'vest');
if recalchealth then sbot[ID].health := round(health*(inttofloat(sbot[ID].maxhealth+player[ID].extrahp)/150));
if (chealth=health) AND (cvest=vest) then exit;
if chealth = 0 then dodamage(ID,1000);
if vest = 0 then begin
while(cvest > 0) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
dodamage(ID,2);
cvest := cvest - 1;
end;
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
dodamage(ID,chealth-health);
exit;
end else begin
if cvest = 0 then begin
givebonus(ID,3);
cvest := 100;
end;
while(chealth <> health) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
if chealth < health then delta := -1 else delta := 1;
dodamage(ID,3*delta);
chealth := chealth - delta;
cvest := wrapvalue(cvest - delta,0,100,true);
if cvest = 0 then begin
givebonus(ID,3);
cvest := 100;
end;
if cvest <> vest then begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
if cvest < vest then delta := -1 else delta := 1;
dodamage(ID,2*delta);
cvest := cvest - delta;
end;
end;
while(cvest <> vest) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
if cvest < vest then delta := -1 else delta := 1;
dodamage(ID,2*delta);
cvest := cvest - delta;
end;
exit;
end;
givebonus(ID,3);
cvest := 100;
while(cvest > vest) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
dodamage(ID,2);
cvest := cvest - 1;
end;
end;
Thank You for your time.