From 124768f30d387cc67503711141f76133f5feb649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20=C3=96hrstr=C3=B6m?= Date: Mon, 25 Sep 2017 10:07:53 +0200 Subject: [PATCH] 0.6.3.2 (#4) * New config system and logs * Update README.md * Update README.md * Fixes and updates During catch, CT's speed is increased with 0.5! Added logging. Added server command sm_reloadbw. General fixes. * Update README.md * Added command sm_nolr * Update README.md --- README.md | 4 +- .../scripting/BetterWarden/Add-Ons/catch.sp | 18 +- .../scripting/BetterWarden/Add-Ons/models.sp | 10 +- .../scripting/BetterWarden/Add-Ons/voteday.sp | 12 +- .../BetterWarden/Add-Ons/wildwest.sp | 10 +- .../scripting/BetterWarden/Add-Ons/zombie.sp | 15 +- .../BetterWarden/WardenMenu/commands.sp | 2 + .../BetterWarden/WardenMenu/forwards.sp | 15 +- .../BetterWarden/WardenMenu/menus.sp | 2 +- .../BetterWarden/WardenMenu/natives.sp | 21 +- .../scripting/BetterWarden/commands.sp | 47 + .../scripting/BetterWarden/events.sp | 13 +- addons/sourcemod/scripting/betterwarden.sp | 65 +- .../scripting/include/autoexecconfig.inc | 877 ++++++++++++++++++ .../scripting/include/betterwarden.inc | 15 +- addons/sourcemod/scripting/wardenmenu.sp | 47 +- .../translations/BetterWarden.phrases.txt | 18 + 17 files changed, 1118 insertions(+), 73 deletions(-) create mode 100644 addons/sourcemod/scripting/include/autoexecconfig.inc diff --git a/README.md b/README.md index a7b78ee..752553f 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ ## Dependencies * [SmartJailDoors](https://forums.alliedmods.net/showthread.php?t=264100) _by Kailo_ -* [SteamWorks Extension](https://forums.alliedmods.net/showthread.php?t=229556) for Automatic Updates (Included in plugin package) +* [SteamWorks Extension](https://forums.alliedmods.net/showthread.php?t=229556) _for Automatic Updates (Included in plugin package)_ ## Features The major function this plugin offers is that the warden can choose special event days to play out for the round. Each day has some special server rules & features that applies in order to make it much more fun for the players! @@ -80,6 +80,8 @@ Some of the other entries in the menu include: |`sm_warden_icon_path`|**decals/BetterWarden/warden**|The path to the icon. Do not include file extensions! The path here should be from whithin the materials/ folder.| |`sm_warden_deathsound`|**1**|Play a sound telling everyone the warden has died? 1 = Enable. 0 = Disable.| |`sm_warden_createsound`|**1**|Play a sound to everyone when someone becomes warden 1 = Enable. 0 = Disable.| +|`sm_warden_logs`|**0**|Do you want the plugin to write logs? Generally only necessary when you're experiencing any sort of issue. 1 = Enable. 0 = Disable.| +|`sm_warden_nolr`|**1**|Allow warden to control if terrorists can do a !lastrequest or !lr when available? 1 = Enable. 0 = Disable.| ### WardenMenu | ConVar | Default | Description | diff --git a/addons/sourcemod/scripting/BetterWarden/Add-Ons/catch.sp b/addons/sourcemod/scripting/BetterWarden/Add-Ons/catch.sp index 6776d0b..bae65a9 100644 --- a/addons/sourcemod/scripting/BetterWarden/Add-Ons/catch.sp +++ b/addons/sourcemod/scripting/BetterWarden/Add-Ons/catch.sp @@ -21,6 +21,7 @@ #include #include #include +#include #pragma semicolon 1 #pragma newdecls required @@ -48,9 +49,11 @@ public void OnPluginStart() { LoadTranslations("BetterWarden.Catch.phrases.txt"); SetGlobalTransTarget(LANG_SERVER); - AutoExecConfig(true, "Catch", "BetterWarden"); - - gc_bFreezeTime = CreateConVar("sm_warden_catch_freezetime", "1", "Freeze all CT's for 5 seconds when game is started?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + AutoExecConfig_SetFile("Catch", "BetterWarden/Add-Ons"); + AutoExecConfig_SetCreateFile(true); + gc_bFreezeTime = AutoExecConfig_CreateConVar("sm_warden_catch_freezetime", "1", "Freeze all CT's for 5 seconds when game is started?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + AutoExecConfig_ExecuteFile(); + AutoExecConfig_CleanFile(); HookEvent("player_death", OnPlayerDeath); HookEvent("round_start", OnRoundStart, EventHookMode_Pre); @@ -70,7 +73,7 @@ public void OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) { } } -public Action OnClientTouch(int client, int other) { +public Action OnClientTouch(int client, int other) { // Client = The CT. other = the victim (T) if(g_bIsCatchActive == false) // Don't do anything if Catch ain't active return Plugin_Continue; if(!IsValidClient(client) || !IsValidClient(other)) // Make sure client !bot & alive @@ -82,6 +85,8 @@ public Action OnClientTouch(int client, int other) { ForcePlayerSuicide(other); CPrintToChatAll("%s %t", g_sPrefix, "Player Caught T", client, other); + AddToBWLog("%N caught %N during catch.", client, other); + return Plugin_Handled; } @@ -117,6 +122,7 @@ public void EndCatch() { // End the whole game and choose a winner if(GetClientTeam(i) != CS_TEAM_T) continue; + SetEntPropFloat(i, Prop_Data, "m_flLaggedMovementValue", 1.0); winner = i; break; } @@ -150,7 +156,7 @@ public Action FreezeTimer(Handle timer) { continue; if(GetClientTeam(i) != CS_TEAM_CT) continue; - SetEntPropFloat(i, Prop_Data, "m_flLaggedMovementValue", 1.0); + SetEntPropFloat(i, Prop_Data, "m_flLaggedMovementValue", 1.5); } secs = 5; return Plugin_Stop; @@ -195,5 +201,7 @@ public int Native_initCatch(Handle plugin, int numParams) { // Called to start t CreateTimer(1.0, FreezeTimer, _, TIMER_REPEAT); } + AddToBWLog("Catch was initiated!"); + return true; } \ No newline at end of file diff --git a/addons/sourcemod/scripting/BetterWarden/Add-Ons/models.sp b/addons/sourcemod/scripting/BetterWarden/Add-Ons/models.sp index 0df8f75..5a7ca43 100644 --- a/addons/sourcemod/scripting/BetterWarden/Add-Ons/models.sp +++ b/addons/sourcemod/scripting/BetterWarden/Add-Ons/models.sp @@ -16,6 +16,7 @@ #include #include #include +#include // Compiler options #pragma semicolon 1 @@ -42,10 +43,13 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max } public void OnPluginStart() { - AutoExecConfig(true, "models", "BetterWarden/Add-Ons"); // Create a addon-specific config! + AutoExecConfig_SetFile("models", "BetterWarden/Add-Ons"); // Create a addon-specific config! + AutoExecConfig_SetCreateFile(true); + gc_bWardenModel = AutoExecConfig_CreateConVar("sm_warden_model", "1", "Enable or disable the warden getting a player model.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bDeputyModel = AutoExecConfig_CreateConVar("sm_warden_deputy_model", "0", "Give the other CT's a fitting model aswell?", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bWardenModel = CreateConVar("sm_warden_model", "1", "Enable or disable the warden getting a player model.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bDeputyModel = CreateConVar("sm_warden_deputy_model", "0", "Give the other CT's a fitting model aswell?", FCVAR_NOTIFY, true, 0.0, true, 1.0); + AutoExecConfig_ExecuteFile(); + AutoExecConfig_CleanFile(); HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Pre); } diff --git a/addons/sourcemod/scripting/BetterWarden/Add-Ons/voteday.sp b/addons/sourcemod/scripting/BetterWarden/Add-Ons/voteday.sp index deff75c..8428dcf 100644 --- a/addons/sourcemod/scripting/BetterWarden/Add-Ons/voteday.sp +++ b/addons/sourcemod/scripting/BetterWarden/Add-Ons/voteday.sp @@ -18,6 +18,7 @@ #include #include #include +#include // Optional plugins (Add-Ons) #undef REQUIRE_PLUGIN @@ -71,9 +72,13 @@ public void OnPluginStart() { HookEvent("round_start", OnRoundStart, EventHookMode_Pre); - AutoExecConfig(true, "voteday", "BetterWarden/Add-Ons"); - gc_fVoteTime = CreateConVar("sm_warden_vote_duration", "30.0", "The duration of event day votes.", FCVAR_NOTIFY, true, 1.0, true, 120.0); - gc_bVoteCooldown = CreateConVar("sm_warden_vote_spam", "1", "Prevent users from starting another vote after one has failed in the same round?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + AutoExecConfig_SetFile("voteday", "BetterWarden/Add-Ons"); + AutoExecConfig_SetCreateFile(true); + gc_fVoteTime = AutoExecConfig_CreateConVar("sm_warden_vote_duration", "30.0", "The duration of event day votes.", FCVAR_NOTIFY, true, 1.0, true, 120.0); + gc_bVoteCooldown = AutoExecConfig_CreateConVar("sm_warden_vote_spam", "1", "Prevent users from starting another vote after one has failed in the same round?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + + AutoExecConfig_ExecuteFile(); + AutoExecConfig_CleanFile(); } public void OnAllPluginsLoaded() { // Handle late loads @@ -285,6 +290,7 @@ public void StartVote(int client, int game) { continue; BWVoteMenu(i); } + AddToBWLog("%N started a vote.", client); } public bool VoteFinished() { diff --git a/addons/sourcemod/scripting/BetterWarden/Add-Ons/wildwest.sp b/addons/sourcemod/scripting/BetterWarden/Add-Ons/wildwest.sp index e68c597..ca80cd7 100644 --- a/addons/sourcemod/scripting/BetterWarden/Add-Ons/wildwest.sp +++ b/addons/sourcemod/scripting/BetterWarden/Add-Ons/wildwest.sp @@ -20,6 +20,7 @@ #include #include #include +#include // Misc variables bool g_bIsWWActive; @@ -54,8 +55,12 @@ public void OnPluginStart() { gc_bInfAmmo = FindConVar("sv_infinite_ammo"); // This will be changed to 2 when it starts and reset to the value in server.cfg when game ends - AutoExecConfig(true, "wildwest", "BetterWarden/Add-Ons"); - gc_sWeaponUsed = CreateConVar("sm_betterwarden_wildwest_weapon", "weapon_revolver", "What weapon is supposed to be used?\nUse the entity names.", FCVAR_NOTIFY); + AutoExecConfig_SetFile("wildwest", "BetterWarden/Add-Ons"); + AutoExecConfig_SetCreateFile(true); + gc_sWeaponUsed = AutoExecConfig_CreateConVar("sm_betterwarden_wildwest_weapon", "weapon_revolver", "What weapon is supposed to be used?\nUse the entity names.", FCVAR_NOTIFY); + + AutoExecConfig_ExecuteFile(); + AutoExecConfig_CleanFile(); } @@ -75,6 +80,7 @@ public void StartWW() { // Start the actual event continue; GivePlayerItem(i, buff); } + AddToBWLog("Wild West was initiated."); g_bIsWWActive = true; SetConVarInt(gc_bInfAmmo, 2); } diff --git a/addons/sourcemod/scripting/BetterWarden/Add-Ons/zombie.sp b/addons/sourcemod/scripting/BetterWarden/Add-Ons/zombie.sp index 5aa79fb..b967359 100644 --- a/addons/sourcemod/scripting/BetterWarden/Add-Ons/zombie.sp +++ b/addons/sourcemod/scripting/BetterWarden/Add-Ons/zombie.sp @@ -21,6 +21,7 @@ #include #include #include +#include // Compiler options #pragma semicolon 1 @@ -58,9 +59,13 @@ public void OnPluginStart() { HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Pre); HookEvent("round_end", OnRoundEnd, EventHookMode_PostNoCopy); - AutoExecConfig(true, "zombie", "BetterWarden/Add-Ons"); - gc_bSwapBack = CreateConVar("sm_warden_zombie_swapback", "1", "In the round after a zombie round, swap back the CT's, that were infected, to Counter-Terrorists?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_iZombieHealth = CreateConVar("sm_warden_zombie_health", "2000", "How much max-health should zombies have?", FCVAR_NOTIFY); + AutoExecConfig_SetFile("zombie", "BetterWarden/Add-Ons"); + AutoExecConfig_SetCreateFile(true); + gc_bSwapBack = AutoExecConfig_CreateConVar("sm_warden_zombie_swapback", "1", "In the round after a zombie round, swap back the CT's, that were infected, to Counter-Terrorists?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_iZombieHealth = AutoExecConfig_CreateConVar("sm_warden_zombie_health", "2000", "How much max-health should zombies have?", FCVAR_NOTIFY); + + AutoExecConfig_ExecuteFile(); + AutoExecConfig_CleanFile(); } public void OnMapStart() { @@ -130,6 +135,7 @@ public void OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast) { if(IsValidClient(client) && GetClientTeam(client) == CS_TEAM_T && g_bIsZombieActive) { // Support respawns SetClientZombie(client); + AddToBWLog("%N was made a zombie.", client); } } @@ -188,6 +194,7 @@ public Action OnTakeDamageAlive(int victim, int &attacker, int &inflictor, float if(iSound == 3) EmitSoundToClientAny(inflictor, "betterwarden/zombie_kill3.mp3"); CPrintToChatAll("%s %t", g_sPrefix, "Zombie Infected", inflictor, victim); + AddToBWLog("%N was infected by %N during zombie round.", victim, inflictor); return Plugin_Handled; } @@ -221,6 +228,8 @@ public int Native_initZombie(Handle plugin, int numParams) { CPrintToChatAll("%s {red}****************************************************", g_sPrefix); CPrintToChatAll(""); + AddToBWLog("Zombie mode has started!"); + return true; } diff --git a/addons/sourcemod/scripting/BetterWarden/WardenMenu/commands.sp b/addons/sourcemod/scripting/BetterWarden/WardenMenu/commands.sp index 020a919..393fa0e 100644 --- a/addons/sourcemod/scripting/BetterWarden/WardenMenu/commands.sp +++ b/addons/sourcemod/scripting/BetterWarden/WardenMenu/commands.sp @@ -49,6 +49,8 @@ public Action sm_abortgames(int client, int args) { CPrintToChatAll("%s %t", g_sCMenuPrefix, "Admin Aborted", client); abortGames(); + AddToBWLog("An admin has stopped the current game."); + return Plugin_Handled; } diff --git a/addons/sourcemod/scripting/BetterWarden/WardenMenu/forwards.sp b/addons/sourcemod/scripting/BetterWarden/WardenMenu/forwards.sp index 1c343ff..0588930 100644 --- a/addons/sourcemod/scripting/BetterWarden/WardenMenu/forwards.sp +++ b/addons/sourcemod/scripting/BetterWarden/WardenMenu/forwards.sp @@ -35,11 +35,12 @@ public void OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) { if(g_iHnsWinners == g_iAliveTs) { abortGames(); CPrintToChatAll("%s %t", g_sCMenuPrefix, "HnS Over"); - + AddToBWLog("Hide n' Seek is now over and there's a winner!"); Call_StartForward(gF_OnHnsOver); Call_Finish(); } else { CPrintToChatAll("%s %t", g_sCMenuPrefix, "HnS Players Left", g_iAliveTs); + AddToBWLog("A Terrorist died during Hide n' Seek but there's still contenders left."); } } } @@ -49,6 +50,7 @@ public Action OnTakeDamageAlive(int victim, int &attacker, int &inflictor, float if(g_iHnsActive == 1 && gc_bHnSGod.IntValue == 1) { if(IsValidClient(victim) && IsValidClient(inflictor) && GetClientTeam(victim) == CS_TEAM_CT && GetClientTeam(inflictor) == CS_TEAM_T) { CPrintToChat(inflictor, "%s %t", g_sCMenuPrefix, "No Rebel HnS"); + AddToBWLog("%N tried attacking %N but was denied since Hide n' Seek is active.", inflictor, victim); return Plugin_Handled; } } @@ -63,10 +65,11 @@ public void OnRoundStart(Event event, const char[] name, bool dontBroadcast) { g_iAliveTs = 0; g_iAliveTs = GetTeamAliveClientCount(CS_TEAM_T); - for(int client = 1; client <= MaxClients; client++) { - if(IsValidClient(client)) { - if(ClientHasFreeday(client)) { - RemoveClientFreeday(client); + for(int i = 1; i <= MaxClients; i++) { + if(IsValidClient(i)) { + if(ClientHasFreeday(i)) { + RemoveClientFreeday(i); + AddToBWLog("%N's freeday was removed since it's a new round.", i); } } } @@ -111,7 +114,7 @@ public void OnWardenCreated(int client) { if(gc_bAutoOpen.IntValue == 1) { openMenu(client); } else { - PrintToServer("Skipping auto open since it's disabled in config."); + AddToBWLog("Skipping auto open since it's disabled in config."); } } diff --git a/addons/sourcemod/scripting/BetterWarden/WardenMenu/menus.sp b/addons/sourcemod/scripting/BetterWarden/WardenMenu/menus.sp index b5893f4..fb7b391 100644 --- a/addons/sourcemod/scripting/BetterWarden/WardenMenu/menus.sp +++ b/addons/sourcemod/scripting/BetterWarden/WardenMenu/menus.sp @@ -316,7 +316,7 @@ public int DaysMenuHandler(Menu menu, MenuAction action, int client, int param2) ExecWarday(); if(StrEqual(info, CHOICE5)) - initGrav(client); + ExecGravday(); if(StrEqual(info, CHOICE6)) initCatch(); diff --git a/addons/sourcemod/scripting/BetterWarden/WardenMenu/natives.sp b/addons/sourcemod/scripting/BetterWarden/WardenMenu/natives.sp index 4580e93..868cf93 100644 --- a/addons/sourcemod/scripting/BetterWarden/WardenMenu/natives.sp +++ b/addons/sourcemod/scripting/BetterWarden/WardenMenu/natives.sp @@ -15,8 +15,7 @@ /* * Natives */ -public int Native_IsEventDayActive(Handle plugin, int numParams) -{ +public int Native_IsEventDayActive(Handle plugin, int numParams) { if(g_bIsGameActive) { return true; } @@ -82,6 +81,7 @@ public int Native_GiveClientFreeday(Handle plugin, int numParams) { if(IsValidClient(client)) { g_iClientFreeday[client] = 1; SetClientBeacon(client, true); + AddToBWLog("%N was given a freeday.", client); return true; } @@ -94,6 +94,7 @@ public int Native_RemoveClientFreeday(Handle plugin, int numParams) { if(IsValidClient(client)) { g_iClientFreeday[client] = 0; SetClientBeacon(client, false); + AddToBWLog("%N's freeday was cancelled.", client); return true; } @@ -131,7 +132,7 @@ public int Native_ExecWarday(Handle plugin, int numParams) { CPrintToChatAll("{blue}-----------------------------------------------------"); g_iWardayActive = 1; g_bIsGameActive = true; - + AddToBWLog("A warday was executed."); return true; } else if(gc_iWardayTimes.IntValue != 0 && g_iWarTimes >= gc_iWardayTimes.IntValue) { CPrintToChat(client, "%s %t", "Too many wardays", g_iWarTimes, gc_iWardayTimes.IntValue); @@ -145,7 +146,7 @@ public int Native_ExecWarday(Handle plugin, int numParams) { g_iWardayActive = 1; g_bIsGameActive = true; g_iWarTimes++; - + AddToBWLog("A warday was executed."); return true; } @@ -162,7 +163,7 @@ public int Native_ExecFreeday(Handle plugin, int numParams) { CPrintToChatAll("{blue}-----------------------------------------------------"); g_iFreedayActive = 1; g_bIsGameActive = true; - + AddToBWLog("A Freeday was executed."); return true; } else if(gc_iFreedayTimes.IntValue != 0 && g_iFreedayTimes >= gc_iFreedayTimes.IntValue) { CPrintToChat(client, "%s %t", g_sCMenuPrefix, "Too many freedays", g_iFreedayTimes, gc_iFreedayTimes.IntValue); @@ -175,7 +176,7 @@ public int Native_ExecFreeday(Handle plugin, int numParams) { g_iFreedayActive = 1; g_bIsGameActive = true; g_iFreedayTimes++; - + AddToBWLog("A Freeday was executed."); return true; } @@ -195,7 +196,7 @@ public int Native_ExecHnS(Handle plugin, int numParams) { g_iHnsActive = 1; g_bIsGameActive = true; CreateTimer(0.5, HnSInfo, _, TIMER_REPEAT); - + AddToBWLog("A Hide n' Seek was executed."); return true; } else if(gc_iHnSTimes.IntValue != 0 && g_iHnsTimes >= gc_iHnSTimes.IntValue) { @@ -212,7 +213,7 @@ public int Native_ExecHnS(Handle plugin, int numParams) { g_bIsGameActive = true; g_iHnsTimes++; CreateTimer(0.5, HnSInfo, _, TIMER_REPEAT); - + AddToBWLog("A Hide n' Seek was executed."); return true; } } else { @@ -249,7 +250,7 @@ public int Native_ExecGravday(Handle plugin, int numParams) { } } } - + AddToBWLog("A Gravity Freeday was executed."); return true; } else if(gc_iGravTimes.IntValue != 0 && g_iGravTimes >= gc_iGravTimes.IntValue) { @@ -280,7 +281,7 @@ public int Native_ExecGravday(Handle plugin, int numParams) { } } } - + AddToBWLog("A Gravity Freeday was executed."); return true; } diff --git a/addons/sourcemod/scripting/BetterWarden/commands.sp b/addons/sourcemod/scripting/BetterWarden/commands.sp index 331717a..0176167 100644 --- a/addons/sourcemod/scripting/BetterWarden/commands.sp +++ b/addons/sourcemod/scripting/BetterWarden/commands.sp @@ -72,6 +72,8 @@ public Action Command_Retire(int client, int args) { Call_PushCell(client); Call_Finish(); + AddToBWLog("The warden retired."); + return Plugin_Handled; } @@ -94,6 +96,8 @@ public Action Command_Noblock(int client, int args) { SetConVarInt(gc_bNoblock, 1, true, false); } + AddToBWLog("The warden toggled noblock."); + return Plugin_Handled; } @@ -111,6 +115,8 @@ public Action Command_OpenCells(int client, int args) { SJD_ToggleDoors(); CPrintToChat(client, "%s %t", g_sPrefix, "Doors Opened"); + AddToBWLog("The warden toggled cell doors"); + return Plugin_Handled; } @@ -181,6 +187,47 @@ public Action Command_SetWarden(int client, int args) { Call_PushCell(client); Call_PushCell(target_list[usr]); Call_Finish(); + + AddToBWLog("%N appointed %N as warden.", client, target_list[usr]); + } + + return Plugin_Handled; +} + +// sm_reloadbw (ServerCMD) +public Action Command_ReloadPlugin(int args) { + ServerCommand("sm plugins reload BetterWarden/betterwarden"); + ServerCommand("sm plugins reload BetterWarden/wardenmenu"); + if(LibraryExists("bwwildwest")) + ServerCommand("sm plugins reload BetterWarden/Add-Ons/wildwest"); + if(LibraryExists("bwzombie")) + ServerCommand("sm plugins reload BetterWarden/Add-Ons/zombie"); + if(LibraryExists("bwcatch")) + ServerCommand("sm plugins reload BetterWarden/Add-Ons/catch"); + if(LibraryExists("bwmodels")) + ServerCommand("sm plugins reload BetterWarden/Add-Ons/models"); + if(LibraryExists("bwvoteday")) + ServerCommand("sm plugins reload BetterWarden/Add-Ons/voteday"); + + return Plugin_Handled; +} + +public Action Command_NoLR(int client, int args) { + if(!IsValidClient(client)) { + CPrintToChat(client, "%s %t", g_sPrefix, "Invalid Client"); + return Plugin_Handled; + } + if(!IsClientWarden(client)) { + CPrintToChat(client, "%s %t", g_sPrefix, "Not Warden"); + return Plugin_Handled; + } + + if(g_iNoLR == 0) { + g_iNoLR = 1; + CPrintToChatAll("%s %t", g_sPrefix, "Deactivated LR"); + } else { + g_iNoLR = 0; + CPrintToChatAll("%s %t", g_sPrefix, "Activated LR"); } return Plugin_Handled; diff --git a/addons/sourcemod/scripting/BetterWarden/events.sp b/addons/sourcemod/scripting/BetterWarden/events.sp index 9dce0c9..95ea610 100644 --- a/addons/sourcemod/scripting/BetterWarden/events.sp +++ b/addons/sourcemod/scripting/BetterWarden/events.sp @@ -100,6 +100,7 @@ public void OnClientDisconnect(int client) { if(IsClientWarden(client)) { RemoveWarden(); CPrintToChatAll("%s %t", g_sPrefix, "Warden Died"); + AddToBWLog("%N disconnected while being warden. Removed warden.", client); Call_StartForward(gF_OnWardenDisconnect); Call_PushCell(client); @@ -115,7 +116,7 @@ public void OnClientDisconnect(int client) { */ public Action OnPlayerChat(int client, char[] command, int args) { if(!IsValidClient(client)) // Make sure warden isn't glitched and is in fact alive etc. - return Plugin_Continue; + return Plugin_Handled; if(!IsClientWarden(client)) // Client is warden; let's make the message cool! return Plugin_Continue; @@ -128,4 +129,14 @@ public Action OnPlayerChat(int client, char[] command, int args) { CPrintToChatAll("{bluegrey}[Warden] {team2}%N :{default} %s", client, message); return Plugin_Handled; +} + +public Action OnPlayerLR(int client, char[] command, int args) { + if(gc_bNoLR.IntValue != 1) + return Plugin_Continue; + if(g_iNoLR == 0) + return Plugin_Continue; + + CPrintToChat(client, "%s %t", g_sPrefix, "No LR Allowed"); + return Plugin_Handled; } \ No newline at end of file diff --git a/addons/sourcemod/scripting/betterwarden.sp b/addons/sourcemod/scripting/betterwarden.sp index 6dfe427..19e4d66 100644 --- a/addons/sourcemod/scripting/betterwarden.sp +++ b/addons/sourcemod/scripting/betterwarden.sp @@ -20,6 +20,7 @@ #include #include #include +#include #undef REQUIRE_PLUGIN #include #include @@ -42,6 +43,7 @@ int g_iAliveTerrorists = 0; int g_iTotalCT = 0; int g_iTotalTerrorists = 0; int g_iIcon[MAXPLAYERS +1] = {-1, ...}; +int g_iNoLR = 0; // Forward handles Handle gF_OnWardenDeath = null; @@ -66,6 +68,8 @@ ConVar gc_bWardenIcon; ConVar gc_sWardenIconPath; ConVar gc_bWardenDeathSound; ConVar gc_bWardenCreatedSound; +ConVar gc_bLogging; +ConVar gc_bNoLR; // Modules #include "BetterWarden/commands.sp" @@ -93,6 +97,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("GetCurrentWarden", Native_GetCurrentWarden); CreateNative("GetTeamAliveClientCount", Native_GetTeamAliveClientCount); CreateNative("IsClientWardenAdmin", Native_IsClientWardenAdmin); + CreateNative("AddToBWLog", Native_AddToBWLog); RegPluginLibrary("betterwarden"); // Global forwards @@ -110,20 +115,26 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max public void OnPluginStart() { // CVars - AutoExecConfig(true, "warden", "BetterWarden"); - CreateConVar("sm_warden_version", VERSION, "Current version of this plugin. DO NOT CHANGE THIS!", FCVAR_DONTRECORD|FCVAR_NOTIFY); - gc_sAdmFlag = CreateConVar("sm_warden_admin", "b", "The flag required to execute admin commands for this plugin.", FCVAR_NOTIFY); - gc_bEnableNoblock = CreateConVar("sm_warden_noblock", "1", "Give the warden the ability to toggle noblock via sm_noblock?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bOpenCells = CreateConVar("sm_warden_cellscmd", "1", "Give the warden ability to toggle cell-doors via sm_open?\nCell doors on every map needs to be setup with SmartJailDoors for this to work!\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bWardenTwice = CreateConVar("sm_warden_same_twice", "0", "Prevent the same warden from becoming warden next round instantly?\nThis should only be used on populated servers for obvious reasons.\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bStatsHint = CreateConVar("sm_warden_stats", "1", "Have a hint message up during the round with information about who's warden, how many players there are etc.\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_iColorR = CreateConVar("sm_warden_color_R", "33", "The Red value of the color the warden gets.", FCVAR_NOTIFY, true, 0.0, true, 255.0); - gc_iColorG = CreateConVar("sm_warden_color_G", "114", "The Green value of the color the warden gets.", FCVAR_NOTIFY, true, 0.0, true, 255.0); - gc_iColorB = CreateConVar("sm_warden_color_B", "255", "The Blue value of the color the warden gets.", FCVAR_NOTIFY, true, 0.0, true, 255.0); - gc_bWardenIcon = CreateConVar("sm_warden_icon", "1", "Have an icon above the wardens' head?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_sWardenIconPath = CreateConVar("sm_warden_icon_path", "decals/BetterWarden/warden", "The path to the icon. Do not include file extensions!\nThe path here should be from whithin the materials/ folder.", FCVAR_NOTIFY); - gc_bWardenDeathSound = CreateConVar("sm_warden_deathsound", "1", "Play a sound telling everyone the warden has died?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bWardenCreatedSound = CreateConVar("sm_warden_createsound", "1", "Play a sound to everyone when someone becomes warden\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + AutoExecConfig_SetFile("warden", "BetterWarden"); // What's the configs name and location? + AutoExecConfig_SetCreateFile(true); // Create config if it does not exist + AutoExecConfig_CreateConVar("sm_warden_version", VERSION, "Current version of this plugin. DO NOT CHANGE THIS!", FCVAR_DONTRECORD|FCVAR_NOTIFY); + gc_sAdmFlag = AutoExecConfig_CreateConVar("sm_warden_admin", "b", "The flag required to execute admin commands for this plugin.", FCVAR_NOTIFY); + gc_bLogging = AutoExecConfig_CreateConVar("sm_warden_logs", "0", "Do you want the plugin to write logs?\nGenerally only necessary when you're experiencing any sort of issue.\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bEnableNoblock = AutoExecConfig_CreateConVar("sm_warden_noblock", "1", "Give the warden the ability to toggle noblock via sm_noblock?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bOpenCells = AutoExecConfig_CreateConVar("sm_warden_cellscmd", "1", "Give the warden ability to toggle cell-doors via sm_open?\nCell doors on every map needs to be setup with SmartJailDoors for this to work!\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bWardenTwice = AutoExecConfig_CreateConVar("sm_warden_same_twice", "0", "Prevent the same warden from becoming warden next round instantly?\nThis should only be used on populated servers for obvious reasons.\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bStatsHint = AutoExecConfig_CreateConVar("sm_warden_stats", "1", "Have a hint message up during the round with information about who's warden, how many players there are etc.\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_iColorR = AutoExecConfig_CreateConVar("sm_warden_color_R", "33", "The Red value of the color the warden gets.", FCVAR_NOTIFY, true, 0.0, true, 255.0); + gc_iColorG = AutoExecConfig_CreateConVar("sm_warden_color_G", "114", "The Green value of the color the warden gets.", FCVAR_NOTIFY, true, 0.0, true, 255.0); + gc_iColorB = AutoExecConfig_CreateConVar("sm_warden_color_B", "255", "The Blue value of the color the warden gets.", FCVAR_NOTIFY, true, 0.0, true, 255.0); + gc_bWardenIcon = AutoExecConfig_CreateConVar("sm_warden_icon", "1", "Have an icon above the wardens' head?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_sWardenIconPath = AutoExecConfig_CreateConVar("sm_warden_icon_path", "decals/BetterWarden/warden", "The path to the icon. Do not include file extensions!\nThe path here should be from whithin the materials/ folder.", FCVAR_NOTIFY); + gc_bWardenDeathSound = AutoExecConfig_CreateConVar("sm_warden_deathsound", "1", "Play a sound telling everyone the warden has died?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bWardenCreatedSound = AutoExecConfig_CreateConVar("sm_warden_createsound", "1", "Play a sound to everyone when someone becomes warden\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bNoLR = AutoExecConfig_CreateConVar("sm_warden_nolr", "1", "Allow warden to control if terrorists can do a !lastrequest or !lr when available?\n1 = Enable.\n0 = Disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + + AutoExecConfig_ExecuteFile(); // Execute the config + AutoExecConfig_CleanFile(); // Clean the .cfg from spaces etc. // Translation stuff LoadTranslations("BetterWarden.phrases.txt"); @@ -139,6 +150,8 @@ public void OnPluginStart() { RegConsoleCmd("sm_open", Command_OpenCells); if(gc_bEnableNoblock.IntValue == 1) RegConsoleCmd("sm_noblock", Command_Noblock); + if(gc_bNoLR.IntValue == 1) + RegConsoleCmd("sm_nolr", Command_NoLR); // Admin Commands RegConsoleCmd("sm_uw", Command_Unwarden); @@ -146,6 +159,9 @@ public void OnPluginStart() { RegConsoleCmd("sm_sw", Command_SetWarden); RegConsoleCmd("sm_setwarden", Command_SetWarden); + // Server Commands + RegServerCmd("sm_reloadbw", Command_ReloadPlugin); + // Event Hooks HookEvent("player_death", OnPlayerDeath); HookEvent("round_start", OnRoundStart); @@ -153,6 +169,8 @@ public void OnPluginStart() { // Command listeners AddCommandListener(OnPlayerChat, "say"); + AddCommandListener(OnPlayerLR, "sm_lr"); + AddCommandListener(OnPlayerLR, "sm_lastrequest"); // Timers if(gc_bStatsHint.IntValue == 1) @@ -195,6 +213,7 @@ public void OnAllPluginsLoaded() { PrintToServer(""); PrintToServer("#### BETTERWARDEN LOADED SUCCESSFULLY WITH %d ADDONS! ####", addons); PrintToServer(""); + AddToBWLog("Betterwarden loaded successfully with %d addons!", addons); } ///////////////////////////// @@ -246,6 +265,7 @@ public void RemoveIcon(int client) { if(g_iIcon[client] > 0 && IsValidEdict(g_iIcon[client])) { AcceptEntityInput(g_iIcon[client], "Kill"); g_iIcon[client] = -1; + AddToBWLog("Removed icon from warden %N", client); } } @@ -299,6 +319,8 @@ public int Native_SetWarden(Handle plugin, int numParams) { if(gc_bWardenCreatedSound.IntValue == 1) EmitSoundToAllAny("betterwarden/newwarden.mp3"); + AddToBWLog("%N was set as warden", client); + return true; } public int Native_RemoveWarden(Handle plugin, int numParams) { @@ -318,6 +340,8 @@ public int Native_RemoveWarden(Handle plugin, int numParams) { g_iCurWarden = -1; g_sCurWardenStat = "None.."; + AddToBWLog("The Warden was successfully removed"); + return true; } public int Native_GetCurrentWarden(Handle plugin, int numParams) { @@ -333,5 +357,18 @@ public int Native_IsClientWardenAdmin(Handle plugin, int numParams) { return true; } + return false; +} +public int Native_AddToBWLog(Handle plugin, int numParams) { + + if(gc_bLogging.IntValue == 1) { + char sBuffer[1024]; + int written; + FormatNativeString(0, 1, 2, sizeof(sBuffer), written, sBuffer); + LogToFile(g_sLogPath, "%s", sBuffer); + + return true; + } + return false; } \ No newline at end of file diff --git a/addons/sourcemod/scripting/include/autoexecconfig.inc b/addons/sourcemod/scripting/include/autoexecconfig.inc new file mode 100644 index 0000000..2e8640b --- /dev/null +++ b/addons/sourcemod/scripting/include/autoexecconfig.inc @@ -0,0 +1,877 @@ +#if defined _autoexecconfig_included + #endinput +#endif +#define _autoexecconfig_included + + +#include + +#define AUTOEXECCONFIG_VERSION "0.1.1" +#define AUTOEXECCONFIG_URL "https://forums.alliedmods.net/showthread.php?t=204254" + +// Append +#define AUTOEXEC_APPEND_BAD_FILENAME 0 +#define AUTOEXEC_APPEND_FILE_NOT_FOUND 1 +#define AUTOEXEC_APPEND_BAD_HANDLE 2 +#define AUTOEXEC_APPEND_SUCCESS 3 + + + +// Find +#define AUTOEXEC_FIND_BAD_FILENAME 10 +#define AUTOEXEC_FIND_FILE_NOT_FOUND 11 +#define AUTOEXEC_FIND_BAD_HANDLE 12 +#define AUTOEXEC_FIND_NOT_FOUND 13 +#define AUTOEXEC_FIND_SUCCESS 14 + + + +// Clean +#define AUTOEXEC_CLEAN_FILE_NOT_FOUND 20 +#define AUTOEXEC_CLEAN_BAD_HANDLE 21 +#define AUTOEXEC_CLEAN_SUCCESS 22 + + + +// General +#define AUTOEXEC_NO_CONFIG 30 + + + +// Formatter +#define AUTOEXEC_FORMAT_BAD_FILENAME 40 +#define AUTOEXEC_FORMAT_SUCCESS 41 + + + +// Global variables +static char g_sConfigFile[PLATFORM_MAX_PATH]; +static char g_sRawFileName[PLATFORM_MAX_PATH]; +static char g_sFolderPath[PLATFORM_MAX_PATH]; + +static StringMap g_hConvarTrie = null; +static bool g_bCacheEnabled = false; + +static bool g_bCreateFile = false; +static Handle g_hPluginHandle = null; + + + +// Workaround for now +static int g_iLastFindResult; +static int g_iLastAppendResult; + + + + +/** + * Returns the last result from the parser. + * + * @return Returns one of the AUTOEXEC_FIND values or -1 if not set. +*/ +stock int AutoExecConfig_GetFindResult() +{ + return g_iLastFindResult; +} + + + + + +/** + * Returns the last result from the appender. + * + * @return Returns one of the AUTOEXEC_APPEND values or -1 if not set. +*/ +stock int AutoExecConfig_GetAppendResult() +{ + return g_iLastAppendResult; +} + + +/** + * Set if the config file should be created by the autoexecconfig include itself if it doesn't exist. + * + * @param create True if config file should be created, false otherwise. + * @noreturn + */ +stock void AutoExecConfig_SetCreateFile(bool create) +{ + g_bCreateFile = create; +} + + +/** + * Returns if the config file should be created if it doesn't exist. + * + * @return Returns true, if the config file should be created or false if it should not. + */ +stock bool AutoExecConfig_GetCreateFile() +{ + return g_bCreateFile; +} + + +/** + * Set the plugin for which the config file should be created. + * Set to null to use the calling plugin. + * Used to print the correct filename in the top comment when creating the file. + * + * @param plugin The plugin to create convars for or null to use the calling plugin. + * @noreturn + */ +stock void AutoExecConfig_SetPlugin(Handle plugin) +{ + g_hPluginHandle = plugin; +} + + +/** + * Returns the plugin's handle for which the config file is created. + * + * @return The plugin handle + */ +stock Handle AutoExecConfig_GetPlugin() +{ + return g_hPluginHandle; +} + + +/** + * Set the global autoconfigfile used by functions of this file. + * + * @param file Name of the config file, path and .cfg extension is being added if not given. + * @param folder Folder under cfg/ to use. By default this is "sourcemod." + * @return True if formatter returned success, false otherwise. +*/ +stock bool AutoExecConfig_SetFile(char[] file, char[] folder="sourcemod") +{ + Format(g_sConfigFile, sizeof(g_sConfigFile), "%s", file); + + // Global buffers for cfg execution + strcopy(g_sRawFileName, sizeof(g_sRawFileName), file); + strcopy(g_sFolderPath, sizeof(g_sFolderPath), folder); + + + // Format the filename + return AutoExecConfig_FormatFileName(g_sConfigFile, sizeof(g_sConfigFile), folder) == AUTOEXEC_FORMAT_SUCCESS; +} + + + + + + +/** + * Get the formatted autoconfigfile used by functions of this file. + * + * @param buffer String to format. + * @param size Maximum size of buffer + * @return True if filename was set, false otherwise. +*/ +stock bool AutoExecConfig_GetFile(char[] buffer,int size) +{ + if (strlen(g_sConfigFile) > 0) + { + strcopy(buffer, size, g_sConfigFile); + + return true; + } + + // Security for decl users + buffer[0] = '\0'; + + return false; +} + + + + + + +/** + * Creates a convar and appends it to the autoconfigfile if not found. + * FCVAR_DONTRECORD will be skipped. + * + * @param name Name of new convar. + * @param defaultValue String containing the default value of new convar. + * @param description Optional description of the convar. + * @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details. + * @param hasMin Optional boolean that determines if the convar has a minimum value. + * @param min Minimum floating point value that the convar can have if hasMin is true. + * @param hasMax Optional boolean that determines if the convar has a maximum value. + * @param max Maximum floating point value that the convar can have if hasMax is true. + * @return A handle to the newly created convar. If the convar already exists, a handle to it will still be returned. + * @error Convar name is blank or is the same as an existing console command. +*/ +stock ConVar AutoExecConfig_CreateConVar(const char[] name, const char[] defaultValue, const char[] description="", int flags=0, bool hasMin=false, float min=0.0, bool hasMax=false, float max=0.0) +{ + // If configfile was set and convar has no dontrecord flag + if (!(flags & FCVAR_DONTRECORD) && strlen(g_sConfigFile) > 0) + { + // Reset the results + g_iLastFindResult = -1; + g_iLastAppendResult = -1; + + + // Add it if not found + char buffer[64]; + + g_iLastFindResult = AutoExecConfig_FindValue(name, buffer, sizeof(buffer), true); + + // We only add this convar if it doesn't exist, or the file doesn't exist and it should be auto-generated + if (g_iLastFindResult == AUTOEXEC_FIND_NOT_FOUND || (g_iLastFindResult == AUTOEXEC_FIND_FILE_NOT_FOUND && g_bCreateFile)) + { + g_iLastAppendResult = AutoExecConfig_AppendValue(name, defaultValue, description, flags, hasMin, min, hasMax, max); + } + } + + + // Create the convar + return CreateConVar(name, defaultValue, description, flags, hasMin, min, hasMax, max); +} + + + + +/** + * Executes the autoconfigfile and adds it to the OnConfigsExecuted forward. + * If we didn't create it ourselves we let SourceMod create it. + * + * @noreturn +*/ +stock void AutoExecConfig_ExecuteFile() +{ + // Only let sourcemod create the file, if we didn't do that already. + AutoExecConfig(!g_bCreateFile, g_sRawFileName, g_sFolderPath); +} + + + + + +/** + * Formats a autoconfigfile, prefixes path and adds .cfg extension if missing. + * + * @param buffer String to format. + * @param size Maximum size of buffer. + * @return Returns one of the AUTOEXEC_FORMAT values.. +*/ +stock static int AutoExecConfig_FormatFileName(char[] buffer, int size, char[] folder="sourcemod") +{ + // No config set + if (strlen(g_sConfigFile) < 1) + { + return AUTOEXEC_NO_CONFIG; + } + + + // Can't be an cfgfile + if (StrContains(g_sConfigFile, ".cfg") == -1 && strlen(g_sConfigFile) < 4) + { + return AUTOEXEC_FORMAT_BAD_FILENAME; + } + + + // Pathprefix + char pathprefixbuffer[PLATFORM_MAX_PATH]; + if (strlen(folder) > 0) + { + Format(pathprefixbuffer, sizeof(pathprefixbuffer), "cfg/%s/", folder); + } + else + { + Format(pathprefixbuffer, sizeof(pathprefixbuffer), "cfg/"); + } + + + char filebuffer[PLATFORM_MAX_PATH]; + filebuffer[0] = '\0'; + + // Add path if file doesn't begin with it + if (StrContains(buffer, pathprefixbuffer) != 0) + { + StrCat(filebuffer, sizeof(filebuffer), pathprefixbuffer); + } + + StrCat(filebuffer, sizeof(filebuffer), g_sConfigFile); + + + // Add .cfg extension if file doesn't end with it + if (StrContains(filebuffer[strlen(filebuffer) - 4], ".cfg") != 0) + { + StrCat(filebuffer, sizeof(filebuffer), ".cfg"); + } + + strcopy(buffer, size, filebuffer); + + return AUTOEXEC_FORMAT_SUCCESS; +} + + + + + + +/** + * Appends a convar to the global autoconfigfile + * + * @param name Name of new convar. + * @param defaultValue String containing the default value of new convar. + * @param description Optional description of the convar. + * @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details. + * @param hasMin Optional boolean that determines if the convar has a minimum value. + * @param min Minimum floating point value that the convar can have if hasMin is true. + * @param hasMax Optional boolean that determines if the convar has a maximum value. + * @param max Maximum floating point value that the convar can have if hasMax is true. + * @return Returns one of the AUTOEXEC_APPEND values +*/ +stock int AutoExecConfig_AppendValue(const char[] name, const char[] defaultValue, const char[] description, int flags, bool hasMin, float min, bool hasMax, float max) +{ + // No config set + if (strlen(g_sConfigFile) < 1) + { + return AUTOEXEC_NO_CONFIG; + } + + + char filebuffer[PLATFORM_MAX_PATH]; + strcopy(filebuffer, sizeof(filebuffer), g_sConfigFile); + + + //PrintToServer("pathbuffer: %s", filebuffer); + + bool bFileExists = FileExists(filebuffer); + + if (g_bCreateFile || bFileExists) + { + // If the file already exists we open it in append mode, otherwise we use a write mode which creates the file + File fFile = OpenFile(filebuffer, (bFileExists ? "a" : "w")); + char writebuffer[2048]; + + + if (fFile == null) + { + return AUTOEXEC_APPEND_BAD_HANDLE; + } + + // We just created the file, so add some header about version and stuff + if (g_bCreateFile && !bFileExists) + { + fFile.WriteLine( "// This file was auto-generated by AutoExecConfig v%s (%s)", AUTOEXECCONFIG_VERSION, AUTOEXECCONFIG_URL); + + GetPluginFilename(g_hPluginHandle, writebuffer, sizeof(writebuffer)); + Format(writebuffer, sizeof(writebuffer), "// ConVars for plugin \"%s\"", writebuffer); + fFile.WriteLine(writebuffer); + } + + // Spacer + fFile.WriteLine("\n"); + + + // This is used for multiline comments + int newlines = GetCharCountInStr('\n', description); + if (newlines == 0) + { + // We have no newlines, we can write the description to the file as is + Format(writebuffer, sizeof(writebuffer), "// %s", description); + fFile.WriteLine(writebuffer); + } + else + { + char[][] newlineBuf = new char[newlines +1][2048]; + ExplodeString(description, "\n", newlineBuf, newlines +1, 2048, false); + + // Each newline gets a commented newline + for (int i; i <= newlines; i++) + { + if (strlen(newlineBuf[i]) > 0) + { + fFile.WriteLine("// %s", newlineBuf[i]); + } + } + } + + + // Descspacer + fFile.WriteLine("// -"); + + + // Default + Format(writebuffer, sizeof(writebuffer), "// Default: \"%s\"", defaultValue); + fFile.WriteLine(writebuffer); + + + // Minimum + if (hasMin) + { + Format(writebuffer, sizeof(writebuffer), "// Minimum: \"%f\"", min); + fFile.WriteLine(writebuffer); + } + + + // Maximum + if (hasMax) + { + Format(writebuffer, sizeof(writebuffer), "// Maximum: \"%f\"", max); + fFile.WriteLine(writebuffer); + } + + + // Write end and defaultvalue + Format(writebuffer, sizeof(writebuffer), "%s \"%s\"", name, defaultValue); + fFile.WriteLine(writebuffer); + + + fFile.Close(); + + + // Clean up the file + //AutoExecConfig_CleanFile(filebuffer, false); + + + return AUTOEXEC_APPEND_SUCCESS; + } + + return AUTOEXEC_APPEND_FILE_NOT_FOUND; +} + + + + + + +/** + * Returns a convar's value from the global autoconfigfile + * + * @param cvar Cvar to search for. + * @param value Buffer to store result into. + * @param size Maximum size of buffer. + * @param caseSensitive Whether or not the search should be case sensitive. + * @return Returns one of the AUTOEXEC_FIND values +*/ +stock int AutoExecConfig_FindValue(const char[] cvar, char[] value, int size, bool caseSensitive=false) +{ + // Security for decl users + value[0] = '\0'; + + + // No config set + if (strlen(g_sConfigFile) < 1) + { + return AUTOEXEC_NO_CONFIG; + } + + if (g_bCacheEnabled) + { + char sTrieValue[64]; + + if (g_hConvarTrie.GetString(cvar, sTrieValue, sizeof(sTrieValue))) + { + strcopy(value, size, sTrieValue); + + return AUTOEXEC_FIND_SUCCESS; + } + + return AUTOEXEC_FIND_NOT_FOUND; + } + + + char filebuffer[PLATFORM_MAX_PATH]; + strcopy(filebuffer, sizeof(filebuffer), g_sConfigFile); + + + + //PrintToServer("pathbuffer: %s", filebuffer); + + bool bFileExists = FileExists(filebuffer); + + // We want to create the config file and it doesn't exist yet. + if (g_bCreateFile && !bFileExists) + { + return AUTOEXEC_FIND_FILE_NOT_FOUND; + } + + + if (bFileExists) + { + File fFile = OpenFile(filebuffer, "r"); + int valuestart; + int valueend; + int cvarend; + + // Just an reminder to self, leave the values that high + char sConvar[64]; + char sValue[64]; + char readbuffer[2048]; + char copybuffer[2048]; + + if (fFile == null) + { + return AUTOEXEC_FIND_BAD_HANDLE; + } + + + while (!fFile.EndOfFile() && fFile.ReadLine(readbuffer, sizeof(readbuffer))) + { + // Is a comment or not valid + if (IsCharSpace(readbuffer[0]) || readbuffer[0] == '/' || !IsCharAlpha(readbuffer[0])) + { + continue; + } + + + // Has not enough spaces, must have at least 1 + if (GetCharCountInStr(' ', readbuffer) < 1) + { + continue; + } + + + // Ignore cvars which aren't quoted + if (GetCharCountInStr('"', readbuffer) != 2) + { + continue; + } + + + + // Get the start of the value + if ( (valuestart = StrContains(readbuffer, "\"")) == -1 ) + { + continue; + } + + + // Get the end of the value + if ( (valueend = StrContains(readbuffer[valuestart+1], "\"")) == -1 ) + { + continue; + } + + + // Get the start of the cvar, + if ( (cvarend = StrContains(readbuffer, " ")) == -1 || cvarend >= valuestart) + { + continue; + } + + + // Skip if cvarendindex is before valuestartindex + if (cvarend >= valuestart) + { + continue; + } + + + // Convar + // Tempcopy for security + strcopy(copybuffer, sizeof(copybuffer), readbuffer); + copybuffer[cvarend] = '\0'; + + strcopy(sConvar, sizeof(sConvar), copybuffer); + + + // Value + // Tempcopy for security + strcopy(copybuffer, sizeof(copybuffer), readbuffer[valuestart+1]); + copybuffer[valueend] = '\0'; + + strcopy(sValue, sizeof(sValue), copybuffer); + + + //PrintToServer("Cvar %s has a value of %s", sConvar, sValue); + + if (StrEqual(sConvar, cvar, caseSensitive)) + { + Format(value, size, "%s", sConvar); + + fFile.Close(); + return AUTOEXEC_FIND_SUCCESS; + } + } + + fFile.Close(); + return AUTOEXEC_FIND_NOT_FOUND; + } + + + return AUTOEXEC_FIND_FILE_NOT_FOUND; +} + + + + + + +/** + * Cleans the global autoconfigfile from too much spaces + * + * @return One of the AUTOEXEC_CLEAN values. +*/ +stock int AutoExecConfig_CleanFile() +{ + // No config set + if (strlen(g_sConfigFile) < 1) + { + return AUTOEXEC_NO_CONFIG; + } + + + char sfile[PLATFORM_MAX_PATH]; + strcopy(sfile, sizeof(sfile), g_sConfigFile); + + + // Security + if (!FileExists(sfile)) + { + return AUTOEXEC_CLEAN_FILE_NOT_FOUND; + } + + + + char sfile2[PLATFORM_MAX_PATH]; + Format(sfile2, sizeof(sfile2), "%s_tempcopy", sfile); + + + char readbuffer[2048]; + int count; + bool firstreached; + + + // Open files + File fFile1 = OpenFile(sfile, "r"); + File fFile2 = OpenFile(sfile2, "w"); + + + + // Check filehandles + if (fFile1 == null || fFile2 == null) + { + if (fFile1 != null) + { + //PrintToServer("Handle1 invalid"); + fFile1.Close(); + } + + if (fFile2 != null) + { + //PrintToServer("Handle2 invalid"); + fFile2.Close(); + } + + return AUTOEXEC_CLEAN_BAD_HANDLE; + } + + + + while (!fFile1.EndOfFile() && fFile1.ReadLine(readbuffer, sizeof(readbuffer))) + { + // Is space + if (IsCharSpace(readbuffer[0])) + { + count++; + } + // No space, count from start + else + { + count = 0; + } + + + // Don't write more than 1 space if seperation after informations have been reached + if (count < 2 || !firstreached) + { + ReplaceString(readbuffer, sizeof(readbuffer), "\n", ""); + fFile2.WriteLine(readbuffer); + } + + + // First bigger seperation after informations has been reached + if (count == 2) + { + firstreached = true; + } + } + + + fFile1.Close(); + fFile2.Close(); + + + // This might be a risk, for now it works + DeleteFile(sfile); + RenameFile(sfile, sfile2); + + return AUTOEXEC_CLEAN_SUCCESS; +} + + + + + + +/** + * Returns how many times the given char occures in the given string. + * + * @param str String to search for in. + * @return Occurences of the given char found in string. +*/ +stock static int GetCharCountInStr(int character, const char[] str) +{ + int len = strlen(str); + int count; + + for (int i; i < len; i++) + { + if (str[i] == character) + { + count++; + } + } + + return count; +} + + + + + + +/** + * Reads the existing config file and caches any convars and values that were found. + * + * @return True when config existed and could be read, false otherwise. +*/ +stock bool AutoExecConfig_CacheConvars() +{ + if (g_hConvarTrie == null) + { + g_hConvarTrie = new StringMap(); + } + + // No config set + if (strlen(g_sConfigFile) < 1) + { + return false; + } + + + char filebuffer[PLATFORM_MAX_PATH]; + strcopy(filebuffer, sizeof(filebuffer), g_sConfigFile); + + + + //PrintToServer("pathbuffer: %s", filebuffer); + + bool bFileExists = FileExists(filebuffer); + + // We want to create the config file and it doesn't exist yet. + if (!bFileExists) + { + return false; + } + + + + File fFile = OpenFile(filebuffer, "r"); + int valuestart; + int valueend; + int cvarend; + + // Just an reminder to self, leave the values that high + char sConvar[64]; + char sValue[64]; + char readbuffer[2048]; + char copybuffer[2048]; + + if (fFile == null) + { + return false; + } + + + while (!fFile.EndOfFile() && fFile.ReadLine(readbuffer, sizeof(readbuffer))) + { + // Is a comment or not valid + if (IsCharSpace(readbuffer[0]) || readbuffer[0] == '/' || !IsCharAlpha(readbuffer[0])) + { + continue; + } + + + // Has not enough spaces, must have at least 1 + if (GetCharCountInStr(' ', readbuffer) < 1) + { + continue; + } + + + // Ignore cvars which aren't quoted + if (GetCharCountInStr('"', readbuffer) != 2) + { + continue; + } + + + + // Get the start of the value + if ( (valuestart = StrContains(readbuffer, "\"")) == -1 ) + { + continue; + } + + + // Get the end of the value + if ( (valueend = StrContains(readbuffer[valuestart+1], "\"")) == -1 ) + { + continue; + } + + + // Get the start of the cvar, + if ( (cvarend = StrContains(readbuffer, " ")) == -1 || cvarend >= valuestart) + { + continue; + } + + + // Skip if cvarendindex is before valuestartindex + if (cvarend >= valuestart) + { + continue; + } + + + // Convar + // Tempcopy for security + strcopy(copybuffer, sizeof(copybuffer), readbuffer); + copybuffer[cvarend] = '\0'; + + strcopy(sConvar, sizeof(sConvar), copybuffer); + + + // Value + // Tempcopy for security + strcopy(copybuffer, sizeof(copybuffer), readbuffer[valuestart+1]); + copybuffer[valueend] = '\0'; + + strcopy(sValue, sizeof(sValue), copybuffer); + + + //PrintToServer("Cvar %s has a value of %s", sConvar, sValue); + + char sTrieValue[64]; + if (!g_hConvarTrie.GetString(sConvar, sTrieValue, sizeof(sTrieValue))) + { + //PrintToServer("Adding convar %s to trie", sConvar); + g_hConvarTrie.SetString(sConvar, sValue); + } + } + + fFile.Close(); + + g_bCacheEnabled = true; + + return true; +} diff --git a/addons/sourcemod/scripting/include/betterwarden.inc b/addons/sourcemod/scripting/include/betterwarden.inc index 16f3e08..921bec2 100644 --- a/addons/sourcemod/scripting/include/betterwarden.inc +++ b/addons/sourcemod/scripting/include/betterwarden.inc @@ -8,9 +8,11 @@ #endinput #endif #define bwardenincluded -#define VERSION "0.6.2c" +#define VERSION "0.6.3.2" stock char g_sPrefix[] = "[{blue}Warden{default}] "; +stock char g_sLogPath[PLATFORM_MAX_PATH] = "addons/sourcemod/logs/betterwarden.log"; + /** * Called when the current warden dies. @@ -147,4 +149,13 @@ stock void PrecacheModelAnyDownload(char[] sModel) Format(sBuffer, sizeof(sBuffer), "materials/%s.vtf", sModel); AddFileToDownloadsTable(sBuffer); PrecacheModel(sBuffer, true); -} \ No newline at end of file +} + +/** +* Adds a message to logfile if enabled in config. +* +* @param sMessage Message to enter in log +* @param ... Formatting arguments +* @return true if successful +*/ +native bool AddToBWLog(const char[] sMessage, any ...); \ No newline at end of file diff --git a/addons/sourcemod/scripting/wardenmenu.sp b/addons/sourcemod/scripting/wardenmenu.sp index 551c989..e3dfe33 100644 --- a/addons/sourcemod/scripting/wardenmenu.sp +++ b/addons/sourcemod/scripting/wardenmenu.sp @@ -23,6 +23,7 @@ #include #include #include +#include // Optional plugins #undef REQUIRE_PLUGIN @@ -138,27 +139,31 @@ public void OnPluginStart() { LoadTranslations("BetterWarden.Catch.phrases.txt"); LoadTranslations("BetterWarden.WildWest.phrases.txt"); LoadTranslations("BetterWarden.Zombie.phrases.txt"); + LoadTranslations("BetterWarden.Votes.phrases.txt"); SetGlobalTransTarget(LANG_SERVER); - AutoExecConfig(true, "menu", "BetterWarden"); + AutoExecConfig_SetFile("menu", "BetterWarden"); // What's the configs name and location? + AutoExecConfig_SetCreateFile(true); // Create config if it does not exist + gc_bHnS = AutoExecConfig_CreateConVar("sm_cmenu_hns", "1", "Add an option for Hide and Seek in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bHnSGod = AutoExecConfig_CreateConVar("sm_cmenu_hns_godmode", "1", "Makes CT's invulnerable against attacks from T's during HnS to prevent rebels.\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_iHnSTimes = AutoExecConfig_CreateConVar("sm_cmenu_hns_rounds", "2", "How many times is HnS allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); + gc_bFreeday = AutoExecConfig_CreateConVar("sm_cmenu_freeday", "1", "Add an option for a freeday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_iFreedayTimes = AutoExecConfig_CreateConVar("sm_cmenu_freeday_rounds", "2", "How many times is a Freeday allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); + gc_bWarday = AutoExecConfig_CreateConVar("sm_cmenu_warday", "1", "Add an option for Warday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_iWardayTimes = AutoExecConfig_CreateConVar("sm_cmenu_warday_rounds", "1", "How many times is a Warday allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); + gc_bGrav = AutoExecConfig_CreateConVar("sm_cmenu_gravity", "1", "Add an option for a gravity freeday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_iGravTeam = AutoExecConfig_CreateConVar("sm_cmenu_gravity_team", "2", "Which team should get a special gravity on Gravity Freedays?\n0 = All teams.\n1 = Counter-Terrorists.\n2 = Terorrists.", FCVAR_NOTIFY, true, 0.0, true, 2.0); + gc_fGravStrength = AutoExecConfig_CreateConVar("sm_cmenu_gravity_strength", "0.5", "What should the gravity be set to on Gravity Freedays?", FCVAR_NOTIFY); + gc_iGravTimes = AutoExecConfig_CreateConVar("sm_cmenu_gravity_rounds", "1", "How many times is a Gravity Freeday allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); + gc_bNoblock = AutoExecConfig_CreateConVar("sm_cmenu_noblock", "1", "sm_warden_noblock needs to be set to 1 for this to work!\nAdd an option for toggling noblock in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bAutoOpen = AutoExecConfig_CreateConVar("sm_cmenu_auto_open", "1", "Automatically open the menu when a user becomes warden?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bEnableWeapons = AutoExecConfig_CreateConVar("sm_cmenu_weapons", "1", "Add an option for giving the warden a list of weapons via the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bRestFreeday = AutoExecConfig_CreateConVar("sm_cmenu_restricted_freeday", "1", "Add an option for a restricted freeday in the menu?\nThis event uses the same configuration as a normal freeday.\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bEnablePlayerFreeday = AutoExecConfig_CreateConVar("sm_cmenu_player_freeday", "1", "Add an option for giving a specific player a freeday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + gc_bEnableDoors = AutoExecConfig_CreateConVar("sm_cmenu_doors", "1", "sm_warden_cellscmd needs to be set to 1 for this to work!\nAdd an option for opening doors via the menu.\n0 = Disable.\n1 = Enable", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bHnS = CreateConVar("sm_cmenu_hns", "1", "Add an option for Hide and Seek in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bHnSGod = CreateConVar("sm_cmenu_hns_godmode", "1", "Makes CT's invulnerable against attacks from T's during HnS to prevent rebels.\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_iHnSTimes = CreateConVar("sm_cmenu_hns_rounds", "2", "How many times is HnS allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); - gc_bFreeday = CreateConVar("sm_cmenu_freeday", "1", "Add an option for a freeday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_iFreedayTimes = CreateConVar("sm_cmenu_freeday_rounds", "2", "How many times is a Freeday allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); - gc_bWarday = CreateConVar("sm_cmenu_warday", "1", "Add an option for Warday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_iWardayTimes = CreateConVar("sm_cmenu_warday_rounds", "1", "How many times is a Warday allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); - gc_bGrav = CreateConVar("sm_cmenu_gravity", "1", "Add an option for a gravity freeday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_iGravTeam = CreateConVar("sm_cmenu_gravity_team", "2", "Which team should get a special gravity on Gravity Freedays?\n0 = All teams.\n1 = Counter-Terrorists.\n2 = Terorrists.", FCVAR_NOTIFY, true, 0.0, true, 2.0); - gc_fGravStrength = CreateConVar("sm_cmenu_gravity_strength", "0.5", "What should the gravity be set to on Gravity Freedays?", FCVAR_NOTIFY); - gc_iGravTimes = CreateConVar("sm_cmenu_gravity_rounds", "1", "How many times is a Gravity Freeday allowed per map?\nSet to 0 for unlimited.", FCVAR_NOTIFY); - gc_bNoblock = CreateConVar("sm_cmenu_noblock", "1", "sm_warden_noblock needs to be set to 1 for this to work!\nAdd an option for toggling noblock in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bAutoOpen = CreateConVar("sm_cmenu_auto_open", "1", "Automatically open the menu when a user becomes warden?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bEnableWeapons = CreateConVar("sm_cmenu_weapons", "1", "Add an option for giving the warden a list of weapons via the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bRestFreeday = CreateConVar("sm_cmenu_restricted_freeday", "1", "Add an option for a restricted freeday in the menu?\nThis event uses the same configuration as a normal freeday.\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bEnablePlayerFreeday = CreateConVar("sm_cmenu_player_freeday", "1", "Add an option for giving a specific player a freeday in the menu?\n0 = Disable.\n1 = Enable.", FCVAR_NOTIFY, true, 0.0, true, 1.0); - gc_bEnableDoors = CreateConVar("sm_cmenu_doors", "1", "sm_warden_cellscmd needs to be set to 1 for this to work!\nAdd an option for opening doors via the menu.\n0 = Disable.\n1 = Enable", FCVAR_NOTIFY, true, 0.0, true, 1.0); + AutoExecConfig_ExecuteFile(); // Execute the config + AutoExecConfig_CleanFile(); // Clean the .cfg from spaces etc. RegConsoleCmd("sm_abortgames", sm_abortgames); RegConsoleCmd("sm_cmenu", sm_cmenu); @@ -236,6 +241,7 @@ public void initRestFreeday(int client) { CPrintToChatAll("{blue}-----------------------------------------------------"); g_iFreedayActive = 1; g_bIsGameActive = true; + AddToBWLog("A Restricted Freeday was executed."); } else if(gc_iFreedayTimes.IntValue != 0 && g_iFreedayTimes >= gc_iFreedayTimes.IntValue) { CPrintToChat(client, "%s %t", g_sCMenuPrefix, "Too many freedays", g_iFreedayTimes, gc_iFreedayTimes.IntValue); } else if(gc_iFreedayTimes.IntValue != 0 && g_iFreedayTimes < gc_iFreedayTimes.IntValue) { @@ -247,13 +253,10 @@ public void initRestFreeday(int client) { g_iFreedayActive = 1; g_bIsGameActive = true; g_iFreedayTimes++; + AddToBWLog("A Restricted Freeday was executed."); } } -public void initGrav(int client) { - -} - public void error(int client, int errorCode) { if(errorCode == 0) { CPrintToChat(client, "%s %t", g_sCMenuPrefix, "Not Warden"); diff --git a/addons/sourcemod/translations/BetterWarden.phrases.txt b/addons/sourcemod/translations/BetterWarden.phrases.txt index 25aa326..180074d 100644 --- a/addons/sourcemod/translations/BetterWarden.phrases.txt +++ b/addons/sourcemod/translations/BetterWarden.phrases.txt @@ -138,4 +138,22 @@ "sv" "Användaren är inte en Counter-Terrorist." "fr" "Le joueur est pas un Counter-Terrorist." } + + "Deactivated LR" + { + "en" "The warden has deactivated Last Request." + "sv" "Direktören har avaktiverat Last Request." + } + + "Activated LR" + { + "en" "The warden has activated Last Request!" + "sv" "Direktören har aktiverat Last Request!" + } + + "No LR Allowed" + { + "en" "The warden does not allow LR right now." + "sv" "Direktören tillåter inte LR för tillfället." + } }