Author Topic: Basic HUD Procedure  (Read 2513 times)

0 Members and 1 Guest are viewing this topic.

Offline DevilX4

  • Major(1)
  • Posts: 30
Basic HUD Procedure
« on: September 23, 2012, 03:41:23 pm »
Script Name: HUD
Script Description: Allows you to use a HUD for your server. Adding kills, xp (for the rpg servers) and other things. Just need to edit for your own use.
Original Author(s): DevilX4
Core Version: 2.7.3
Code:
Code: [Select]
Procedure HUD(ID: byte);
var line:array[1..30] of string; something: string;
begin

 line[1]:=' '; // DO NOT USE
 line[2]:=' '; // DO NOT USE
 line[3]:=' '; // DO NOT USE
 line[4]:=' '; // DO NOT USE
 line[5]:=' ';
 line[6]:=' ';
 line[7]:=' ';
 line[8]:=' ';
 line[9]:=' ';
line[10]:=' ';
line[11]:=' ';
line[12]:=' ';
line[13]:=' ';
line[14]:=' ';
line[15]:=' ';
line[16]:=' ';
line[17]:=' ';
line[18]:=' ';
line[19]:=' ';
line[20]:=' ';
line[21]:=' ';
line[22]:=' ';
line[23]:=' ';
line[24]:=' ';
// ABOVE LINES ARE OVERLAPPED BY CONSOLE
line[25]:=' ';
line[26]:=' ';
line[27]:=' '+something+' ';
line[28]:=' ';
line[29]:=' ';
line[30]:=' ';

DrawText(ID,line[1]+chr(13)+chr(10)+line[2]+chr(13)+chr(10)+line[3]+chr(13)+chr(10)+line[4]+chr(13)+chr(10)+line[5]+chr(13)+chr(10)+line[6]+chr(13)+chr(10)+line[7]+chr(13)+chr(10)+line[8]+chr(13)+chr(10)+line[9]+chr(13)+chr(10)+line[10]+chr(13)+chr(10)+line[11]+chr(13)+chr(10)+line[12]+chr(13)+chr(10)+line[13]+chr(13)+chr(10)+line[14]+chr(13)+chr(10)+line[15]+chr(13)+chr(10)+line[16]+chr(13)+chr(10)+line[17]+chr(13)+chr(10)+line[18]+chr(13)+chr(10)+line[19]+chr(13)+chr(10)+line[20]+chr(13)+chr(10)+line[21]+chr(13)+chr(10)+line[22]+chr(13)+chr(10)+line[23]+chr(13)+chr(10)+line[24]+chr(13)+chr(10)+line[25]+chr(13)+chr(10)+line[26]+chr(13)+chr(10)+line[27]+chr(13)+chr(10)+line[28]+chr(13)+chr(10)+line[29]+chr(13)+chr(10)+line[30],500,$FFFF00,0.079,1,1);

end;

also add this to your AppOnIdle procedure:
Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
  for i := 1 to 32 do begin
    HUD(i);
  end;
end;

DarkCrusade

  • Guest
Re: Basic HUD Procedure
« Reply #1 on: September 24, 2012, 10:18:27 am »
If you use a 'for loop' without checking whether the player is active or not. Your script can be enhanced very easily. Just take a look at my example to see where you made failures or what could be made better:

Code: (pascal) [Select]
const
  // For line breaks.
  br=#13#10;

  // HUD colour.
  cl_interface=$FFFFFF;

  // Frame for the HUD.
  l_line='-----';

  // Example use for the HUD.
  l_health='Health: ';

procedure draw_hud(id:byte);
  begin
    drawtext(id,l_line+br+
                l_health+getplayerstat(id,'health')+'/150'+br+
                l_line
               ,120,cl_interface,0.075,15,300); 
  end;

procedure apponidle(t:integer);
var
  i:byte, 
  begin
    for i:=1 to 32 do
      // Check if the slot is active before trying to do anything with  it.
      // Also check if the slot is used by a human player.
      if (getplayerstat(i,'active')=true) and (getplayerstat(i,'human')=true) then
        draw_hud(i);
  end;

Offline DevilX4

  • Major(1)
  • Posts: 30
Re: Basic HUD Procedure
« Reply #2 on: September 24, 2012, 03:30:14 pm »
Works fine as it is, but thanks for the advice.

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Re: Basic HUD Procedure
« Reply #3 on: September 25, 2012, 08:07:32 am »
Works fine as it is, but thanks for the advice.

The script itself will work fine.. But if you got a heavier script (which you basically intend people to do with this script offer here).. then you should try to optimize whererever you can.. You can basically make everywhere scripts/tools/whatever.. They may work.. But they will take more ressources and are just not that stable (see soldat itself).. So code optimization is always one of the MOST important things if you code some things...^^

I read somewhere that sentence..: "98% of programming consists of optimizing/bug fixing" that's so true..

best regards,
ExHunter ;)

DarkCrusade

  • Guest
Re: Basic HUD Procedure
« Reply #4 on: September 25, 2012, 12:34:18 pm »
Is the bug that was crashing a server when you tried to access player-data of a not active ID still present? If so, the check is essential.

Offline KoGAi

  • Major(1)
  • Posts: 32
  • The Light of the Universe
Re: Basic HUD Procedure
« Reply #5 on: October 09, 2012, 06:44:57 pm »
This is interesting. I tried it on my lab server but it's a bit uncomfortable that it rapidly replaces the embedded messages Soldat shows like "You killed..." or "You were killed by..." as well as the "Alpha Team scores".
Maybe if the multilayer DrawText function were there, we could use it without compromising other messages on-screen.

I'll keep on playing with it. :)
Thanks for the addition.
=₳US7RAL|¹² is a growing Soldat Community making a difference by offering a wide variety of top-notch servers across North America- a new alternative to everyone.
Jump into our servers in NA with the new domain (austral12.com)! Check our Facebook Page.
_______
#austral12soldat @ QuakeNet ▲ facebook.com/AUS7RAL12 ▲ twitter.com/AUS7RAL12