All pastes #781050 Raw Edit

Pause

public text v1 · immutable
·published 2007-11-18 19:17 UTC
rendered paste body
{$VERSION 2.6.0}
const
  UNP_CNTDOWNLENGTH = 5; //-- /unpause: countdown length in seconds
var
  iUnpauseTarget: integer;	//-- /unpause
  inpause,startunpause: boolean;

procedure DoUnpause;
begin
//Command('/pause');
	if (inpause AND NOT startunpause) then
		begin
			command('/say unpausing server in '+IntToStr(UNP_CNTDOWNLENGTH)+' seconds');
			startunpause := true;
			iUnpauseTarget := StrToInt(FormatDate('ss'))+ UNP_CNTDOWNLENGTH;
			if (iUnpauseTarget > 59) then iUnpauseTarget := iUnpauseTarget-60;
		end;
//Command('/pause');
ThreadFunc([],'PauseBack')
end;

procedure PauseBack;
var
i: Integer;
begin
Command('/pause');
 for i:=0 to 25 do begin
  Sleep(1);
  Command('/pause');
 end;
end;

procedure DoPause(const ID:integer);
begin
	if (NOT inpause) then
		begin
			command('/say PAUSED ');
			inpause := true;
		end
	else
		begin
			SayToID(ID,'Its already paused. Use /unp to unpause');
			//command('/pause');		
		end;
end;

procedure DoUnpauseCountdown;
var
  secleft,secnow:integer;
begin
Command('/pause');
SayToID(1,':O');
secnow :=StrToInt(FormatDate('ss'));
	if (secnow <> iUnpauseTarget) then
		begin
			// countdown output
			secleft := iUnpauseTarget - secnow;
			if (secleft<0) then secleft := iUnpauseTarget - secnow + 60;
			command('/say '+IntToStr(secleft));
		end	
	else
		begin
			// unpausing
			command('/say Go!');
			command('/unpause');
			inpause := false;
			startunpause := false;
		end;
end;


procedure AppOnIdle(Ticks: integer);
begin
	if (startunpause) then DoUnpauseCountdown;
end;




function OnCommand(ID: Byte; Text: string): boolean;
begin
  //NOTE: This function will be called when an admin types a / command.
  Result := false; // Return true if you want to ignore the command typed.
  if (Copy(Text,1,6) = '/pause') then DoPause(ID)
  else if (Copy(Text,1,4) = '/unp') then DoUnpause
  else if ((Copy(Text,1,8) = '/restart') or (Copy(Text,1,8) = '/nextmap') or (Copy(Text,1,5) = '/map ')) then
  	begin
  		inpause:= false;
  		startunpause:=false;
	end;
end;


procedure OnPlayerSpeak(ID: byte; Text: string);
begin
 
 Text:= Lowercase(Text);
if (MaskCheck(Text,'pause*') or MaskCheck(Text,'stop*')) and (ServerPort = 23073) then begin command('/pause'); DoPause(ID); end
 else ThreadFunc([ID,Text],'CheckBadWords');

end;