Skip to content

Instantly share code, notes, and snippets.

Created February 5, 2017 15:38
Show Gist options
  • Save anonymous/96d7f09b44795c99166c9c09ac706970 to your computer and use it in GitHub Desktop.
Save anonymous/96d7f09b44795c99166c9c09ac706970 to your computer and use it in GitHub Desktop.
Run mode script v0.0.4 for soldat server
unit Run;
interface
implementation
var Decl: byte;
const
DeffaultMoveSpeed = 0.30; //> is faster < is slow
MouseMovementAccuracy = 0.001; // def 0.001
MovementOffsetSpeedAdd = 0.0073; //0.0004 deffault
CursorMaxSearch = 125;
DeffaultCheckPointRange = 50;d
MinimalCheckPointRange = 40;
BigTextLayer = 2;
type
TCheckPoints = record
Check, RunerActive, StartFinish: boolean;
CheckPointsId, Typ, lap:integer;
Pos: array[1..2] of single;
Range: single;
LastPoss: single;
TimeToActive: array[1..7] of integer;
PlayerPos: array[1..2] of single;
EditMode: array[1..32] of boolean;
end;
type
TPlayerStat = record
RunMode:boolean;
CheckPointGet,Lap:integer;
Timer:int64;
end;
var
MapCheckPoints: TStringList;
PlInfo: array[1..32] of TPlayerStat;
CheckPoint: TCheckPoints;
SpeedMovementText: single;
bot:boolean; botprev: TStringList; xio:int64;
procedure SaveCheckPoint();
begin
if (CheckPoint.Check) then begin
if (CheckPoint.CheckPointsID>MapCheckPoints.Count) then begin
MapCheckPoints.Append('X'+floattostr(CheckPoint.Pos[1])+'Y'+floattostr(CheckPoint.Pos[2])+'R'+floattostr(CheckPoint.Range)+'T'+inttostr(CheckPoint.Typ)+'L'+inttostr(CheckPoint.Lap));
MapCheckPoints.SaveToFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
CheckPoint.Check:=false;
end else
begin
MapCheckPoints.Insert(CheckPoint.CheckPointsID,'X'+floattostr(CheckPoint.Pos[1])+'Y'+floattostr(CheckPoint.Pos[2])+'R'+floattostr(CheckPoint.Range)+'T'+inttostr(CheckPoint.Typ)+'L'+inttostr(CheckPoint.Lap));
MapCheckPoints.Delete(CheckPoint.CheckPointsID+1);
MapCheckPoints.SaveToFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
CheckPoint.Check:=false;
end;
end;
end;
procedure SaveSetLap();
var TempX,TempY,TempRange: single; temptyp:byte;
begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'X',1),'Y',0)); TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'Y',1),'R',0)); TempRange:=strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'R',1),'T',0)); temptyp:=strtoint(GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0));
MapCheckPoints.Insert(0,'X'+floattostr(TempX)+'Y'+floattostr(TempY)+'R'+floattostr(TempRange)+'T'+inttostr(temptyp)+'L'+inttostr(CheckPoint.Lap));
MapCheckPoints.Delete(1);
MapCheckPoints.SaveToFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
end;
procedure SaveSetType(i,typett:integer);
var TempX,TempY,TempRange: single; temptyp:byte;
begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'X',1),'Y',0)); TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'Y',1),'R',0)); TempRange:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'R',1),'T',0)); temptyp:=strtoint(GetPiece(GetPiece(MapCheckPoints[i],'T',1),'L',0));
MapCheckPoints.Insert(i,'X'+floattostr(TempX)+'Y'+floattostr(TempY)+'R'+floattostr(TempRange)+'T'+inttostr(typett)+'L'+inttostr(CheckPoint.Lap));
MapCheckPoints.Delete(i+1);
MapCheckPoints.SaveToFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
end;
function FindCheckPoint(ID: byte; MaxDistance: integer): integer;
var i: integer; TempX, TempY, X2, Y2, CursorMaxDist, NearestDistCursor, MaxDist, Dist: single;
begin
MaxDist:=MaxDistance*MaxDistance; CursorMaxDist:=CursorMaxSearch*CursorMaxSearch;
Result:=-1;
if (MapCheckPoints.Count=0) then exit;
for i := 0 to MapCheckPoints.Count-1 do begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'Y',1),'R',0));
X2:=TempX; Y2:=TempY;
X2:=X2-Players[ID].MouseAimX; Y2:=Y2-Players[ID].MouseAimY; NearestDistCursor:=X2*X2+Y2*Y2;
X2:=TempX; Y2:=TempY;
X2:=X2-Players[ID].X; Y2:=Y2-Players[ID].Y; Dist:=X2*X2+Y2*Y2;
if (NearestDistCursor<CursorMaxDist) and (Dist<MaxDist) then begin
Result:=i;
CursorMaxDist:=NearestDistCursor;
end;
end;
end;
procedure OffAndReset(ID:byte);
begin
CheckPoint.RunerActive:=false;
PlInfo[ID].RunMode:=false;
PlInfo[ID].CheckPointGet:=0;
PlInfo[ID].Timer:=0;
PlInfo[ID].Lap:=1;
Players[ID].Team:=5;
end;
function Commands(Player: TActivePlayer; Text: string): Boolean;
var selectid,b:integer; TempX,TempY,TempRange:single; i:byte;
begin
if (Text='/playbot') then begin
if (File.Exists(Script.Dir+'data/mapsdata/aplos')) then begin
xio:=0;
botprev := File.CreateStringListFromFile(Script.Dir+'data/mapsdata/aplos');
if (bot) then bot:=false else bot:=true;
end;
end;
if (Text='/play') then begin
if (CheckPoint.RunerActive) then begin
for b := 1 to 32 do if (Players[b].Active) and (PlInfo[b].RunMode) then begin
if (Player.ID=b) then begin
OffAndReset(Player.ID);
Players.WriteConsole(Player.Name+' stoped runs!',$FFBB);
end else Player.WriteConsole('Now play: '+Players[b].Name+', plese wait for end his game.',$FFBB);
end;
end else
begin
if (MapCheckPoints.Count>2) then begin
for i := 1 to 32 do if (Players[i].Active) and (i<>Player.ID) and (Players[i].Team<>5) then Players[i].Team:=5;
if not (PlInfo[Player.ID].RunMode) then begin
PlInfo[Player.ID].RunMode:=true; CheckPoint.RunerActive:=true; File.Delete(Script.Dir+'data/mapsdata/aplos');
Players[Player.ID].Team:=4;
PlInfo[Player.ID].CheckPointGet:=0;
PlInfo[Player.ID].Timer:=0;
PlInfo[Player.ID].Lap:=1;
Player.Move(strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'X',1),'Y',0)),strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'Y',1),'R',0)));
Players.WriteConsole(Player.Name+' its run begins!',$FFBB);
end;
end else Player.WriteConsole('This map has too few checkpoints, minimal must be 3.',$FFBB);
end;
end;
if (Player.IsAdmin) then begin
if (Text='/editmodehelp') then begin
Player.WriteConsole('Movement keys : Default : Description',$FFBB);
Player.WriteConsole('Movement key : A,W,S,D : Move Checkpoint',$FFBB);
Player.WriteConsole('Jet key : Right Mouse & Move <> : Press and move left or right to set',$FFBB);
Player.WriteConsole('------------- : --------------------- : movement speed /setcheckpointspeed',$FFBB);
Player.WriteConsole('Reload ket : R : Press to save all settings checkpoint /savecheckpoint',$FFBB);
Player.WriteConsole('Shooting key : Left M. on checkpoint : Press to start edit checkpoint /selectcheckpoint',$FFBB);
Player.WriteConsole('------------- : no editing checkpoint : -----------',$FFBB);
Player.WriteConsole('Throw key : F checkpoing is edit : Cancel edit /canceleditcheckpoint',$FFBB);
Player.WriteConsole('Throw key : F checkpoint non edit : Press to delete checkpoint edit /deletecheckpoint',$FFBB);
Player.WriteConsole('------------- : mouse on checkpoint : -----------',$FFBB);
Player.WriteConsole('Change Weap : q : Press to start create checkpoint',$FFBB);
Player.WriteConsole('Shooting key : If editing checkpoint : Press to set range',$FFBB);
Player.WriteConsole('------------- : Left M. : -----------',$FFBB);
end;
if (Text='/canceleditcheckpoint') then begin
CheckPoint.Check:=false;
Player.WriteConsole('Interrupt, editing or creating checkpoint.',$FFBB);
end;
if (Text='/helpcreate') then begin
Player.WriteConsole('Use move keys to move checkpoint.',$FFBB);
Player.WriteConsole('Use /setcheckpointspeed <num:1,2,3 or 1.123> to change speed move checkpoint.',$FFBB);
Player.WriteConsole('Use /checkpointrange <num:1,2,3 or 1.123> to change range checkpoint.',$FFBB);
Player.WriteConsole('Use /setrunlaps <num:1,2,3> to change run laps.',$FFBB);
Player.WriteConsole('Use /savecheckpoint to accept and save checkpoint.',$FFBB);
Player.WriteConsole('Use /selectcheckpoint <num> to edit checkpoint.',$FFBB);
Player.WriteConsole('Use /deletecheckpoint <num> to delete checkpoint.',$FFBB);
Player.WriteConsole('Use /editmode to ON useful checkpoint editor.',$FFBB);
end;
if (Text='/createcheckpoint') then begin
if (CheckPoint.Check=false) then begin
CheckPoint.Check:=true;
CheckPoint.CheckPointsID:=MapCheckPoints.Count+1;
CheckPoint.Range:=DeffaultCheckPointRange;
CheckPoint.Typ:=2;
CheckPoint.Pos[1]:=Player.X; CheckPoint.PlayerPos[1]:=Player.X;
CheckPoint.Pos[2]:=Player.Y; CheckPoint.PlayerPos[2]:=Player.Y;
Player.WriteConsole('You start create checkpoint: '+inttostr(CheckPoint.CheckPointsID),$FFBB);
Player.WriteConsole('Use move keys to move checkpoint.',$FFBB);
Player.WriteConsole('Use /setcheckpointspeed <num:1,2,3 or 1.123> to change speed move checkpoint.',$FFBB);
Player.WriteConsole('Use /checkpointrange <num:1,2,3 or 1.123> to change range checkpoint.',$FFBB);
Player.WriteConsole('Use /setrunlaps <num:1,2,3> to change run laps.',$FFBB);
Player.WriteConsole('Use /savecheckpoint to accept and save checkpoint.',$FFBB);
Player.WriteConsole('Use /selectcheckpoint <num> to edit checkpoint.',$FFBB);
Player.WriteConsole('Use /deletecheckpoint <num> to delete checkpoint.',$FFBB);
Player.WriteConsole('Use /editmode to ON useful checkpoint editor.',$FFBB);
end else CheckPoint.Check:=false;
end;
if (Text='/editmode') then begin
if (CheckPoint.EditMode[Player.ID]=false) then begin
CheckPoint.EditMode[Player.ID]:=true;
Player.WriteConsole('Edit mode is on!',$FFBB);
Player.WriteConsole('Write /editmodehelp to see help how use.',$FFBB);
end else
begin
CheckPoint.EditMode[Player.ID]:=false;
Player.WriteConsole('Edit mode is off!',$FFBB);
end;
end;
if (Text='/savecheckpoint') then begin
SaveCheckPoint();
Player.WriteConsole('Save all settings checkpoint: '+inttostr(CheckPoint.CheckPointsID+1),$FFBB);
end;
if (Copy(Text,1,17)='/selectcheckpoint') then begin
selectid:=-1;
try
delete(Text,1,17);
selectid:=strtoint(text)-1;
if (selectid>-1) then begin
if (selectid<MapCheckPoints.Count) then begin
CheckPoint.Check:=true;
CheckPoint.CheckPointsID:=selectid;
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'Y',1),'R',0));
TempRange:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'R',1),'T',0));
CheckPoint.Typ:=strtoint(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'T',1),'L',0));
CheckPoint.Pos[1]:=TempX; CheckPoint.PlayerPos[1]:=TempX;
CheckPoint.Pos[2]:=TempY; CheckPoint.PlayerPos[2]:=TempY;
CheckPoint.Range:=TempRange;
Player.WriteConsole('Select checkpoint:'+text,$FFBB);
end else Player.WriteConsole('Checkpoint id is too high. The highest id: '+inttostr(MapCheckPoints.Count),$FFBB);
end else Player.WriteConsole('ID must be greater than 0.',$FFBB);
except
Player.WriteConsole('An error occurred, please enter a valid number of checkpoint.',$FFBB);
end;
end;
if (Copy(Text,1,17)='/deletecheckpoint') then begin
if not (CheckPoint.Check) then begin
selectid:=-1;
try
delete(Text,1,17);
selectid:=strtoint(text)-1;
if (selectid>-1) then begin
if (selectid<MapCheckPoints.Count) then begin
Player.WriteConsole('Remove checkpoint:'+text,$FFBB);
if (selectid=0) and (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='4') then begin
Player.WriteConsole('We see that delete Start/Finish checkpoint. And see lap '+inttostr(CheckPoint.Lap)+', we set laps to 1 ;)',$FFBB);
CheckPoint.Lap:=1;
SaveSetLap();
end;
if (selectid=0) and (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='1') then begin
SaveSetType(MapCheckPoints.Count-1,2);
Player.WriteConsole('We detect you delete start checkpoint. We change finish checkpoint to normal.',$FFBB);
end;
if (selectid=MapCheckPoints.Count-1) and (GetPiece(GetPiece(MapCheckPoints[MapCheckPoints.Count-1],'T',1),'L',0)='3') then begin
SaveSetType(0,2);
Player.WriteConsole('We detect you delete finish checkpoint. We change start checkpoint to normal.',$FFBB);
end;
MapCheckPoints.Delete(selectid);
MapCheckPoints.SaveToFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
for b := 0 to MapCheckPoints.Count+1 do Players.WorldText(b+1,'',70,$33CC00,0.0001,0,0);
end else Player.WriteConsole('Checkpoint id is too high. The highest id: '+inttostr(MapCheckPoints.Count),$FFBB);
end else Player.WriteConsole('ID must be greater than 0.',$FFBB);
except
Player.WriteConsole('An error occurred, please enter a valid number of checkpoint.',$FFBB);
end;
end else Player.WriteConsole('You can not remove a checkpoint when creating or editing other checkpoint.',$FFBB);
end;
if (Copy(Text,1,16)='/checkpointrange') then begin
if (CheckPoint.Check) then begin
try
delete(Text,1,16);
TempRange:=strtofloat(text);
if (TempRange<MinimalCheckPointRange) then begin
TempRange:=MinimalCheckPointRange;
Player.WriteConsole('Value is higher than the minimum, I set to minimal: '+formatfloat('0.0000',MinimalCheckPointRange),$FFBB);
end else Player.WriteConsole('Checkpoint range set to: '+formatfloat('0.0000',TempRange),$FFBB);
except
Player.WriteConsole('An error occurred, please enter a valid number (can be 123 etc or 1.1234). I set to default value: '+formatfloat('0.0000',DeffaultCheckPointRange),$FFBB);
TempRange:=DeffaultCheckPointRange;
end;
CheckPoint.Range:=TempRange;
end;
end;
if (Copy(Text,1,11)='/setrunlaps') then begin
if (MapCheckPoints.Count>2) then begin
if (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='4') then begin
try
delete(Text,1,11);
selectid:=strtoint(text);
if (selectid<=0) then begin
selectid:=1;
Player.WriteConsole('The minimum number of laps is 1. Changed to the minimum value.',$FFBB);
end else Player.WriteConsole('Changed the number of laps on '+inttostr(selectid)+'.',$FFBB);
except
Player.WriteConsole('An error occurred, please enter a valid number (can be 123 etc). I set to last value: '+inttostr(Checkpoint.Lap),$FFBB);
selectid:=Checkpoint.Lap;
end;
CheckPoint.Lap:=selectid;
SaveSetLap();
end else
begin
Player.WriteConsole('First plese change "Checkpoint 1!" or "[ Start ]" change to checkpoint Start/Finish.',$FFBB);
Player.WriteConsole('To change first start edit checkpoint 1 next write /setcheckpointtype 4 and save checkpoint.',$FFBB);
end;
end else Player.WriteConsole('First create minimum 3 checkpoints.',$FFBB);
end;
if (Copy(Text,1,18)='/setcheckpointtype') then begin
if (CheckPoint.Check) then begin
if (MapCheckPoints.Count>2) then begin
try
delete(Text,1,18);
selectid:=strtoint(text);
if (selectid>0) then begin
if (selectid<5) then begin
if (CheckPoint.CheckPointsId<=MapCheckPoints.Count) then begin
case selectid of
1: begin
if (CheckPoint.CheckPointsId=0) then begin
CheckPoint.Typ:=selectid;
Player.WriteConsole('Checkpoint change to start.',$FFBB);
if (GetPiece(GetPiece(MapCheckPoints[MapCheckPoints.Count-1],'T',1),'L',0)<>'3') then begin
SaveSetType(MapCheckPoints.Count-1,3);
Player.WriteConsole('We setup for you to finish checkpoint type on the last checkpoint.',$FFBB);
end;
if (CheckPoint.Lap>1) then begin
Player.WriteConsole('We see that disable laps mode. And see lap '+inttostr(CheckPoint.Lap)+', we set laps to 1 ;)',$FFBB);
CheckPoint.Lap:=1;
SaveSetLap();
end;
end else Player.WriteConsole('To set to start checkpoint id must be 1.',$FFBB);
end;
2: begin
CheckPoint.Typ:=selectid;
Player.WriteConsole('Checkpoint change to normal.',$FFBB);
if (CheckPoint.CheckPointsId=0) then begin
if (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='1') then begin
SaveSetType(0,2);
Player.WriteConsole('You set start checkpoint to normal we set checkpoint finish also to normal checkpoin for you.',$FFBB);
end;
if (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='4') then begin
Player.WriteConsole('We detect checkpoint Start/Finish and we disable this checkpoint.',$FFBB);
if (CheckPoint.Lap>1) then begin
Player.WriteConsole('We see that disable laps mode. And see lap '+inttostr(CheckPoint.Lap)+', we set laps to 1 ;)',$FFBB);
CheckPoint.Lap:=1;
SaveSetLap();
end;
end;
end;
if (CheckPoint.CheckPointsId=MapCheckPoints.Count-1) then begin
if (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='1') then begin
SaveSetType(0,2);
Player.WriteConsole('You set finish checkpoint to normal we set checkpoint start also to normal checkpoin for you.',$FFBB);
end;
end;
end;
3: begin
if (CheckPoint.CheckPointsId=MapCheckPoints.Count-1) then begin
CheckPoint.Typ:=selectid;
Player.WriteConsole('Checkpoint change to end.',$FFBB);
if (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)<>'1') then begin
SaveSetType(0,1);
Player.WriteConsole('We setup for you to start checkpoint type on at the first checkpoint.',$FFBB);
end;
if (CheckPoint.Lap>1) then begin
Player.WriteConsole('We see that disable laps mode. And see lap '+inttostr(CheckPoint.Lap)+', we set laps to 1 ;)',$FFBB);
CheckPoint.Lap:=1;
SaveSetLap();
end;
end else Player.WriteConsole('To set to start checkpoint id must be '+inttostr(MapCheckPoints.Count)+'.'+inttostr(CheckPoint.CheckPointsId),$FFBB);
end;
4: begin
if (CheckPoint.CheckPointsId=0) then begin
CheckPoint.Typ:=selectid;
if (GetPiece(GetPiece(MapCheckPoints[MapCheckPoints.Count-1],'T',1),'L',0)='3') then begin
SaveSetType(MapCheckPoints.Count-1,2);
Player.WriteConsole('We find finish checkpoint and change to normal checkpoint.',$FFBB);
end else Player.WriteConsole('Checkpoint change to start and end.',$FFBB);
end else Player.WriteConsole('To set to start checkpoint id must be 1.',$FFBB);
end;
end;
end else Player.WriteConsole('Plese first save new checkpoint next edit and start change checkpoint type.',$FFBB);
end else Player.WriteConsole('Checkpoint type too high number. 1 start, 2 normal, 3 end, 4 start and end',$FFBB);
end else Player.WriteConsole('Checkpoint type too low number. 1 start, 2 normal, 3 end, 4 start and end',$FFBB);
except
Player.WriteConsole('An error occurred, please enter a valid number(1-4). We set to normal checkpoint.',$FFBB);
selectid:=2;
end;
end else Player.WriteConsole('Must create minimum 3 checkpoint to start change type.',$FFBB);
end else Player.WriteConsole('First start edit checkpoint.',$FFBB);
end;
if (Copy(Text,1,19)='/setcheckpointspeed') then begin
try
delete(Text,1,19);
TempRange:=strtofloat(text);
if (TempRange<0.01) then begin
TempRange:=0.01;
Player.WriteConsole('Value is higher than the minimum, I set to minimal: 0.01',$FFBB);
end else
begin
Player.WriteConsole('Last speed: '+formatfloat('0.0000',SpeedMovementText)+', default: '+formatfloat('0.0000',DeffaultMoveSpeed),$FFBB);
Player.WriteConsole('Checkpoint movement speed set to: '+formatfloat('0.0000',TempRange),$FFBB);
end;
except
Player.WriteConsole('An error occurred, please enter a valid number (can be 123 etc or 1.1234). I set to default value: '+formatfloat('0.0000',DeffaultMoveSpeed),$FFBB);
TempRange:=DeffaultMoveSpeed;
end;
SpeedMovementText:=TempRange;
end;
end;
Result:=False;
end;
procedure ChangeAfter(Next: string);
begin
if (File.Exists(Script.Dir+'data/mapsdata/'+next)) then begin
MapCheckPoints := File.CreateStringListFromFile(Script.Dir+'data/mapsdata/'+next);
if (MapCheckPoints.Count>0) then begin
CheckPoint.Lap := strtoint(GetPiece(MapCheckPoints[0],'L',1));
if (CheckPoint.Lap<1) then CheckPoint.Lap:=1;
end else CheckPoint.Lap:=1;
end else
begin
MapCheckPoints := File.CreateStringList();
CheckPoint.Lap:=1;
end;
end;
function DistplayTime(times:double):string;
var min,sec,ms: integer; temp: double;
begin
min := trunc(times/3600.0);
sec := trunc((times-(min*3600.0))/60.0);
temp:= times-((min*3600.0)+(sec*60.0));
ms := trunc(temp/60.0*1000);
if (min>0) then Result:=inttostr(min)+'min, ';
if (sec>0) then if (result<>'') then Result:=Result+inttostr(sec)+'sec, ' else Result:=inttostr(sec)+'sec, ';
if (ms>0) then if (result<>'') then Result:=Result+inttostr(ms)+'ms' else Result:=inttostr(ms)+'ms';
if (Result[Length(Result)]=',') then Result:=Copy(Result,1,Length(Result)-1);
end;
procedure AppOnIdleSC3(Ticks: integer);
var SearchRunnerID,CheckPType: byte; i,b: integer; tempcolor: longint; TempX,TempY,TempRange,TempAcc,XTam,YTam: single; kd: double; NS, NW: TNewWeapon; TempTimes: string;
begin
//--- Search Runner ID ---\\
SearchRunnerID:=33;
for i := 1 to 32 do if (Players[i].Active) and (PlInfo[i].RunMode) then SearchRunnerID:=i;
//--- Display Timer ---\\
if (CheckPoint.RunerActive) and (SearchRunnerID<33) then begin
PlInfo[SearchRunnerID].Timer := PlInfo[SearchRunnerID].Timer+1;
TempTimes := DistplayTime(PlInfo[SearchRunnerID].Timer);
Players[SearchRunnerID].BigText(BigTextLayer,'Your time: '+TempTimes, 20,$FFBB,0.065,12,425);
for i := 1 to 32 do begin
if (Players[i].Active) and (i<>SearchRunnerID) then begin
Players[i].BigText(BigTextLayer,Players[SearchRunnerID].Name+' time: '+TempTimes, 20,$FFBB,0.065,12,425);
end;
end;
end;
//--- Display All Checkpoints ---\\
for i := 0 to MapCheckPoints.Count-iif(CheckPoint.StartFinish,0,1) do begin
if (CheckPoint.CheckPointsID=i) and (CheckPoint.Check) then continue;
//--- Get Temp Checkpoin Info ---\\
if (i=MapCheckPoints.Count) then begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'Y',1),'R',0));
TempRange:=strtofloat(GetPiece(GetPiece(MapCheckPoints[0],'R',1),'T',0));
CheckPType:=strtoint(GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0));
end else
begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'Y',1),'R',0));
TempRange:=strtofloat(GetPiece(GetPiece(MapCheckPoints[i],'R',1),'T',0));
CheckPType:=strtoint(GetPiece(GetPiece(MapCheckPoints[i],'T',1),'L',0));
end;
if (CheckPoint.RunerActive) and (SearchRunnerID<33) then begin
if (PlInfo[SearchRunnerID].CheckPointGet=i) then begin
TempAcc:=Distance(TempX,TempY,Players[SearchRunnerID].X,Players[SearchRunnerID].Y);
if (TempAcc<=TempRange) then begin
PlInfo[SearchRunnerID].CheckPointGet:=PlInfo[SearchRunnerID].CheckPointGet+1;
if (PlInfo[SearchRunnerID].CheckPointGet=MapCheckPoints.Count+iif(CheckPoint.StartFinish,1,0)) then begin
if (PlInfo[SearchRunnerID].Lap=CheckPoint.Lap) then begin
OffAndReset(SearchRunnerID);
Players.WriteConsole(Players[SearchRunnerID].Name+' have time: '+TempTimes,$FFBB);
Players[SearchRunnerID].BigText(BigTextLayer,'Your time: '+TempTimes, 250,$FFBB,0.065,12,425);
for b := 1 to 32 do begin
if (Players[b].Active) and (b<>SearchRunnerID) then begin
Players[b].BigText(BigTextLayer,Players[SearchRunnerID].Name+' time: '+TempTimes, 250,$FFBB,0.065,12,425);
end;
end;
end else
begin
PlInfo[SearchRunnerID].Lap:=PlInfo[SearchRunnerID].Lap+1;
PlInfo[SearchRunnerID].CheckPointGet:=0;
end;
end;
end;
end;
//--- Get Checkpoint Color ---\\
if (i<PlInfo[SearchRunnerID].CheckPointGet) then tempcolor:=$FF9900 else tempcolor:=$33CC00;
//--- Display Checkpoint If Runer Active ---\\
case (CheckPType) of
1: begin Players.WorldText(i+1,'[ Start ]',70,tempcolor,0.055,TempX-31.95,TempY); CheckPoint.StartFinish:=false; end;
2: Players.WorldText(i+1,'Checkpoint '+inttostr(i+1)+'!',70,tempcolor,0.055,TempX-43.5,TempY);
3: begin Players.WorldText(i+1,'[ Finish! ]',70,tempcolor,0.055,TempX-34,TempY); CheckPoint.StartFinish:=false; end;
4: if (PlInfo[SearchRunnerID].CheckPointGet>1) then begin
CheckPoint.StartFinish:=true;
if (CheckPoint.Lap>1) then Players.WorldText(i+MapCheckPoints.Count+12,'[ Lap '+inttostr(PlInfo[SearchRunnerID].Lap)+'/'+inttostr(CheckPoint.Lap)+'! ]',70,tempcolor+12000,0.035,TempX-22.8,TempY-6.5);
Players.WorldText(i+1,'[ Finish! ]',70,tempcolor,0.055,TempX-34,TempY);
end else
begin
CheckPoint.StartFinish:=false;
if (CheckPoint.Lap>1) then Players.WorldText(i+MapCheckPoints.Count+12,'[ Lap '+inttostr(PlInfo[SearchRunnerID].Lap)+'/'+inttostr(CheckPoint.Lap)+'! ]',70,tempcolor+12000,0.035,TempX-22.8,TempY-6.5);
Players.WorldText(i+1,'[ Start ]',70,tempcolor,0.055,TempX-31.95,TempY);
end;
end;
end else
begin
//--- If No Runer Active Display Checkpoint ---\\
case (CheckPType) of
1: Players.WorldText(i+1,'[ Start ]',70,$33CC00,0.055,TempX-31.95,TempY);
2: Players.WorldText(i+1,'Checkpoint '+inttostr(i+1)+'!',70,$33CC00,0.055,TempX-43.5,TempY);
3: Players.WorldText(i+1,'[ Finish! ]',70,$33CC00,0.055,TempX-34,TempY);
4: begin
if (CheckPoint.Lap>1) then Players.WorldText(i+MapCheckPoints.Count+12,'[ Lap '+inttostr(CheckPoint.Lap)+' ]',70,$FF9900+12000,0.035,TempX-17,TempY-6.5);
Players.WorldText(i+1,'[Start/Finish]',70,$33CC00,0.055,TempX-45.5,TempY);
end;
end;
end;
end;
//-- Disable Edit Mode And More If Player Is Runing --\\
if (CheckPoint.RunerActive) then WriteLnFile(Script.Dir+'data/mapsdata/aplos',Floattostr(Players[SearchRunnerID].X)+':'+Floattostr(Players[SearchRunnerID].Y));
if (bot) then begin
XTam:= strtofloat(GetPiece(botprev[xio],':',0));
YTam:= strtofloat(GetPiece(botprev[xio],':',1));
map.CreateBullet(XTam,YTam , 0, 0, 0, 5, Players[1]);
if xio< botprev.count then xio:=xio+1;
if xio= botprev.count then begin
bot:=false;
File.Delete(Script.Dir+'data/mapsdata/aplos');
end;
end;
if (CheckPoint.RunerActive) then exit;
for i := 1 to 32 do begin
if (Players[i].Active) and (Players[i].IsAdmin) and (CheckPoint.Check) then begin
//--- Move Text ---\\
if (Players[i].KeyUp) then CheckPoint.Pos[2]:=CheckPoint.Pos[2]-SpeedMovementText;
if (Players[i].KeyCrouch) then CheckPoint.Pos[2]:=CheckPoint.Pos[2]+SpeedMovementText;
if (Players[i].KeyLeft) then CheckPoint.Pos[1]:=CheckPoint.Pos[1]-SpeedMovementText;
if (Players[i].KeyRight) then CheckPoint.Pos[1]:=CheckPoint.Pos[1]+SpeedMovementText;
//--- Off Move Player ---\\
Players[i].Move(CheckPoint.PlayerPos[1],CheckPoint.PlayerPos[2]);
Players[i].SetVelocity(0,0);
//--- Display Text ---\\
Players.WorldText(MapCheckPoints.Count+11,'[-]',55,$FF00FF ,0.025,CheckPoint.Pos[1]-3.8,CheckPoint.Pos[2]);
Players.WorldText(MapCheckPoints.Count+2,'Pos X: '+FormatFloat('0.0000',CheckPoint.Pos[1])+', Pos Y: '+FormatFloat('0.0000',CheckPoint.Pos[2])+', Range: '+FormatFloat('0.0000',CheckPoint.Range),70,$FF9999,0.025,CheckPoint.Pos[1]-71.5,CheckPoint.Pos[2]-3.1);
case (CheckPoint.Typ) of
1: Players.WorldText(MapCheckPoints.Count+3,'[ Start ]',70,$33CC00,0.055,CheckPoint.Pos[1]-31.95,CheckPoint.Pos[2]);
2: if (CheckPoint.CheckPointsID>MapCheckPoints.Count) then Players.WorldText(MapCheckPoints.Count+3,'Checkpoint '+inttostr(CheckPoint.CheckPointsID)+'!',70,$33CC00,0.055,CheckPoint.Pos[1]-43.5,CheckPoint.Pos[2]) else Players.WorldText(MapCheckPoints.Count+3,'Checkpoint '+inttostr(CheckPoint.CheckPointsID+1)+'!',70,$33CC00,0.055,CheckPoint.Pos[1]-43.5,CheckPoint.Pos[2]);
3: Players.WorldText(MapCheckPoints.Count+3,'[ Finish! ]',70,$33CC00,0.055,CheckPoint.Pos[1]-34,CheckPoint.Pos[2]);
4: begin
if (CheckPoint.Lap>1) then Players.WorldText(MapCheckPoints.Count+13,'[ Lap '+inttostr(CheckPoint.Lap)+' ]',70,$FF9900+12000,0.035,CheckPoint.Pos[1]-17,CheckPoint.Pos[2]-6.5);
Players.WorldText(MapCheckPoints.Count+3,'[Start/Finish]',70,$33CC00,0.055,CheckPoint.Pos[1]-45.5,CheckPoint.Pos[2]);
end;
end;
end;
//--- Edit Mode ---\\
if (Players[i].Active) and (Players[i].IsAdmin) and (CheckPoint.EditMode[i]) then begin
//--- Set Weapon For Good Mouse Work ---\\
if (CheckPoint.TimeToActive[6]>0) or (CheckPoint.TimeToActive[3]>0) then begin
NS:=TNewWeapon.Create(); NS.WType:=12; NS.Ammo:=1;
NW:=TNewWeapon.Create(); NW.WType:=255; NW.Ammo:=1;
Players[i].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end else
begin
NS:=TNewWeapon.Create(); NS.WType:=255; NS.Ammo:=1;
NW:=TNewWeapon.Create(); NW.WType:=255; NW.Ammo:=1;
Players[i].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end;
//--- Mouse Move Speed Add ---\\
if (Players[i].KeyJetpack) and (CheckPoint.Check) then begin
if (CheckPoint.TimeToActive[1]>=10) then begin
if CheckPoint.TimeToActive[1]=10 then begin
CheckPoint.LastPoss:=single(Players[i].MouseAimX);
CheckPoint.TimeToActive[1]:=CheckPoint.TimeToActive[1]+1;
end;
TempAcc:=CheckPoint.LastPoss-single(Players[i].MouseAimX);
if TempAcc>MouseMovementAccuracy then SpeedMovementText:=SpeedMovementText-MovementOffsetSpeedAdd else if TempAcc<-MouseMovementAccuracy then SpeedMovementText:=SpeedMovementText+MovementOffsetSpeedAdd;
if (SpeedMovementText<0.01) then SpeedMovementText:=0.01;
CheckPoint.LastPoss:=single(Players[i].MouseAimX);
Players.WorldText(MapCheckPoints.Count+4,'SpeedMove: '+FormatFloat('0.0000',SpeedMovementText),70,$33CC00,0.035,Players[i].MouseAimX-38,Players[i].MouseAimY-12.1);
end else CheckPoint.TimeToActive[1]:=CheckPoint.TimeToActive[1]+1;
end else CheckPoint.TimeToActive[1]:=0;
//--- Key Save Check Point ---\\
if (Players[i].KeyReload) and (CheckPoint.Check) then begin
if (CheckPoint.TimeToActive[2]>=18) then begin
Players.WorldText(MapCheckPoints.Count+5,'Save Complete :)',70,$CC3300,0.035,CheckPoint.Pos[1]-32.4,CheckPoint.Pos[2]-8.8);
SaveCheckPoint();
end else
begin
//-- Display Save Info --\\
kd := (CheckPoint.TimeToActive[2]/18.0)*100;
Players.WorldText(MapCheckPoints.Count+5,'Save '+formatfloat('0.00',kd)+'% :)',70,$CC3300,0.035,CheckPoint.Pos[1]-28,CheckPoint.Pos[2]-8.8);
CheckPoint.TimeToActive[2]:=CheckPoint.TimeToActive[2]+1;
end;
end else CheckPoint.TimeToActive[2]:=0;
//--- Key Get Edit ---\\
if (Players[i].KeyShoot) and (CheckPoint.Check=false) then begin
if (CheckPoint.TimeToActive[3]>=45) then begin
//-- Start Edit --\\
CheckPoint.CheckPointsID:=FindCheckPoint(i,700);
if (CheckPoint.CheckPointsID>-1) then begin
CheckPoint.Check:=true;
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'Y',1),'R',0));
CheckPoint.Typ:=strtoint(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'T',1),'L',0));
CheckPoint.Pos[1]:=TempX; CheckPoint.PlayerPos[1]:=TempX;
CheckPoint.Pos[2]:=TempY; CheckPoint.PlayerPos[2]:=TempY;
CheckPoint.Range:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'R',1),'T',0));
Players.WorldText(MapCheckPoints.Count+6,'Start Editing :)',70,$CC3300,0.035,CheckPoint.Pos[1]-27.5,CheckPoint.Pos[2]-8.8);
end else if (CheckPoint.CheckPointsID=-1) then CheckPoint.TimeToActive[3]:=0;
end else
begin
//-- Search Check Point --\\
CheckPoint.CheckPointsID:=FindCheckPoint(i,700);
if (CheckPoint.CheckPointsID>-1) then begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'Y',1),'R',0));
//-- Display Start Edit Info --\\
kd := (CheckPoint.TimeToActive[3]/45.0)*100;
Players.WorldText(MapCheckPoints.Count+6,'Begin Edit '+formatfloat('0.00',kd)+'% :)',70,$CC3300,0.035,TempX-38,TempY-4.2);
CheckPoint.TimeToActive[3]:=CheckPoint.TimeToActive[3]+1;
end else if (CheckPoint.CheckPointsID=-1) then CheckPoint.TimeToActive[3]:=0;
end;
end else CheckPoint.TimeToActive[3]:=0;
//--- Key Canceled Edit ---\\
if (Players[i].KeyThrow) and (CheckPoint.Check) then begin
if (CheckPoint.TimeToActive[4]>=18) then begin
//-- Canceled Edit --\\
Players.WorldText(MapCheckPoints.Count+7,'Canceled Editing!',70,$CC3300,0.035,CheckPoint.Pos[1]-33,CheckPoint.Pos[2]-8.8);
CheckPoint.Check:=false;
end else
begin
//-- Display Canceled Edit Info --\\
kd := (CheckPoint.TimeToActive[4]/18.0)*100;
Players.WorldText(MapCheckPoints.Count+7,'Canceled Editing '+formatfloat('0.00',kd)+'%',70,$CC3300,0.035,CheckPoint.Pos[1]-46.5,CheckPoint.Pos[2]-8.8);
CheckPoint.TimeToActive[4]:=CheckPoint.TimeToActive[4]+1;
end;
end else CheckPoint.TimeToActive[4]:=0;
//--- Key Create Checkpoint ---\\
if (Players[i].KeyChangeWeap) and (CheckPoint.Check=false) then begin
if (CheckPoint.TimeToActive[5]>=25) then begin
//-- Ket Create Checkpoint --\\
CheckPoint.Check:=true;
CheckPoint.CheckPointsID:=MapCheckPoints.Count+1;
CheckPoint.Pos[1]:=Players[i].X; CheckPoint.PlayerPos[1]:=Players[i].X;
CheckPoint.Pos[2]:=Players[i].Y; CheckPoint.PlayerPos[2]:=Players[i].Y;
CheckPoint.Range:=DeffaultCheckPointRange;
CheckPoint.Typ:=2;
Players.WorldText(MapCheckPoints.Count+8,'Create Create Checkpoint!',70,$CC3300,0.035,CheckPoint.Pos[1]-50.5,CheckPoint.Pos[2]-8.8);
end else
begin
//-- Display Create Checkpoint Info --\\
kd := (CheckPoint.TimeToActive[5]/25.0)*100;
Players.WorldText(MapCheckPoints.Count+8,'Create Checkpoint '+formatfloat('0.00',kd)+'%',70,$CC3300,0.035,Players[i].X-51,Players[i].Y-8.8);
CheckPoint.TimeToActive[5]:=CheckPoint.TimeToActive[5]+1;
end;
end else CheckPoint.TimeToActive[5]:=0;
//--- Mouse Set Range ---\\
if (Players[i].KeyShoot) and (CheckPoint.Check) then begin
if (CheckPoint.TimeToActive[6]>=22) then begin
CheckPoint.Range := Distance(CheckPoint.Pos[1],CheckPoint.Pos[2],single(Players[i].MouseAimX),single(Players[i].MouseAimY));
if (CheckPoint.Range<MinimalCheckPointRange) then CheckPoint.Range:=MinimalCheckPointRange;
Players.WorldText(MapCheckPoints.Count+9,'Range: '+formatfloat('0.0000',CheckPoint.Range),70,$33CC00,0.035,Players[i].MouseAimX-31.3,Players[i].MouseAimY-12.1);
end else CheckPoint.TimeToActive[6]:=CheckPoint.TimeToActive[6]+1;
end else CheckPoint.TimeToActive[6]:=0;
//--- Key Delete Checkpoint ---\\
if (Players[i].KeyThrow) and (CheckPoint.Check=false) then begin
if (CheckPoint.TimeToActive[7]>=45) then begin
CheckPoint.CheckPointsID:=FindCheckPoint(i,700);
if (CheckPoint.CheckPointsID>-1) then begin
Players[i].WriteConsole('Remove checkpoint: '+inttostr(CheckPoint.CheckPointsID+1),$FFBB);
if (CheckPoint.CheckPointsID=0) and (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='4') then begin
Players[i].WriteConsole('We see that delete Start/Finish checkpoint. And see lap '+inttostr(CheckPoint.Lap)+', we set laps to 1 ;)',$FFBB);
CheckPoint.Lap:=1;
SaveSetLap();
end;
if (CheckPoint.CheckPointsID=0) and (GetPiece(GetPiece(MapCheckPoints[0],'T',1),'L',0)='1') then begin
SaveSetType(MapCheckPoints.Count-1,2);
Players[i].WriteConsole('We detect you delete start checkpoint. We change finish checkpoint to normal.',$FFBB);
end;
if (CheckPoint.CheckPointsID=MapCheckPoints.Count-1) and (GetPiece(GetPiece(MapCheckPoints[MapCheckPoints.Count-1],'T',1),'L',0)='3') then begin
SaveSetType(0,2);
Players[i].WriteConsole('We detect you delete finish checkpoint. We change start checkpoint to normal.',$FFBB);
end;
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'Y',1),'R',0));
Players.WorldText(MapCheckPoints.Count+10,'Delete Complete :)',70,$CC3300,0.035,TempX-37,TempY-4.2);
MapCheckPoints.Delete(CheckPoint.CheckPointsID); CheckPoint.TimeToActive[7]:=0;
MapCheckPoints.SaveToFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
for b := 0 to MapCheckPoints.Count+1 do Players.WorldText(b+1,'',70,$33CC00,0.0001,0,0);
end else if (CheckPoint.CheckPointsID=-1) then CheckPoint.TimeToActive[7]:=0;
end else
begin
//-- Display Delete Info --\\-
CheckPoint.CheckPointsID:=FindCheckPoint(i,700);
if (CheckPoint.CheckPointsID>-1) then begin
TempX:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'X',1),'Y',0));
TempY:=strtofloat(GetPiece(GetPiece(MapCheckPoints[CheckPoint.CheckPointsID],'Y',1),'R',0));
kd := (CheckPoint.TimeToActive[7]/45.0)*100;
Players.WorldText(MapCheckPoints.Count+10,'Delete '+formatfloat('0.00',kd)+'% :)',70,$CC3300,0.035,TempX-32.5,TempY-4.2);
CheckPoint.TimeToActive[7]:=CheckPoint.TimeToActive[7]+1;
end else if (CheckPoint.CheckPointsID=-1) then CheckPoint.TimeToActive[7]:=0;
end;
end else CheckPoint.TimeToActive[7]:=0;
end;
end;
end;
Procedure JoinTeam(Player: TActivePlayer; Team: TTeam);
begin
if (CheckPoint.RunerActive) then begin
if not (PlInfo[Player.ID].RunMode) and (Team.ID<>5) then Player.Team:=5;
if (PlInfo[Player.ID].RunMode) and (Team.ID<>4) then begin
OffAndReset(Player.ID);
Players.WriteConsole(Player.Name+' stoped runing!',$FFBB);
end;
end;
end;
procedure LeaveGame(Player: TActivePlayer; Kicked: Boolean);
begin
if (PlInfo[Player.ID].RunMode) then OffAndReset(Player.ID);
if (CheckPoint.EditMode[Player.ID]) then begin
CheckPoint.EditMode[Player.ID]:=false;
CheckPoint.Check:=false;
end;
end;
initialization
begin
//---Instal Script ---\\
for Decl := 1 to 32 do Players[Decl].OnCommand := @Commands;
for Decl := 1 to 5 do Game.Teams[Decl].OnJoin := @JoinTeam;
Game.TickThreshold := 1;
Game.OnLeave := @LeaveGame;
Map.OnAfterMapChange := @ChangeAfter;
Game.OnClockTick := @AppOnIdleSC3;
//-- Vars --\\
SpeedMovementText:=DeffaultMoveSpeed;
//--- Load Map Checkpoints ---\\
if (File.Exists(Script.Dir+'data/mapsdata/'+Game.CurrentMap)) then begin
MapCheckPoints := File.CreateStringListFromFile(Script.Dir+'data/mapsdata/'+Game.CurrentMap);
if (MapCheckPoints.Count>0) then begin
CheckPoint.Lap := strtoint(GetPiece(MapCheckPoints[0],'L',1));
if (CheckPoint.Lap<1) then CheckPoint.Lap:=1;
end else CheckPoint.Lap:=1;
end else
begin
MapCheckPoints := File.CreateStringList();
CheckPoint.Lap:=1;
end;
end;
finalization;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment