Well, I just started scripting for Soldat's Dedicated Server 2.6.1 a few days ago. I am not a Pascal programmer, so I am still getting used to it as I learn how things are done on Dedicated Server scripts.
This topic is about the second script I've made and the goal is to do a procedure that receives a string and draws it on the screen with DrawText() fitting "perfectly" just as the default messages from Soldat as "You killed player" or "Killed by player". In this procedure, differently from DrawText() you don't need to specify any coordinates or scale. Just give it the string, and my procedure should do the rest.
At the time, I think it is working a bit fine for sentences with non-capital letters. I will try to explain my code, and I expect you to help me improving it, making it possible to draw sentences with numbers and capital-letters too.
{This is where I call my procedure for testing purposes...}
procedure OnPlayerSpeak(ID: byte; Text: string);
begin
DrawOnPlayersScreen(ID,Text);
end;
{and here is the code of the procedure I am talking about...}
var
scale: single;
patternLength: integer;
argumentLength: integer;
procedure DrawOnPlayersScreen(ID: byte; Text: string);
begin
patternLength := Length('caatinga');
argumentLength := Length(Text);
scale := patternLength / argumentLength;
scale := scale * 0.4;
//0.4 is the scale that works (fits perfectly) for the string caatinga
DrawText(ID,Text,330,RGB(255,0,0),scale,40,380);
end;
OK, here's my idea:
Firstly I defined the coordinates to be static (40,380) on a position close to the one where "You killed someone" is drawn (it doesn't works too well with small words - it gets too bigger and stays out of the screen, but it works fine with medium length sentences. Later I'll try to make the Y coordinate dynamic too).
Then I've took a medium word with non-capital letters (caatinga) and tested with the DrawText() procedure until I found wich was the scale that fits fine on the coordinates I've specified. I've found 0.4 .
Now, based on my pattern word (caatinga) and the scale 0.4, I can find an aproximate scale for any other known word or sentence just using proportions concepts.
http://en.wikipedia.org/wiki/Proportionality_(mathematics)
The bigger the length, smaller the scale. So, Scale and Length of the word are inversely proportional.
Scale = K * (1/Length)
Scale * Length = K (constant)
What means that the product of Scale and Length should be always the same if it fits correctly.
So, patternScale * patternLength = argumentScale * argumentLength
the only value I don't have is the argumentScale so I'm going to isolate it.
patternScale * patternLength / argumentLength = argumentScale
So this is what I do on my code.
patternScale is 0.4 (got by testing the word caatinga on DrawText()),
patternLength is the Length of the word caatinga,
and argumentLength is the Length of the word I am trying to find the scale...
Finally I draw the sentence:
DrawText(ID,Text,330,RGB(255,0,0),argumentScale,40,380);
Well I think it I've written a lot for such a small code, I hope that you understood and thanks a lot for who read it all... thanks for your attention too.
I'm waiting anxiously for your replies =)
Grateful,
CAATINGA