Author Topic: Rate script, roundto() problem  (Read 1123 times)

0 Members and 1 Guest are viewing this topic.

Offline StayAlive

  • Major(1)
  • Posts: 8
Rate script, roundto() problem
« on: June 07, 2012, 04:37:41 am »
Hi guys,
I have problem with rate script, i'm just learning this whole thing about scripting and I dont know pascal very well so I'm just downloading already existing versions of scripts (form Scripting Releases). I downloaded KD ratio script by iftach and then Ratio 1.5.2 by dominikkk26 but there were some bugs.
I still cant solve problem with function roundto() - it simply doesent work.

Code:
Code: [Select]
const
 Color = $FFFFFFFF;

procedure Ratio(ID: Integer);
var
KD: Double;
Kills: double;
Deaths: double;
begin
kills:=GetPlayerStat(ID,'kills');
deaths:=GetPlayerStat(ID,'deaths');
if(GetPlayerStat(ID,'team')=5) then
WriteConsole(0,GetPlayerStat(ID,'name')+', you are spectating',Color)
  else if(GetPlayerStat(ID,'deaths')=0) then
  WriteConsole(0,GetPlayerStat(ID,'name')+', your rate is incalculable.',Color)
    else begin
    KD := kills/deaths;
    WriteConsole(0,GetPlayerStat(ID,'name')+', your rate is '+FloatToStr(RoundTo(KD,2)),Color);
    end;
end;

procedure OnPlayerSpeak(ID: byte; Text: string);
begin
  if (Text = '!ratio') or (Text = '!rate') then Ratio(ID);
end;

It always gives me not rounded result, like "Your rate is 1.000000000000".
Anyone can help?

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Rate script, roundto() problem
« Reply #1 on: June 07, 2012, 07:30:37 am »
It's not RoundTo(), it's FloatToStr() displaying all the zeros, your number got clearly rounded to 1. It's a bug of soldatserver itself and has been already reported here. For now you need to workaround it by parsing FloatToStr() output by yourself or switching to linux, it somehow works just fine over there.
« Last Edit: June 07, 2012, 07:33:47 am by FalconPL »
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline StayAlive

  • Major(1)
  • Posts: 8
Re: Rate script, roundto() problem
« Reply #2 on: June 07, 2012, 09:26:51 am »
Thanks, I wasn't sure if it is my fault or not.
I've done my version of it with going around bug and now it's working perfectly, but code is quite funny :D

If someone would like to use it too: (Don't forget to add me to credits!  ;D)
Code: [Select]
procedure Rate(ID: Integer);
var
KD: double;
KD2: double;
KD3: integer;
Number1: integer;
Number2: integer;
Number3: integer;
Kills: double;
Deaths: double;
K1: integer;
D1: integer;
begin
kills:=GetPlayerStat(ID,'kills');
deaths:=GetPlayerStat(ID,'deaths');
k1:=GetPlayerStat(ID,'kills');
d1:=GetPlayerStat(ID,'deaths');
if(GetPlayerStat(ID,'team')=5) then
WriteConsole(0,'Cannot show rate, '+GetPlayerStat(ID,'name')+' is spectating.',Color)
  else if(GetPlayerStat(ID,'deaths')=0) then
  WriteConsole(0,GetPlayerStat(ID,'Name')+'''s rate: '+IntToStr(k1)+'.00 ('+IntToStr(k1)+'/'+IntToStr(d1)+') with '+IntToStr(GetPlayerStat(ID,'Flags'))+' caps.',Color)
    else begin
    KD := kills/deaths;
KD2 := KD*100;
KD3 := Round(KD2);
Number1 := KD3/100;
Number2 := ((KD3 - (Number1*100))/10);
Number3 := (KD3 - ((Number2*10)+(Number1*100)));
    WriteConsole(0,GetPlayerStat(ID,'Name')+'''s rate: '+IntToStr(Number1)+'.'+IntToStr(Number2)+''+IntToStr(Number3)+' ('+intToStr(k1)+'/'+IntToStr(d1)+') with '+IntToStr(GetPlayerStat(ID,'Flags'))+' caps.',Color);
    end;
end;
« Last Edit: June 07, 2012, 01:26:22 pm by StayAlive »

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Rate script, roundto() problem
« Reply #3 on: June 10, 2012, 11:40:45 am »
Resolved in next version, more info: http://bugs.soldat.pl/view.php?id=15
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.