View Single Post
Author Message
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 03-29-2011 , 06:21   [L4D & L4D2] Hats (1.50) [12-Mar-2024]
Reply With Quote #1

About:

Not your average hats...


Thanks:
  • Mr.RuyC - For helping test the plugin on his server.
  • Ja-Forces - Creating an "error" free L4D1 hats config + bug reports. (found here)
  • bubbabyte - Testing 1.5 on their server and reporting several bugs.
  • Krevik - Lots of help testing 1.45.
  • Ja-Forces - L4D1 data config found here: https://forums.alliedmods.net/showpo...7&postcount=57
  • Don't Fear The Reaper - German translations.
  • Dragokas - Russian and Ukrainian translations.
  • pan0s and NoroHime - Simplified Chinese and Traditional Chinese translations.


Bugs:
  • Hats covering a players eyes can block the players "use" function (opening doors etc). - Install: Use Priority Patch plugin to fix.


Changing Models:
  • The position, angles and model name is saved to l4d_hats.cfg in your servers \addons\sourcemod\data\ folder.
  • Each model has it's own section and each section is numbered from 1 to the current max of 128.
  • Each section has 3 keys. "mod" which is required and the path to the model / hat.
  • The 2 optional keys: "ang" and "pos" store the angle / position and can be set in-game with sm_hatang and sm_hatpos.
  • You can customise the hat names with the "name" key as seen in the example below.

To edit models:
  1. You can view the model list and indexes by typing sm_hatlist.
  2. Use sm_hatadd to add a model to the config (must be the full model path as seen below).
  3. You can remove hats by typing sm_hatdel and part of the model name or the index number (1-64).

To edit hat positions:
  1. Choose your hat with the sm_hat command.
  2. Use the command sm_hatload to load on all players.
  3. Use the commands sm_hatpos and sm_hatang.
  4. These affect all players (which is why I recommend using sm_hatload)
  5. Once you're happy with the pos/ang use the command sm_hatsave.

To edit hat sizes:
  1. Choose your hat with the sm_hat command.
  2. Use the command sm_hatload to load on all players.
  3. Use the command sm_hatsize to set the size.
  4. This affects all players (which is why I recommend using sm_hatload)
  5. Once you're happy with the size use the command sm_hatsave.
  6. NOTE: Not all models can be resized.


Example:
Code:
"1"
{
	"mod"		"models/infected/gibs/gibs.mdl"
	"ang"		"0.000000 0.000000 0.000000"
	"loc"		"2.000000 0.500000 0.500000"
	"size"		"1.5"
	"name"		"Hand Gib"
}


Optional Translations for hat names:
  • If you want to translate hat names into multiple languages, save the following as hatnames.phrases.txt in your servers \addons\sourcemod\translations folder.
  • (Now included by default inside the plugins zip archive)
Spoiler




Commands:

PHP Code:
// All players
sm_hat         // Displays a menu of hats allowing players to change what they are wearing. Optional args: [0 - 128 or hat name or "random"]
sm_hats        // Displays a menu to customize various settings for hats.
sm_hatoff      // Toggle to turn on or off the ability of wearing hats.
sm_hatshow     // Toggle to see or hide your own hat. Applies to first person view or third person using the optional command argument "tp" e.g. "sm_hatshow tp"
sm_hatview     // ^^
sm_hatshowon   // See your own hat. Applies to first person view or third person using the optional command argument "tp" e.g. "sm_hatshowon tp"
sm_hatshowoff  // Hide your own hat. Applies to first person view or third person using the optional command argument "tp" e.g. "sm_hatshowoff tp"
sm_hatall      // Toggles the visibility of everyone's hats.

// Admins only (requires "z" flag):
sm_hatclient   // Set a clients hat. Usage: sm_hatclient <#userid|name> [hat name or hat index: 0-128 (MAX_HATS)].
sm_hatc        // Displays a menu listing players, select one to change their hat.
sm_hatallc     // Toggle the visibility of all hats on specific players
sm_hatoffc     // Toggle the ability of wearing hats on specific players.
sm_hatrandom   // Randomizes all players hats.
sm_hatrand     // ^^

// Add and remove hat models with these commands.
sm_hatadd      // Adds specified model to the config (must be the full model path).
sm_hatdel      // Removes a model from the config (either by index or partial name matching).
sm_hatlist     // Displays a list of all the hat models and indexs (for use with sm_hatdel).

// These commands are useful for editing the hat appearances.
sm_hatsave     // Saves the hat origin and angles to the data config.
sm_hatload     // Changes all players hats to the one you have.
sm_hatpos      // Displays a menu allowing you to adjust the hat position (affects all hats/players).
sm_hatang      // Displays a menu allowing you to adjust the hat angles (affects all hats/players).
sm_hatsize     // Shows a menu allowing you to adjust the hat size (affects all hats/players). 


Cvars:

Saved to l4d_hats.cfg in your servers \cfg\sourcemod\ folder.

PHP Code:
// 0=Plugin off, 1=Plugin on.
l4d_hats_allow "1"

// Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).
l4d_hats_modes ""

// Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).
l4d_hats_modes_off ""

// Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.
l4d_hats_modes_tog ""

// 0=Disallow bots from spawning with Hats. 1=Allow bots to spawn with hats.
l4d_hats_bots "1"

// 0=Off. Other value puts the player into thirdperson for this many seconds when selecting a hat.
l4d_hats_change "1.3"

// 0.0=Off. How often to detect thirdperson view. Also uses ThirdPersonShoulder_Detect plugin if available.
l4d_hats_detect "0.3"

// Specify admin flags or blank to allow all players to spawn with a hat, requires the l4d_hats_random cvar to spawn.
l4d_hats_make ""

// Specify admin flags or blank to allow all players access to the hats menu.
l4d_hats_menu ""

// How transparent or solid should the hats appear. 0=Translucent, 255=Opaque.
l4d_hats_opaque "255"

// Prevent pre-caching models on these maps, separate by commas (no spaces). Enabling plugin on these maps will crash the server.
l4d_hats_precache ""

// Attach a random hat when survivors spawn. 0=Never. 1=On round start. 2=Only first spawn (keeps the same hat next round).
l4d_hats_random "1"

// 0=Off, 1=Save the players selected hats and attach when they spawn or rejoin the server.
l4d_hats_save "1"

// When a player is in third person view, display their hat. Hide when in first person view.
l4d_hats_third "1"

// 0=Show hats glowing through walls, 1=Hide hats glowing when behind walls (creates 1 extra entity per hat).
l4d_hats_wall "1"

// Hats plugin version.
l4d_hats_version 


Changes:
Code:
1.50 (12-Mar-2024)
    - Added a thirdperson camera detection for "m_hViewEntity". Thanks to "Marttt" for reporting.
    - More fixes to keep the hat visible when changing between thirdperson modes (events, cvar, TP plugin). Thanks to "Yabi" for reporting.

1.49 (27-Nov-2023)
    - Fixed the hat showing when being healed by someone else.
    - Fixed hats randomly showing in first person. Thanks to "Yabi" for reporting.
    - Fixed the "l4d_hats_random" value "2" not saving across map changes. Thanks to "Yabi" for reporting.

1.48 (24-Nov-2023)
    - Fixed the hat showing after staggering when the stagger timer didn't reset (due to some plugins such as "Stagger Gravity").

1.47 (22-Nov-2023)
    - Now shows hats in 3rd person view when healing someone, using a generator or opening a footlocker, and possibly more situations. Thanks to "Voevoda" for reporting.
    - Fixed invalid handle errors caused by the last update. Should have worked, seems to be some weirdness with SourceMod. Thanks to "Voevoda" for reporting and "HarryPotter" for help.

1.46 (07-Nov-2023)
    - Now shows hats in 3rd person view when deploying upgrade ammo packs, staggering or recovering from a pounce/charge. Thanks to "Voevoda" for reporting.

1.45a (27-Aug-2022)
    - Updated "Russian" translation file. Thanks to "A1ekin" for making changes.

1.45 (29-May-2022)
    - Added public command "sm_hats" to display a menu of hat options. Thanks to "pan0s" for writing.
    - Added public command "sm_hatall" to toggle the visibility of everyone's hats. Requested by "LordVGames".
    - Added admin command "sm_hatallc" to toggle a clients visibility hats. Requested by "Krevik".

    - Added saving a players visibility of all hats from the new commands above.
    - Added changes by "pan0s" to save the first and third person view of hats status.
    - Added a new colors stock for printing text, supports {RED} and {BLUE} colors. Thanks to "pan0s" for providing.
    - Added support for the "Ready-Up" plugin to hide or show the panel when using the Hats menu. Requested by "Krevik".

    - Changed commands "sm_hatshow", "sm_hatshowon" and "sm_hatshowoff" to only affect 1st person view, and 3rd person view with an optional argument "tp".
    - Fixed crashing if a model was missing. Plugin now fails to load forcing a config fix. Thanks to "Dragokas" for reporting.
    - Fixed hats not saving depending on the "l4d_hats_make" cvar value.

    - Thanks to "Krevik" and "pan0s" for help lots of help and testing.
    - Thanks to "pan0s" for updating the Chinese translations.
    - Thanks to "Impact" for updating the German translations.
    - Thanks to "Dragokas" for updating the Russian and Ukrainian translations.

    - Translation files have updated. Please update or errors will occur and the plugin won't work.

1.44 (15-Apr-2022)
    - Changed command "sm_hat" to accept 3 letter or smaller words for partial matching, e.g. "sm_hat saw".
    - Fixed command "sm_hatdel" not deleting the whole entry.
    - Fixed command "sm_hat" changing other players hats after using "sm_hatc" command. Thanks to "kot4404" for reporting.
    - Removed the "Big Helicopter" model from the data config. Too many reports of client-side glowing sprites remaining behind.

1.43 (06-Feb-2022)
    - Added a hackish fix for L4D2 not precaching models properly which has been causing stutter when using a model for the first time.
    - Fixed menus closing when selecting a player with a userid greater than 999. Thanks to "Electr000999" for reporting.

1.42 (16-Dec-2021)
    - Fixed simple mistake from last update causing wrong menu listing when not using a "hatnames" translation. Thanks to "Mi.Cura" for reporting.

1.41 (14-Dec-2021)
    - Fixed spawning and respawning with a hat when it was turned off. Thanks to "kot4404" for reporting.

    - Changed the "hatnames.phrases.txt" translation file format for better modifications when adding or removing hats from the data config.
    - Now supports adding hats and breaking the plugin when missing from the "hatnames.phrases.txt" translations file.
    - New "hatnames" translations no longer uses indexes and only model names.
    - Still supports the old version but suggest upgrading to the new.
    - Included the script for converting the translation file based on the config. Search for "TRANSLATE CODE" in the source.

1.40 (11-Dec-2021)
    - Fixed not saving hat angles and origins correctly when "l4d_hats_wall" was set to "0". Thanks to "NoroHime" for reporting.
    - Now saves when a hat was removed, if saving is enabled. Requested by "kot4404".

1.39 (09-Dec-2021)
    - Changed command "sm_hat" to accept "rand" or "random" as a parameter option to give a random hat.
    - Updated the "chi" and "zho" translation "hatnames.phrases.txt" files to be correct. Thanks to "NoroHime".

1.38 (03-Dec-2021)
    - Added "Off" option to the menu. Requested by "kot4404".
    - Fixed command "sm_hatadd" from not adding new entries. Thanks to "swiftswing1" for reporting.
    - Changes to fix warnings when compiling on SourceMod 1.11.

1.37 (09-Sep-2021)
    - Plugin now deletes the client cookie and hat if they no longer have access to use hats. Requested by "Darkwob".

1.36 (20-Jul-2021)
    - Removed cvar "l4d_hats_view" - recommended to use "ThirdPersonShoulder_Detect" plugin to turn on/off the hat view when in 3rd/1st person view.

1.35 (10-Jul-2021)
    - Fixed giving random hats to players when the "l4d_hats_random" cvar was set to "0". Thanks to "XYZC" for reporting.

1.34 (05-Jul-2021)
    - Fixed giving random hats on round_start when "l4d_hats_save" cvar was set to "1".

1.33 (04-Jul-2021)
    - Fixed "sm_hatrand" and "sm_hatrandom" from not giving random hats. Not sure when this broke.

1.32 (01-Jul-2021)
    - Added a warning message to suggest installing the "Attachments API" and "Use Priority Patch" plugins if missing.

1.31 (03-May-2021)
    - Added Simplified Chinese (chi) and Traditional Chinese (zho) translations. Thanks to "pan0s" for providing.
    - Fixed not giving random hats to clients who have no saved hats. Thanks to "pan0s" for reporting.

1.30 (28-Apr-2021)
    - Fixed client not in-game errors. Thanks to "HarryPotter" for reporting.

1.29 (10-Apr-2021)
    - Added cvar "l4d_hats_bots" to allow or disallow bots from spawning with hats.
    - Added cvar "l4d_hats_make" to allow players with specific flags only to auto spawn with hats.

1.28 (20-Mar-2021)
    - Added cvar "l4d_hats_wall" to prevent hats glowing through walls. Thanks to "Marttt" for the method and "Dragokas" for requesting.
    - Fixed personal hats not showing when changing hat in external view.

1.27 (01-Mar-2021)
    - Fixed invalid client errors due to the last update. Thanks to "ur5efj" for reporting.

1.26 (01-Mar-2021)
    - Now blocks showing hats when spectating someone in first person view. Thanks to "Alex101192" for reporting.

1.25 (23-Feb-2021)
    - Fixed hats not hiding after being revived. Thanks to "Alex101192" for reporting.

1.24 (01-Oct-2020)
    - Changed "l4d_hats_precache" cvar default value to blank.
    - Changed the way "l4d_hats_detect" works. Now also detects if reviving someone (events were unreliable and causing bugs).
    - Fixed 1st and 3rd person view of hats wrongfully toggling under certain conditions. Thanks to "Alex101192" for reporting.
    - Fixed some spelling mistakes in the "data/l4d_hats.cfg" hat names.

1.23 (16-Jun-2020)
    - Added Russian and Ukrainian translations - Thanks to "Dragokas" for providing.
    - Fixed changing hats when "l4d_hats_save" and "l4d_hats_random" were set. Random is superseded by saved if present.
    - Fixed command "sm_hatclient" throwing an error when only a client was specified.
    - Fixed hat view "ThirdPersonShoulder_Detect" and "Survivor Thirdperson" plugins clashing.

1.22 (10-May-2020)
    - Extra checks to prevent "IsAllowedGameMode" throwing errors.
    - Fixed not always loading client cookies before creating hats. Thanks to "Alex101192" for reporting.
    - Fixed potentially not translating some strings.
    - Fixed some functions not working for more than 100 hats.
    - Fixed hats affecting Survivor Thirdperson view under certain conditions.
    - Various changes to tidy up code.
    - Various optimizations and fixes.

1.21 (30-Apr-2020)
    - Added cvar "l4d_hats_detect" to enable clients to see their own hat when 3rd person view is detected.
    - Optionally uses "ThirdPersonShoulder_Detect" plugin by "Lux" and "MasterMind420", if available.

    - Added bunch of maps to the default value of "l4d_hats_precache". Thanks to "Alex101192" for providing.
    - Increased "l4d_hats_precache" cvar length, max usable length 490 (due to game limitations).

1.20 (01-Apr-2020)
    - Fixed "IsAllowedGameMode" from throwing errors when the "_tog" cvar was changed before MapStart.
    - Removed "colors.inc" dependency.
    - Updated these translation file encodings to UTF-8 (to display all characters correctly): German (de).

1.19 (19-Dec-2019)
    - Added command "sm_hatclient" to set a clients hat, requested by "foxhound27".

1.18 (23-Oct-2019)
    - Added commands "sm_hatshowon" and "sm_hatshowoff" to turn on/off personal hat visibility.
    - Fixed cvar "l4d_hats_precache" from modifying the allow cvar. Now correctly disables on blocked maps.

1.17 (10-Sep-2019)
    - Added cvar "l4d_hats_precache" to prevent pre-caching models on specified maps.

1.17b (19-Aug-2019)
    - Fixed ghosts from having hats.

1.16 (02-Aug-2019)
    - Fixed "m_TimeForceExternalView not found" error for L4D1 - Thanks to "Ja-Forces" for reporting.

1.15.0 (05-May-2018)
    - Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
    - Changed cvar "l4d_hats_modes_tog" now supports L4D1.

1.14 (25-Jun-2017)
    - Added "Reset" option to the ang/pos/size menus, requested by "ZBzibing".
    - Fixed depreciated FCVAR_PLUGIN and GetClientAuthString.
    - Increased MAX_HATS value and added many extra L4D2 hats thanks to "Munch".

1.13 (29-Mar-2015)
    - Fixed the plugin not working in L4D1 due to a SetEntPropFloat property not found error.

1.12 (07-Oct-2012)
    - Fixed hats blocking players +USE by adding a single line of code - Thanks to "Machine".

1.11 (30-Jun-2012)
    - Fixed cvar "l4d_hats_random" from not working properly - Thanks to "Don't Fear The Reaper" for reporting.

1.10 (20-Jun-2012)
    - Added German translations - Thanks to "Don't Fear The Reaper".
    - Small fixes.

1.9 (22-May-2012)
    - Fixed multiple hat changes only showing the first hat to players.
    - Changing hats will no longer return the player to firstperson if thirdperson was already on.

1.8 (21-May-2012)
    - Fixed command "sm_hatc" making the client thirdpeson and not the target.

1.7 (20-May-2012)
    - Added cvar "l4d_hats_change" to put the player into thirdperson view when they select a hat, requested by "disawar1".

1.6.1 (15-May-2012)
    - Fixed a bug when printing to chat after changing someones hat.
    - Fixed cvar "l4d_hats_menu" not allowing access if it was empty.

1.6 (15-May-2012)
    - Fixed the allow cvars not affecting everything.

1.5 (10-May-2012)
    - Added translations, required for the commands and menu title.
    - Added optional translations for the hat names as requested by disawar1.
    - Added cvar "l4d_hats_allow" to turn on/off the plugin.
    - Added cvar "l4d_hats_modes" to control which game modes the plugin works in.
    - Added cvar "l4d_hats_modes_off" same as above.
    - Added cvar "l4d_hats_modes_tog" same as above, but only works for L4D2.
    - Added cvar "l4d_hats_save" to save a players hat for next time they spawn or connect.
    - Added command "sm_hatsize" to change the scale/size of hats as suggested by worminater.
    - Fixed "l4d_hats_menu" flags not setting correctly.
    - Optimized the plugin by hooking cvar changes.
    - Selecting a hat from the menu no longer returns to the first page.

1.4.3 (07-May-2011)
    - Added "name" key to the config for reading hat names.

1.4.2 (16-Apr-2011)
    - Changed the way models are checked to exist and precached.

1.4.1 (16-Apr-2011)
    - Added new hat models to the config. Deleted and repositioned models blocking the "use" function.
    - Changed the hat entity from prop_dynamic to prop_dynamic_override (allows physics models to be attached).
    - Fixed command "sm_hatadd" causing crashes due to models not being pre-cached, cannot cache during a round, causes crash.
    - Fixed pre-caching models which are missing (logs an error telling you an incorrect model is specified).

1.4.0 (11-Apr-2011)
    - Added cvar "l4d_hats_opaque" to set hat transparency.
    - Changed cvar "l4d_hats_random" to create a random hat when survivors spawn. 0=Never. 1=On round start. 2=Only first spawn (keeps the same hat next round).
    - Fixed hats changing when returning from idle.
    - Replaced underscores (_) with spaces in the menu.

1.3.4 (09-Apr-2011)
    - Fixed hooking L4D2 events in L4D1.

1.3.3 (07-Apr-2011)
    - Fixed command "sm_hatc" not displaying for admins when they are dead/infected team.
    - Minor bug fixes.

1.3.2 (06-Apr-2011)
    - Fixed command "sm_hatc" displaying invalid player.

1.3.1 (05-Apr-2011)
    - Fixed the fix of command "sm_hat" flags not applying.

1.3 (05-Apr-2011)
    - Fixed command "sm_hat" flags not applying.

1.2 (03-Apr-2011)
    - Added command "sm_hatoffc" for admins to disable hats on specific clients.
    - Added cvar "l4d_hats_third" to control the previous update's addition.

1.1.1a (03-Apr-2011)
    - Added events to show / hide the hat when in third / first person view.

1.1.1 (02-Apr-2011)
    - Added cvar "l4d_hats_view" to toggle if a players hat is visible by default when they join.
    - Resets variables for clients when they connect.

1.1 (01-Apr-2011)
    - Added command "sm_hatoff" - Toggle to turn on or off the ability of wearing hats.
    - Added command "sm_hatadd" - To add models into the config.
    - Added command "sm_hatdel" - To remove a model from the config.
    - Added command "sm_hatlist" - To display a list of all models (for use with sm_hatdel)

1.0 (29-Mar-2011)
    - Initial release.


Compiling:
  1. Put this plugins .sp file into your \addons\sourcemod\scripting\ folder.
  2. Compile the plugin.


Installation:
  1. Download the .zip and extract the files to their respective folders in your servers \addons\sourcemod\ folder.
  2. Install the Use Priority Patch plugin to prevent blocking +USE.
  3. Optionally install: ThirdPersonShoulder_Detect to enable viewing Hats when thirdperson view is detected.

Updating from 1.35 or older:
  • New cvars have been added: use the Cvar Configs Updater, or delete the old cvars config or manually add them.

Updating from 1.44 or older:
  • Translation files have been modified. Update them or the plugin will throw errors and not work.

Current Translations: English (en), German (de), Russian (ru), Ukrainian (ua), Simplified Chinese (chi) and Traditional Chinese (zho).
Attached Files
File Type: zip l4d_hats.zip (72.8 KB, 109 views)
__________________

Last edited by Silvers; 03-12-2024 at 06:04.
Silvers is offline