Poll

Awesome?

Awesome!
2 (22.2%)
Good...
1 (11.1%)
Bad
0 (0%)
Ugly!
1 (11.1%)
OMFG HALO!!!!!!!!
5 (55.6%)

Total Members Voted: 9

Author Topic: help needed on awesome script...  (Read 1166 times)

0 Members and 1 Guest are viewing this topic.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
help needed on awesome script...
« on: November 03, 2007, 04:42:55 pm »
Code: [Select]
const
  EchoDamage=true;
var
  Active: array[1..32] of boolean;
  Health: array[1..32] of integer;
  PHealth: array[1..32] of integer;
  i: integer;
begin
  for i:=1 to 32 do begin
    Active[i]:=GetPlayerStat(i,'active');
    Health[i]:=GetPlayerStat(i,'health');
    if ReadINI('Soldat.ini','GAME','Realistic_Mode','0') = '1' then begin
      PHealth[i]:=Round((60/100)*Health[i]);
    end else PHealth[i]:=Round((150/100)*Health[i]);
  end;
end.

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer):integer;
begin
  Case PHealth[Victim] of
    75 to 100: begin
      Result:=Round(Damage*1.00);
      if EchoDamage then WriteLn(Result);
    end;
    50 to 74: begin
      Result:=Round(Damage*0.75);
      if EchoDamage then WriteLn(Result);
    end;
    25 to 49: begin
      Result:=Round(Damage*0.50);
      if EchoDamage then WriteLn(Result);
    end;
    0 to 24: begin
      SayToPlayer(Victim,'Your shields are down, get to cover!');
      Result:=Round(Damage*0.25);
      if EchoDamage then WriteLn(Result);
    end;
  end;
end;

any specific reason why this does not do anything? it's an overshields script (yes I am a halo-fanatic/worshiper/forerunner enthusiast)

Quote from:
If you die out there, I'll kill you.
« Last Edit: November 03, 2007, 04:53:22 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: help needed on awesome script...
« Reply #1 on: November 04, 2007, 04:20:06 am »
You don't have AppOnIdle in there at all, and there's full stop instead of a semicolon after "end". I don't know where you picked up the "x to x" stuff from, but as far as I know it's not even valid code. Also note that reading from the ini file every second is unnecessary as there's no risk for the value to change during runtime.

Here's a fixed version:

Code: [Select]
const
EchoDamage=true;
var
Active: array[1..32] of boolean;
Health: array[1..32] of integer;
PHealth: array[1..32] of integer;
RealisticMode: boolean;

procedure ActivateServer();
begin
if ReadINI('Soldat.ini','GAME','Realistic_Mode','0')='1' then
RealisticMode:=true
else
RealisticMode:=false;
end;

procedure AppOnIdle(Ticks: integer);
var
i: byte;
begin
for i:=1 to 32 do begin
Active[i]:=GetPlayerStat(i,'active');

if Active[i]=false then continue;

Health[i]:=GetPlayerStat(i,'health');
if RealisticMode then
PHealth[i]:=Round((60/100)*Health[i])
else
PHealth[i]:=Round((150/100)*Health[i]);
end;
end;

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

if PHealth[Victim]>=75 then begin
Result:=Round(Damage*1.00);
if EchoDamage then WriteLn(inttostr(Result));
end else if PHealth[Victim]>=50 then begin
Result:=Round(Damage*0.75);
if EchoDamage then WriteLn(inttostr(Result));
end else if PHealth[Victim]>=25 then begin
Result:=Round(Damage*0.50);
if EchoDamage then WriteLn(inttostr(Result));
end else begin
SayToPlayer(Victim,'Your shields are down, get to cover!');
Result:=Round(Damage*0.25);
if EchoDamage then WriteLn(inttostr(Result));
end;
end;

Now, I don't know if this works as you intended it to or not, because to be quite honest I have no clue at all what you're trying to accomplish. Good luck, nevertheless.
« Last Edit: November 04, 2007, 04:22:16 am by Toumaz »

Offline Quantifier

  • Major
  • *
  • Posts: 70
Re: help needed on awesome script...
« Reply #2 on: November 05, 2007, 06:50:10 am »
You don't have AppOnIdle in there at all, and there's full stop instead of a semicolon after "end".

the syntax
begin {...} end.
is used in standalone programs, it's equivalent of main() function, and you don't have that in these scripts.


Here's a fixed version:

[ ... code ... ]

Now, I don't know if this works as you intended it to or not [...]

It doesn't, you broke some of it's logic (you missed few sanity checks).

Also if you take PHealth as Percent Health, then its calculation was broken from start. It should be 100*(Health/max), not (max/100)*Health. And in Realistic mode max health is 65, not 60.

Here's my shot at it:
Code: [Select]
const
EchoDamage=true;
var
Active: array[1..32] of boolean;
Health: array[1..32] of integer;
PHealth: array[1..32] of integer;
max_health: single;

procedure ActivateServer();
begin
if ReadINI('Soldat.ini','GAME','Realistic_Mode','0')='1' then
max_health:=0.65
else
max_health:=1.5;
end;

procedure AppOnIdle(Ticks: integer);
var
i: byte;
begin
for i:=1 to 32 do begin
Active[i]:=GetPlayerStat(i,'active');

if Active[i]=false then continue;

Health[i]:=GetPlayerStat(i,'health');
PHealth[i]:=Round(Health[i]/max_health);
end;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer):integer;
var multiplier: single;
begin
if PHealth[victim] < 0 then exit;
multiplier := 0.25 * ((PHealth[victim] div 25) +1);
if multiplier > 1.0 then multiplier:=1.0;
Result:=round(damage*multiplier);
if EchoDamage then WriteLn(inttostr(Result));
if multiplier = 0.25 then SayToPlayer(Victim,'Your shields are down, get to cover!');
{uncomment below for finer time granularity than 1 second in AppOnIdle}
{
Health[victim] = getplayerstat(victim,'health') - result;
PHealth[victim]:=Round(Health[victim]/max_health);
}
end;

it's an overshields script (yes I am a halo-fanatic/worshiper/forerunner enthusiast)
Why the hell not just spawn a bulletproof vest?

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: help needed on awesome script...
« Reply #3 on: November 05, 2007, 12:57:44 pm »
because vests arent overshields ;) I noticed when you are low health in Halo, your overshields can save you while your health is "pulsing red" with the "beepbeep" sounding

I might also make damage at 1 health try a random number between 0 and 100 and if it's under 80 or something you don't take any damage for that instant (to "save" you from dying)

I just noticed I can remove my own topics right now, too ;) (unless this school comp is goin crazy)

Date Posted: November 05, 2007, 12:50:07 pm
and wouldn't "if not active then continue;" work for "if active=false then continue"?

and wouldn't it be "if Active then continue;" because if player is inactive, then wouldn't they not have health?

and I just don't understand your script quantifier, but if it works I guess I shouldn't complain (I'll test it at home)
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: help needed on awesome script...
« Reply #4 on: November 05, 2007, 02:15:29 pm »
Code: [Select]
Case PHealth[Victim] of
    75..100: begin
      Result:=Round(Damage*1.00);
      if EchoDamage then WriteLn(Result);
    end;
    50..74: begin
      Result:=Round(Damage*0.75);
      if EchoDamage then WriteLn(Result);
    end;
    25..49: begin
      Result:=Round(Damage*0.50);
      if EchoDamage then WriteLn(Result);
    end;
    0..24: begin
      SayToPlayer(Victim,'Your shields are down, get to cover!');
      Result:=Round(Damage*0.25);
      if EchoDamage then WriteLn(Result);
    end;
  end;

This fixed version is valid code in delphi/pascal, but I'm not sure if it's correct in the scripting engine, due to the scripting engine using a smaller subset of features of the language.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: help needed on awesome script...
« Reply #5 on: November 05, 2007, 03:10:21 pm »
I understand yours more chrisgbk :P
I'll test all of these codes at home...

heres my version but with a few changes
Code: [Select]
const
  EchoDamage=true;
var
  Active, Nocall: array[1..32] of boolean;
  Health: array[1..32] of integer;
  PHealth: array[1..32] of integer;
  MHealth: single;
  HealTime: array[1..32] of integer;
  i: integer;

procedure AppOnIdle(Ticks: integer);
begin
  for i:=1 to 32 do begin
    if HealTime[i]>0 then HealTime[i]:=HealTime[i]-1;
    if HealTime[i]=0 then begin
      NoCall[i]:=true;
      DoDamage(i,Round(GetPlayerStat(i,'Health')/3));
      NoCall[i]:=false;
    end;
  end;
end;

procedure ActivateServer();
begin
  if ReadINI('Soldat.ini','GAME','Realistic_Mode','0')='1' then begin
    MHealth:=0.65;
  end else MHealth:=1.5;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer):integer;
var
  Flip: integer;
begin
  if not NoCall then begin
    for i:=1 to 32 do begin
      Health[i]:=GetPlayerStat(i,'health');
      PHealth[i]:=Round(MHealth*Health[i])
    end;
    Case PHealth[Victim] of
      75..100: begin
        Result:=Round(Damage*1.00);
        if EchoDamage then WriteLn(Result);
      end;
      50..74: begin
        Result:=Round(Damage*0.75);
        if EchoDamage then WriteLn(Result);
      end;
      25..49: begin
        Result:=Round(Damage*0.50);
        if EchoDamage then WriteLn(Result);
      end;
      2..24: begin
        SayToPlayer(Victim,'Your shields are down, get to cover!');
        Result:=Round(Damage*0.25);
        if EchoDamage then WriteLn(Result);
      end;
      0..1: begin
        Flip:=Random(0,100);
        if Flip < 80 then Result:=0
        else Result:=Damage;
      end;
    end;
  end else if NoCall then exit;
end;
Does this make any sense at all?
I'm trying anyway...
« Last Edit: November 05, 2007, 04:30:23 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: help needed on awesome script...
« Reply #6 on: November 05, 2007, 03:49:43 pm »
I do not believe it will work as it is; everything after 'end.' is discarded, because 'end.' signifies the end of the file; and the first block of code would only run once, when the script is loaded, so the values would never be updated.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: help needed on awesome script...
« Reply #7 on: November 05, 2007, 09:48:09 pm »
(I had to go to class, so I couldn't finish changing the script, but I fin'd it)

I have a good idea for an addition to SoldatServer: add procedures to prevent calling of events

procedure NoCall(Event): {if ** then} begin
blah blah
blah blah
end;

(I doubt EnEsCe will see this, and I doubt it is possible)
if this is possible, I wouldn't have to make a nocall variable «.«

My latest version that compiles but doesn't work:
Code: [Select]
const
  EchoDamage=true;
var
  Active, Nocall: array[1..32] of boolean;
  Health: array[1..32] of integer;
  PHealth: array[1..32] of integer;
  MHealth: single;
  HealTime: array[1..32] of integer;
  i: integer;

procedure OnJoinGame(ID, Team: Byte);
begin
  HealTime[ID]:=-1;
end;

procedure AppOnIdle(Ticks: integer);
begin
  for i:=1 to 32 do begin
    if (NumPlayers>0) and (HealTime[i]>0) then HealTime[i]:=HealTime[i]-1;
    if (NumPlayers>0) and (HealTime[i]=0) then begin
      NoCall[i]:=true;
      DoDamage(i,Round(GetPlayerStat(i,'Health')/3));
      NoCall[i]:=false;
    end;
    if (NumPlayers>0) and (HealTime[i]<0) then exit;
  end;
end;

procedure ActivateServer();
begin
  if ReadINI('Soldat.ini','GAME','Realistic_Mode','0')='1' then begin
    MHealth:=0.65;
  end else MHealth:=1.5;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer):integer;
var
  Flip: integer;
begin
  for i:=1 to 32 do begin
    Active[i]:=GetPlayerStat(i,'Active');
    Health[i]:=GetPlayerStat(i,'health');
    PHealth[i]:=Round(MHealth*Health[i]);
    if (Active[Victim]) and (NumPlayers > 0) and (not NoCall[i]) then begin
      if (PHealth[Victim] > 75) and (PHealth[Victim] < 100) then begin
        Result:=Round(Damage*1.00);
        if EchoDamage then WriteLn(inttostr(Result));
      end;
      if (PHealth[Victim] > 50) and (PHealth[Victim] < 75) then begin
        Result:=Round(Damage*0.75);
        if EchoDamage then WriteLn(inttostr(Result));
      end;
      if (PHealth[Victim] > 25) and (PHealth[Victim] < 50) then begin
        Result:=Round(Damage*0.50);
        if EchoDamage then WriteLn(inttostr(Result));
      end;
      if (PHealth[Victim] > 1) and (PHealth[Victim] < 25) then begin
        SayToPlayer(Victim,'Your shields are down, get to cover!');
        Result:=Round(Damage*0.25);
        if EchoDamage then WriteLn(inttostr(Result));
      end;
      if (PHealth[Victim] = 1) then begin
        Flip:=Random(0,100);
        if Flip < 80 then Result:=0
        else Result:=Damage;
      end;
    end else if NoCall[i] then exit;
  end;
end;

...
« Last Edit: November 05, 2007, 09:55:46 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."