Author Topic: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);  (Read 1871 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« on: February 20, 2010, 02:41:59 am »
This function sets a players health and vest simultaneously. Very useful.

Code: [Select]
procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
var chealth,cvest,delta: 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);
if vest = 0 then begin
while(cvest > 0) do begin
dodamage(ID,2);
cvest := cvest - 1;
end;
dodamage(ID,chealth-health);
exit;
end else begin
if cvest = 0 then begin
givebonus(ID,3);
cvest := 100;
end;
while(chealth <> health) do begin
if chealth < health then delta := -1 else delta := 1;
dodamage(ID,3*delta);
chealth := chealth - delta;
cvest := cvest - delta;
if cvest < 0 then cvest := 0;
if cvest > 100 then cvest := 100;
if cvest = 0 then begin
givebonus(ID,3);
cvest := 100;
end;
if cvest <> vest then begin
if cvest < vest then delta := -1 else delta := 1;
dodamage(ID,2*delta);
cvest := cvest - delta;
end;
end;
while(cvest <> vest) do begin
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
dodamage(ID,2);
cvest := cvest - 1;
end;
end;

As of 4/18/210 this is fixed, was using a func i made and didnt upload, didnt even realize it.

Updated with new version.
« Last Edit: April 18, 2010, 02:24:57 pm by Hacktank »


Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #1 on: February 20, 2010, 03:57:49 am »
Why do you use integer if vest is 0-100 and health is 0-200...
« Last Edit: February 20, 2010, 04:02:09 am by Gizd »

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #2 on: February 20, 2010, 04:48:21 am »
Because soldat pascal likes to give me random out of range errors when i use bytes for anything but id looping.


Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #3 on: February 20, 2010, 05:26:03 am »
Out of range errors aren't random...

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #4 on: February 20, 2010, 05:34:50 am »
Quote
Because soldat pascal likes to give me random out of range errors when i use bytes
Your explaination fails.
There are no errors thrown without a reason just because it's "soldat pascal". Out of ranges are thrown if your shitty script tries to access an element of an array which doesn't exist. Here, you don't use any arrays, so there is no way to cause the out of range exception.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #5 on: February 20, 2010, 05:35:39 am »
Try setting a byte var to something over 255, it jumps to some number. It does not make any errors. Nice proc anyway :D

I'm sure that people have been told you that sometimes already, but please get rid of no spaces at beginning of a line, it is really horrible to read for some people then. A few lines in the procedures would be nice too, it really increases the readability of your scripts ;d

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #6 on: February 20, 2010, 12:52:43 pm »
just fyi Hacktank - in addition to the previous comments about the the out of range errors, a reason you may have been getting it from whatever script is probably because -1 in a byte is 255, and you must do checks and stuff; plus I always do if (GetArrayLength(__) > 0) first since for MyByte := -1 to 0 means 255 to 0 when MyByte is a byte. I used to have that problem all the time, and I made it a habit to use if length > 0, even if my iteration type is a signed integer

btw gj & ty for the function - i wanted to make one a while ago but ended up giving up ^^ not that i tried very hard but still.... yeah..

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #7 on: February 20, 2010, 01:24:25 pm »
am i being ignorant, or does a 32 bit int take the same amount of memory as a "byte" anyway?

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: procedure SetPlayerHealth(ID: byte; Health,Vest: integer);
« Reply #8 on: February 20, 2010, 04:22:54 pm »
A byte is 8 bits, an therefore a quarter of the size.

And about my 'misuse', its not like it makes a difference. Unless your running your server on a calculator its not going to run out of memory.