0 Members and 1 Guest are viewing this topic.
const MaxDays=3; AutoOff=true;var TT, SS, MM, HH, DD: integer;procedure ActivateServer();begin TT:=0; SS:=0; MM:=0; HH:=0; DD:=0;end;function ResetTime(const Tvar, Svar, Mvar, Hvar, Dvar:variant; const Value:integer; const Return:boolean):integer;begin Result:=Value; Tvar:=Result; Svar:=Result; Mvar:=Result; Hvar:=Result; Dvar:=Result; if Return = true then begin WriteLn('Time is now '+inttostr(Dvar)+':'+inttostr(Hvar)+':'+inttostr(Mvar)+':'+inttostr(Svar)+':'+inttostr(Tvar)+'.'); end else exit;end;procedure AppOnIdle(Ticks: integer);begin if Ticks Mod (1 * 1) = 0 then begin TT:=TT+1; end; if TT = 60 then begin TT:=0; SS:=SS+1; end; if SS = 60 then begin SS:=0; MM:=MM+1; end; if MM = 60 then begin MM:=0; HH:=HH+1; end; if HH = 24 then begin HH:=0; DD:=DD+1; end; if DD = MaxDays then begin if AutoOff = true then begin ResetTime('TT', 'SS', 'MM', 'HH', 'DD', 0, false); Shutdown(); end else ResetTime('TT', 'SS', 'MM', 'HH', 'DD', 0, false); end;end;function OnPlayerCommand(ID: Byte;Text: string):boolean;var Temp1: string;begin Result:=false; Temp1:=GetPiece(LowerCase(Text), ' ', 0); if Temp1 = '/Time' then begin SayToPlayer(ID, 'Total running time is '+inttostr(DD)+':'+inttostr(HH)+':'+inttostr(MM)+':'+inttostr(SS)+':'+inttostr(TT)+'.'); end;end;function OnCommand(ID: byte; Text: string):boolean;var Temp1: string; Temp2: integer;begin Result:=false; Temp1:=GetPiece(LowerCase(Text), ' ', 0); if Temp1 = '/TimeReset' then begin if StrPos(Text, ' ') > 0 then begin Temp2:=strtoint(GetPiece(Text, ' ', 1)); ResetTime('TT', 'SS', 'MM', 'HH', 'DD', Temp2, false); end else ResetTime('TT', 'SS', 'MM', 'HH', 'DD', 0, false); end;end;
function GetTimeSeconds(): single;var arr: TStringArray; hours, minutes, seconds, milliseconds: integer;begin arr := xsplit(FormatDate('h:n:s:z'), ':'); hours := StrToInt(arr[0]); minutes := StrToInt(arr[1]); seconds := StrToInt(arr[2]); milliseconds := StrToInt(arr[3]); Result := hours * 3600.0 + minutes * 60.0 + seconds + milliseconds/1000.0;end;function GetSecondsInterval(seconds1, seconds2: single): single;begin if seconds2 < seconds1 then seconds2 := seconds2 + 24 * 3600.0; Result := seconds2 - seconds1;end;function FormatSeconds(seconds: single; sign: boolean): string;var parts: TStringArray; n, n2: integer;begin Result := FloatToStr(RoundTo(seconds, 2)); parts := xsplit(Result, '.'); n := StrToInt(parts[0]); if n <= 0 then begin n := -n; parts[0] := IntToStr(n); end; if GetArrayLength(parts) = 1 then begin SetArrayLength(parts, 2); parts[1] := '00'; end; if Length(parts[1]) = 1 then parts[1] := parts[1] + '0'; if n < 10 then begin Result := '0' + parts[0] + '.' + parts[1]; end else if n < 60 then begin Result := parts[0] + '.' + parts[1]; end else begin n2 := n div 60; n := n mod 60; Result := IntToStr(n2) + ':'; if n2 < 10 then Result := '0' + IntToStr(n2) + ':'; if n < 10 then Result := Result + '0' + IntToStr(n) + '.' + parts[1] else Result := Result + IntToStr(n) + '.' + parts[1]; end; if seconds < 0.0 then Result := '-' + Result else if sign = true then Result := '+' + Result;end;
var seconds: single;function OnCommand(ID: byte; Text: string): boolean;begin Result := false; if Text = '/resettimer' then seconds := GetTimeSeconds() else if Text = '/showtimer' then WriteConsole(0, 'Time interval: ' + FormatSeconds(GetSecondsInterval(seconds, GetTimeSeconds())), $FFFF0000);end;