-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlateconfigs.sp
More file actions
140 lines (109 loc) · 3.46 KB
/
lateconfigs.sp
File metadata and controls
140 lines (109 loc) · 3.46 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma semicolon 1
#define DEBUG 0
#define PLUGIN_AUTHOR "Remzo"
#define PLUGIN_VERSION "1.00"
#define TAG "[LateConfigs]"
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
bool isMapEnd;
ArrayList convarList;
ConVar cvEnabled;
ConVar cvDelay;
public Plugin myinfo =
{
name = "Late configs",
author = PLUGIN_AUTHOR,
description = "Runs comamnds after a specified time from map start",
version = PLUGIN_VERSION,
url = "https://strefagier.com.pl"
};
public void OnPluginStart()
{
cvEnabled = CreateConVar("sm_lateconfigs_enabled", "1", "Determines if enabled or not", 0, true, 0.0, true, 1.0);
cvDelay = CreateConVar("sm_lateconfigs_delay", "3", "Time in seconds after comamnds will be executed", 0, true, 0.0);
RegAdminCmd("sm_lateconfigs_reload", Command_Reload, ADMFLAG_RCON, "Reloads configs");
RegAdminCmd("sm_lateconfigs_run", Command_Run, ADMFLAG_RCON, "Runs configs - for testing purposes");
AutoExecConfig();
}
public void OnMapStart() {
readConfigs();
isMapEnd = false;
}
public void OnMapEnd() {
isMapEnd = true;
}
public void OnAutoConfigsBuffered()
{
if(cvEnabled.BoolValue) {
PrintToServer("%s Configs will be executed in %f seconds", TAG, cvDelay.FloatValue);
CreateTimer(cvDelay.FloatValue, Timer_ExecuteConfigs);
}
}
public Action Timer_ExecuteConfigs(Handle timer) {
if(!isMapEnd) {
executeConfigs();
}
}
void executeConfigs() {
for (int i = 0; i < convarList.Length; i++) {
char convar[64];
convarList.GetString(i, convar, sizeof(convar));
#if DEBUG
PrintToServer("%s Executing command: %s", TAG, convar);
#endif
ServerCommand("%s", convar);
}
}
void readConfigs() {
convarList = new ArrayList(64);
char configsPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, configsPath, sizeof(configsPath), "/configs/lateconfigs.cfg");
if(!FileExists(configsPath)) {
createEmptyConfigsFile(configsPath);
return;
}
File configsFile = OpenFile(configsPath, "r");
if(configsFile == null) {
SetFailState("Can not read convars from config file /configs/lateconfigs.cfg It should be auto generated if not exists!");
return;
}
char buffer[128];
while(!configsFile.EndOfFile() && configsFile.ReadLine(buffer, sizeof(buffer))) {
TrimString(buffer);
if(strlen(buffer) <= 1) { // empty line or just one char - ignone, continue to next line
continue;
}
if(buffer[0] == '/' && buffer[1] == '/') { // this line is commented - continue
continue;
}
convarList.PushString(buffer);
}
configsFile.Close();
}
void createEmptyConfigsFile(char[] configsPath) {
File file = OpenFile(configsPath, "a");
if(file == null) {
SetFailState("Can not create config file /configs/lateconfigs.cfg!");
return;
}
file.WriteLine("// This is config file for lateconfigs.smx plugin");
file.WriteLine("// Type your convars line by line without any characters at line start.");
file.WriteLine("// It will be executed after delay time");
file.Close();
}
public Action Command_Reload(int client, int args) {
readConfigs();
ReplyToCommand(client, "%s Config reloaded.", TAG);
return Plugin_Handled;
}
public Action Command_Run(int client, int args) {
if(convarList == null || convarList.Length == 0) {
ReplyToCommand(client, "%s There is nothing to run. Empty config file.", TAG);
}
else {
executeConfigs();
ReplyToCommand(client, "%s Configs executed.", TAG);
}
return Plugin_Handled;
}