Author Topic: Own admin drawing text  (Read 732 times)

0 Members and 2 Guests are viewing this topic.

Offline Spade

  • Major(1)
  • Posts: 8
Own admin drawing text
« on: November 23, 2008, 06:06:36 pm »
Hi!

This is just my first script:
Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
begin
  if Copy(Text, 0, 5) = '/text' then begin
    DrawText(0, Copy(Text, 7, Length(Text)), 330, RGB(255, 0, 255), 0.10, 15, 400);
  end;
end;

What it does? It simply draws your own text (if you're admin) to the screen of each player in the game. Syntax: /text Hello world!

It all is great, but if you try to draw some longer text, there is screen-size problem. Can anybody help me how to break line if there is so long text automatically? The position of last line has to be still the same, of course.

Thank you for possible help.
It's time to kick some ass and chew bubble gum.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Own admin drawing text
« Reply #1 on: November 23, 2008, 09:26:08 pm »
if Length(Text) > some_constant_number then begin
  find the first space before the some_constant_number'th position in the string, and insert a \r\n there (#13#10 in pascal)
  if u want it to be more complicated, you can repeat the process starting at the spot you just inserted the \r\n at, and the length of the text from that point on
end;

or you can have the size of the text change according to the length of the text, have some formula relating to the length of the text

Offline Spade

  • Major(1)
  • Posts: 8
Re: Own admin drawing text
« Reply #2 on: November 24, 2008, 06:58:23 pm »
Really thanks for advice :-)
I've just done this:
Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
var
  co, line1, line2: string;
  i, medzera: integer;
begin
  if Copy(Text, 0, 5) = '/text' then begin
    co := Copy(Text, 7, Length(Text));
    // If there's more than 38 chars => it has to be broken to 2 lines...
    if Length(co) > 38 then begin
      for i := 38 downto 1 do begin
        if co[i] = ' ' then begin
          medzera := i;
          break;
        end;
      end;
      line1 := Copy(co, 0, medzera-1);
      line2 := Copy(co, medzera+1, Length(co));
      co := line1 +chr(13)+chr(10) + line2;
      DrawText(0, co, 330, RGB(255, 0, 255), 0.10, 15, 380);
    end
    // If it has less than 38 chars...
    else begin
      DrawText(0, co, 330, RGB(255, 0, 255), 0.10, 15, 400);
    end;
  end;
end;
It's time to kick some ass and chew bubble gum.