Server Talk > Scripting Discussions and Help

Fixing old scripts guide.

(1/1)

Falcon`:
Since there are so many problems with running old scripts on new server, i'm posting here a short guide on how to fix/adjust old scripts to work.


* Missing semicolon: to solve it just add that missing semicolon, either in line it's pointing out or line above (see which one misses it)

* Invalid variant type cast: Variants variables/function results are used without conversion in your code. Wrap them with IntToStr()/FloatToStr()/StrToInt() and similar to get rid of them
Examples:
Before:

--- Quote ---var
  Msg: String;
begin
  Msg := 'Player''s kills: ' + GetPlayerStat(1, 'Kills') + ', deaths: ' + GetPlayerStat(1, 'Deaths')
end;

--- End quote ---
After:

--- Quote ---var
  Msg: String;
begin
  Msg := 'Player''s kills: ' + IntToStr(GetPlayerStat(1, 'Kills')) + ', deaths: ' + IntToStr(GetPlayerStat(1, 'Deaths'))
end;

--- End quote ---

* Wrong division result: Some divisions that you expect to produce floating point value might give you rounded result (integer). To get rid of this, cast dividend, divisor or both to single or double (wrap them with Single() or Double())
Examples:
Before:

--- Quote ---var
  Ratio: Single;
  Kills, Deaths: Integer;
begin
  Kills := GetPlayerStat(1, 'Kills');
  Deaths := GetPlayerStat(1, 'Deaths');
  Ratio := Kills/Deaths;
end;

--- End quote ---
After:

--- Quote ---var
  Ratio: Single;
  Kills, Deaths: Integer;
begin
  Kills := GetPlayerStat(1, 'Kills');
  Deaths := GetPlayerStat(1, 'Deaths');
  Ratio := Single(Kills)/Single(Deaths);
end;

--- End quote ---

* Wrong Inc, Dec parameters: Replace them with variable assigments, like this:
Examples:
Before:

--- Quote ---Inc(i, 1);
Dec(Player[ID].Points, 5);

--- End quote ---
After:

--- Quote ---i := i + 1;
Player[ID].Points := Player[ID].Points - 5;

--- End quote ---

If you encounter any other problems which you cannot solve yourself then please either reply here, or ask on #soldat.devs - i'll add solutions to those that seem to be common as well. Or if the errors seems to be API related, report it on bugtracker

Sorry for the inconvenience.

Navigation

[0] Message Index

Go to full version