-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.pas
98 lines (75 loc) · 1.94 KB
/
utils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
procedure logWrapper(id: byte; text: string; severity: eLogSeverity);
begin
if (id = 255) then writeln(ScriptName + '> ' + text)
else case (severity) of
sevInfo: writeconsole(id, text, ColorInfo);
sevWarning: writeconsole(id, text, ColorWarning);
sevError: writeconsole(id, text, ColorError);
end;
end;
procedure logInfo(id: byte; text: string);
begin
logWrapper(id, text, sevInfo);
end;
procedure logWarning(id: byte; text: string);
begin
logWrapper(id, text, sevWarning);
end;
procedure logError(id: byte; text: string);
begin
logWrapper(id, text, sevError);
end;
function floor(val: double): integer;
begin
result := round(val - 0.5);
end;
function ceil(val: double): integer;
begin
result := round(val + 0.5);
end;
function plural(value: integer; text: string): string;
begin
result := iif(value = 1, text, text + 's');
end;
procedure setActive(playerId: byte);
begin
if (getplayerstat(playerId, 'active')) then
player[playerId].active := true;
end;
procedure setInactive(playerId: byte);
begin
player[playerId].active := false;
end;
function isActive(playerId: byte): boolean;
begin
result := false;
if ((playerId < 1) or (playerId > 32)) then exit;
result := player[playerId].active;
end;
function playerCount(): byte;
var playerId: byte;
begin
result := 0;
for playerId := 1 to 32 do
if (isActive(playerId))
then inc(result, 1);
end;
function usedAdminCommandAlready(callerId: byte): boolean;
begin
if (callerId = 255) then begin
result := true;
exit;
end;
result := player[callerId].lastCmd <> cmdNone;
end;
procedure clearLastCommand(callerId: byte);
begin
if (callerId = 255) then exit;
player[callerId].lastCmd := cmdNone;
end;
function getParams(text: string): string;
var pos: integer;
begin
pos := length(getpiece(text, ' ', 0)) + 1;
result := copy(text, pos + 1, length(text) - pos);
end;