diff --git a/addons/sourcemod/scripting/include/shavit/hud.inc b/addons/sourcemod/scripting/include/shavit/hud.inc index 51c7af53..8e29aecf 100644 --- a/addons/sourcemod/scripting/include/shavit/hud.inc +++ b/addons/sourcemod/scripting/include/shavit/hud.inc @@ -37,6 +37,8 @@ #define HUD_2DVEL (1 << 10) // shows 2d velocity #define HUD_NOSOUNDS (1 << 11) // disables sounds on personal best, world record etc #define HUD_NOPRACALERT (1 << 12) // hides practice mode chat alert +#define HUD_USP (1 << 13) // makes you spawn with a USP +#define HUD_GLOCK (1 << 14) // makes you spawn with a Glock // HUD2 - these settings will *disable* elements for the main hud #define HUD2_TIME (1 << 0) @@ -53,6 +55,8 @@ #define HUD2_PERFS (1 << 11) #define HUD2_TOPLEFT_RANK (1 << 12) #define HUD2_VELOCITYDIFFERENCE (1 << 13) +#define HUD2_USPSILENCER (1 << 14) // spawns usps with a silencer on (only used in CSS) +#define HUD2_GLOCKBURST (1 << 15) // spawns glocks with burst #define HUD_DEFAULT (HUD_MASTER|HUD_CENTER|HUD_ZONEHUD|HUD_OBSERVE|HUD_TOPLEFT|HUD_SYNC|HUD_TIMELEFT|HUD_2DVEL|HUD_SPECTATORS) #define HUD_DEFAULT2 (HUD2_PERFS) @@ -87,6 +91,15 @@ native int Shavit_ForceHUDUpdate(int client, bool spectators); */ native int Shavit_GetHUDSettings(int client); +/** + * Gets the HUD2 settings of a player. + * See the HUD2_* defines for information. + * + * @param client Client index. + * @return HUD settings. + */ +native int Shavit_GetHUD2Settings(int client); + public SharedPlugin __pl_shavit_hud = { name = "shavit-hud", @@ -103,5 +116,6 @@ public void __pl_shavit_hud_SetNTVOptional() { MarkNativeAsOptional("Shavit_ForceHUDUpdate"); MarkNativeAsOptional("Shavit_GetHUDSettings"); + MarkNativeAsOptional("Shavit_GetHUD2Settings"); } #endif diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 89376edc..d805f405 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -36,6 +36,9 @@ #include #include +#undef REQUIRE_EXTENSIONS +#include + #pragma newdecls required #pragma semicolon 1 @@ -147,6 +150,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max // natives CreateNative("Shavit_ForceHUDUpdate", Native_ForceHUDUpdate); CreateNative("Shavit_GetHUDSettings", Native_GetHUDSettings); + CreateNative("Shavit_GetHUD2Settings", Native_GetHUD2Settings); // registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins RegPluginLibrary("shavit-hud"); @@ -204,7 +208,10 @@ public void OnPluginStart() ..."HUD_TIMELEFT 512\n" ..."HUD_2DVEL 1024\n" ..."HUD_NOSOUNDS 2048\n" - ..."HUD_NOPRACALERT 4096\n"); + ..."HUD_NOPRACALERT 4096\n" + ..."HUD_USP 8192\n" + ..."HUD_GLOCK 16384\n" + ); IntToString(HUD_DEFAULT2, defaultHUD, 8); gCV_DefaultHUD2 = new Convar("shavit_hud2_default", defaultHUD, "Default HUD2 settings as a bitflag of what to remove\n" @@ -222,6 +229,8 @@ public void OnPluginStart() ..."HUD2_PERFS 2048\n" ..."HUD2_TOPLEFT_RANK 4096\n" ..."HUD2_VELOCITYDIFFERENCE 8192\n" + ..."HUD2_USPSILENCER 16384\n" + ..."HUD2_GLOCKBURST 32768\n" ); Convar.AutoExecConfig(); @@ -260,6 +269,8 @@ public void OnPluginStart() gH_HUDCookie = RegClientCookie("shavit_hud_setting", "HUD settings", CookieAccess_Protected); gH_HUDCookieMain = RegClientCookie("shavit_hud_settingmain", "HUD settings for hint text.", CookieAccess_Protected); + HookEvent("player_spawn", Player_Spawn); + if(gB_Late) { Shavit_OnStyleConfigLoaded(Shavit_GetStyleCount()); @@ -700,6 +711,13 @@ Action ShowHUDMenu(int client, int item) FormatEx(sHudItem, 64, "%T", "HudPracticeModeAlert", client); menu.AddItem(sInfo, sHudItem); + if (gEV_Type != Engine_TF2) + { + FormatEx(sInfo, 16, "#%d", HUD_USP); + FormatEx(sHudItem, 64, "%T", "HudDefaultPistol", client); + menu.AddItem(sInfo, sHudItem); + } + // HUD2 - disables selected elements FormatEx(sInfo, 16, "@%d", HUD2_TIME); FormatEx(sHudItem, 64, "%T", "HudTimeText", client); @@ -763,6 +781,20 @@ Action ShowHUDMenu(int client, int item) menu.AddItem(sInfo, sHudItem); } + if (gEV_Type != Engine_TF2) + { + FormatEx(sInfo, 16, "@%d", HUD2_GLOCKBURST); + FormatEx(sHudItem, 64, "%T", "HudGlockBurst", client); + menu.AddItem(sInfo, sHudItem); + } + + if (gEV_Type == Engine_CSS) + { + FormatEx(sInfo, 16, "@%d", HUD2_USPSILENCER); + FormatEx(sHudItem, 64, "%T", "HudUSPSilencer", client); + menu.AddItem(sInfo, sHudItem); + } + menu.ExitButton = true; menu.DisplayAt(client, item, MENU_TIME_FOREVER); @@ -776,9 +808,10 @@ public int MenuHandler_HUD(Menu menu, MenuAction action, int param1, int param2) char sCookie[16]; menu.GetItem(param2, sCookie, 16); - int type = (sCookie[0] == '!')? 1:2; + int type = (sCookie[0] == '!') ? 1 : (sCookie[0] == '@' ? 2 : 3); ReplaceString(sCookie, 16, "!", ""); ReplaceString(sCookie, 16, "@", ""); + ReplaceString(sCookie, 16, "#", ""); int iSelection = StringToInt(sCookie); @@ -788,13 +821,32 @@ public int MenuHandler_HUD(Menu menu, MenuAction action, int param1, int param2) IntToString(gI_HUDSettings[param1], sCookie, 16); SetClientCookie(param1, gH_HUDCookie, sCookie); } - - else + else if (type == 2) { gI_HUD2Settings[param1] ^= iSelection; IntToString(gI_HUD2Settings[param1], sCookie, 16); SetClientCookie(param1, gH_HUDCookieMain, sCookie); } + else if (type == 3) // special trinary ones :) + { + int mask = (iSelection | (iSelection << 1)); + + if (!(gI_HUDSettings[param1] & mask)) + { + gI_HUDSettings[param1] |= iSelection; + } + else if (gI_HUDSettings[param1] & iSelection) + { + gI_HUDSettings[param1] ^= mask; + } + else + { + gI_HUDSettings[param1] &= ~mask; + } + + IntToString(gI_HUDSettings[param1], sCookie, 16); + SetClientCookie(param1, gH_HUDCookie, sCookie); + } if(gEV_Type == Engine_TF2 && iSelection == HUD_CENTER && (gI_HUDSettings[param1] & HUD_MASTER) > 0) { @@ -811,18 +863,26 @@ public int MenuHandler_HUD(Menu menu, MenuAction action, int param1, int param2) int style = 0; menu.GetItem(param2, sInfo, 16, style, sDisplay, 64); - int type = (sInfo[0] == '!')? 1:2; + int type = (sInfo[0] == '!') ? 1 : (sInfo[0] == '@' ? 2 : 3); ReplaceString(sInfo, 16, "!", ""); ReplaceString(sInfo, 16, "@", ""); + ReplaceString(sInfo, 16, "#", ""); + + int iSelection = StringToInt(sInfo); if(type == 1) { - Format(sDisplay, 64, "[%s] %s", ((gI_HUDSettings[param1] & StringToInt(sInfo)) > 0)? "+":"-", sDisplay); + Format(sDisplay, 64, "[%s] %s", ((gI_HUDSettings[param1] & iSelection) > 0)? "+":"-", sDisplay); } - - else + else if (type == 2) { - Format(sDisplay, 64, "[%s] %s", ((gI_HUD2Settings[param1] & StringToInt(sInfo)) == 0)? "+":"-", sDisplay); + Format(sDisplay, 64, "[%s] %s", ((gI_HUD2Settings[param1] & iSelection) == 0)? "+":"-", sDisplay); + } + else if (type == 3) // special trinary ones :) + { + bool first = 0 != (gI_HUDSettings[param1] & iSelection); + bool second = 0 != (gI_HUDSettings[param1] & (iSelection << 1)); + Format(sDisplay, 64, "[%s] %s", first ? "1" : (second ? "2" : "0"), sDisplay); } return RedrawMenuItem(sDisplay); @@ -836,6 +896,74 @@ public int MenuHandler_HUD(Menu menu, MenuAction action, int param1, int param2) return 0; } +public void OnEntityCreated(int entity, const char[] classname) +{ + if ((gEV_Type == Engine_CSS && StrEqual(classname, "weapon_usp")) + || (StrEqual(classname, "weapon_glock"))) + { + SDKHook(entity, SDKHook_Touch, Hook_GunTouch); + } +} + +public Action Hook_GunTouch(int entity, int client) +{ + if (1 <= client <= MaxClients) + { + char classname[64]; + GetEntityClassname(entity, classname, sizeof(classname)); + + if (StrEqual(classname, "weapon_glock")) + { + if (!IsFakeClient(client) && !(gI_HUD2Settings[client] & HUD2_GLOCKBURST)) + { + SetEntProp(entity, Prop_Send, "m_bBurstMode", 1); + } + } + else if (gEV_Type == Engine_CSS && StrEqual(classname, "weapon_usp") && !(gI_HUD2Settings[client] & HUD2_USPSILENCER)) + { + SetEntProp(entity, Prop_Send, "m_bSilencerOn", 1); + SetEntProp(entity, Prop_Send, "m_weaponMode", 1); + SetEntPropFloat(entity, Prop_Send, "m_flDoneSwitchingSilencer", GetGameTime() - 0.1); + } + } + + return Plugin_Continue; +} + +public void Player_Spawn(Event event, const char[] name, bool dontBroadcast) +{ + int client = GetClientOfUserId(event.GetInt("userid")); + + if (!IsFakeClient(client)) + { + if (gEV_Type != Engine_TF2 && (gI_HUDSettings[client] & (HUD_GLOCK|HUD_USP))) + { + PrintToChat(client, "0x%X", (gI_HUDSettings[client] & (HUD_GLOCK|HUD_USP))); + int iSlot = CS_SLOT_SECONDARY; + int iWeapon = GetPlayerWeaponSlot(client, iSlot); + char sWeapon[32]; + + if (gI_HUDSettings[client] & HUD_USP) + { + strcopy(sWeapon, 32, (gEV_Type == Engine_CSS) ? "weapon_usp" : "weapon_usp_silencer"); + } + else + { + strcopy(sWeapon, 32, "weapon_glock"); + } + + if (iWeapon != -1) + { + RemovePlayerItem(client, iWeapon); + AcceptEntityInput(iWeapon, "Kill"); + } + + iWeapon = GivePlayerItem(client, sWeapon); + FakeClientCommand(client, "use %s", sWeapon); + } + } +} + public void OnGameFrame() { if((GetGameTickCount() % gCV_TicksPerUpdate.IntValue) == 0) @@ -2063,6 +2191,12 @@ public int Native_GetHUDSettings(Handle handler, int numParams) return gI_HUDSettings[client]; } +public int Native_GetHUD2Settings(Handle handler, int numParams) +{ + int client = GetNativeCell(1); + return gI_HUD2Settings[client]; +} + void PrintCSGOHUDText(int client, const char[] str) { char buff[MAX_HINT_SIZE]; diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index c3522d05..b0daf064 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -93,7 +93,6 @@ Convar gCV_CreateSpawnPoints = null; Convar gCV_DisableRadio = null; Convar gCV_Scoreboard = null; Convar gCV_WeaponCommands = null; -Convar gCV_WeaponsSpawnGood = null; Convar gCV_PlayerOpacity = null; Convar gCV_NoclipMe = null; Convar gCV_AdvertisementInterval = null; @@ -261,7 +260,6 @@ public void OnPluginStart() gCV_DisableRadio = new Convar("shavit_misc_disableradio", "1", "Block radio commands.\n0 - Disabled (radio commands work)\n1 - Enabled (radio commands are blocked)", 0, true, 0.0, true, 1.0); gCV_Scoreboard = new Convar("shavit_misc_scoreboard", "1", "Manipulate scoreboard so score is -{time} and deaths are {rank})?\nDeaths part requires shavit-rankings.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0); gCV_WeaponCommands = new Convar("shavit_misc_weaponcommands", "2", "Enable sm_usp, sm_glock and sm_knife?\n0 - Disabled\n1 - Enabled\n2 - Also give infinite reserved ammo.\n3 - Also give infinite clip ammo.", 0, true, 0.0, true, 3.0); - gCV_WeaponsSpawnGood = new Convar("shavit_misc_weaponsspawngood", "3", "Bitflag for making glocks spawn on burst-fire and USPs spawn with a silencer on.\n0 - Disabled\n1 - Spawn USPs with a silencer.\n2 - Spawn glocks on burst-fire mode.\n3 - Spawn both USPs and glocks GOOD.", 0, true, 0.0, true, 3.0); gCV_PlayerOpacity = new Convar("shavit_misc_playeropacity", "69", "Player opacity (alpha) to set on spawn.\n-1 - Disabled\nValue can go up to 255. 0 for invisibility.", 0, true, -1.0, true, 255.0); gCV_NoclipMe = new Convar("shavit_misc_noclipme", "1", "Allow +noclip, sm_p and all the noclip commands?\n0 - Disabled\n1 - Enabled\n2 - requires 'admin_noclipme' override or ADMFLAG_CHEATS flag.", 0, true, 0.0, true, 2.0); gCV_AdvertisementInterval = new Convar("shavit_misc_advertisementinterval", "600.0", "Interval between each chat advertisement.\nConfiguration file for those is configs/shavit-advertisements.cfg.\nSet to 0.0 to disable.\nRequires server restart for changes to take effect.", 0, true, 0.0); @@ -999,7 +997,7 @@ public Action Timer_Advertisement(Handle timer) gA_Advertisements.GetString(gI_AdvertisementsCycle, sTempMessage, 300); char sName[MAX_NAME_LENGTH]; - GetClientName(i, sName, MAX_NAME_LENGTH); + SanerGetClientName(i, sName); ReplaceString(sTempMessage, 300, "{name}", sName); ReplaceString(sTempMessage, 300, "{timeleft}", sTimeLeft); ReplaceString(sTempMessage, 300, "{timeleftraw}", sTimeLeftRaw); @@ -1561,7 +1559,7 @@ public Action Command_Teleport(int client, int args) IntToString(GetClientSerial(i), serial, 16); char sName[MAX_NAME_LENGTH]; - GetClientName(i, sName, MAX_NAME_LENGTH); + SanerGetClientName(i, sName); menu.AddItem(serial, sName); } @@ -1622,40 +1620,6 @@ bool Teleport(int client, int targetserial) return true; } -public Action Hook_GunTouch(int entity, int client) -{ - if (1 <= client <= MaxClients) - { - char classname[64]; - GetEntityClassname(entity, classname, sizeof(classname)); - - if (StrEqual(classname, "weapon_glock")) - { - if (!IsValidClient(client) || !IsFakeClient(client)) - { - SetEntProp(entity, Prop_Send, "m_bBurstMode", 1); - } - } - else if (gEV_Type == Engine_CSS && StrEqual(classname, "weapon_usp")) - { - SetEntProp(entity, Prop_Send, "m_bSilencerOn", 1); - SetEntProp(entity, Prop_Send, "m_weaponMode", 1); - SetEntPropFloat(entity, Prop_Send, "m_flDoneSwitchingSilencer", GetGameTime() - 0.1); - } - } - - return Plugin_Continue; -} - -public void OnEntityCreated(int entity, const char[] classname) -{ - if (((gCV_WeaponsSpawnGood.IntValue & 1) && gEV_Type == Engine_CSS && StrEqual(classname, "weapon_usp")) - || ((gCV_WeaponsSpawnGood.IntValue & 2) && StrEqual(classname, "weapon_glock"))) - { - SDKHook(entity, SDKHook_Touch, Hook_GunTouch); - } -} - public Action Command_Weapon(int client, int args) { if(!IsValidClient(client) || gEV_Type == Engine_TF2) diff --git a/addons/sourcemod/translations/shavit-hud.phrases.txt b/addons/sourcemod/translations/shavit-hud.phrases.txt index 930ec71e..3611cca2 100644 --- a/addons/sourcemod/translations/shavit-hud.phrases.txt +++ b/addons/sourcemod/translations/shavit-hud.phrases.txt @@ -75,6 +75,18 @@ { "en" "Perfect jumps" } + "HudDefaultPistol" + { + "en" "Default Pistol: 1=USP 2=Glock" + } + "HudUSPSilencer" + { + "en" "Spawn USPs with a silencer attached" + } + "HudGlockBurst" + { + "en" "Spawn Glocks with Burst" + } "HudPracticeMode" { "en" "[PRACTICE]"