From 8696cb462f45733973b870cc77dae08cb3176e7e Mon Sep 17 00:00:00 2001 From: zaCade Date: Sat, 5 Jan 2019 18:49:54 +0100 Subject: [PATCH] MapAdmin: With per map configs. --- .../mapadmin/ze_Ancient_wrath_v1_fix2.cfg | 55 +++ MapAdmin/scripting/MapAdmin.sp | 340 ++++++++++++++++++ 2 files changed, 395 insertions(+) create mode 100644 MapAdmin/configs/mapadmin/ze_Ancient_wrath_v1_fix2.cfg create mode 100644 MapAdmin/scripting/MapAdmin.sp diff --git a/MapAdmin/configs/mapadmin/ze_Ancient_wrath_v1_fix2.cfg b/MapAdmin/configs/mapadmin/ze_Ancient_wrath_v1_fix2.cfg new file mode 100644 index 00000000..8248d0ca --- /dev/null +++ b/MapAdmin/configs/mapadmin/ze_Ancient_wrath_v1_fix2.cfg @@ -0,0 +1,55 @@ +"mapadmin" +{ + "adminroom" "-1446.649292 2565.642822 70.031311" + "stages" + { + "0" + { + "name" "Stage 1" + "triggers" + { + "0" "1" + } + "actions" + { + "0" "#1100931:Press" + } + } + "1" + { + "name" "Stage 2" + "triggers" + { + "0" "2" + } + "actions" + { + "0" "#1100968:Press" + } + } + "2" + { + "name" "Stage 3" + "triggers" + { + "0" "3" + } + "actions" + { + "0" "#1100986:Press" + } + } + "3" + { + "name" "Stage 4" + "triggers" + { + "0" "4" + } + "actions" + { + "0" "#1100992:Press" + } + } + } +} \ No newline at end of file diff --git a/MapAdmin/scripting/MapAdmin.sp b/MapAdmin/scripting/MapAdmin.sp new file mode 100644 index 00000000..f4c86a1c --- /dev/null +++ b/MapAdmin/scripting/MapAdmin.sp @@ -0,0 +1,340 @@ +#pragma semicolon 1 +#pragma newdecls required + +#include +#include + +KeyValues g_Config; + +public Plugin myinfo = +{ + name = "MapAdmin", + author = "BotoX", + description = "Adminroom teleport and changing stages.", + version = "0.1", + url = "" +}; + +public void OnPluginStart() +{ + LoadTranslations("common.phrases"); + + RegAdminCmd("sm_adminroom", Command_AdminRoom, ADMFLAG_GENERIC, "sm_adminroom [#userid|name]"); + RegAdminCmd("sm_stage", Command_Stage, ADMFLAG_GENERIC, "sm_stage "); +} + +public void OnMapStart() +{ + if(g_Config) + delete g_Config; + + char sMapName[PLATFORM_MAX_PATH]; + GetCurrentMap(sMapName, sizeof(sMapName)); + + char sConfigFile[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/mapadmin/%s.cfg", sMapName); + + if(!FileExists(sConfigFile)) + { + LogMessage("Could not find mapconfig: \"%s\"", sConfigFile); + return; + } + + LogMessage("Found mapconfig: \"%s\"", sConfigFile); + + g_Config = new KeyValues("mapadmin"); + if(!g_Config.ImportFromFile(sConfigFile)) + { + delete g_Config; + SetFailState("ImportFromFile() failed!"); + return; + } + g_Config.Rewind(); +} + +public Action Command_AdminRoom(int client, int argc) +{ + if(!g_Config) + { + ReplyToCommand(client, "[SM] The current map is not supported."); + return Plugin_Handled; + } + + char sAdminRoom[64]; + g_Config.GetString("adminroom", sAdminRoom, sizeof(sAdminRoom), ""); + + if(!sAdminRoom[0]) + { + ReplyToCommand(client, "[SM] The current map does not have an adminroom (configured)."); + return Plugin_Handled; + } + + if(argc > 1) + { + ReplyToCommand(client, "[SM] Usage: sm_adminroom [#userid|name]"); + return Plugin_Handled; + } + + char sOrigins[3][16]; + ExplodeString(sAdminRoom, " ", sOrigins, sizeof(sOrigins), sizeof(sOrigins[])); + + float fOrigin[3]; + fOrigin[0] = StringToFloat(sOrigins[0]); + fOrigin[1] = StringToFloat(sOrigins[1]); + fOrigin[2] = StringToFloat(sOrigins[2]); + + char sArgs[64]; + char sTargetName[MAX_TARGET_LENGTH]; + int iTargets[MAXPLAYERS]; + int iTargetCount; + bool bIsML; + + if(argc == 1) + GetCmdArg(1, sArgs, sizeof(sArgs)); + else + strcopy(sArgs, sizeof(sArgs), "@me"); + + if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0) + { + ReplyToTargetError(client, iTargetCount); + return Plugin_Handled; + } + + for(int i = 0; i < iTargetCount; i++) + { + TeleportEntity(iTargets[i], fOrigin, NULL_VECTOR, NULL_VECTOR); + } + + ShowActivity2(client, "\x01[SM] \x04", "\x01Teleported \x04%s\x01 to the adminroom.", sTargetName); + if(iTargetCount > 1) + LogAction(client, -1, "\"%L\" teleported \"%s\" to the adminroom.", client, sTargetName); + else + LogAction(client, iTargets[0], "\"%L\" teleported \"%L\" to the adminroom.", client, iTargets[0]); + + return Plugin_Handled; +} + +public Action Command_Stage(int client, int argc) +{ + if(!g_Config) + { + ReplyToCommand(client, "[SM] The current map is not supported."); + return Plugin_Handled; + } + + if(!g_Config.JumpToKey("stages", false)) + { + ReplyToCommand(client, "[SM] The current map does not have stages (configured)."); + return Plugin_Handled; + } + + if(!g_Config.GotoFirstSubKey(false)) + { + ReplyToCommand(client, "[SM] The current map does not have any stages configured."); + g_Config.GoBack(); // "stages" + return Plugin_Handled; + } + + if(argc < 1) + { + ReplyToCommand(client, "[SM] Available stages:"); + + do + { + char sSection[32]; + g_Config.GetSectionName(sSection, sizeof(sSection)); + + char sName[64]; + g_Config.GetString("name", sName, sizeof(sName), "MISSING_NAME"); + + if(!g_Config.JumpToKey("triggers", false)) + { + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), missing \"triggers\" block.", sSection, sName); + return Plugin_Handled; + } + + if(!g_Config.GotoFirstSubKey(false)) + { + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + g_Config.GoBack(); // "triggers" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), empty \"triggers\" block.", sSection, sName); + return Plugin_Handled; + } + + char sTriggers[128]; + do + { + char sTrigger[32]; + g_Config.GetString(NULL_STRING, sTrigger, sizeof(sTrigger)); + + StrCat(sTrigger, sizeof(sTrigger), ", "); + StrCat(sTriggers, sizeof(sTriggers), sTrigger); + } while(g_Config.GotoNextKey(false)); + + g_Config.GoBack(); // "triggers" + g_Config.GoBack(); // "GotoFirstSubKey" + + // Remove last ", " + sTriggers[strlen(sTriggers) - 2] = 0; + + ReplyToCommand(client, "%s: %s", sName, sTriggers); + + } while(g_Config.GotoNextKey(false)); + + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + + return Plugin_Handled; + } + + char sArg[64]; + GetCmdArgString(sArg, sizeof(sArg)); + + do + { + char sSection[32]; + g_Config.GetSectionName(sSection, sizeof(sSection)); + + char sName[64]; + g_Config.GetString("name", sName, sizeof(sName), "MISSING_NAME"); + + if(!g_Config.JumpToKey("triggers", false)) + { + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), missing \"triggers\" block.", sSection, sName); + return Plugin_Handled; + } + + if(!g_Config.GotoFirstSubKey(false)) + { + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + g_Config.GoBack(); // "triggers" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), empty \"triggers\" block.", sSection, sName); + return Plugin_Handled; + } + + bool bFound = false; + do + { + char sTrigger[32]; + g_Config.GetString(NULL_STRING, sTrigger, sizeof(sTrigger)); + + if(StrEqual(sArg, sTrigger, true)) + { + bFound = true; + break; + } + + } while(g_Config.GotoNextKey(false)); + + g_Config.GoBack(); // "triggers" + g_Config.GoBack(); // "GotoFirstSubKey" + + if(!bFound) + continue; + + ReplyToCommand(client, "Triggering \"%s\"", sName); + + if(!g_Config.JumpToKey("actions", false)) + { + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), missing \"actions\" block.", sSection, sName); + return Plugin_Handled; + } + + if(!g_Config.GotoFirstSubKey(false)) + { + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + g_Config.GoBack(); // "actions" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), empty \"actions\" block.", sSection, sName); + return Plugin_Handled; + } + + do + { + char sAction[256]; + g_Config.GetString(NULL_STRING, sAction, sizeof(sAction)); + + int iDelim = FindCharInString(sAction, ':'); + if(iDelim == -1) + { + char sActionSection[32]; + g_Config.GetSectionName(sActionSection, sizeof(sActionSection)); + + g_Config.GoBack(); // "actions" + g_Config.GoBack(); // "GotoFirstSubKey" + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + + ReplyToCommand(client, "Config error in stage \"%s\"(\"%s\"), action \"%s\" missing delim ':'.", sSection, sName, sActionSection); + return Plugin_Handled; + } + + ReplyToCommand(client, "Firing \"%s\"", sAction); + sAction[iDelim++] = 0; + + int entity = INVALID_ENT_REFERENCE; + while((entity = FindEntityByTargetname(entity, sAction, "*")) != INVALID_ENT_REFERENCE) + { + AcceptEntityInput(entity, sAction[iDelim], client, client); + } + + } while(g_Config.GotoNextKey(false)); + + g_Config.GoBack(); // "actions" + g_Config.GoBack(); // "GotoFirstSubKey" + + ShowActivity2(client, "\x01[SM] \x04", "\x01Changed the stage to \x04%s\x01.", sName); + LogAction(client, -1, "\"%L\" changed the stage to \"%s\".", client, sName); + + break; + } while(g_Config.GotoNextKey(false)); + + g_Config.GoBack(); // "stages" + g_Config.GoBack(); // "GotoFirstSubKey" + + return Plugin_Handled; +} + +int FindEntityByTargetname(int entity, const char[] sTargetname, const char[] sClassname="*") +{ + if(sTargetname[0] == '#') // HammerID + { + int HammerID = StringToInt(sTargetname[1]); + + while((entity = FindEntityByClassname(entity, sClassname)) != INVALID_ENT_REFERENCE) + { + if(GetEntProp(entity, Prop_Data, "m_iHammerID") == HammerID) + return entity; + } + } + else // Targetname + { + int Wildcard = FindCharInString(sTargetname, '*'); + char sTargetnameBuf[64]; + + while((entity = FindEntityByClassname(entity, sClassname)) != INVALID_ENT_REFERENCE) + { + if(GetEntPropString(entity, Prop_Data, "m_iName", sTargetnameBuf, sizeof(sTargetnameBuf)) <= 0) + continue; + + if(strncmp(sTargetnameBuf, sTargetname, Wildcard) == 0) + return entity; + } + } + + return INVALID_ENT_REFERENCE; +}