Member
|
05-02-2019
, 11:32
Re: How unload all plugins from folder?
|
#6
|
Quote:
#include <sourcemod>
enum enumMods {
String:Folder[32],
String:Cmd[16]
}
int g_Mods[32][enumMods];
int g_numbMods;
public void OnMapStart() {
ReadConfig();
}
public void OnPluginStart() {
RegAdminCmd("sm_mods", Command_Mods, ADMFLAG_CONFIG);
}
public void ReadConfig() {
KeyValues kv = new KeyValues("root");
kv.ImportFromFile("addons/sourcemod/configs/multimods.cfg");
if(!FileExists("addons/sourcemod/configs/multimods.cfg")) {
LogError("File addons/sourcemod/configs/multimods.cfg do not exist");
delete kv;
return;
}
if (!kv.GotoFirstSubKey()) {
LogError("Config addons/sourcemod/configs/multimods.cfg not exist");
delete kv;
return;
}
do {
g_numbMods++;
kv.GetSectionName(g_Mods[g_numbMods][Cmd], 32);
kv.GetString("folder", g_Mods[g_numbMods][Folder], 32);
} while (kv.GotoNextKey());
delete kv;
}
public Action Command_Mods(int client, int args) {
if(args < 2) {
return Plugin_Handled;
}
char szArg[32];
GetCmdArg(1, szArg, sizeof(szArg));
int mod = getMods(szArg);
if(mod == 0) {
ReplyToCommand(client, "[SM] This mod not exist");
return Plugin_Handled;
}
char szEnablePath[256], szDisablePath[256];
Format(szEnablePath, 256, "addons/sourcemod/plugins/%s", g_Mods[mod][Folder]);
Format(szDisablePath, 256, "addons/sourcemod/plugins/disabled/%s", g_Mods[mod][Folder]);
GetCmdArg(2, szArg, sizeof(szArg));
if(StrEqual(szArg, "enable", false)) {
if(ChangeStatus(szDisablePath, szEnablePath)) {
ReplyToCommand(client, "[SM] Enable mod %s", g_Mods[mod][Cmd]);
} else {
ReplyToCommand(client, "[SM] %s can't be enable", g_Mods[mod][Cmd]);
}
return Plugin_Handled;
}
if(StrEqual(szArg, "disable", false)) {
if(ChangeStatus(szEnablePath, szDisablePath)) {
ReplyToCommand(client, "[SM] Disable mod %s", g_Mods[mod][Cmd]);
} else {
ReplyToCommand(client, "[SM] %s can't be disable", g_Mods[mod][Cmd]);
}
return Plugin_Handled;
}
return Plugin_Handled;
}
public int getMods(char[] cmd) {
int mod;
for (int i = 1; i <= g_numbMods; i++) {
if(StrEqual(g_Mods[i][Cmd], cmd, false)) {
mod = i;
break;
}
}
return mod;
}
public bool ChangeStatus(char[] oldpath, char[] newpath) {
if(!DirExists(oldpath)) {
LogError("[SM] Directory %s not exist", oldpath);
return false;
}
DirectoryListing Directory = OpenDirectory(oldpath);
char szFile[32], szOldPath[256], szNewPath[256];
bool change;
FileType type = FileType_File | FileType_Directory;
while(ReadDirEntry(Directory, szFile, 32, type)) {
if(szFile[0] != '.') {
Format(szOldPath, 256, "%s/%s", oldpath, szFile);
Format(szNewPath, 256, "%s/%s", newpath, szFile);
RenameFile(newpath, oldpath);
change = true;
}
}
Directory.Close();
if(change) {
RemoveDir(oldpath);
}
return change;
}
|
config/multimod.cfg
Quote:
"Multimods"
{
"name1"
{
"folder" "thefolder"
}
"name2"
{
"folder" "anotherfolder"
}
}
|
This plugin is created by Verygames community
For use the command "sm_mods <name> <enable|disable>" the admin need "config" flag (ADMFLAG_CONFIG)
Follow this exemple for use multimods
.You don't need use "addons/sourcemod/plugins" on "folder" config, the plugin already get it
In this exemple, for enable or disable "name1" and "name2", just type it on the chat:
. !mods name1 enable OR !mods name1 disable
. !mods name2 enable OR !mods name2 disable
->change map is require after that
Last edited by TheBOSS; 05-02-2019 at 11:34.
|
|