forked from TeamUlysses/ulib
Normalizing line endings
This commit is contained in:
parent
5a393ca6fd
commit
7170aceb0a
558
ULib_readme.txt
558
ULib_readme.txt
@ -1,279 +1,279 @@
|
||||
Title: ULib Readme
|
||||
|
||||
*ULib v2.60 (released 00/00/00)*
|
||||
|
||||
ULib is a developer library for GMod 10 (<http://garrysmod.com/>).
|
||||
|
||||
ULib provides such features as universal physics, user access lists, and much, much more!
|
||||
|
||||
Visit our homepage at <http://ulyssesmod.net/>.
|
||||
|
||||
You can talk to us on our forums at <http://forums.ulyssesmod.net/>.
|
||||
|
||||
Group: Author
|
||||
|
||||
ULib is brought to you by..
|
||||
|
||||
* Brett "Megiddo" Smith - Contact: <megiddo@ulyssesmod.net>
|
||||
* JamminR - Contact: <jamminr@ulyssesmod.net>
|
||||
* Stickly Man! - Contact: <sticklyman@ulyssesmod.net>
|
||||
* MrPresident - Contact: <mrpresident@ulyssesmod.net>
|
||||
|
||||
Group: Requirements
|
||||
|
||||
ULib requires a working copy of the latest garrysmod, and that's it!
|
||||
|
||||
Group: Installation
|
||||
|
||||
To install ULib, simply extract the files from the archive to your garrysmod/addons folder.
|
||||
When you've done this, you should have a file structure like this--
|
||||
<garrysmod>/addons/ulib/lua/ULib/init.lua
|
||||
<garrysmod>/addons/ulib/lua/ULib/server/util.lua
|
||||
<garrysmod>/addons/ulib/lua/autorun/ulib_init.lua
|
||||
<garrysmod>/addons/ulib/data/ULib/users.txt
|
||||
etc..
|
||||
|
||||
Please note that installation is the same on dedicated servers.
|
||||
|
||||
You absolutely, positively have to do a full server restart after installing the files. A simple map
|
||||
change will not cut it!
|
||||
|
||||
Group: Usage
|
||||
|
||||
Server admins do not "use" ULib, they simply enjoy the benefits it has to offer.
|
||||
After installing ULib correctly, scripts that take advantage of ULib will take care of the rest.
|
||||
Rest easy!
|
||||
|
||||
Group: Changelog
|
||||
v2.60 - *(00/00/00)*
|
||||
* [ADD] ULib.ucl.getUserInfoFromID for getting user info from an ID.
|
||||
* [ADD] CAMI support.
|
||||
* [ADD] "noMount" parameter to file-related APIs.
|
||||
* [ADD] ULibGetUser(s)CustomKeyword hooks (Thanks, LuaTenshi).
|
||||
* [FIX] The usual random slew of Garry-breakages (Thanks, Fuzzik).
|
||||
* [FIX] An assumption regarding player authentication that led to a player's group being reset to user sometimes.
|
||||
* [FIX] Garry API change for ULib.findinDir (Thanks, ascentechit).
|
||||
* [FIX] Workaround for Garry's odd handling of bot UIDs (Thanks, BurgerLUA).
|
||||
* [FIX] Improved how well ULib files handle being autorefreshed.
|
||||
* [FIX] Exploitable console command could potentially cause errors and/or crashes.
|
||||
* [FIX] Exploit involving file system mounting.
|
||||
* [CHANGE] Hook system. It's much faster (CPU-wise) and a little easier to use now (Many thanks for input from darkjacky and Divran).
|
||||
|
||||
v2.52 - *(03/09/15)*
|
||||
* [ADD] Admin parameter to ULib.unban for overriding purposes (Thanks for the idea, MStruntze).
|
||||
* [ADD] A list of players is presented when a target string for getUser matches more than one player (Thanks, RhapsodySL).
|
||||
* [FIX] ULib.ucl.registerAccess not allowing an access tag to be registered to no groups.
|
||||
* [FIX] Several incorrect file I/O calls (Thanks, Q4-Bi).
|
||||
* [FIX] Hook priority being messed up for parent hook when hooks are called recursively (Thanks, NoBrainCZ).
|
||||
* [FIX] Some fiddly-bits with group case-sensitivity (Thanks, BryanFlannery).
|
||||
* [CHANGE] hook.Run to match Garry's changes.
|
||||
* [CHANGE] ULib.HOOK_LOCALPLAYERREADY is now called on InitPostEntity instead of OnEntCreate.
|
||||
|
||||
v2.51 - *(08/30/13)*
|
||||
* [FIX] ULib.ucl.userAllow not working on disconnected players (Thanks, JackYack13).
|
||||
* [FIX] Issue with setting groups with capitals in the group name (Thanks, FPtje!).
|
||||
* [FIX] Calling SetUserGroup not passing on information to clients (Thanks, Bo98).
|
||||
* [FIX] Garry's File I/O bugs by wrapping all his I/O.
|
||||
* [FIX] A user group lower casing that no longer belonged in the code (Thanks, iamalexer).
|
||||
* [FIX] Some issues with casing in ULib commands (Thanks, TheSpy7).
|
||||
* [FIX] Invalid time restrictions throwing an error (Thanks, Scratch).
|
||||
* [FIX] A problem with targeting in single player (Effected XGUI. Thanks, bender180).
|
||||
* [FIX] A problem with self-target restrictions breaking commands under certain conditions (Thanks, iSnipeu).
|
||||
* [FIX] A bug with being able to update replicated variables after running a listen server and then joining another server.
|
||||
* [REMOVED] Temp garry-patch for reading from the data directory that appears to be fixed now.
|
||||
|
||||
v2.50 - *(01/27/13)*
|
||||
* [ADD] ULib.pcallError -- Does what global PCallError used to do before it was removed.
|
||||
* [ADD] Shows reasons to kicked person upon kick or ban (Thanks FPtje!).
|
||||
* [ADD] Operator to target only a specific group, ignoring inheritance ('#').
|
||||
* [ADD] Operator to target a specific id ('$').
|
||||
* [ADD] ULib.namedQueueFunctionCall to allow scripts to create their own queues separate of the main one.
|
||||
* [ADD] The ability to have aliased chat commands.
|
||||
* [FIX] The usual assortment of garry breakages.
|
||||
* [FIX] Changed away from our custom implementation of datastream to use Garry's new net library.
|
||||
* [FIX] Error with returning from invisibility when the player has no weapons (Thanks HellFox).
|
||||
* [FIX] "ULibCommandCalled" hook not being called on chat commands (Thanks Adult).
|
||||
* [CHANGE] Replicated cvars aren't actually relying on source replication anymore since Garry broke it (but they function the same).
|
||||
* [CHANGE] Lots of changes to match GM13.
|
||||
* [CHANGE] NumArg now allows for time string format.
|
||||
* [CHANGE] Hook library to match garry's. hook.isInHook was removed, no longer able to support with garry's changes.
|
||||
|
||||
v2.42 - *(01/01/12)*
|
||||
* [FIX] Garry breakages.
|
||||
|
||||
v2.41 - *(09/22/11)*
|
||||
* [ADD] ULib.ucl.getUserRegisteredID.
|
||||
* [ADD] ULib.stringTimeToSeconds (Thanks lavacano201014).
|
||||
* [FIX] Now properly kicks users who are banned while joining (Thanks Willdy).
|
||||
|
||||
v2.40 - *(05/13/11)*
|
||||
* [ADD] ULib.tsayColor and Ulib.tsayError
|
||||
* [ADD] Replicated cvars. Nearly a direct port from the UPS implementation, with a few improvements.
|
||||
* [ADD] queueFunctionCall, ported from UPS.
|
||||
* [ADD] Player:GetUserGroup().
|
||||
* [ADD] Player:CheckGroup(), ability to check if a user in a group via inheritance.
|
||||
* [ADD] ULib.getPlyByUID().
|
||||
* [ADD] ULib.clientRPC(), send massive amounts of data to a client with ease.
|
||||
* [ADD] Upgrade script.
|
||||
* [ADD] hook.getCurrentHooks(), returns all currently processing hooks.
|
||||
* [ADD] hook.isInHook( name ), returns if you're in the specified hook or not.
|
||||
* [ADD] ULib.splitPort(), ULib.isValidSteamID(), ULib.isValidIP().
|
||||
* [ADD] ULib.backupFile().
|
||||
* [ADD] ULib.throwBadArg(), useful for argument checking.
|
||||
* [ADD] ULib.checkArg(), useful for argument checking.
|
||||
* [ADD] ULib.getPicker(), returns a user directly in front of another user.
|
||||
* [ADD] Utilities for table inheritance.
|
||||
* [ADD] New 'translation' command system that acts as a wrapper between a user and lua.
|
||||
* [ADD] New (and very different) command system.
|
||||
* [ADD] Lots of new hooks.
|
||||
* [ADD] Support for gatekeeper in ULib.kick.
|
||||
* [ADD] Our own optimized version of datastream, since garry's implementation is always broken.
|
||||
* [ADD] ULib.getAllReadyPlayers(), useful for sending usermessages to everyone.
|
||||
* [ADD] Basic spam detection system for ULib commands.
|
||||
* [FIX] ULib.filesInDir, was completely broken.
|
||||
* [FIX] The usual assortment of garry breakages.
|
||||
* [FIX] Some case-sensitive issues with the ULib add-command functions.
|
||||
* [FIX] Attempting to delete misc_registered.txt when it didn't exist.
|
||||
* [FIX] ULib.splitArgs now really properly handles escaped quotes and now unescapes them.
|
||||
* [FIX] Concommands created by ULib removing empty args.
|
||||
* [FIX] Overflowing command buffer when executing large config files.
|
||||
* [FIX] Optimized various functions to support up to 4000 bans (at least!).
|
||||
* [FIX] Bug where reloading ban information when a temp ban had less than a minute left made the ban permanent.
|
||||
* [FIX] Bug where ULib was reading in bad characters from source bans (Thanks edk141).
|
||||
* [CHANGE] Chat hooks are now a high priority due to other aggressive admin mods overriding ULX.
|
||||
* [CHANGE] Rewrote UCL entirely. The upgrade script should take care of bringing over old data into the new system.
|
||||
* [CHANGE] Added the ability to have access tags for each access string. These allow the accesses to have customizable behavior.
|
||||
* [CHANGE] Access tags now have comments attached to them (for the "what is it?" among us).
|
||||
* [CHANGE] Added lots of keywords (and keyword negation!) to ULib.getUsers and ULib.getUser.
|
||||
* [CHANGE] Invisible gets rid of shadows now.
|
||||
* [CHANGE] Garry's hook table spec is now more closely followed. (Thanks aVoN!)
|
||||
* [CHANGE] Moved the hook changes to the shared portion so clients can use the enhanced hooks as well.
|
||||
* [CHANGE] Updated the hooks file to match garry's recent changes. Also increased efficiency in hooks (faster than garry's!)
|
||||
* [CHANGE] Slaps now do a view punch as well.
|
||||
* [CHANGE] Allow nil access on ULib.addSayCommand so that you can create a command you always have access to.
|
||||
* [CHANGE] ULib.ucl.query always returns true when a nil access string is passed in.
|
||||
* [REMOVE] Ability to have passwords in UCL, don't think it worked anymore and it was never really used.
|
||||
* [REMOVE] Immunity no longer exists, since the new UCL has a much better method of doing the same thing.
|
||||
* [REMOVE] Some hooks due to garry breakage.
|
||||
* [REMOVE] Chat sounds on tsay, engine no longer makes sounds so neither should tsay.
|
||||
|
||||
v2.30 - *(06/20/09)*
|
||||
* [FIX] Umsgs being sent too early in certain circumstances.
|
||||
* [FIX] Some issues garry introduced in the Jan09 update regarding player initialization.
|
||||
* [FIX] ParseKeyValues not unescaping backslashes.
|
||||
* [CHANGE] Rewrote splitArgs and parseKeyValues.
|
||||
* [CHANGE] misc_registered.txt now self-destructs on missing or empty groups.txt.
|
||||
* [CHANGE] All gamemode.Call refs to hook.Call, thanks aVoN!
|
||||
* [CHANGE] SetUserGroup now REMOVES any other groups and sets an exclusive group. Sorry about this, but this is for the better.
|
||||
|
||||
v2.21 - *(06/08/08)*
|
||||
* [ADD] Support for client/server-side only modules.
|
||||
* [FIX] Bug in ULib.tsay that would incorrectly print to console if the target player was disconnecting.
|
||||
* [FIX] Makes sure that prop protectors don't take ownership of props using physgun reload while a prop is unmovable.
|
||||
* [CHANGE] ULib.getUsers now returns multiple users on an asterisk "*" when enable_keywords is true. "<ALL>" can still be used. (Thanks Kyzer)
|
||||
|
||||
|
||||
v2.20 - *(01/26/08)*
|
||||
* [ADD] ULib now has three shiny new hooks to let you know about client initialization and a new hook to signal a player name change.
|
||||
* [FIX] A possible bug in the physics helpers.
|
||||
* [CHANGE] Various things to bring ULib into new engine compatibility.
|
||||
* [CHANGE] Removed all timers dealing with initialization and now rely on flags from the client. This makes the ULib initialization much more dependable.
|
||||
* [CHANGE] Converted all calls from ULib.consoleCommand( "exec ..." ) to ULib.execFile() to avoid running into the block on "exec" without our module.
|
||||
* [REMOVE] Removing the module for now, might re-appear in the next version
|
||||
|
||||
|
||||
v2.10 - *(09/23/07)*
|
||||
* [ADD] New hook library. Completely backwards compatible, but can now do priorities. (Server-side only)
|
||||
* [ADD] ULib.parseKeyValues, ULib.makeKeyValues
|
||||
* [ADD] ULib.getSpawnInfo, ULib.Spawn - Enhanced Spawn... will replace original health/armor when called if getSpawnInfo called first.
|
||||
* [ADD] READDED hexing system to get around garry's ConCommand() blocks. So much is now blocked that it's interferring with normal ULX operations.
|
||||
* [ADD] Our server module again. This time with only console-executing abilities. This is because garry has blocked much of what we need. Source is included.
|
||||
* [ADD] Custom ban list to store temp bans and additional ban info. Permanent bans are still stored in banned_user.cfg, and the two lists are synchronized.
|
||||
* [FIX] Can now query players from client side.
|
||||
* [FIX] An exploit in DisallowDelete() that allowed players to still remove the props
|
||||
* [FIX] Various initialization functions trying to access a disconnected player
|
||||
* [FIX] ULib.csay() sending umsgs to invalid players.
|
||||
* [FIX] UCL by clantag not working.
|
||||
* [CHANGE] Big changes in ucl.query() and concommand functions. Probably won't be backwards compatible.
|
||||
* [CHANGE] UCL now uses our new keyvalues functions. It should be backwards compatible with your old data, but we make no promises. If you're having trouble with it, try starting from scratch.
|
||||
* [CHANGE] ULib.tsay has a wait parameter to send on next frame
|
||||
* [CHANGE] subconcommands are now case insensitive
|
||||
* [CHANGE] Csay's now have fade.
|
||||
* [CHANGE] DisallowSpawning() now implements SpawnObject. For example, people can't sit and precache props while in the ulx jail.
|
||||
* [CHANGE] Say commands are now case insensitive and default to needing a space between command and arg (can flag to use old behavior though)
|
||||
* [CHANGE] ULib.ban, and ULib.kickban now accept additional information and pass data to ULib.addBan.
|
||||
* [CHANGE] Immunity is now an access string instead of a group
|
||||
* [CHANGE] Overcoming immunity is no longer bound to superadmins
|
||||
* [CHANGE] Increased performance of UCL.
|
||||
* [REMOVED] The vgui panels, derma is the vgui of choice now.
|
||||
|
||||
v2.05 - *(06/19/07)*
|
||||
* [ADD] ply:SetUserGroup() -- Thanks aVoN!
|
||||
* [ADD] ply:DisallowVehicles( bool )
|
||||
* [FIX] A timer error in UCL, was messing up scoreboard sometimes.
|
||||
* [FIX] Security hole where exploiters could gain superadmin access
|
||||
* [CHANGE] You can assign allow/denies to the default user group, "user" now. (IE, allow guests to slap)
|
||||
* [CHANGE] DisallowSpawning now disallows tools that can spawn things.
|
||||
* [REMOVED] Old settings/users.txt stuff, handled by SetUserGroup now
|
||||
|
||||
v2.04 - *(05/05/07)*
|
||||
* [ADD] ULib.isSandbox
|
||||
* [ADD] Player/ent hooks DisallowMoving, DisallowDeleting, DisallowSpawning, DisallowNoclip
|
||||
* [ADD] Some vgui libs (URoundButton, URoundMenu)
|
||||
* [FIX] Double printing in console.
|
||||
* [CHANGE] Implemented garry's "proper" way of including c-side files.
|
||||
* [CHANGE] Implemented client side UCL
|
||||
* [CHANGE] Now in addon format
|
||||
* [CHANGE] Slapping noclipped players will take them out of noclip to prevent them flying very far out of the world
|
||||
* [CHANGE] Improved the umsg send/receive functions
|
||||
* [REMOVED] Hexing system to get around garry's ConCommand() blocks. Very little is blocked now.
|
||||
* [REMOVED] Dll, MOTD functionality is handled by ULX now.
|
||||
|
||||
v2.03 - *(01/10/07)*
|
||||
* [ADD] ULib module, has functions for motd, concommands, and downloading files. SOURCE CODE!
|
||||
* [FIX] Player slap after dead problem.
|
||||
|
||||
v2.02 - *(01/07/07)*
|
||||
* [ADD] New system for giving files to clients. Strips comments and puts them in a separate folder.
|
||||
* [FIX] Autocompletes aren't handled so hackishly now. This should fix some occasional errors.
|
||||
* [FIX] Lots of general fixes.
|
||||
|
||||
v2.01 - *(01/02/07)*
|
||||
* [FIX] Importing from garry's default user file.
|
||||
* [FIX] All users receiving "you do not have access" message.
|
||||
|
||||
v2.0 - *(01/01/07)*
|
||||
* Initial version for GM10
|
||||
|
||||
Group: Developers
|
||||
|
||||
To all developers, I sincerely hope you enjoy what ULib has to offer!
|
||||
If you have any suggestions, comments, or complaints, please tell us at <http://forums.ulyssesmod.net/>.
|
||||
|
||||
If you want an overview of what's in ULib, please visit the documentation at <http://ulyssesmod.net/docs/>.
|
||||
If you find any bugs, you can report them at <https://github.com/Nayruden/Ulysses/issues>.
|
||||
|
||||
All ULib's functions are kept in the table "ULib" to prevent conflicts.
|
||||
|
||||
Revisions are kept in the function/variable documentation. If you don't see revisions listed, it hasn't changed since v2.0
|
||||
|
||||
If you write a script taking advantage of ULib, stick the init script inside ULib/modules. ULib will load your script after
|
||||
ULib loads, and will send it to and load it on clients as well.
|
||||
|
||||
Some important quirks developers should know about --
|
||||
* autocomplete - You have to define the autocomplete on the client, so if you pass a string for autocomplete to ULib.concommand,
|
||||
it will assume you mean a client function. There's also a delay in the sending of these to the client.
|
||||
|
||||
Group: Credits
|
||||
|
||||
Thanks to JamminR, who is always there to offer help and advice to those who need it.
|
||||
|
||||
Group: License
|
||||
|
||||
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
|
||||
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
|
||||
Creative Commons
|
||||
543 Howard Street
|
||||
5th Floor
|
||||
San Francisco, California 94105
|
||||
USA
|
||||
Title: ULib Readme
|
||||
|
||||
*ULib v2.60 (released 00/00/00)*
|
||||
|
||||
ULib is a developer library for GMod 10 (<http://garrysmod.com/>).
|
||||
|
||||
ULib provides such features as universal physics, user access lists, and much, much more!
|
||||
|
||||
Visit our homepage at <http://ulyssesmod.net/>.
|
||||
|
||||
You can talk to us on our forums at <http://forums.ulyssesmod.net/>.
|
||||
|
||||
Group: Author
|
||||
|
||||
ULib is brought to you by..
|
||||
|
||||
* Brett "Megiddo" Smith - Contact: <megiddo@ulyssesmod.net>
|
||||
* JamminR - Contact: <jamminr@ulyssesmod.net>
|
||||
* Stickly Man! - Contact: <sticklyman@ulyssesmod.net>
|
||||
* MrPresident - Contact: <mrpresident@ulyssesmod.net>
|
||||
|
||||
Group: Requirements
|
||||
|
||||
ULib requires a working copy of the latest garrysmod, and that's it!
|
||||
|
||||
Group: Installation
|
||||
|
||||
To install ULib, simply extract the files from the archive to your garrysmod/addons folder.
|
||||
When you've done this, you should have a file structure like this--
|
||||
<garrysmod>/addons/ulib/lua/ULib/init.lua
|
||||
<garrysmod>/addons/ulib/lua/ULib/server/util.lua
|
||||
<garrysmod>/addons/ulib/lua/autorun/ulib_init.lua
|
||||
<garrysmod>/addons/ulib/data/ULib/users.txt
|
||||
etc..
|
||||
|
||||
Please note that installation is the same on dedicated servers.
|
||||
|
||||
You absolutely, positively have to do a full server restart after installing the files. A simple map
|
||||
change will not cut it!
|
||||
|
||||
Group: Usage
|
||||
|
||||
Server admins do not "use" ULib, they simply enjoy the benefits it has to offer.
|
||||
After installing ULib correctly, scripts that take advantage of ULib will take care of the rest.
|
||||
Rest easy!
|
||||
|
||||
Group: Changelog
|
||||
v2.60 - *(00/00/00)*
|
||||
* [ADD] ULib.ucl.getUserInfoFromID for getting user info from an ID.
|
||||
* [ADD] CAMI support.
|
||||
* [ADD] "noMount" parameter to file-related APIs.
|
||||
* [ADD] ULibGetUser(s)CustomKeyword hooks (Thanks, LuaTenshi).
|
||||
* [FIX] The usual random slew of Garry-breakages (Thanks, Fuzzik).
|
||||
* [FIX] An assumption regarding player authentication that led to a player's group being reset to user sometimes.
|
||||
* [FIX] Garry API change for ULib.findinDir (Thanks, ascentechit).
|
||||
* [FIX] Workaround for Garry's odd handling of bot UIDs (Thanks, BurgerLUA).
|
||||
* [FIX] Improved how well ULib files handle being autorefreshed.
|
||||
* [FIX] Exploitable console command could potentially cause errors and/or crashes.
|
||||
* [FIX] Exploit involving file system mounting.
|
||||
* [CHANGE] Hook system. It's much faster (CPU-wise) and a little easier to use now (Many thanks for input from darkjacky and Divran).
|
||||
|
||||
v2.52 - *(03/09/15)*
|
||||
* [ADD] Admin parameter to ULib.unban for overriding purposes (Thanks for the idea, MStruntze).
|
||||
* [ADD] A list of players is presented when a target string for getUser matches more than one player (Thanks, RhapsodySL).
|
||||
* [FIX] ULib.ucl.registerAccess not allowing an access tag to be registered to no groups.
|
||||
* [FIX] Several incorrect file I/O calls (Thanks, Q4-Bi).
|
||||
* [FIX] Hook priority being messed up for parent hook when hooks are called recursively (Thanks, NoBrainCZ).
|
||||
* [FIX] Some fiddly-bits with group case-sensitivity (Thanks, BryanFlannery).
|
||||
* [CHANGE] hook.Run to match Garry's changes.
|
||||
* [CHANGE] ULib.HOOK_LOCALPLAYERREADY is now called on InitPostEntity instead of OnEntCreate.
|
||||
|
||||
v2.51 - *(08/30/13)*
|
||||
* [FIX] ULib.ucl.userAllow not working on disconnected players (Thanks, JackYack13).
|
||||
* [FIX] Issue with setting groups with capitals in the group name (Thanks, FPtje!).
|
||||
* [FIX] Calling SetUserGroup not passing on information to clients (Thanks, Bo98).
|
||||
* [FIX] Garry's File I/O bugs by wrapping all his I/O.
|
||||
* [FIX] A user group lower casing that no longer belonged in the code (Thanks, iamalexer).
|
||||
* [FIX] Some issues with casing in ULib commands (Thanks, TheSpy7).
|
||||
* [FIX] Invalid time restrictions throwing an error (Thanks, Scratch).
|
||||
* [FIX] A problem with targeting in single player (Effected XGUI. Thanks, bender180).
|
||||
* [FIX] A problem with self-target restrictions breaking commands under certain conditions (Thanks, iSnipeu).
|
||||
* [FIX] A bug with being able to update replicated variables after running a listen server and then joining another server.
|
||||
* [REMOVED] Temp garry-patch for reading from the data directory that appears to be fixed now.
|
||||
|
||||
v2.50 - *(01/27/13)*
|
||||
* [ADD] ULib.pcallError -- Does what global PCallError used to do before it was removed.
|
||||
* [ADD] Shows reasons to kicked person upon kick or ban (Thanks FPtje!).
|
||||
* [ADD] Operator to target only a specific group, ignoring inheritance ('#').
|
||||
* [ADD] Operator to target a specific id ('$').
|
||||
* [ADD] ULib.namedQueueFunctionCall to allow scripts to create their own queues separate of the main one.
|
||||
* [ADD] The ability to have aliased chat commands.
|
||||
* [FIX] The usual assortment of garry breakages.
|
||||
* [FIX] Changed away from our custom implementation of datastream to use Garry's new net library.
|
||||
* [FIX] Error with returning from invisibility when the player has no weapons (Thanks HellFox).
|
||||
* [FIX] "ULibCommandCalled" hook not being called on chat commands (Thanks Adult).
|
||||
* [CHANGE] Replicated cvars aren't actually relying on source replication anymore since Garry broke it (but they function the same).
|
||||
* [CHANGE] Lots of changes to match GM13.
|
||||
* [CHANGE] NumArg now allows for time string format.
|
||||
* [CHANGE] Hook library to match garry's. hook.isInHook was removed, no longer able to support with garry's changes.
|
||||
|
||||
v2.42 - *(01/01/12)*
|
||||
* [FIX] Garry breakages.
|
||||
|
||||
v2.41 - *(09/22/11)*
|
||||
* [ADD] ULib.ucl.getUserRegisteredID.
|
||||
* [ADD] ULib.stringTimeToSeconds (Thanks lavacano201014).
|
||||
* [FIX] Now properly kicks users who are banned while joining (Thanks Willdy).
|
||||
|
||||
v2.40 - *(05/13/11)*
|
||||
* [ADD] ULib.tsayColor and Ulib.tsayError
|
||||
* [ADD] Replicated cvars. Nearly a direct port from the UPS implementation, with a few improvements.
|
||||
* [ADD] queueFunctionCall, ported from UPS.
|
||||
* [ADD] Player:GetUserGroup().
|
||||
* [ADD] Player:CheckGroup(), ability to check if a user in a group via inheritance.
|
||||
* [ADD] ULib.getPlyByUID().
|
||||
* [ADD] ULib.clientRPC(), send massive amounts of data to a client with ease.
|
||||
* [ADD] Upgrade script.
|
||||
* [ADD] hook.getCurrentHooks(), returns all currently processing hooks.
|
||||
* [ADD] hook.isInHook( name ), returns if you're in the specified hook or not.
|
||||
* [ADD] ULib.splitPort(), ULib.isValidSteamID(), ULib.isValidIP().
|
||||
* [ADD] ULib.backupFile().
|
||||
* [ADD] ULib.throwBadArg(), useful for argument checking.
|
||||
* [ADD] ULib.checkArg(), useful for argument checking.
|
||||
* [ADD] ULib.getPicker(), returns a user directly in front of another user.
|
||||
* [ADD] Utilities for table inheritance.
|
||||
* [ADD] New 'translation' command system that acts as a wrapper between a user and lua.
|
||||
* [ADD] New (and very different) command system.
|
||||
* [ADD] Lots of new hooks.
|
||||
* [ADD] Support for gatekeeper in ULib.kick.
|
||||
* [ADD] Our own optimized version of datastream, since garry's implementation is always broken.
|
||||
* [ADD] ULib.getAllReadyPlayers(), useful for sending usermessages to everyone.
|
||||
* [ADD] Basic spam detection system for ULib commands.
|
||||
* [FIX] ULib.filesInDir, was completely broken.
|
||||
* [FIX] The usual assortment of garry breakages.
|
||||
* [FIX] Some case-sensitive issues with the ULib add-command functions.
|
||||
* [FIX] Attempting to delete misc_registered.txt when it didn't exist.
|
||||
* [FIX] ULib.splitArgs now really properly handles escaped quotes and now unescapes them.
|
||||
* [FIX] Concommands created by ULib removing empty args.
|
||||
* [FIX] Overflowing command buffer when executing large config files.
|
||||
* [FIX] Optimized various functions to support up to 4000 bans (at least!).
|
||||
* [FIX] Bug where reloading ban information when a temp ban had less than a minute left made the ban permanent.
|
||||
* [FIX] Bug where ULib was reading in bad characters from source bans (Thanks edk141).
|
||||
* [CHANGE] Chat hooks are now a high priority due to other aggressive admin mods overriding ULX.
|
||||
* [CHANGE] Rewrote UCL entirely. The upgrade script should take care of bringing over old data into the new system.
|
||||
* [CHANGE] Added the ability to have access tags for each access string. These allow the accesses to have customizable behavior.
|
||||
* [CHANGE] Access tags now have comments attached to them (for the "what is it?" among us).
|
||||
* [CHANGE] Added lots of keywords (and keyword negation!) to ULib.getUsers and ULib.getUser.
|
||||
* [CHANGE] Invisible gets rid of shadows now.
|
||||
* [CHANGE] Garry's hook table spec is now more closely followed. (Thanks aVoN!)
|
||||
* [CHANGE] Moved the hook changes to the shared portion so clients can use the enhanced hooks as well.
|
||||
* [CHANGE] Updated the hooks file to match garry's recent changes. Also increased efficiency in hooks (faster than garry's!)
|
||||
* [CHANGE] Slaps now do a view punch as well.
|
||||
* [CHANGE] Allow nil access on ULib.addSayCommand so that you can create a command you always have access to.
|
||||
* [CHANGE] ULib.ucl.query always returns true when a nil access string is passed in.
|
||||
* [REMOVE] Ability to have passwords in UCL, don't think it worked anymore and it was never really used.
|
||||
* [REMOVE] Immunity no longer exists, since the new UCL has a much better method of doing the same thing.
|
||||
* [REMOVE] Some hooks due to garry breakage.
|
||||
* [REMOVE] Chat sounds on tsay, engine no longer makes sounds so neither should tsay.
|
||||
|
||||
v2.30 - *(06/20/09)*
|
||||
* [FIX] Umsgs being sent too early in certain circumstances.
|
||||
* [FIX] Some issues garry introduced in the Jan09 update regarding player initialization.
|
||||
* [FIX] ParseKeyValues not unescaping backslashes.
|
||||
* [CHANGE] Rewrote splitArgs and parseKeyValues.
|
||||
* [CHANGE] misc_registered.txt now self-destructs on missing or empty groups.txt.
|
||||
* [CHANGE] All gamemode.Call refs to hook.Call, thanks aVoN!
|
||||
* [CHANGE] SetUserGroup now REMOVES any other groups and sets an exclusive group. Sorry about this, but this is for the better.
|
||||
|
||||
v2.21 - *(06/08/08)*
|
||||
* [ADD] Support for client/server-side only modules.
|
||||
* [FIX] Bug in ULib.tsay that would incorrectly print to console if the target player was disconnecting.
|
||||
* [FIX] Makes sure that prop protectors don't take ownership of props using physgun reload while a prop is unmovable.
|
||||
* [CHANGE] ULib.getUsers now returns multiple users on an asterisk "*" when enable_keywords is true. "<ALL>" can still be used. (Thanks Kyzer)
|
||||
|
||||
|
||||
v2.20 - *(01/26/08)*
|
||||
* [ADD] ULib now has three shiny new hooks to let you know about client initialization and a new hook to signal a player name change.
|
||||
* [FIX] A possible bug in the physics helpers.
|
||||
* [CHANGE] Various things to bring ULib into new engine compatibility.
|
||||
* [CHANGE] Removed all timers dealing with initialization and now rely on flags from the client. This makes the ULib initialization much more dependable.
|
||||
* [CHANGE] Converted all calls from ULib.consoleCommand( "exec ..." ) to ULib.execFile() to avoid running into the block on "exec" without our module.
|
||||
* [REMOVE] Removing the module for now, might re-appear in the next version
|
||||
|
||||
|
||||
v2.10 - *(09/23/07)*
|
||||
* [ADD] New hook library. Completely backwards compatible, but can now do priorities. (Server-side only)
|
||||
* [ADD] ULib.parseKeyValues, ULib.makeKeyValues
|
||||
* [ADD] ULib.getSpawnInfo, ULib.Spawn - Enhanced Spawn... will replace original health/armor when called if getSpawnInfo called first.
|
||||
* [ADD] READDED hexing system to get around garry's ConCommand() blocks. So much is now blocked that it's interferring with normal ULX operations.
|
||||
* [ADD] Our server module again. This time with only console-executing abilities. This is because garry has blocked much of what we need. Source is included.
|
||||
* [ADD] Custom ban list to store temp bans and additional ban info. Permanent bans are still stored in banned_user.cfg, and the two lists are synchronized.
|
||||
* [FIX] Can now query players from client side.
|
||||
* [FIX] An exploit in DisallowDelete() that allowed players to still remove the props
|
||||
* [FIX] Various initialization functions trying to access a disconnected player
|
||||
* [FIX] ULib.csay() sending umsgs to invalid players.
|
||||
* [FIX] UCL by clantag not working.
|
||||
* [CHANGE] Big changes in ucl.query() and concommand functions. Probably won't be backwards compatible.
|
||||
* [CHANGE] UCL now uses our new keyvalues functions. It should be backwards compatible with your old data, but we make no promises. If you're having trouble with it, try starting from scratch.
|
||||
* [CHANGE] ULib.tsay has a wait parameter to send on next frame
|
||||
* [CHANGE] subconcommands are now case insensitive
|
||||
* [CHANGE] Csay's now have fade.
|
||||
* [CHANGE] DisallowSpawning() now implements SpawnObject. For example, people can't sit and precache props while in the ulx jail.
|
||||
* [CHANGE] Say commands are now case insensitive and default to needing a space between command and arg (can flag to use old behavior though)
|
||||
* [CHANGE] ULib.ban, and ULib.kickban now accept additional information and pass data to ULib.addBan.
|
||||
* [CHANGE] Immunity is now an access string instead of a group
|
||||
* [CHANGE] Overcoming immunity is no longer bound to superadmins
|
||||
* [CHANGE] Increased performance of UCL.
|
||||
* [REMOVED] The vgui panels, derma is the vgui of choice now.
|
||||
|
||||
v2.05 - *(06/19/07)*
|
||||
* [ADD] ply:SetUserGroup() -- Thanks aVoN!
|
||||
* [ADD] ply:DisallowVehicles( bool )
|
||||
* [FIX] A timer error in UCL, was messing up scoreboard sometimes.
|
||||
* [FIX] Security hole where exploiters could gain superadmin access
|
||||
* [CHANGE] You can assign allow/denies to the default user group, "user" now. (IE, allow guests to slap)
|
||||
* [CHANGE] DisallowSpawning now disallows tools that can spawn things.
|
||||
* [REMOVED] Old settings/users.txt stuff, handled by SetUserGroup now
|
||||
|
||||
v2.04 - *(05/05/07)*
|
||||
* [ADD] ULib.isSandbox
|
||||
* [ADD] Player/ent hooks DisallowMoving, DisallowDeleting, DisallowSpawning, DisallowNoclip
|
||||
* [ADD] Some vgui libs (URoundButton, URoundMenu)
|
||||
* [FIX] Double printing in console.
|
||||
* [CHANGE] Implemented garry's "proper" way of including c-side files.
|
||||
* [CHANGE] Implemented client side UCL
|
||||
* [CHANGE] Now in addon format
|
||||
* [CHANGE] Slapping noclipped players will take them out of noclip to prevent them flying very far out of the world
|
||||
* [CHANGE] Improved the umsg send/receive functions
|
||||
* [REMOVED] Hexing system to get around garry's ConCommand() blocks. Very little is blocked now.
|
||||
* [REMOVED] Dll, MOTD functionality is handled by ULX now.
|
||||
|
||||
v2.03 - *(01/10/07)*
|
||||
* [ADD] ULib module, has functions for motd, concommands, and downloading files. SOURCE CODE!
|
||||
* [FIX] Player slap after dead problem.
|
||||
|
||||
v2.02 - *(01/07/07)*
|
||||
* [ADD] New system for giving files to clients. Strips comments and puts them in a separate folder.
|
||||
* [FIX] Autocompletes aren't handled so hackishly now. This should fix some occasional errors.
|
||||
* [FIX] Lots of general fixes.
|
||||
|
||||
v2.01 - *(01/02/07)*
|
||||
* [FIX] Importing from garry's default user file.
|
||||
* [FIX] All users receiving "you do not have access" message.
|
||||
|
||||
v2.0 - *(01/01/07)*
|
||||
* Initial version for GM10
|
||||
|
||||
Group: Developers
|
||||
|
||||
To all developers, I sincerely hope you enjoy what ULib has to offer!
|
||||
If you have any suggestions, comments, or complaints, please tell us at <http://forums.ulyssesmod.net/>.
|
||||
|
||||
If you want an overview of what's in ULib, please visit the documentation at <http://ulyssesmod.net/docs/>.
|
||||
If you find any bugs, you can report them at <https://github.com/Nayruden/Ulysses/issues>.
|
||||
|
||||
All ULib's functions are kept in the table "ULib" to prevent conflicts.
|
||||
|
||||
Revisions are kept in the function/variable documentation. If you don't see revisions listed, it hasn't changed since v2.0
|
||||
|
||||
If you write a script taking advantage of ULib, stick the init script inside ULib/modules. ULib will load your script after
|
||||
ULib loads, and will send it to and load it on clients as well.
|
||||
|
||||
Some important quirks developers should know about --
|
||||
* autocomplete - You have to define the autocomplete on the client, so if you pass a string for autocomplete to ULib.concommand,
|
||||
it will assume you mean a client function. There's also a delay in the sending of these to the client.
|
||||
|
||||
Group: Credits
|
||||
|
||||
Thanks to JamminR, who is always there to offer help and advice to those who need it.
|
||||
|
||||
Group: License
|
||||
|
||||
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
|
||||
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
|
||||
Creative Commons
|
||||
543 Howard Street
|
||||
5th Floor
|
||||
San Francisco, California 94105
|
||||
USA
|
||||
|
22
addon.txt
22
addon.txt
@ -1,11 +1,11 @@
|
||||
"AddonInfo"
|
||||
{
|
||||
"name" "ULib"
|
||||
"version" "2.60"
|
||||
"up_date" "00/00/00"
|
||||
"author_name" "Team Ulysses"
|
||||
"author_email" "teamulysses@ulyssesmod.net"
|
||||
"author_url" "http://www.ulyssesmod.net/"
|
||||
"info" "Lua Library"
|
||||
"override" "0"
|
||||
}
|
||||
"AddonInfo"
|
||||
{
|
||||
"name" "ULib"
|
||||
"version" "2.60"
|
||||
"up_date" "00/00/00"
|
||||
"author_name" "Team Ulysses"
|
||||
"author_email" "teamulysses@ulyssesmod.net"
|
||||
"author_url" "http://www.ulyssesmod.net/"
|
||||
"info" "Lua Library"
|
||||
"override" "0"
|
||||
}
|
||||
|
@ -1,39 +1,39 @@
|
||||
Format of admin account in users.txt--
|
||||
"<steamid|ip|unique id>"
|
||||
{
|
||||
"group" "superadmin"
|
||||
"allow"
|
||||
{
|
||||
"ulx kick"
|
||||
"ulx ban"
|
||||
}
|
||||
"deny"
|
||||
{
|
||||
"ulx cexec"
|
||||
}
|
||||
}
|
||||
|
||||
Example of a superadmin:
|
||||
"STEAM_0:1:123456"
|
||||
{
|
||||
"group" "superadmin"
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"deny"
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Format of group that gets the same allows as a superadmin in groups.txt--
|
||||
"<group_name>"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
"ulx kick"
|
||||
"ulx ban"
|
||||
}
|
||||
"inherit_from" "superadmin"
|
||||
Format of admin account in users.txt--
|
||||
"<steamid|ip|unique id>"
|
||||
{
|
||||
"group" "superadmin"
|
||||
"allow"
|
||||
{
|
||||
"ulx kick"
|
||||
"ulx ban"
|
||||
}
|
||||
"deny"
|
||||
{
|
||||
"ulx cexec"
|
||||
}
|
||||
}
|
||||
|
||||
Example of a superadmin:
|
||||
"STEAM_0:1:123456"
|
||||
{
|
||||
"group" "superadmin"
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"deny"
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Format of group that gets the same allows as a superadmin in groups.txt--
|
||||
"<group_name>"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
"ulx kick"
|
||||
"ulx ban"
|
||||
}
|
||||
"inherit_from" "superadmin"
|
||||
}
|
@ -1,35 +1,35 @@
|
||||
//ATTENTION! This is a default file. DO NOT EDIT THIS FILE!!!
|
||||
//Instead, edit the version in <garrysmod root>/data/ULib/groups.txt if it exists. If it doesn't, copy this file over to create it.
|
||||
//IF YOU MAKE CHANGES TO THIS FILE THEY WILL BE ERASED!
|
||||
|
||||
"operator"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"can_target" "!%admin"
|
||||
}
|
||||
|
||||
"admin"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"inherit_from" "operator"
|
||||
"can_target" "!%superadmin"
|
||||
}
|
||||
|
||||
"superadmin"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"inherit_from" "admin"
|
||||
}
|
||||
|
||||
"user"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
}
|
||||
//ATTENTION! This is a default file. DO NOT EDIT THIS FILE!!!
|
||||
//Instead, edit the version in <garrysmod root>/data/ULib/groups.txt if it exists. If it doesn't, copy this file over to create it.
|
||||
//IF YOU MAKE CHANGES TO THIS FILE THEY WILL BE ERASED!
|
||||
|
||||
"operator"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"can_target" "!%admin"
|
||||
}
|
||||
|
||||
"admin"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"inherit_from" "operator"
|
||||
"can_target" "!%superadmin"
|
||||
}
|
||||
|
||||
"superadmin"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
"inherit_from" "admin"
|
||||
}
|
||||
|
||||
"user"
|
||||
{
|
||||
"allow"
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
//ATTENTION! This is a default file. DO NOT EDIT THIS FILE!!!
|
||||
//Instead, edit the version in <garrysmod root>/data/ULib/users.txt if it exists. If it doesn't, copy this file over to create it.
|
||||
//IF YOU MAKE CHANGES TO THIS FILE THEY WILL BE ERASED!
|
||||
//ATTENTION! This is a default file. DO NOT EDIT THIS FILE!!!
|
||||
//Instead, edit the version in <garrysmod root>/data/ULib/users.txt if it exists. If it doesn't, copy this file over to create it.
|
||||
//IF YOU MAKE CHANGES TO THIS FILE THEY WILL BE ERASED!
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- Short and sweet
|
||||
if SERVER then
|
||||
include( "ulib/init.lua" )
|
||||
else
|
||||
include( "ulib/cl_init.lua" )
|
||||
end
|
||||
-- Short and sweet
|
||||
if SERVER then
|
||||
include( "ulib/init.lua" )
|
||||
else
|
||||
include( "ulib/cl_init.lua" )
|
||||
end
|
||||
|
@ -1,63 +1,63 @@
|
||||
ULib = ULib or {} -- Init table
|
||||
|
||||
include( "ulib/shared/defines.lua" )
|
||||
include( "ulib/shared/misc.lua" )
|
||||
include( "ulib/shared/util.lua" )
|
||||
include( "ulib/shared/hook.lua" )
|
||||
include( "ulib/shared/tables.lua" )
|
||||
include( "ulib/client/commands.lua" )
|
||||
include( "ulib/shared/messages.lua" )
|
||||
include( "ulib/shared/player.lua" )
|
||||
include( "ulib/client/cl_util.lua" )
|
||||
include( "ulib/client/draw.lua" )
|
||||
include( "ulib/shared/commands.lua" )
|
||||
include( "ulib/shared/sh_ucl.lua" )
|
||||
include( "ulib/shared/cami_global.lua" )
|
||||
include( "ulib/shared/cami_ulib.lua" )
|
||||
|
||||
Msg( string.format( "You are running ULib version %.2f.\n", ULib.VERSION ) )
|
||||
|
||||
--Shared modules
|
||||
local files = file.Find( "ulib/modules/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading SHARED module: " .. file .. "\n" )
|
||||
include( "ulib/modules/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
--Client modules
|
||||
local files = file.Find( "ulib/modules/client/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading CLIENT module: " .. file .. "\n" )
|
||||
include( "ulib/modules/client/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
local needs_auth = {}
|
||||
|
||||
local function onEntCreated( ent )
|
||||
if ent:IsPlayer() and needs_auth[ ent:UserID() ] then
|
||||
hook.Call( ULib.HOOK_UCLAUTH, _, ent ) -- Because otherwise the server might call this before the player is created
|
||||
needs_auth[ ent:UserID() ] = nil
|
||||
end
|
||||
end
|
||||
hook.Add( "OnEntityCreated", "ULibPlayerAuthCheck", onEntCreated, HOOK_MONITOR_HIGH ) -- Listen for player creations
|
||||
|
||||
local function onInitPostEntity()
|
||||
if LocalPlayer():IsValid() then
|
||||
hook.Call( ULib.HOOK_LOCALPLAYERREADY, _, LocalPlayer() )
|
||||
RunConsoleCommand( "ulib_cl_ready" )
|
||||
end
|
||||
end
|
||||
hook.Add( "InitPostEntity", "ULibLocalPlayerReady", onInitPostEntity, HOOK_MONITOR_HIGH ) -- Flag server when LocalPlayer() should be valid
|
||||
|
||||
-- We're trying to make sure that the player auths after the player object is created, this function is part of that check
|
||||
function authPlayerIfReady( ply, userid )
|
||||
if ply and ply:IsValid() then
|
||||
hook.Call( ULib.HOOK_UCLAUTH, _, ply ) -- Call hook
|
||||
else
|
||||
needs_auth[ userid ] = true
|
||||
end
|
||||
end
|
||||
ULib = ULib or {} -- Init table
|
||||
|
||||
include( "ulib/shared/defines.lua" )
|
||||
include( "ulib/shared/misc.lua" )
|
||||
include( "ulib/shared/util.lua" )
|
||||
include( "ulib/shared/hook.lua" )
|
||||
include( "ulib/shared/tables.lua" )
|
||||
include( "ulib/client/commands.lua" )
|
||||
include( "ulib/shared/messages.lua" )
|
||||
include( "ulib/shared/player.lua" )
|
||||
include( "ulib/client/cl_util.lua" )
|
||||
include( "ulib/client/draw.lua" )
|
||||
include( "ulib/shared/commands.lua" )
|
||||
include( "ulib/shared/sh_ucl.lua" )
|
||||
include( "ulib/shared/cami_global.lua" )
|
||||
include( "ulib/shared/cami_ulib.lua" )
|
||||
|
||||
Msg( string.format( "You are running ULib version %.2f.\n", ULib.VERSION ) )
|
||||
|
||||
--Shared modules
|
||||
local files = file.Find( "ulib/modules/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading SHARED module: " .. file .. "\n" )
|
||||
include( "ulib/modules/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
--Client modules
|
||||
local files = file.Find( "ulib/modules/client/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading CLIENT module: " .. file .. "\n" )
|
||||
include( "ulib/modules/client/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
local needs_auth = {}
|
||||
|
||||
local function onEntCreated( ent )
|
||||
if ent:IsPlayer() and needs_auth[ ent:UserID() ] then
|
||||
hook.Call( ULib.HOOK_UCLAUTH, _, ent ) -- Because otherwise the server might call this before the player is created
|
||||
needs_auth[ ent:UserID() ] = nil
|
||||
end
|
||||
end
|
||||
hook.Add( "OnEntityCreated", "ULibPlayerAuthCheck", onEntCreated, HOOK_MONITOR_HIGH ) -- Listen for player creations
|
||||
|
||||
local function onInitPostEntity()
|
||||
if LocalPlayer():IsValid() then
|
||||
hook.Call( ULib.HOOK_LOCALPLAYERREADY, _, LocalPlayer() )
|
||||
RunConsoleCommand( "ulib_cl_ready" )
|
||||
end
|
||||
end
|
||||
hook.Add( "InitPostEntity", "ULibLocalPlayerReady", onInitPostEntity, HOOK_MONITOR_HIGH ) -- Flag server when LocalPlayer() should be valid
|
||||
|
||||
-- We're trying to make sure that the player auths after the player object is created, this function is part of that check
|
||||
function authPlayerIfReady( ply, userid )
|
||||
if ply and ply:IsValid() then
|
||||
hook.Call( ULib.HOOK_UCLAUTH, _, ply ) -- Call hook
|
||||
else
|
||||
needs_auth[ userid ] = true
|
||||
end
|
||||
end
|
||||
|
@ -1,156 +1,156 @@
|
||||
--[[
|
||||
Title: Utilities
|
||||
|
||||
Some client-side utilties
|
||||
]]
|
||||
|
||||
local function ULibRPC()
|
||||
local fn_string = net.ReadString()
|
||||
local args = net.ReadTable()
|
||||
local fn = ULib.findVar( fn_string )
|
||||
if type( fn ) ~= "function" then return error( "Received bad RPC, invalid function (" .. tostring( fn_string ) .. ")!" ) end
|
||||
|
||||
-- Since the table length operator can't always be trusted if there are holes in it, find the length by ourself
|
||||
local max = 0
|
||||
for k, v in pairs( args ) do
|
||||
local n = tonumber( k )
|
||||
if n and n > max then
|
||||
max = n
|
||||
end
|
||||
end
|
||||
|
||||
fn( unpack( args, 1, max ) )
|
||||
end
|
||||
net.Receive( "URPC", ULibRPC )
|
||||
|
||||
--[[
|
||||
Function: umsgRcv
|
||||
|
||||
Receive a umsg sent by ULib.umsgSend
|
||||
|
||||
Parameters:
|
||||
|
||||
um - The user message object
|
||||
|
||||
Returns:
|
||||
|
||||
The variable from the umsg.
|
||||
]]
|
||||
function ULib.umsgRcv( um, control )
|
||||
local tv = control or um:ReadChar()
|
||||
|
||||
local ret -- Our return value
|
||||
if tv == ULib.TYPE_STRING then
|
||||
ret = um:ReadString()
|
||||
elseif tv == ULib.TYPE_FLOAT then
|
||||
ret = um:ReadFloat()
|
||||
elseif tv == ULib.TYPE_SHORT then
|
||||
ret = um:ReadShort()
|
||||
elseif tv == ULib.TYPE_LONG then
|
||||
ret = um:ReadLong()
|
||||
elseif tv == ULib.TYPE_BOOLEAN then
|
||||
ret = um:ReadBool()
|
||||
elseif tv == ULib.TYPE_ENTITY then
|
||||
ret = um:ReadEntity()
|
||||
elseif tv == ULib.TYPE_VECTOR then
|
||||
ret = um:ReadVector()
|
||||
elseif tv == ULib.TYPE_ANGLE then
|
||||
ret = um:ReadAngle()
|
||||
elseif tv == ULib.TYPE_CHAR then
|
||||
ret = um:ReadChar()
|
||||
elseif tv == ULib.TYPE_TABLE_BEGIN then
|
||||
ret = {}
|
||||
while true do -- Yes an infite loop. We have a break inside.
|
||||
local key = ULib.umsgRcv( um )
|
||||
if key == nil then break end -- Here's our break
|
||||
ret[ key ] = ULib.umsgRcv( um )
|
||||
end
|
||||
elseif tv == ULib.TYPE_TABLE_END then
|
||||
return nil
|
||||
elseif tv == ULib.TYPE_NIL then
|
||||
return nil
|
||||
else
|
||||
ULib.error( "Unknown type passed to umsgRcv - " .. tv )
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
-- This will play sounds client side
|
||||
local function rcvSound( um )
|
||||
local str = um:ReadString()
|
||||
if not ULib.fileExists( "sound/" .. str ) then
|
||||
Msg( "[LC ULib ERROR] Received invalid sound\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if LocalPlayer():IsValid() then
|
||||
LocalPlayer():EmitSound( Sound( str ) )
|
||||
end
|
||||
end
|
||||
usermessage.Hook( "ulib_sound", rcvSound )
|
||||
|
||||
local cvarinfo = {} -- Stores the client cvar object indexed by name of the server cvar
|
||||
local reversecvar = {} -- Stores the name of server cvars indexed by the client cvar
|
||||
|
||||
-- When our client side cvar is changed, notify the server to change it's cvar too.
|
||||
local function clCvarChanged( cl_cvar, oldvalue, newvalue )
|
||||
if not reversecvar[ cl_cvar ] then -- Error
|
||||
return
|
||||
elseif reversecvar[ cl_cvar ].ignore then -- ignore
|
||||
reversecvar[ cl_cvar ].ignore = nil
|
||||
return
|
||||
end
|
||||
|
||||
local sv_cvar = reversecvar[ cl_cvar ].sv_cvar
|
||||
RunConsoleCommand( "ulib_update_cvar", sv_cvar, newvalue )
|
||||
end
|
||||
|
||||
-- This is the counterpart to <replicatedWithWritableCvar>. See that function for more info. We also add callbacks from here.
|
||||
local function readCvar( um )
|
||||
local sv_cvar = um:ReadString()
|
||||
local cl_cvar = um:ReadString()
|
||||
local default_value = um:ReadString()
|
||||
local current_value = um:ReadString()
|
||||
|
||||
cvarinfo[ sv_cvar ] = GetConVar( cl_cvar ) or CreateClientConVar( cl_cvar, default_value, false, false ) -- Make sure it's created one way or another (second case is most common)
|
||||
reversecvar[ cl_cvar ] = { sv_cvar=sv_cvar }
|
||||
|
||||
ULib.queueFunctionCall( function() -- Queued to ensure we don't overload the client console
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, cl_cvar, nil, nil, current_value )
|
||||
if cvarinfo[ sv_cvar ]:GetString() ~= current_value then
|
||||
reversecvar[ cl_cvar ].ignore = true -- Flag so hook doesn't do anything. Flag is removed at hook.
|
||||
RunConsoleCommand( cl_cvar, current_value )
|
||||
end
|
||||
end )
|
||||
|
||||
cvars.AddChangeCallback( cl_cvar, clCvarChanged )
|
||||
end
|
||||
usermessage.Hook( "ulib_repWriteCvar", readCvar )
|
||||
|
||||
-- This is called when they've attempted to change a cvar they don't have access to.
|
||||
local function changeCvar( um )
|
||||
local ply = um:ReadEntity()
|
||||
local cl_cvar = um:ReadString()
|
||||
local oldvalue = um:ReadString()
|
||||
local newvalue = um:ReadString()
|
||||
local changed = oldvalue ~= newvalue
|
||||
|
||||
if not reversecvar[ cl_cvar ] then -- Error!
|
||||
return
|
||||
end
|
||||
|
||||
local sv_cvar = reversecvar[ cl_cvar ].sv_cvar
|
||||
|
||||
ULib.queueFunctionCall( function() -- Queued so we won't overload the client console and so that changes are always going to be called via the hook AFTER the initial hook is called
|
||||
if changed then
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, cl_cvar, ply, oldvalue, newvalue )
|
||||
end
|
||||
|
||||
if GetConVarString( cl_cvar ) ~= newvalue then
|
||||
reversecvar[ cl_cvar ].ignore = true -- Flag so hook doesn't do anything. Flag is removed at hook.
|
||||
RunConsoleCommand( cl_cvar, newvalue)
|
||||
end
|
||||
end )
|
||||
end
|
||||
usermessage.Hook( "ulib_repChangeCvar", changeCvar )
|
||||
--[[
|
||||
Title: Utilities
|
||||
|
||||
Some client-side utilties
|
||||
]]
|
||||
|
||||
local function ULibRPC()
|
||||
local fn_string = net.ReadString()
|
||||
local args = net.ReadTable()
|
||||
local fn = ULib.findVar( fn_string )
|
||||
if type( fn ) ~= "function" then return error( "Received bad RPC, invalid function (" .. tostring( fn_string ) .. ")!" ) end
|
||||
|
||||
-- Since the table length operator can't always be trusted if there are holes in it, find the length by ourself
|
||||
local max = 0
|
||||
for k, v in pairs( args ) do
|
||||
local n = tonumber( k )
|
||||
if n and n > max then
|
||||
max = n
|
||||
end
|
||||
end
|
||||
|
||||
fn( unpack( args, 1, max ) )
|
||||
end
|
||||
net.Receive( "URPC", ULibRPC )
|
||||
|
||||
--[[
|
||||
Function: umsgRcv
|
||||
|
||||
Receive a umsg sent by ULib.umsgSend
|
||||
|
||||
Parameters:
|
||||
|
||||
um - The user message object
|
||||
|
||||
Returns:
|
||||
|
||||
The variable from the umsg.
|
||||
]]
|
||||
function ULib.umsgRcv( um, control )
|
||||
local tv = control or um:ReadChar()
|
||||
|
||||
local ret -- Our return value
|
||||
if tv == ULib.TYPE_STRING then
|
||||
ret = um:ReadString()
|
||||
elseif tv == ULib.TYPE_FLOAT then
|
||||
ret = um:ReadFloat()
|
||||
elseif tv == ULib.TYPE_SHORT then
|
||||
ret = um:ReadShort()
|
||||
elseif tv == ULib.TYPE_LONG then
|
||||
ret = um:ReadLong()
|
||||
elseif tv == ULib.TYPE_BOOLEAN then
|
||||
ret = um:ReadBool()
|
||||
elseif tv == ULib.TYPE_ENTITY then
|
||||
ret = um:ReadEntity()
|
||||
elseif tv == ULib.TYPE_VECTOR then
|
||||
ret = um:ReadVector()
|
||||
elseif tv == ULib.TYPE_ANGLE then
|
||||
ret = um:ReadAngle()
|
||||
elseif tv == ULib.TYPE_CHAR then
|
||||
ret = um:ReadChar()
|
||||
elseif tv == ULib.TYPE_TABLE_BEGIN then
|
||||
ret = {}
|
||||
while true do -- Yes an infite loop. We have a break inside.
|
||||
local key = ULib.umsgRcv( um )
|
||||
if key == nil then break end -- Here's our break
|
||||
ret[ key ] = ULib.umsgRcv( um )
|
||||
end
|
||||
elseif tv == ULib.TYPE_TABLE_END then
|
||||
return nil
|
||||
elseif tv == ULib.TYPE_NIL then
|
||||
return nil
|
||||
else
|
||||
ULib.error( "Unknown type passed to umsgRcv - " .. tv )
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
-- This will play sounds client side
|
||||
local function rcvSound( um )
|
||||
local str = um:ReadString()
|
||||
if not ULib.fileExists( "sound/" .. str ) then
|
||||
Msg( "[LC ULib ERROR] Received invalid sound\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if LocalPlayer():IsValid() then
|
||||
LocalPlayer():EmitSound( Sound( str ) )
|
||||
end
|
||||
end
|
||||
usermessage.Hook( "ulib_sound", rcvSound )
|
||||
|
||||
local cvarinfo = {} -- Stores the client cvar object indexed by name of the server cvar
|
||||
local reversecvar = {} -- Stores the name of server cvars indexed by the client cvar
|
||||
|
||||
-- When our client side cvar is changed, notify the server to change it's cvar too.
|
||||
local function clCvarChanged( cl_cvar, oldvalue, newvalue )
|
||||
if not reversecvar[ cl_cvar ] then -- Error
|
||||
return
|
||||
elseif reversecvar[ cl_cvar ].ignore then -- ignore
|
||||
reversecvar[ cl_cvar ].ignore = nil
|
||||
return
|
||||
end
|
||||
|
||||
local sv_cvar = reversecvar[ cl_cvar ].sv_cvar
|
||||
RunConsoleCommand( "ulib_update_cvar", sv_cvar, newvalue )
|
||||
end
|
||||
|
||||
-- This is the counterpart to <replicatedWithWritableCvar>. See that function for more info. We also add callbacks from here.
|
||||
local function readCvar( um )
|
||||
local sv_cvar = um:ReadString()
|
||||
local cl_cvar = um:ReadString()
|
||||
local default_value = um:ReadString()
|
||||
local current_value = um:ReadString()
|
||||
|
||||
cvarinfo[ sv_cvar ] = GetConVar( cl_cvar ) or CreateClientConVar( cl_cvar, default_value, false, false ) -- Make sure it's created one way or another (second case is most common)
|
||||
reversecvar[ cl_cvar ] = { sv_cvar=sv_cvar }
|
||||
|
||||
ULib.queueFunctionCall( function() -- Queued to ensure we don't overload the client console
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, cl_cvar, nil, nil, current_value )
|
||||
if cvarinfo[ sv_cvar ]:GetString() ~= current_value then
|
||||
reversecvar[ cl_cvar ].ignore = true -- Flag so hook doesn't do anything. Flag is removed at hook.
|
||||
RunConsoleCommand( cl_cvar, current_value )
|
||||
end
|
||||
end )
|
||||
|
||||
cvars.AddChangeCallback( cl_cvar, clCvarChanged )
|
||||
end
|
||||
usermessage.Hook( "ulib_repWriteCvar", readCvar )
|
||||
|
||||
-- This is called when they've attempted to change a cvar they don't have access to.
|
||||
local function changeCvar( um )
|
||||
local ply = um:ReadEntity()
|
||||
local cl_cvar = um:ReadString()
|
||||
local oldvalue = um:ReadString()
|
||||
local newvalue = um:ReadString()
|
||||
local changed = oldvalue ~= newvalue
|
||||
|
||||
if not reversecvar[ cl_cvar ] then -- Error!
|
||||
return
|
||||
end
|
||||
|
||||
local sv_cvar = reversecvar[ cl_cvar ].sv_cvar
|
||||
|
||||
ULib.queueFunctionCall( function() -- Queued so we won't overload the client console and so that changes are always going to be called via the hook AFTER the initial hook is called
|
||||
if changed then
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, cl_cvar, ply, oldvalue, newvalue )
|
||||
end
|
||||
|
||||
if GetConVarString( cl_cvar ) ~= newvalue then
|
||||
reversecvar[ cl_cvar ].ignore = true -- Flag so hook doesn't do anything. Flag is removed at hook.
|
||||
RunConsoleCommand( cl_cvar, newvalue)
|
||||
end
|
||||
end )
|
||||
end
|
||||
usermessage.Hook( "ulib_repChangeCvar", changeCvar )
|
||||
|
@ -1,54 +1,54 @@
|
||||
--[[
|
||||
Title: Draw
|
||||
|
||||
Our client-side draw functions
|
||||
]]
|
||||
|
||||
--[[
|
||||
Function: csayDraw
|
||||
|
||||
Draws a csay text on the screen.
|
||||
|
||||
Parameters:
|
||||
|
||||
msg - The message to draw.
|
||||
color - *(Optional, defaults to 255, 255, 255, 255)* The color of the text
|
||||
duration - *(Optional, defaults to 5)* The length of the text
|
||||
fade - *(Optional, defaults to 0.5)* The length of fade time
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added fade parameter
|
||||
]]
|
||||
function ULib.csayDraw( msg, color, duration, fade )
|
||||
color = color or Color( 255, 255, 255, 255 )
|
||||
duration = duration or 5
|
||||
fade = fade or 0.5
|
||||
local start = CurTime()
|
||||
|
||||
local function drawToScreen()
|
||||
local alpha = 255
|
||||
local dtime = CurTime() - start
|
||||
|
||||
if dtime > duration then -- Our time has come :'(
|
||||
hook.Remove( "HUDPaint", "CSayHelperDraw" )
|
||||
return
|
||||
end
|
||||
|
||||
if fade - dtime > 0 then -- beginning fade
|
||||
alpha = (fade - dtime) / fade -- 0 to 1
|
||||
alpha = 1 - alpha -- Reverse
|
||||
alpha = alpha * 255
|
||||
end
|
||||
|
||||
if duration - dtime < fade then -- ending fade
|
||||
alpha = (duration - dtime) / fade -- 0 to 1
|
||||
alpha = alpha * 255
|
||||
end
|
||||
color.a = alpha
|
||||
|
||||
draw.DrawText( msg, "TargetID", ScrW() * 0.5, ScrH() * 0.25, color, TEXT_ALIGN_CENTER )
|
||||
end
|
||||
|
||||
hook.Add( "HUDPaint", "CSayHelperDraw", drawToScreen )
|
||||
end
|
||||
--[[
|
||||
Title: Draw
|
||||
|
||||
Our client-side draw functions
|
||||
]]
|
||||
|
||||
--[[
|
||||
Function: csayDraw
|
||||
|
||||
Draws a csay text on the screen.
|
||||
|
||||
Parameters:
|
||||
|
||||
msg - The message to draw.
|
||||
color - *(Optional, defaults to 255, 255, 255, 255)* The color of the text
|
||||
duration - *(Optional, defaults to 5)* The length of the text
|
||||
fade - *(Optional, defaults to 0.5)* The length of fade time
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added fade parameter
|
||||
]]
|
||||
function ULib.csayDraw( msg, color, duration, fade )
|
||||
color = color or Color( 255, 255, 255, 255 )
|
||||
duration = duration or 5
|
||||
fade = fade or 0.5
|
||||
local start = CurTime()
|
||||
|
||||
local function drawToScreen()
|
||||
local alpha = 255
|
||||
local dtime = CurTime() - start
|
||||
|
||||
if dtime > duration then -- Our time has come :'(
|
||||
hook.Remove( "HUDPaint", "CSayHelperDraw" )
|
||||
return
|
||||
end
|
||||
|
||||
if fade - dtime > 0 then -- beginning fade
|
||||
alpha = (fade - dtime) / fade -- 0 to 1
|
||||
alpha = 1 - alpha -- Reverse
|
||||
alpha = alpha * 255
|
||||
end
|
||||
|
||||
if duration - dtime < fade then -- ending fade
|
||||
alpha = (duration - dtime) / fade -- 0 to 1
|
||||
alpha = alpha * 255
|
||||
end
|
||||
color.a = alpha
|
||||
|
||||
draw.DrawText( msg, "TargetID", ScrW() * 0.5, ScrH() * 0.25, color, TEXT_ALIGN_CENTER )
|
||||
end
|
||||
|
||||
hook.Add( "HUDPaint", "CSayHelperDraw", drawToScreen )
|
||||
end
|
||||
|
@ -1,100 +1,100 @@
|
||||
if not ULib then
|
||||
ULib = {}
|
||||
|
||||
-- For historical purposes
|
||||
if not ULib.consoleCommand then ULib.consoleCommand = game.ConsoleCommand end
|
||||
|
||||
file.CreateDir( "ulib" )
|
||||
|
||||
Msg( "///////////////////////////////\n" )
|
||||
Msg( "// Ulysses Library //\n" )
|
||||
Msg( "///////////////////////////////\n" )
|
||||
Msg( "// Loading... //\n" )
|
||||
|
||||
Msg( "// shared/defines.lua //\n" )
|
||||
include( "ulib/shared/defines.lua" )
|
||||
Msg( "// shared/misc.lua //\n" )
|
||||
include( "ulib/shared/misc.lua" )
|
||||
Msg( "// shared/util.lua //\n" )
|
||||
include( "ulib/shared/util.lua" )
|
||||
Msg( "// shared/hook.lua //\n" )
|
||||
include( "ulib/shared/hook.lua" )
|
||||
Msg( "// shared/table.lua //\n" )
|
||||
include( "ulib/shared/tables.lua" )
|
||||
Msg( "// shared/player.lua //\n" )
|
||||
include( "ulib/shared/player.lua" )
|
||||
Msg( "// server/player.lua //\n" )
|
||||
include( "ulib/server/player.lua" )
|
||||
Msg( "// shared/messages.lua //\n" )
|
||||
include( "ulib/shared/messages.lua" )
|
||||
Msg( "// shared/commands.lua //\n" )
|
||||
include( "ulib/shared/commands.lua" )
|
||||
Msg( "// server/concommand.lua //\n" )
|
||||
include( "ulib/server/concommand.lua" )
|
||||
Msg( "// server/util.lua //\n" )
|
||||
include( "ulib/server/util.lua" )
|
||||
Msg( "// shared/sh_ucl.lua //\n" )
|
||||
include( "ulib/shared/sh_ucl.lua" )
|
||||
Msg( "// server/ucl.lua //\n" )
|
||||
include( "ulib/server/ucl.lua" )
|
||||
Msg( "// server/phys.lua //\n" )
|
||||
include( "ulib/server/phys.lua" )
|
||||
Msg( "// server/player_ext.lua //\n" )
|
||||
include( "server/player_ext.lua" )
|
||||
Msg( "// server/entity_ext.lua //\n" )
|
||||
include( "server/entity_ext.lua" )
|
||||
Msg( "// shared/cami_global.lua //\n" )
|
||||
include( "shared/cami_global.lua" )
|
||||
Msg( "// shared/cami_ulib.lua //\n" )
|
||||
include( "shared/cami_ulib.lua" )
|
||||
Msg( "// Load Complete! //\n" )
|
||||
Msg( "///////////////////////////////\n" )
|
||||
|
||||
AddCSLuaFile( "ulib/cl_init.lua" )
|
||||
AddCSLuaFile( "autorun/ulib_init.lua" )
|
||||
local folder = "ulib/shared"
|
||||
local files = file.Find( folder .. "/" .. "*.lua", "LUA" )
|
||||
for _, file in ipairs( files ) do
|
||||
AddCSLuaFile( folder .. "/" .. file )
|
||||
end
|
||||
|
||||
folder = "ulib/client"
|
||||
files = file.Find( folder .. "/" .. "*.lua", "LUA" )
|
||||
for _, file in ipairs( files ) do
|
||||
AddCSLuaFile( folder .. "/" .. file )
|
||||
end
|
||||
|
||||
--Shared modules
|
||||
local files = file.Find( "ulib/modules/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading SHARED module: " .. file .. "\n" )
|
||||
include( "ulib/modules/" .. file )
|
||||
AddCSLuaFile( "ulib/modules/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
--Server modules
|
||||
local files = file.Find( "ulib/modules/server/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading SERVER module: " .. file .. "\n" )
|
||||
include( "ulib/modules/server/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
--Client modules
|
||||
local files = file.Find( "ulib/modules/client/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading CLIENT module: " .. file .. "\n" )
|
||||
AddCSLuaFile( "ulib/modules/client/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
local function clReady( ply )
|
||||
ply.ulib_ready = true
|
||||
hook.Call( ULib.HOOK_LOCALPLAYERREADY, _, ply )
|
||||
end
|
||||
concommand.Add( "ulib_cl_ready", clReady ) -- Called when the c-side player object is ready
|
||||
end
|
||||
if not ULib then
|
||||
ULib = {}
|
||||
|
||||
-- For historical purposes
|
||||
if not ULib.consoleCommand then ULib.consoleCommand = game.ConsoleCommand end
|
||||
|
||||
file.CreateDir( "ulib" )
|
||||
|
||||
Msg( "///////////////////////////////\n" )
|
||||
Msg( "// Ulysses Library //\n" )
|
||||
Msg( "///////////////////////////////\n" )
|
||||
Msg( "// Loading... //\n" )
|
||||
|
||||
Msg( "// shared/defines.lua //\n" )
|
||||
include( "ulib/shared/defines.lua" )
|
||||
Msg( "// shared/misc.lua //\n" )
|
||||
include( "ulib/shared/misc.lua" )
|
||||
Msg( "// shared/util.lua //\n" )
|
||||
include( "ulib/shared/util.lua" )
|
||||
Msg( "// shared/hook.lua //\n" )
|
||||
include( "ulib/shared/hook.lua" )
|
||||
Msg( "// shared/table.lua //\n" )
|
||||
include( "ulib/shared/tables.lua" )
|
||||
Msg( "// shared/player.lua //\n" )
|
||||
include( "ulib/shared/player.lua" )
|
||||
Msg( "// server/player.lua //\n" )
|
||||
include( "ulib/server/player.lua" )
|
||||
Msg( "// shared/messages.lua //\n" )
|
||||
include( "ulib/shared/messages.lua" )
|
||||
Msg( "// shared/commands.lua //\n" )
|
||||
include( "ulib/shared/commands.lua" )
|
||||
Msg( "// server/concommand.lua //\n" )
|
||||
include( "ulib/server/concommand.lua" )
|
||||
Msg( "// server/util.lua //\n" )
|
||||
include( "ulib/server/util.lua" )
|
||||
Msg( "// shared/sh_ucl.lua //\n" )
|
||||
include( "ulib/shared/sh_ucl.lua" )
|
||||
Msg( "// server/ucl.lua //\n" )
|
||||
include( "ulib/server/ucl.lua" )
|
||||
Msg( "// server/phys.lua //\n" )
|
||||
include( "ulib/server/phys.lua" )
|
||||
Msg( "// server/player_ext.lua //\n" )
|
||||
include( "server/player_ext.lua" )
|
||||
Msg( "// server/entity_ext.lua //\n" )
|
||||
include( "server/entity_ext.lua" )
|
||||
Msg( "// shared/cami_global.lua //\n" )
|
||||
include( "shared/cami_global.lua" )
|
||||
Msg( "// shared/cami_ulib.lua //\n" )
|
||||
include( "shared/cami_ulib.lua" )
|
||||
Msg( "// Load Complete! //\n" )
|
||||
Msg( "///////////////////////////////\n" )
|
||||
|
||||
AddCSLuaFile( "ulib/cl_init.lua" )
|
||||
AddCSLuaFile( "autorun/ulib_init.lua" )
|
||||
local folder = "ulib/shared"
|
||||
local files = file.Find( folder .. "/" .. "*.lua", "LUA" )
|
||||
for _, file in ipairs( files ) do
|
||||
AddCSLuaFile( folder .. "/" .. file )
|
||||
end
|
||||
|
||||
folder = "ulib/client"
|
||||
files = file.Find( folder .. "/" .. "*.lua", "LUA" )
|
||||
for _, file in ipairs( files ) do
|
||||
AddCSLuaFile( folder .. "/" .. file )
|
||||
end
|
||||
|
||||
--Shared modules
|
||||
local files = file.Find( "ulib/modules/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading SHARED module: " .. file .. "\n" )
|
||||
include( "ulib/modules/" .. file )
|
||||
AddCSLuaFile( "ulib/modules/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
--Server modules
|
||||
local files = file.Find( "ulib/modules/server/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading SERVER module: " .. file .. "\n" )
|
||||
include( "ulib/modules/server/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
--Client modules
|
||||
local files = file.Find( "ulib/modules/client/*.lua", "LUA" )
|
||||
if #files > 0 then
|
||||
for _, file in ipairs( files ) do
|
||||
Msg( "[ULIB] Loading CLIENT module: " .. file .. "\n" )
|
||||
AddCSLuaFile( "ulib/modules/client/" .. file )
|
||||
end
|
||||
end
|
||||
|
||||
local function clReady( ply )
|
||||
ply.ulib_ready = true
|
||||
hook.Call( ULib.HOOK_LOCALPLAYERREADY, _, ply )
|
||||
end
|
||||
concommand.Add( "ulib_cl_ready", clReady ) -- Called when the c-side player object is ready
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
This folder is similar to the lua/autorun folder, except all scripts in this folder are loaded after ULib.
|
||||
Scripts in this directory are shared ( loaded both server and client side ).
|
||||
This folder is similar to the lua/autorun folder, except all scripts in this folder are loaded after ULib.
|
||||
Scripts in this directory are shared ( loaded both server and client side ).
|
||||
Scripts in the client and server sub-folders are loaded only on the client and server respectively.
|
@ -1,117 +1,117 @@
|
||||
--[[
|
||||
Title: Concommand Helpers
|
||||
|
||||
Server-side compliment of the shared commands.lua
|
||||
]]
|
||||
|
||||
--[[
|
||||
Table: sayCmds
|
||||
|
||||
This table holds our say commands.
|
||||
]]
|
||||
ULib.sayCmds = ULib.sayCmds or {}
|
||||
|
||||
--[[
|
||||
Function: sayCmdCheck
|
||||
|
||||
Say callback which will check to see if there's a say command being used. *DO NOT CALL DIRECTLY*
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player.
|
||||
strText - The text.
|
||||
bTeam - Team say.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Made case-insensitive
|
||||
]]
|
||||
local function sayCmdCheck( ply, strText, bTeam )
|
||||
local match
|
||||
for str, data in pairs( ULib.sayCmds ) do
|
||||
local str2 = str
|
||||
if strText:len() < str:len() then -- Go ahead and allow commands w/o spaces
|
||||
str2 = string.Trim( str )
|
||||
end
|
||||
|
||||
if strText:sub( 1, str2:len() ):lower() == str2 then
|
||||
if not match or match:len() <= str:len() then -- Don't rematch if there's a more specific one already.
|
||||
match = str
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if match then -- We've got a winner!
|
||||
local data = ULib.sayCmds[ match ]
|
||||
|
||||
local args = string.Trim( strText:sub( match:len() + 1 ) ) -- Strip the caller command out
|
||||
local argv = ULib.splitArgs( args )
|
||||
|
||||
-- ULib command callback
|
||||
if data.__cmd then
|
||||
local return_value = hook.Call( ULib.HOOK_COMMAND_CALLED, _, ply, data.__cmd, argv )
|
||||
if return_value == false then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
if not ULib.ucl.query( ply, data.access ) then
|
||||
ULib.tsay( ply, "You do not have access to this command, " .. ply:Nick() .. "." )
|
||||
-- Print their name to intimidate them :)
|
||||
return "" -- Block from appearing
|
||||
end
|
||||
|
||||
local fn = data.fn
|
||||
local hide = data.hide
|
||||
|
||||
ULib.pcallError( fn, ply, match:Trim(), argv, args )
|
||||
if hide then return "" end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
hook.Add( "PlayerSay", "ULib_saycmd", sayCmdCheck, HOOK_HIGH ) -- High-priority
|
||||
|
||||
|
||||
--[[
|
||||
Function: addSayCommand
|
||||
|
||||
Just like ULib's <concommand()> except that the callback is called when the command is said in chat instead of typed in the console.
|
||||
|
||||
Parameters:
|
||||
|
||||
say_cmd - A command string for says. IE: "!kick", then when someone says "!kick", it'll call the callback.
|
||||
fn_call - The function to call when the command's called.
|
||||
access - The access string to associate access with this say command. (IE: "ulx kick"). Remember to call <ULib.ucl.registerAccess()> if the access string isn't being used in a command.
|
||||
hide_say - *(Optional, defaults to false)* If true, will hide the chat message. Use this if you don't want other people to see the command.
|
||||
nospace - *(Optional, defaults to false)* If true, a space won't be required after the command "IE: !slapbob" vs "!slap bob".
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added nospace parameter, made case insensitive
|
||||
v2.40 - Removed the command help parameter, now accepts nil as access (for always allowed)
|
||||
]]
|
||||
function ULib.addSayCommand( say_cmd, fn_call, access, hide_say, nospace )
|
||||
say_cmd = string.Trim( say_cmd:lower() )
|
||||
|
||||
if not nospace then
|
||||
say_cmd = say_cmd .. " "
|
||||
end
|
||||
|
||||
ULib.sayCmds[ say_cmd ] = { fn=fn_call, hide=hide_say, access=access }
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: removeSayCommand
|
||||
|
||||
Removes a say command.
|
||||
|
||||
Parameters:
|
||||
|
||||
say_cmd - The command string for says to remove.
|
||||
]]
|
||||
function ULib.removeSayCommand( say_cmd )
|
||||
ULib.sayCmds[ say_cmd ] = nil -- Remove both forms
|
||||
ULib.sayCmds[ say_cmd .. " " ] = nil
|
||||
end
|
||||
--[[
|
||||
Title: Concommand Helpers
|
||||
|
||||
Server-side compliment of the shared commands.lua
|
||||
]]
|
||||
|
||||
--[[
|
||||
Table: sayCmds
|
||||
|
||||
This table holds our say commands.
|
||||
]]
|
||||
ULib.sayCmds = ULib.sayCmds or {}
|
||||
|
||||
--[[
|
||||
Function: sayCmdCheck
|
||||
|
||||
Say callback which will check to see if there's a say command being used. *DO NOT CALL DIRECTLY*
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player.
|
||||
strText - The text.
|
||||
bTeam - Team say.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Made case-insensitive
|
||||
]]
|
||||
local function sayCmdCheck( ply, strText, bTeam )
|
||||
local match
|
||||
for str, data in pairs( ULib.sayCmds ) do
|
||||
local str2 = str
|
||||
if strText:len() < str:len() then -- Go ahead and allow commands w/o spaces
|
||||
str2 = string.Trim( str )
|
||||
end
|
||||
|
||||
if strText:sub( 1, str2:len() ):lower() == str2 then
|
||||
if not match or match:len() <= str:len() then -- Don't rematch if there's a more specific one already.
|
||||
match = str
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if match then -- We've got a winner!
|
||||
local data = ULib.sayCmds[ match ]
|
||||
|
||||
local args = string.Trim( strText:sub( match:len() + 1 ) ) -- Strip the caller command out
|
||||
local argv = ULib.splitArgs( args )
|
||||
|
||||
-- ULib command callback
|
||||
if data.__cmd then
|
||||
local return_value = hook.Call( ULib.HOOK_COMMAND_CALLED, _, ply, data.__cmd, argv )
|
||||
if return_value == false then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
if not ULib.ucl.query( ply, data.access ) then
|
||||
ULib.tsay( ply, "You do not have access to this command, " .. ply:Nick() .. "." )
|
||||
-- Print their name to intimidate them :)
|
||||
return "" -- Block from appearing
|
||||
end
|
||||
|
||||
local fn = data.fn
|
||||
local hide = data.hide
|
||||
|
||||
ULib.pcallError( fn, ply, match:Trim(), argv, args )
|
||||
if hide then return "" end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
hook.Add( "PlayerSay", "ULib_saycmd", sayCmdCheck, HOOK_HIGH ) -- High-priority
|
||||
|
||||
|
||||
--[[
|
||||
Function: addSayCommand
|
||||
|
||||
Just like ULib's <concommand()> except that the callback is called when the command is said in chat instead of typed in the console.
|
||||
|
||||
Parameters:
|
||||
|
||||
say_cmd - A command string for says. IE: "!kick", then when someone says "!kick", it'll call the callback.
|
||||
fn_call - The function to call when the command's called.
|
||||
access - The access string to associate access with this say command. (IE: "ulx kick"). Remember to call <ULib.ucl.registerAccess()> if the access string isn't being used in a command.
|
||||
hide_say - *(Optional, defaults to false)* If true, will hide the chat message. Use this if you don't want other people to see the command.
|
||||
nospace - *(Optional, defaults to false)* If true, a space won't be required after the command "IE: !slapbob" vs "!slap bob".
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added nospace parameter, made case insensitive
|
||||
v2.40 - Removed the command help parameter, now accepts nil as access (for always allowed)
|
||||
]]
|
||||
function ULib.addSayCommand( say_cmd, fn_call, access, hide_say, nospace )
|
||||
say_cmd = string.Trim( say_cmd:lower() )
|
||||
|
||||
if not nospace then
|
||||
say_cmd = say_cmd .. " "
|
||||
end
|
||||
|
||||
ULib.sayCmds[ say_cmd ] = { fn=fn_call, hide=hide_say, access=access }
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: removeSayCommand
|
||||
|
||||
Removes a say command.
|
||||
|
||||
Parameters:
|
||||
|
||||
say_cmd - The command string for says to remove.
|
||||
]]
|
||||
function ULib.removeSayCommand( say_cmd )
|
||||
ULib.sayCmds[ say_cmd ] = nil -- Remove both forms
|
||||
ULib.sayCmds[ say_cmd .. " " ] = nil
|
||||
end
|
||||
|
@ -1,192 +1,192 @@
|
||||
local meta = FindMetaTable( "Entity" )
|
||||
|
||||
-- Return if there's nothing to add on to
|
||||
if not meta then return end
|
||||
|
||||
|
||||
-- Are you a STOOL author who's angry that your tool isn't on this list?
|
||||
-- Just add this to your code:
|
||||
-- if ULib then table.insert( ULib.delWhiteList, "my_stool" ) end
|
||||
ULib.delWhitelist = -- White list for objects that can't be deleted
|
||||
{
|
||||
"colour",
|
||||
"material",
|
||||
"paint",
|
||||
"hoverball",
|
||||
"emitter",
|
||||
"elastic",
|
||||
"hydraulic",
|
||||
"muscle",
|
||||
"nail",
|
||||
"ballsocket",
|
||||
"ballsocket_adv",
|
||||
"pulley",
|
||||
"rope",
|
||||
"slider",
|
||||
"weld",
|
||||
"winch",
|
||||
"balloon",
|
||||
"button",
|
||||
"duplicator",
|
||||
"dynamite",
|
||||
"keepupright",
|
||||
"lamp",
|
||||
"nocollide",
|
||||
"thruster",
|
||||
"turret",
|
||||
"wheel",
|
||||
"eyeposer",
|
||||
"faceposer",
|
||||
"statue",
|
||||
"weld_ez",
|
||||
"axis",
|
||||
|
||||
-- Properties
|
||||
"gravity",
|
||||
"collision",
|
||||
--"keepupright", -- Already above
|
||||
"persist",
|
||||
}
|
||||
|
||||
-- Are you a STOOL author who's angry that your tool isn't on this list?
|
||||
-- Just add this to your code:
|
||||
-- if ULib then table.insert( ULib.moveWhiteList, "my_stool" ) end
|
||||
ULib.moveWhitelist = -- White list for objects that can't be moved
|
||||
{
|
||||
"colour",
|
||||
"material",
|
||||
"paint",
|
||||
"duplicator",
|
||||
"eyeposer",
|
||||
"faceposer",
|
||||
"remover",
|
||||
|
||||
-- Properties
|
||||
--"remover", -- Already above
|
||||
"persist",
|
||||
}
|
||||
|
||||
function meta:DisallowMoving( bool )
|
||||
self.NoMoving = bool
|
||||
end
|
||||
|
||||
function meta:DisallowDeleting( bool, callback, no_replication )
|
||||
self.NoDeleting = bool
|
||||
self.NoDeletingCallback = callback
|
||||
self.NoReplication = no_replication
|
||||
end
|
||||
|
||||
local function tool( ply, tr, toolmode, second )
|
||||
-- In the case of the nail gun, let's check the entity they're nailing TO first.
|
||||
if toolmode == "nail" and not second then
|
||||
local tr2 = {}
|
||||
tr2.start = tr.HitPos
|
||||
tr2.endpos = tr.HitPos + ply:GetAimVector() * 16
|
||||
tr2.filter = { ply, tr.Entity }
|
||||
local trace = util.TraceLine( tr2 )
|
||||
|
||||
if trace.Entity and trace.Entity:IsValid() and not trace.Entity:IsPlayer() then
|
||||
local ret = tool( ply, trace, toolmode, true )
|
||||
if ret ~= nil then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- In the case of the remover, we have to make sure they're not trying to right click remove one of no delete ents
|
||||
if toolmode == "remover" and ply:KeyDown( IN_ATTACK2 ) and not ply:KeyDownLast( IN_ATTACK2 ) then
|
||||
local ConstrainedEntities = constraint.GetAllConstrainedEntities( tr.Entity )
|
||||
if ConstrainedEntities then -- If we have anything to worry about
|
||||
-- Loop through all the entities in the system
|
||||
for _, ent in pairs( ConstrainedEntities ) do
|
||||
if ent.NoDeleting then
|
||||
ULib.tsay( ply, "You cannot use a right click delete on this ent because it is constrained to a non-deleteable entity." )
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if tr.Entity.NoMoving then
|
||||
if not table.HasValue( ULib.moveWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if tr.Entity.NoDeleting then
|
||||
if not table.HasValue( ULib.delWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
hook.Add( "CanTool", "ULibEntToolCheck", tool, HOOK_HIGH )
|
||||
|
||||
local function property( ply, propertymode, ent )
|
||||
if ent.NoMoving then
|
||||
if not table.HasValue( ULib.moveWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if ent.NoDeleting then
|
||||
if not table.HasValue( ULib.delWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
hook.Add( "CanProperty", "ULibEntPropertyCheck", property, HOOK_HIGH )
|
||||
|
||||
local function physgun( ply, ent )
|
||||
if ent.NoMoving then return false end
|
||||
end
|
||||
hook.Add( "PhysgunPickup", "ULibEntPhysCheck", physgun, HOOK_HIGH )
|
||||
hook.Add( "CanPlayerUnfreeze", "ULibEntUnfreezeCheck", physgun, HOOK_HIGH )
|
||||
|
||||
local function physgunReload( weapon, ply )
|
||||
local trace = util.GetPlayerTrace( ply )
|
||||
local tr = util.TraceLine( trace )
|
||||
|
||||
local ent = tr.Entity
|
||||
if not ent or not ent:IsValid() or ent:IsWorld() then return end -- Invalid or not interested
|
||||
if ent.NoMoving then return false end
|
||||
end
|
||||
hook.Add( "OnPhysgunReload", "ULibEntPhysReloadCheck", physgunReload, HOOK_HIGH )
|
||||
|
||||
local function damageCheck( ent )
|
||||
if ent.NoDeleting then
|
||||
-- return false
|
||||
end
|
||||
end
|
||||
hook.Add( "EntityTakeDamage", "ULibEntDamagedCheck", damageCheck, HOOK_MONITOR_HIGH )
|
||||
|
||||
-- This is just in case we have some horribly programmed addon that goes rampant in deleting things
|
||||
local function removedCheck( ent )
|
||||
if ent.NoDeleting and not ent.NoReplication then
|
||||
local class = ent:GetClass()
|
||||
local pos = ent:GetPos()
|
||||
local ang = ent:GetAngles()
|
||||
local model = ent:GetModel()
|
||||
local frozen = false
|
||||
if ent:GetPhysicsObject():IsValid() and not ent:GetPhysicsObject():IsMoveable() then
|
||||
frozen = true
|
||||
end
|
||||
local t = ent:GetTable()
|
||||
|
||||
ULib.queueFunctionCall( function() -- Create it next frame because 1. Old ent won't be in way and 2. We won't overflow the server while shutting down
|
||||
local ent2 = ents.Create( class )
|
||||
table.Merge( ent2:GetTable(), t )
|
||||
ent2:SetModel( model )
|
||||
ent2:SetPos( pos )
|
||||
ent2:SetAngles( ang )
|
||||
ent2:Spawn()
|
||||
if frozen then
|
||||
ent2:GetPhysicsObject():EnableMotion( false )
|
||||
end
|
||||
|
||||
if ent2.NoDeletingCallback then
|
||||
ent2.NoDeletingCallback( ent, ent2 )
|
||||
end
|
||||
end )
|
||||
end
|
||||
end
|
||||
hook.Add( "EntityRemoved", "ULibEntRemovedCheck", removedCheck, HOOK_MONITOR_HIGH )
|
||||
local meta = FindMetaTable( "Entity" )
|
||||
|
||||
-- Return if there's nothing to add on to
|
||||
if not meta then return end
|
||||
|
||||
|
||||
-- Are you a STOOL author who's angry that your tool isn't on this list?
|
||||
-- Just add this to your code:
|
||||
-- if ULib then table.insert( ULib.delWhiteList, "my_stool" ) end
|
||||
ULib.delWhitelist = -- White list for objects that can't be deleted
|
||||
{
|
||||
"colour",
|
||||
"material",
|
||||
"paint",
|
||||
"hoverball",
|
||||
"emitter",
|
||||
"elastic",
|
||||
"hydraulic",
|
||||
"muscle",
|
||||
"nail",
|
||||
"ballsocket",
|
||||
"ballsocket_adv",
|
||||
"pulley",
|
||||
"rope",
|
||||
"slider",
|
||||
"weld",
|
||||
"winch",
|
||||
"balloon",
|
||||
"button",
|
||||
"duplicator",
|
||||
"dynamite",
|
||||
"keepupright",
|
||||
"lamp",
|
||||
"nocollide",
|
||||
"thruster",
|
||||
"turret",
|
||||
"wheel",
|
||||
"eyeposer",
|
||||
"faceposer",
|
||||
"statue",
|
||||
"weld_ez",
|
||||
"axis",
|
||||
|
||||
-- Properties
|
||||
"gravity",
|
||||
"collision",
|
||||
--"keepupright", -- Already above
|
||||
"persist",
|
||||
}
|
||||
|
||||
-- Are you a STOOL author who's angry that your tool isn't on this list?
|
||||
-- Just add this to your code:
|
||||
-- if ULib then table.insert( ULib.moveWhiteList, "my_stool" ) end
|
||||
ULib.moveWhitelist = -- White list for objects that can't be moved
|
||||
{
|
||||
"colour",
|
||||
"material",
|
||||
"paint",
|
||||
"duplicator",
|
||||
"eyeposer",
|
||||
"faceposer",
|
||||
"remover",
|
||||
|
||||
-- Properties
|
||||
--"remover", -- Already above
|
||||
"persist",
|
||||
}
|
||||
|
||||
function meta:DisallowMoving( bool )
|
||||
self.NoMoving = bool
|
||||
end
|
||||
|
||||
function meta:DisallowDeleting( bool, callback, no_replication )
|
||||
self.NoDeleting = bool
|
||||
self.NoDeletingCallback = callback
|
||||
self.NoReplication = no_replication
|
||||
end
|
||||
|
||||
local function tool( ply, tr, toolmode, second )
|
||||
-- In the case of the nail gun, let's check the entity they're nailing TO first.
|
||||
if toolmode == "nail" and not second then
|
||||
local tr2 = {}
|
||||
tr2.start = tr.HitPos
|
||||
tr2.endpos = tr.HitPos + ply:GetAimVector() * 16
|
||||
tr2.filter = { ply, tr.Entity }
|
||||
local trace = util.TraceLine( tr2 )
|
||||
|
||||
if trace.Entity and trace.Entity:IsValid() and not trace.Entity:IsPlayer() then
|
||||
local ret = tool( ply, trace, toolmode, true )
|
||||
if ret ~= nil then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- In the case of the remover, we have to make sure they're not trying to right click remove one of no delete ents
|
||||
if toolmode == "remover" and ply:KeyDown( IN_ATTACK2 ) and not ply:KeyDownLast( IN_ATTACK2 ) then
|
||||
local ConstrainedEntities = constraint.GetAllConstrainedEntities( tr.Entity )
|
||||
if ConstrainedEntities then -- If we have anything to worry about
|
||||
-- Loop through all the entities in the system
|
||||
for _, ent in pairs( ConstrainedEntities ) do
|
||||
if ent.NoDeleting then
|
||||
ULib.tsay( ply, "You cannot use a right click delete on this ent because it is constrained to a non-deleteable entity." )
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if tr.Entity.NoMoving then
|
||||
if not table.HasValue( ULib.moveWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if tr.Entity.NoDeleting then
|
||||
if not table.HasValue( ULib.delWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
hook.Add( "CanTool", "ULibEntToolCheck", tool, HOOK_HIGH )
|
||||
|
||||
local function property( ply, propertymode, ent )
|
||||
if ent.NoMoving then
|
||||
if not table.HasValue( ULib.moveWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if ent.NoDeleting then
|
||||
if not table.HasValue( ULib.delWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
hook.Add( "CanProperty", "ULibEntPropertyCheck", property, HOOK_HIGH )
|
||||
|
||||
local function physgun( ply, ent )
|
||||
if ent.NoMoving then return false end
|
||||
end
|
||||
hook.Add( "PhysgunPickup", "ULibEntPhysCheck", physgun, HOOK_HIGH )
|
||||
hook.Add( "CanPlayerUnfreeze", "ULibEntUnfreezeCheck", physgun, HOOK_HIGH )
|
||||
|
||||
local function physgunReload( weapon, ply )
|
||||
local trace = util.GetPlayerTrace( ply )
|
||||
local tr = util.TraceLine( trace )
|
||||
|
||||
local ent = tr.Entity
|
||||
if not ent or not ent:IsValid() or ent:IsWorld() then return end -- Invalid or not interested
|
||||
if ent.NoMoving then return false end
|
||||
end
|
||||
hook.Add( "OnPhysgunReload", "ULibEntPhysReloadCheck", physgunReload, HOOK_HIGH )
|
||||
|
||||
local function damageCheck( ent )
|
||||
if ent.NoDeleting then
|
||||
-- return false
|
||||
end
|
||||
end
|
||||
hook.Add( "EntityTakeDamage", "ULibEntDamagedCheck", damageCheck, HOOK_MONITOR_HIGH )
|
||||
|
||||
-- This is just in case we have some horribly programmed addon that goes rampant in deleting things
|
||||
local function removedCheck( ent )
|
||||
if ent.NoDeleting and not ent.NoReplication then
|
||||
local class = ent:GetClass()
|
||||
local pos = ent:GetPos()
|
||||
local ang = ent:GetAngles()
|
||||
local model = ent:GetModel()
|
||||
local frozen = false
|
||||
if ent:GetPhysicsObject():IsValid() and not ent:GetPhysicsObject():IsMoveable() then
|
||||
frozen = true
|
||||
end
|
||||
local t = ent:GetTable()
|
||||
|
||||
ULib.queueFunctionCall( function() -- Create it next frame because 1. Old ent won't be in way and 2. We won't overflow the server while shutting down
|
||||
local ent2 = ents.Create( class )
|
||||
table.Merge( ent2:GetTable(), t )
|
||||
ent2:SetModel( model )
|
||||
ent2:SetPos( pos )
|
||||
ent2:SetAngles( ang )
|
||||
ent2:Spawn()
|
||||
if frozen then
|
||||
ent2:GetPhysicsObject():EnableMotion( false )
|
||||
end
|
||||
|
||||
if ent2.NoDeletingCallback then
|
||||
ent2.NoDeletingCallback( ent, ent2 )
|
||||
end
|
||||
end )
|
||||
end
|
||||
end
|
||||
hook.Add( "EntityRemoved", "ULibEntRemovedCheck", removedCheck, HOOK_MONITOR_HIGH )
|
||||
|
@ -1,115 +1,115 @@
|
||||
--[[
|
||||
Title: Physics Helpers
|
||||
|
||||
Various functions to make dealing with the HL2 physics engine a little easier.
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyAccel
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the acceleration to
|
||||
magnitude - The amount of acceleration ( Use nil if the magnitude is specified in the direction )
|
||||
direction - The direction to apply the acceleration in ( if the magnitude is part of the direction, specify nil for the magnitude )
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the acceleration )
|
||||
]]
|
||||
function ULib.applyAccel( ent, magnitude, direction, dTime )
|
||||
if dTime == nil then dTime = 1 end
|
||||
|
||||
if magnitude ~= nil then
|
||||
direction:Normalize()
|
||||
else
|
||||
magnitude = 1
|
||||
end
|
||||
|
||||
-- Times it by the time elapsed since the last update.
|
||||
local accel = magnitude * dTime
|
||||
-- Convert our scalar accel to a vector accel
|
||||
accel = direction * accel
|
||||
|
||||
if ent:GetMoveType() == MOVETYPE_VPHYSICS then
|
||||
-- a = f/m , so times by mass to get the force.
|
||||
local force = accel * ent:GetPhysicsObject():GetMass()
|
||||
ent:GetPhysicsObject():ApplyForceCenter( force )
|
||||
else
|
||||
ent:SetVelocity( accel ) -- As it turns out, SetVelocity() is actually SetAccel() in GM10
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyForce
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the force to
|
||||
magnitude - The amount of force ( Use nil if the magnitude is specified in the direction )
|
||||
direction - The direction to apply the force in ( if the magnitude is part of the direction, specify nil for the magnitude )
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the force )
|
||||
]]
|
||||
function ULib.applyForce( ent, magnitude, direction, dTime )
|
||||
if dTime == nil then dTime = 1 end
|
||||
|
||||
if magnitude ~= nil then
|
||||
direction:Normalize()
|
||||
else
|
||||
magnitude = 1
|
||||
end
|
||||
|
||||
-- Times it by the time elapsed since the last update.
|
||||
local force = magnitude * dTime
|
||||
-- Convert our scalar force to a vector force
|
||||
force = direction * force
|
||||
|
||||
if ent:GetMoveType() == MOVETYPE_VPHYSICS then
|
||||
ent:GetPhysicsObject():ApplyForceCenter( force )
|
||||
else
|
||||
-- Because we're not dealing with objects that have vphysics, they might not have a mass. This would cause errors, let's catch them here.
|
||||
local mass = ent:GetPhysicsObject():GetMass()
|
||||
if not mass then
|
||||
mass = 1
|
||||
Msg( "applyForce was called with a non-physics entity that doesn't have a mass. To continue calculations, we're assuming it has a mass of one. This could very well produce unrealistic looking physics!\n")
|
||||
end
|
||||
-- f = m*a, so divide it by mass to get the accel
|
||||
local accel = force * 1/mass
|
||||
ent:SetVelocity( accel ) -- As it turns out, SetVelocity() is actually SetAccel() in GM10
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyAccelInCurDirection
|
||||
|
||||
Applies an acceleration in the entities current *velocity* direction ( not the entity's heading ). See <applyAccel>.
|
||||
Basically makes the entity go faster or slower ( if a negative magnitude is passed ).
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the force to
|
||||
magnitude - The amount of acceleration
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the acceleration )
|
||||
]]
|
||||
function ULib.applyAccelInCurDirection( ent, magnitude, dTime )
|
||||
local direction = ent:GetVelocity( entid ):GetNormalized()
|
||||
ULib.applyAccel( entid, magnitude, direction, dTime )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyForceInCurDirection
|
||||
|
||||
Applies a force in the entities current *velocity* direction ( not the entity's heading ). See <applyForce>.
|
||||
Basically makes the entity go faster or slower ( if a negative magnitude is passed ).
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the force to
|
||||
magnitude - The amount of force
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the force )
|
||||
]]
|
||||
function ULib.applyForceInCurDirection( ent, magnitude, dTime )
|
||||
local direction = ent:GetVelocity( entid ):GetNormalized()
|
||||
ULib.applyForce( entid, magnitude, direction, dTime )
|
||||
--[[
|
||||
Title: Physics Helpers
|
||||
|
||||
Various functions to make dealing with the HL2 physics engine a little easier.
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyAccel
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the acceleration to
|
||||
magnitude - The amount of acceleration ( Use nil if the magnitude is specified in the direction )
|
||||
direction - The direction to apply the acceleration in ( if the magnitude is part of the direction, specify nil for the magnitude )
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the acceleration )
|
||||
]]
|
||||
function ULib.applyAccel( ent, magnitude, direction, dTime )
|
||||
if dTime == nil then dTime = 1 end
|
||||
|
||||
if magnitude ~= nil then
|
||||
direction:Normalize()
|
||||
else
|
||||
magnitude = 1
|
||||
end
|
||||
|
||||
-- Times it by the time elapsed since the last update.
|
||||
local accel = magnitude * dTime
|
||||
-- Convert our scalar accel to a vector accel
|
||||
accel = direction * accel
|
||||
|
||||
if ent:GetMoveType() == MOVETYPE_VPHYSICS then
|
||||
-- a = f/m , so times by mass to get the force.
|
||||
local force = accel * ent:GetPhysicsObject():GetMass()
|
||||
ent:GetPhysicsObject():ApplyForceCenter( force )
|
||||
else
|
||||
ent:SetVelocity( accel ) -- As it turns out, SetVelocity() is actually SetAccel() in GM10
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyForce
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the force to
|
||||
magnitude - The amount of force ( Use nil if the magnitude is specified in the direction )
|
||||
direction - The direction to apply the force in ( if the magnitude is part of the direction, specify nil for the magnitude )
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the force )
|
||||
]]
|
||||
function ULib.applyForce( ent, magnitude, direction, dTime )
|
||||
if dTime == nil then dTime = 1 end
|
||||
|
||||
if magnitude ~= nil then
|
||||
direction:Normalize()
|
||||
else
|
||||
magnitude = 1
|
||||
end
|
||||
|
||||
-- Times it by the time elapsed since the last update.
|
||||
local force = magnitude * dTime
|
||||
-- Convert our scalar force to a vector force
|
||||
force = direction * force
|
||||
|
||||
if ent:GetMoveType() == MOVETYPE_VPHYSICS then
|
||||
ent:GetPhysicsObject():ApplyForceCenter( force )
|
||||
else
|
||||
-- Because we're not dealing with objects that have vphysics, they might not have a mass. This would cause errors, let's catch them here.
|
||||
local mass = ent:GetPhysicsObject():GetMass()
|
||||
if not mass then
|
||||
mass = 1
|
||||
Msg( "applyForce was called with a non-physics entity that doesn't have a mass. To continue calculations, we're assuming it has a mass of one. This could very well produce unrealistic looking physics!\n")
|
||||
end
|
||||
-- f = m*a, so divide it by mass to get the accel
|
||||
local accel = force * 1/mass
|
||||
ent:SetVelocity( accel ) -- As it turns out, SetVelocity() is actually SetAccel() in GM10
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyAccelInCurDirection
|
||||
|
||||
Applies an acceleration in the entities current *velocity* direction ( not the entity's heading ). See <applyAccel>.
|
||||
Basically makes the entity go faster or slower ( if a negative magnitude is passed ).
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the force to
|
||||
magnitude - The amount of acceleration
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the acceleration )
|
||||
]]
|
||||
function ULib.applyAccelInCurDirection( ent, magnitude, dTime )
|
||||
local direction = ent:GetVelocity( entid ):GetNormalized()
|
||||
ULib.applyAccel( entid, magnitude, direction, dTime )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: applyForceInCurDirection
|
||||
|
||||
Applies a force in the entities current *velocity* direction ( not the entity's heading ). See <applyForce>.
|
||||
Basically makes the entity go faster or slower ( if a negative magnitude is passed ).
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The entity to apply the force to
|
||||
magnitude - The amount of force
|
||||
dTime - *(Optional, defaults to 1)* The time passed since the last update in seconds ( IE: 0.5 for dTime would only apply half the force )
|
||||
]]
|
||||
function ULib.applyForceInCurDirection( ent, magnitude, dTime )
|
||||
local direction = ent:GetVelocity( entid ):GetNormalized()
|
||||
ULib.applyForce( entid, magnitude, direction, dTime )
|
||||
end
|
@ -1,491 +1,491 @@
|
||||
--[[
|
||||
Title: Player
|
||||
|
||||
Holds some helpful player functions.
|
||||
]]
|
||||
|
||||
--[[
|
||||
Table: slapSounds
|
||||
|
||||
These are the sounds used for slaps.
|
||||
]]
|
||||
local slapSounds = {
|
||||
"physics/body/body_medium_impact_hard1.wav",
|
||||
"physics/body/body_medium_impact_hard2.wav",
|
||||
"physics/body/body_medium_impact_hard3.wav",
|
||||
"physics/body/body_medium_impact_hard5.wav",
|
||||
"physics/body/body_medium_impact_hard6.wav",
|
||||
"physics/body/body_medium_impact_soft5.wav",
|
||||
"physics/body/body_medium_impact_soft6.wav",
|
||||
"physics/body/body_medium_impact_soft7.wav",
|
||||
}
|
||||
|
||||
|
||||
--[[
|
||||
Function: slap
|
||||
|
||||
Slaps an entity, can be a user or any entity.
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The target ent.
|
||||
damage - *(Optional, defaults to 0)* The amount of damage to inflict on the entity.
|
||||
power - *(Optional, defaults to 30)* The power of the slap.
|
||||
nosound - *(Optional, defaults to false)* If true, no sound will be played.
|
||||
]]
|
||||
function ULib.slap( ent, damage, power, nosound )
|
||||
if ent:GetMoveType() == MOVETYPE_OBSERVER then return end -- Nothing we can do.
|
||||
|
||||
damage = damage or 0
|
||||
power = power or 500
|
||||
|
||||
if ent:IsPlayer() then
|
||||
if not ent:Alive() then
|
||||
return -- Nothing we can do.
|
||||
end
|
||||
|
||||
if ent:InVehicle() then
|
||||
ent:ExitVehicle()
|
||||
end
|
||||
|
||||
if ent:GetMoveType() == MOVETYPE_NOCLIP then
|
||||
ent:SetMoveType( MOVETYPE_WALK )
|
||||
end
|
||||
end
|
||||
|
||||
if not nosound then -- Play a slap sound
|
||||
local sound_num = math.random( #slapSounds ) -- Choose at random
|
||||
ent:EmitSound( slapSounds[ sound_num ] )
|
||||
end
|
||||
|
||||
local direction = Vector( math.random( 20 )-10, math.random( 20 )-10, math.random( 20 )-5 ) -- Make it random, slightly biased to go up.
|
||||
ULib.applyAccel( ent, power, direction )
|
||||
|
||||
local angle_punch_pitch = math.Rand( -20, 20 )
|
||||
local angle_punch_yaw = math.sqrt( 20*20 - angle_punch_pitch * angle_punch_pitch )
|
||||
if math.random( 0, 1 ) == 1 then
|
||||
angle_punch_yaw = angle_punch_yaw * -1
|
||||
end
|
||||
ent:ViewPunch( Angle( angle_punch_pitch, angle_punch_yaw, 0 ) )
|
||||
|
||||
local newHp = ent:Health() - damage
|
||||
if newHp <= 0 then
|
||||
if ent:IsPlayer() then
|
||||
ent:Kill()
|
||||
else
|
||||
ent:Fire( "break", 1, 0 )
|
||||
end
|
||||
return
|
||||
end
|
||||
ent:SetHealth( newHp )
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: kick
|
||||
|
||||
Kicks a user.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to kick.
|
||||
reason - *(Optional)* The reason to give for kicking.
|
||||
]]
|
||||
function ULib.kick( ply, reason, calling_ply )
|
||||
if reason and calling_ply ~= nil then
|
||||
local nick = calling_ply:IsValid() and string.format( "%s(%s)", calling_ply:Nick(), calling_ply:SteamID() ) or "Console"
|
||||
ply:Kick( string.format( "Kicked by %s (%s)", nick, reason or "[ULX] Kicked from server" ) )
|
||||
else
|
||||
ply:Kick( reason or "[ULX] Kicked from server" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: ban
|
||||
|
||||
Bans a user.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to ban.
|
||||
time - *(Optional)* The time in minutes to ban the person for, leave nil or 0 for permaban.
|
||||
reason - *(Optional)* The reason for banning
|
||||
admin - *(Optional)* Admin player enacting ban
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added support for custom ban list
|
||||
]]
|
||||
function ULib.ban( ply, time, reason, admin )
|
||||
if not time or type( time ) ~= "number" then
|
||||
time = 0
|
||||
end
|
||||
|
||||
ULib.addBan( ply:SteamID(), time, reason, ply:Name(), admin )
|
||||
|
||||
-- Load our currently banned users so we don't overwrite them
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: kickban
|
||||
|
||||
Kicks and bans a user.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to ban.
|
||||
time - *(Optional)* The time in minutes to ban the person for, leave nil or 0 for permaban.
|
||||
reason - *(Optional)* The reason for banning
|
||||
admin - *(Optional)* Admin player enacting ban
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added support for custom ban list
|
||||
]]
|
||||
function ULib.kickban( ply, time, reason, admin )
|
||||
if not time or type( time ) ~= "number" then
|
||||
time = 0
|
||||
end
|
||||
|
||||
ULib.addBan( ply:SteamID(), time, reason, ply:Name(), admin )
|
||||
|
||||
-- Load our currently banned users so we don't overwrite them
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: addBan
|
||||
|
||||
Helper function to store additional data about bans.
|
||||
|
||||
Parameters:
|
||||
|
||||
steamid - Banned player's steamid
|
||||
time - Length of ban
|
||||
reason - *(Optional)* Reason for banning
|
||||
name - *(Optional)* Name of player banned
|
||||
admin - *(Optional)* Admin player enacting the ban
|
||||
|
||||
Revisions:
|
||||
|
||||
2.10 - Initial
|
||||
2.40 - If the steamid is connected, kicks them with the reason given
|
||||
]]
|
||||
function ULib.addBan( steamid, time, reason, name, admin )
|
||||
local strTime = time ~= 0 and string.format( "for %s minute(s)", time ) or "permanently"
|
||||
local showReason = string.format( "Banned %s: %s", strTime, reason )
|
||||
|
||||
local players = player.GetAll()
|
||||
for i=1, #players do
|
||||
if players[ i ]:SteamID() == steamid then
|
||||
ULib.kick( players[ i ], showReason, admin )
|
||||
end
|
||||
end
|
||||
|
||||
-- Remove all semicolons from the reason to prevent command injection
|
||||
showReason = string.gsub(showReason, ";", "")
|
||||
|
||||
-- This redundant kick code is to ensure they're kicked -- even if they're joining
|
||||
game.ConsoleCommand( string.format( "kickid %s %s\n", steamid, showReason or "" ) )
|
||||
game.ConsoleCommand( string.format( "banid %f %s kick\n", time, steamid ) )
|
||||
game.ConsoleCommand( "writeid\n" )
|
||||
|
||||
local admin_name
|
||||
if admin then
|
||||
admin_name = "(Console)"
|
||||
if admin:IsValid() then
|
||||
admin_name = string.format( "%s(%s)", admin:Name(), admin:SteamID() )
|
||||
end
|
||||
end
|
||||
|
||||
local t = {}
|
||||
if ULib.bans[ steamid ] then
|
||||
t = ULib.bans[ steamid ]
|
||||
t.modified_admin = admin_name
|
||||
t.modified_time = os.time()
|
||||
else
|
||||
t.admin = admin_name
|
||||
end
|
||||
t.time = t.time or os.time()
|
||||
if time > 0 then
|
||||
t.unban = ( ( time * 60 ) + os.time() )
|
||||
else
|
||||
t.unban = 0
|
||||
end
|
||||
if reason then
|
||||
t.reason = reason
|
||||
end
|
||||
if name then
|
||||
t.name = name
|
||||
end
|
||||
ULib.bans[ steamid ] = t
|
||||
ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) )
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: unban
|
||||
|
||||
Unbans the given steamid.
|
||||
|
||||
Parameters:
|
||||
|
||||
steamid - The steamid to unban.
|
||||
admin - *(Optional)* Admin player unbanning steamid
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Initial
|
||||
]]
|
||||
function ULib.unban( steamid, admin )
|
||||
|
||||
--Default banlist
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
end
|
||||
ULib.queueFunctionCall( game.ConsoleCommand, "removeid " .. steamid .. ";writeid\n" ) -- Execute after done loading bans
|
||||
|
||||
--ULib banlist
|
||||
ULib.bans[ steamid ] = nil
|
||||
ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) )
|
||||
end
|
||||
|
||||
local function doInvis()
|
||||
local players = player.GetAll()
|
||||
local remove = true
|
||||
for _, player in ipairs( players ) do
|
||||
local t = player:GetTable()
|
||||
if t.invis then
|
||||
remove = false
|
||||
if player:Alive() and player:GetActiveWeapon():IsValid() then
|
||||
if player:GetActiveWeapon() ~= t.invis.wep then
|
||||
|
||||
if t.invis.wep and IsValid( t.invis.wep ) then -- If changed weapon, set the old weapon to be visible.
|
||||
t.invis.wep:SetRenderMode( RENDERMODE_NORMAL )
|
||||
t.invis.wep:Fire( "alpha", 255, 0 )
|
||||
t.invis.wep:SetMaterial( "" )
|
||||
end
|
||||
|
||||
t.invis.wep = player:GetActiveWeapon()
|
||||
ULib.invisible( player, true, t.invis.vis )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if remove then
|
||||
hook.Remove( "Think", "InvisThink" )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: invisible
|
||||
|
||||
Makes a user invisible
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to affect.
|
||||
bool - Whether they're invisible or not
|
||||
visibility - *(Optional, defaults to 0)* A number from 0 to 255 for their visibility.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Removes shadow when invisible
|
||||
]]
|
||||
function ULib.invisible( ply, bool, visibility )
|
||||
if not ply:IsValid() then return end -- This is called on a timer so we need to verify they're still connected
|
||||
|
||||
if bool then
|
||||
visibility = visibility or 0
|
||||
ply:DrawShadow( false )
|
||||
ply:SetMaterial( "models/effects/vol_light001" )
|
||||
ply:SetRenderMode( RENDERMODE_TRANSALPHA )
|
||||
ply:Fire( "alpha", visibility, 0 )
|
||||
ply:GetTable().invis = { vis=visibility, wep=ply:GetActiveWeapon() }
|
||||
|
||||
if IsValid( ply:GetActiveWeapon() ) then
|
||||
ply:GetActiveWeapon():SetRenderMode( RENDERMODE_TRANSALPHA )
|
||||
ply:GetActiveWeapon():Fire( "alpha", visibility, 0 )
|
||||
ply:GetActiveWeapon():SetMaterial( "models/effects/vol_light001" )
|
||||
if ply:GetActiveWeapon():GetClass() == "gmod_tool" then
|
||||
ply:DrawWorldModel( false ) -- tool gun has problems
|
||||
else
|
||||
ply:DrawWorldModel( true )
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add( "Think", "InvisThink", doInvis )
|
||||
else
|
||||
ply:DrawShadow( true )
|
||||
ply:SetMaterial( "" )
|
||||
ply:SetRenderMode( RENDERMODE_NORMAL )
|
||||
ply:Fire( "alpha", 255, 0 )
|
||||
local activeWeapon = ply:GetActiveWeapon()
|
||||
if IsValid( activeWeapon ) then
|
||||
activeWeapon:SetRenderMode( RENDERMODE_NORMAL )
|
||||
activeWeapon:Fire( "alpha", 255, 0 )
|
||||
activeWeapon:SetMaterial( "" )
|
||||
end
|
||||
ply:GetTable().invis = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: refreshBans
|
||||
|
||||
Refreshes the ULib bans.
|
||||
]]
|
||||
function ULib.refreshBans()
|
||||
local err
|
||||
if not ULib.fileExists( ULib.BANS_FILE ) then
|
||||
ULib.bans = {}
|
||||
else
|
||||
ULib.bans, err = ULib.parseKeyValues( ULib.fileRead( ULib.BANS_FILE ) )
|
||||
end
|
||||
|
||||
if err then
|
||||
Msg( "Bans file was not formatted correctly. Attempting to fix and backing up original\n" )
|
||||
if err then
|
||||
Msg( "Error while reading bans file was: " .. err .. "\n" )
|
||||
end
|
||||
Msg( "Original file was backed up to " .. ULib.backupFile( ULib.BANS_FILE ) .. "\n" )
|
||||
ULib.bans = {}
|
||||
end
|
||||
|
||||
local default_bans = ""
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
ULib.queueFunctionCall( game.ConsoleCommand, "writeid\n" )
|
||||
default_bans = ULib.fileRead( "cfg/banned_user.cfg" )
|
||||
end
|
||||
|
||||
--default_bans = ULib.makePatternSafe( default_bans )
|
||||
default_bans = string.gsub( default_bans, "banid %d+ ", "" )
|
||||
default_bans = string.Explode( "\n", default_bans:gsub( "\r", "" ) )
|
||||
local ban_set = {}
|
||||
for _, v in pairs( default_bans ) do
|
||||
if v ~= "" then
|
||||
ban_set[ v ] = true
|
||||
if not ULib.bans[ v ] then
|
||||
ULib.bans[ v ] = { unban = 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs( ULib.bans ) do
|
||||
if type( v ) == "table" and type( k ) == "string" then
|
||||
local time = ( v.unban - os.time() ) / 60
|
||||
if time > 0 then
|
||||
game.ConsoleCommand( string.format( "banid %f %s\n", time, k ) )
|
||||
elseif math.floor( v.unban ) == 0 then -- We floor it because GM10 has floating point errors that might make it be 0.1e-20 or something dumb.
|
||||
if not ban_set[ k ] then
|
||||
ULib.bans[ k ] = nil
|
||||
end
|
||||
else
|
||||
ULib.bans[ k ] = nil
|
||||
end
|
||||
else
|
||||
Msg( "Warning: Bad ban data is being ignored, key = " .. tostring( k ) .. "\n" )
|
||||
ULib.bans[ k ] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- We're queueing this because it will split the load out for VERY large ban files
|
||||
ULib.queueFunctionCall( function() ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) ) end )
|
||||
end
|
||||
ULib.pcallError( ULib.refreshBans )
|
||||
|
||||
|
||||
--[[
|
||||
Function: getSpawnInfo
|
||||
|
||||
Grabs and returns player information that can be used to respawn player with same health/armor as before the spawn.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to grab information for.
|
||||
|
||||
|
||||
Returns:
|
||||
|
||||
Updates player object to store health and armor. Has no effect unless ULib.Spawn is used later.
|
||||
]]
|
||||
function ULib.getSpawnInfo( player )
|
||||
local result = {}
|
||||
|
||||
local t = {}
|
||||
player.ULibSpawnInfo = t
|
||||
t.health = player:Health()
|
||||
t.armor = player:Armor()
|
||||
if player:GetActiveWeapon():IsValid() then
|
||||
t.curweapon = player:GetActiveWeapon():GetClass()
|
||||
end
|
||||
|
||||
local weapons = player:GetWeapons()
|
||||
local data = {}
|
||||
for _, weapon in ipairs( weapons ) do
|
||||
printname = weapon:GetClass()
|
||||
data[ printname ] = {}
|
||||
data[ printname ].clip1 = weapon:Clip1()
|
||||
data[ printname ].clip2 = weapon:Clip2()
|
||||
data[ printname ].ammo1 = player:GetAmmoCount( weapon:GetPrimaryAmmoType() )
|
||||
data[ printname ].ammo2 = player:GetAmmoCount( weapon:GetSecondaryAmmoType() )
|
||||
end
|
||||
t.data = data
|
||||
end
|
||||
|
||||
-- Helper function for ULib.spawn()
|
||||
local function doWeapons( player, t )
|
||||
if not player:IsValid() then return end -- Drat, missed 'em.
|
||||
|
||||
player:StripAmmo()
|
||||
player:StripWeapons()
|
||||
|
||||
for printname, data in pairs( t.data ) do
|
||||
player:Give( printname )
|
||||
local weapon = player:GetWeapon( printname )
|
||||
weapon:SetClip1( data.clip1 )
|
||||
weapon:SetClip2( data.clip2 )
|
||||
player:SetAmmo( data.ammo1, weapon:GetPrimaryAmmoType() )
|
||||
player:SetAmmo( data.ammo2, weapon:GetSecondaryAmmoType() )
|
||||
end
|
||||
|
||||
if t.curweapon then
|
||||
player:SelectWeapon( t.curweapon )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: spawn
|
||||
|
||||
Enhanced spawn player. Can spawn player and return health/armor to status before the spawn. (Only IF ULib.getSpawnInfo was used previously.)
|
||||
Clears previously set values that were stored from ULib.getSpawnInfo.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to grab information for.
|
||||
bool - If true, spawn will set player information to values stored using ULib.SpawnInfo
|
||||
|
||||
Returns:
|
||||
|
||||
Spawns player. Sets health/armor to stored defaults if ULib.getSpawnInfo was used previously. Clears SpawnInfo table afterwards.
|
||||
]]
|
||||
function ULib.spawn( player, bool )
|
||||
player:Spawn()
|
||||
|
||||
if bool and player.ULibSpawnInfo then
|
||||
local t = player.ULibSpawnInfo
|
||||
player:SetHealth( t.health )
|
||||
player:SetArmor( t.armor )
|
||||
timer.Simple( 0.1, function() doWeapons( player, t ) end )
|
||||
player.ULibSpawnInfo = nil
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Title: Player
|
||||
|
||||
Holds some helpful player functions.
|
||||
]]
|
||||
|
||||
--[[
|
||||
Table: slapSounds
|
||||
|
||||
These are the sounds used for slaps.
|
||||
]]
|
||||
local slapSounds = {
|
||||
"physics/body/body_medium_impact_hard1.wav",
|
||||
"physics/body/body_medium_impact_hard2.wav",
|
||||
"physics/body/body_medium_impact_hard3.wav",
|
||||
"physics/body/body_medium_impact_hard5.wav",
|
||||
"physics/body/body_medium_impact_hard6.wav",
|
||||
"physics/body/body_medium_impact_soft5.wav",
|
||||
"physics/body/body_medium_impact_soft6.wav",
|
||||
"physics/body/body_medium_impact_soft7.wav",
|
||||
}
|
||||
|
||||
|
||||
--[[
|
||||
Function: slap
|
||||
|
||||
Slaps an entity, can be a user or any entity.
|
||||
|
||||
Parameters:
|
||||
|
||||
ent - The target ent.
|
||||
damage - *(Optional, defaults to 0)* The amount of damage to inflict on the entity.
|
||||
power - *(Optional, defaults to 30)* The power of the slap.
|
||||
nosound - *(Optional, defaults to false)* If true, no sound will be played.
|
||||
]]
|
||||
function ULib.slap( ent, damage, power, nosound )
|
||||
if ent:GetMoveType() == MOVETYPE_OBSERVER then return end -- Nothing we can do.
|
||||
|
||||
damage = damage or 0
|
||||
power = power or 500
|
||||
|
||||
if ent:IsPlayer() then
|
||||
if not ent:Alive() then
|
||||
return -- Nothing we can do.
|
||||
end
|
||||
|
||||
if ent:InVehicle() then
|
||||
ent:ExitVehicle()
|
||||
end
|
||||
|
||||
if ent:GetMoveType() == MOVETYPE_NOCLIP then
|
||||
ent:SetMoveType( MOVETYPE_WALK )
|
||||
end
|
||||
end
|
||||
|
||||
if not nosound then -- Play a slap sound
|
||||
local sound_num = math.random( #slapSounds ) -- Choose at random
|
||||
ent:EmitSound( slapSounds[ sound_num ] )
|
||||
end
|
||||
|
||||
local direction = Vector( math.random( 20 )-10, math.random( 20 )-10, math.random( 20 )-5 ) -- Make it random, slightly biased to go up.
|
||||
ULib.applyAccel( ent, power, direction )
|
||||
|
||||
local angle_punch_pitch = math.Rand( -20, 20 )
|
||||
local angle_punch_yaw = math.sqrt( 20*20 - angle_punch_pitch * angle_punch_pitch )
|
||||
if math.random( 0, 1 ) == 1 then
|
||||
angle_punch_yaw = angle_punch_yaw * -1
|
||||
end
|
||||
ent:ViewPunch( Angle( angle_punch_pitch, angle_punch_yaw, 0 ) )
|
||||
|
||||
local newHp = ent:Health() - damage
|
||||
if newHp <= 0 then
|
||||
if ent:IsPlayer() then
|
||||
ent:Kill()
|
||||
else
|
||||
ent:Fire( "break", 1, 0 )
|
||||
end
|
||||
return
|
||||
end
|
||||
ent:SetHealth( newHp )
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: kick
|
||||
|
||||
Kicks a user.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to kick.
|
||||
reason - *(Optional)* The reason to give for kicking.
|
||||
]]
|
||||
function ULib.kick( ply, reason, calling_ply )
|
||||
if reason and calling_ply ~= nil then
|
||||
local nick = calling_ply:IsValid() and string.format( "%s(%s)", calling_ply:Nick(), calling_ply:SteamID() ) or "Console"
|
||||
ply:Kick( string.format( "Kicked by %s (%s)", nick, reason or "[ULX] Kicked from server" ) )
|
||||
else
|
||||
ply:Kick( reason or "[ULX] Kicked from server" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: ban
|
||||
|
||||
Bans a user.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to ban.
|
||||
time - *(Optional)* The time in minutes to ban the person for, leave nil or 0 for permaban.
|
||||
reason - *(Optional)* The reason for banning
|
||||
admin - *(Optional)* Admin player enacting ban
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added support for custom ban list
|
||||
]]
|
||||
function ULib.ban( ply, time, reason, admin )
|
||||
if not time or type( time ) ~= "number" then
|
||||
time = 0
|
||||
end
|
||||
|
||||
ULib.addBan( ply:SteamID(), time, reason, ply:Name(), admin )
|
||||
|
||||
-- Load our currently banned users so we don't overwrite them
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: kickban
|
||||
|
||||
Kicks and bans a user.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to ban.
|
||||
time - *(Optional)* The time in minutes to ban the person for, leave nil or 0 for permaban.
|
||||
reason - *(Optional)* The reason for banning
|
||||
admin - *(Optional)* Admin player enacting ban
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added support for custom ban list
|
||||
]]
|
||||
function ULib.kickban( ply, time, reason, admin )
|
||||
if not time or type( time ) ~= "number" then
|
||||
time = 0
|
||||
end
|
||||
|
||||
ULib.addBan( ply:SteamID(), time, reason, ply:Name(), admin )
|
||||
|
||||
-- Load our currently banned users so we don't overwrite them
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: addBan
|
||||
|
||||
Helper function to store additional data about bans.
|
||||
|
||||
Parameters:
|
||||
|
||||
steamid - Banned player's steamid
|
||||
time - Length of ban
|
||||
reason - *(Optional)* Reason for banning
|
||||
name - *(Optional)* Name of player banned
|
||||
admin - *(Optional)* Admin player enacting the ban
|
||||
|
||||
Revisions:
|
||||
|
||||
2.10 - Initial
|
||||
2.40 - If the steamid is connected, kicks them with the reason given
|
||||
]]
|
||||
function ULib.addBan( steamid, time, reason, name, admin )
|
||||
local strTime = time ~= 0 and string.format( "for %s minute(s)", time ) or "permanently"
|
||||
local showReason = string.format( "Banned %s: %s", strTime, reason )
|
||||
|
||||
local players = player.GetAll()
|
||||
for i=1, #players do
|
||||
if players[ i ]:SteamID() == steamid then
|
||||
ULib.kick( players[ i ], showReason, admin )
|
||||
end
|
||||
end
|
||||
|
||||
-- Remove all semicolons from the reason to prevent command injection
|
||||
showReason = string.gsub(showReason, ";", "")
|
||||
|
||||
-- This redundant kick code is to ensure they're kicked -- even if they're joining
|
||||
game.ConsoleCommand( string.format( "kickid %s %s\n", steamid, showReason or "" ) )
|
||||
game.ConsoleCommand( string.format( "banid %f %s kick\n", time, steamid ) )
|
||||
game.ConsoleCommand( "writeid\n" )
|
||||
|
||||
local admin_name
|
||||
if admin then
|
||||
admin_name = "(Console)"
|
||||
if admin:IsValid() then
|
||||
admin_name = string.format( "%s(%s)", admin:Name(), admin:SteamID() )
|
||||
end
|
||||
end
|
||||
|
||||
local t = {}
|
||||
if ULib.bans[ steamid ] then
|
||||
t = ULib.bans[ steamid ]
|
||||
t.modified_admin = admin_name
|
||||
t.modified_time = os.time()
|
||||
else
|
||||
t.admin = admin_name
|
||||
end
|
||||
t.time = t.time or os.time()
|
||||
if time > 0 then
|
||||
t.unban = ( ( time * 60 ) + os.time() )
|
||||
else
|
||||
t.unban = 0
|
||||
end
|
||||
if reason then
|
||||
t.reason = reason
|
||||
end
|
||||
if name then
|
||||
t.name = name
|
||||
end
|
||||
ULib.bans[ steamid ] = t
|
||||
ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) )
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: unban
|
||||
|
||||
Unbans the given steamid.
|
||||
|
||||
Parameters:
|
||||
|
||||
steamid - The steamid to unban.
|
||||
admin - *(Optional)* Admin player unbanning steamid
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Initial
|
||||
]]
|
||||
function ULib.unban( steamid, admin )
|
||||
|
||||
--Default banlist
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
end
|
||||
ULib.queueFunctionCall( game.ConsoleCommand, "removeid " .. steamid .. ";writeid\n" ) -- Execute after done loading bans
|
||||
|
||||
--ULib banlist
|
||||
ULib.bans[ steamid ] = nil
|
||||
ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) )
|
||||
end
|
||||
|
||||
local function doInvis()
|
||||
local players = player.GetAll()
|
||||
local remove = true
|
||||
for _, player in ipairs( players ) do
|
||||
local t = player:GetTable()
|
||||
if t.invis then
|
||||
remove = false
|
||||
if player:Alive() and player:GetActiveWeapon():IsValid() then
|
||||
if player:GetActiveWeapon() ~= t.invis.wep then
|
||||
|
||||
if t.invis.wep and IsValid( t.invis.wep ) then -- If changed weapon, set the old weapon to be visible.
|
||||
t.invis.wep:SetRenderMode( RENDERMODE_NORMAL )
|
||||
t.invis.wep:Fire( "alpha", 255, 0 )
|
||||
t.invis.wep:SetMaterial( "" )
|
||||
end
|
||||
|
||||
t.invis.wep = player:GetActiveWeapon()
|
||||
ULib.invisible( player, true, t.invis.vis )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if remove then
|
||||
hook.Remove( "Think", "InvisThink" )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: invisible
|
||||
|
||||
Makes a user invisible
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to affect.
|
||||
bool - Whether they're invisible or not
|
||||
visibility - *(Optional, defaults to 0)* A number from 0 to 255 for their visibility.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Removes shadow when invisible
|
||||
]]
|
||||
function ULib.invisible( ply, bool, visibility )
|
||||
if not ply:IsValid() then return end -- This is called on a timer so we need to verify they're still connected
|
||||
|
||||
if bool then
|
||||
visibility = visibility or 0
|
||||
ply:DrawShadow( false )
|
||||
ply:SetMaterial( "models/effects/vol_light001" )
|
||||
ply:SetRenderMode( RENDERMODE_TRANSALPHA )
|
||||
ply:Fire( "alpha", visibility, 0 )
|
||||
ply:GetTable().invis = { vis=visibility, wep=ply:GetActiveWeapon() }
|
||||
|
||||
if IsValid( ply:GetActiveWeapon() ) then
|
||||
ply:GetActiveWeapon():SetRenderMode( RENDERMODE_TRANSALPHA )
|
||||
ply:GetActiveWeapon():Fire( "alpha", visibility, 0 )
|
||||
ply:GetActiveWeapon():SetMaterial( "models/effects/vol_light001" )
|
||||
if ply:GetActiveWeapon():GetClass() == "gmod_tool" then
|
||||
ply:DrawWorldModel( false ) -- tool gun has problems
|
||||
else
|
||||
ply:DrawWorldModel( true )
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add( "Think", "InvisThink", doInvis )
|
||||
else
|
||||
ply:DrawShadow( true )
|
||||
ply:SetMaterial( "" )
|
||||
ply:SetRenderMode( RENDERMODE_NORMAL )
|
||||
ply:Fire( "alpha", 255, 0 )
|
||||
local activeWeapon = ply:GetActiveWeapon()
|
||||
if IsValid( activeWeapon ) then
|
||||
activeWeapon:SetRenderMode( RENDERMODE_NORMAL )
|
||||
activeWeapon:Fire( "alpha", 255, 0 )
|
||||
activeWeapon:SetMaterial( "" )
|
||||
end
|
||||
ply:GetTable().invis = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: refreshBans
|
||||
|
||||
Refreshes the ULib bans.
|
||||
]]
|
||||
function ULib.refreshBans()
|
||||
local err
|
||||
if not ULib.fileExists( ULib.BANS_FILE ) then
|
||||
ULib.bans = {}
|
||||
else
|
||||
ULib.bans, err = ULib.parseKeyValues( ULib.fileRead( ULib.BANS_FILE ) )
|
||||
end
|
||||
|
||||
if err then
|
||||
Msg( "Bans file was not formatted correctly. Attempting to fix and backing up original\n" )
|
||||
if err then
|
||||
Msg( "Error while reading bans file was: " .. err .. "\n" )
|
||||
end
|
||||
Msg( "Original file was backed up to " .. ULib.backupFile( ULib.BANS_FILE ) .. "\n" )
|
||||
ULib.bans = {}
|
||||
end
|
||||
|
||||
local default_bans = ""
|
||||
if ULib.fileExists( "cfg/banned_user.cfg" ) then
|
||||
ULib.execFile( "cfg/banned_user.cfg" )
|
||||
ULib.queueFunctionCall( game.ConsoleCommand, "writeid\n" )
|
||||
default_bans = ULib.fileRead( "cfg/banned_user.cfg" )
|
||||
end
|
||||
|
||||
--default_bans = ULib.makePatternSafe( default_bans )
|
||||
default_bans = string.gsub( default_bans, "banid %d+ ", "" )
|
||||
default_bans = string.Explode( "\n", default_bans:gsub( "\r", "" ) )
|
||||
local ban_set = {}
|
||||
for _, v in pairs( default_bans ) do
|
||||
if v ~= "" then
|
||||
ban_set[ v ] = true
|
||||
if not ULib.bans[ v ] then
|
||||
ULib.bans[ v ] = { unban = 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs( ULib.bans ) do
|
||||
if type( v ) == "table" and type( k ) == "string" then
|
||||
local time = ( v.unban - os.time() ) / 60
|
||||
if time > 0 then
|
||||
game.ConsoleCommand( string.format( "banid %f %s\n", time, k ) )
|
||||
elseif math.floor( v.unban ) == 0 then -- We floor it because GM10 has floating point errors that might make it be 0.1e-20 or something dumb.
|
||||
if not ban_set[ k ] then
|
||||
ULib.bans[ k ] = nil
|
||||
end
|
||||
else
|
||||
ULib.bans[ k ] = nil
|
||||
end
|
||||
else
|
||||
Msg( "Warning: Bad ban data is being ignored, key = " .. tostring( k ) .. "\n" )
|
||||
ULib.bans[ k ] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- We're queueing this because it will split the load out for VERY large ban files
|
||||
ULib.queueFunctionCall( function() ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) ) end )
|
||||
end
|
||||
ULib.pcallError( ULib.refreshBans )
|
||||
|
||||
|
||||
--[[
|
||||
Function: getSpawnInfo
|
||||
|
||||
Grabs and returns player information that can be used to respawn player with same health/armor as before the spawn.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to grab information for.
|
||||
|
||||
|
||||
Returns:
|
||||
|
||||
Updates player object to store health and armor. Has no effect unless ULib.Spawn is used later.
|
||||
]]
|
||||
function ULib.getSpawnInfo( player )
|
||||
local result = {}
|
||||
|
||||
local t = {}
|
||||
player.ULibSpawnInfo = t
|
||||
t.health = player:Health()
|
||||
t.armor = player:Armor()
|
||||
if player:GetActiveWeapon():IsValid() then
|
||||
t.curweapon = player:GetActiveWeapon():GetClass()
|
||||
end
|
||||
|
||||
local weapons = player:GetWeapons()
|
||||
local data = {}
|
||||
for _, weapon in ipairs( weapons ) do
|
||||
printname = weapon:GetClass()
|
||||
data[ printname ] = {}
|
||||
data[ printname ].clip1 = weapon:Clip1()
|
||||
data[ printname ].clip2 = weapon:Clip2()
|
||||
data[ printname ].ammo1 = player:GetAmmoCount( weapon:GetPrimaryAmmoType() )
|
||||
data[ printname ].ammo2 = player:GetAmmoCount( weapon:GetSecondaryAmmoType() )
|
||||
end
|
||||
t.data = data
|
||||
end
|
||||
|
||||
-- Helper function for ULib.spawn()
|
||||
local function doWeapons( player, t )
|
||||
if not player:IsValid() then return end -- Drat, missed 'em.
|
||||
|
||||
player:StripAmmo()
|
||||
player:StripWeapons()
|
||||
|
||||
for printname, data in pairs( t.data ) do
|
||||
player:Give( printname )
|
||||
local weapon = player:GetWeapon( printname )
|
||||
weapon:SetClip1( data.clip1 )
|
||||
weapon:SetClip2( data.clip2 )
|
||||
player:SetAmmo( data.ammo1, weapon:GetPrimaryAmmoType() )
|
||||
player:SetAmmo( data.ammo2, weapon:GetSecondaryAmmoType() )
|
||||
end
|
||||
|
||||
if t.curweapon then
|
||||
player:SelectWeapon( t.curweapon )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: spawn
|
||||
|
||||
Enhanced spawn player. Can spawn player and return health/armor to status before the spawn. (Only IF ULib.getSpawnInfo was used previously.)
|
||||
Clears previously set values that were stored from ULib.getSpawnInfo.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to grab information for.
|
||||
bool - If true, spawn will set player information to values stored using ULib.SpawnInfo
|
||||
|
||||
Returns:
|
||||
|
||||
Spawns player. Sets health/armor to stored defaults if ULib.getSpawnInfo was used previously. Clears SpawnInfo table afterwards.
|
||||
]]
|
||||
function ULib.spawn( player, bool )
|
||||
player:Spawn()
|
||||
|
||||
if bool and player.ULibSpawnInfo then
|
||||
local t = player.ULibSpawnInfo
|
||||
player:SetHealth( t.health )
|
||||
player:SetArmor( t.armor )
|
||||
timer.Simple( 0.1, function() doWeapons( player, t ) end )
|
||||
player.ULibSpawnInfo = nil
|
||||
end
|
||||
end
|
||||
|
@ -1,67 +1,67 @@
|
||||
local meta = FindMetaTable( "Player" )
|
||||
|
||||
ULib.spawnWhitelist = -- Tool white list for tools that don't spawn things
|
||||
{
|
||||
"colour",
|
||||
"material",
|
||||
"paint",
|
||||
"ballsocket",
|
||||
"ballsocket_adv",
|
||||
"weld",
|
||||
"keepupright",
|
||||
"nocollide",
|
||||
"eyeposer",
|
||||
"faceposer",
|
||||
"statue",
|
||||
"weld_ez",
|
||||
"axis",
|
||||
}
|
||||
|
||||
-- Return if there's nothing to add on to
|
||||
if not meta then return end
|
||||
|
||||
function meta:DisallowNoclip( bool )
|
||||
self.NoNoclip = bool
|
||||
end
|
||||
|
||||
function meta:DisallowSpawning( bool )
|
||||
self.NoSpawning = bool
|
||||
end
|
||||
|
||||
function meta:DisallowVehicles( bool )
|
||||
self.NoVehicles = bool
|
||||
end
|
||||
|
||||
local function tool( ply, tr, toolmode )
|
||||
if ply.NoSpawning then
|
||||
if not table.HasValue( ULib.spawnWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
hook.Add( "CanTool", "ULibPlayerToolCheck", tool, HOOK_HIGH )
|
||||
|
||||
local function noclip( ply )
|
||||
if ply.NoNoclip then return false end
|
||||
end
|
||||
hook.Add( "PlayerNoClip", "ULibNoclipCheck", noclip, HOOK_HIGH )
|
||||
|
||||
local function spawnblock( ply )
|
||||
if ply.NoSpawning then return false end
|
||||
end
|
||||
hook.Add( "PlayerSpawnObject", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnEffect", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnProp", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnNPC", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnVehicle", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnRagdoll", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnSENT", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerGiveSWEP", "ULibSpawnBlock", spawnblock )
|
||||
|
||||
local function vehicleblock( ply, ent )
|
||||
if ply.NoVehicles then
|
||||
return false
|
||||
end
|
||||
end
|
||||
hook.Add( "CanPlayerEnterVehicle", "ULibVehicleBlock", vehicleblock, HOOK_HIGH )
|
||||
hook.Add( "CanDrive", "ULibVehicleDriveBlock", vehicleblock, HOOK_HIGH )
|
||||
local meta = FindMetaTable( "Player" )
|
||||
|
||||
ULib.spawnWhitelist = -- Tool white list for tools that don't spawn things
|
||||
{
|
||||
"colour",
|
||||
"material",
|
||||
"paint",
|
||||
"ballsocket",
|
||||
"ballsocket_adv",
|
||||
"weld",
|
||||
"keepupright",
|
||||
"nocollide",
|
||||
"eyeposer",
|
||||
"faceposer",
|
||||
"statue",
|
||||
"weld_ez",
|
||||
"axis",
|
||||
}
|
||||
|
||||
-- Return if there's nothing to add on to
|
||||
if not meta then return end
|
||||
|
||||
function meta:DisallowNoclip( bool )
|
||||
self.NoNoclip = bool
|
||||
end
|
||||
|
||||
function meta:DisallowSpawning( bool )
|
||||
self.NoSpawning = bool
|
||||
end
|
||||
|
||||
function meta:DisallowVehicles( bool )
|
||||
self.NoVehicles = bool
|
||||
end
|
||||
|
||||
local function tool( ply, tr, toolmode )
|
||||
if ply.NoSpawning then
|
||||
if not table.HasValue( ULib.spawnWhitelist, toolmode ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
hook.Add( "CanTool", "ULibPlayerToolCheck", tool, HOOK_HIGH )
|
||||
|
||||
local function noclip( ply )
|
||||
if ply.NoNoclip then return false end
|
||||
end
|
||||
hook.Add( "PlayerNoClip", "ULibNoclipCheck", noclip, HOOK_HIGH )
|
||||
|
||||
local function spawnblock( ply )
|
||||
if ply.NoSpawning then return false end
|
||||
end
|
||||
hook.Add( "PlayerSpawnObject", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnEffect", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnProp", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnNPC", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnVehicle", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnRagdoll", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerSpawnSENT", "ULibSpawnBlock", spawnblock )
|
||||
hook.Add( "PlayerGiveSWEP", "ULibSpawnBlock", spawnblock )
|
||||
|
||||
local function vehicleblock( ply, ent )
|
||||
if ply.NoVehicles then
|
||||
return false
|
||||
end
|
||||
end
|
||||
hook.Add( "CanPlayerEnterVehicle", "ULibVehicleBlock", vehicleblock, HOOK_HIGH )
|
||||
hook.Add( "CanDrive", "ULibVehicleDriveBlock", vehicleblock, HOOK_HIGH )
|
||||
|
@ -1,274 +1,274 @@
|
||||
--[[
|
||||
Title: Utilities
|
||||
|
||||
Has some useful server utilities
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
Function: clientRPC
|
||||
|
||||
Think of this function as if you're calling a client function directly from the server. You state who should run it, what the name of
|
||||
the function is, and then a list of parameters to pass to that function on the client. ULib handles the rest. Parameters can be any
|
||||
data type that's allowed on the network and of any size. Send huge tables or strings, it's all the same, and it all works.
|
||||
|
||||
Parameters:
|
||||
|
||||
filter - The Player object, table of Player objects for who you want to send this to, nil sends to everyone.
|
||||
fn - A string of the function to run on the client. Does *not* need to be in the global namespace, "myTable.myFunction" works too.
|
||||
... - *Optional* The parameters to pass to the function.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
]]
|
||||
function ULib.clientRPC( plys, fn, ... )
|
||||
ULib.checkArg( 1, "ULib.clientRPC", {"nil","Player","table"}, plys )
|
||||
ULib.checkArg( 2, "ULib.clientRPC", {"string"}, fn )
|
||||
|
||||
net.Start( "URPC" )
|
||||
net.WriteString( fn )
|
||||
net.WriteTable( {...} )
|
||||
if plys then
|
||||
net.Send( plys )
|
||||
else
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: umsgSend
|
||||
|
||||
Makes sending umsgs a blast. You don't have to bother knowing what type you're sending, just use ULib.umsgRcv() on the client.
|
||||
Note that while you can send tables with this function, you're limited by the max umsg size. If you're sending a large amount of data,
|
||||
consider using <clientRPC()> instead.
|
||||
|
||||
Parameters:
|
||||
|
||||
v - The value to send.
|
||||
queue - *(For use by <clientRPC()> ONLY)* A boolean of whether the messages should be queued with RPC or not.
|
||||
]]
|
||||
function ULib.umsgSend( v, queue )
|
||||
local tv = type( v )
|
||||
local function call( fn, ... )
|
||||
if queue then
|
||||
queueRPC( fn, ... )
|
||||
else
|
||||
fn( ... )
|
||||
end
|
||||
end
|
||||
|
||||
if tv == "string" then
|
||||
call( umsg.Char, ULib.TYPE_STRING )
|
||||
call( umsg.String, v )
|
||||
elseif tv == "number" then
|
||||
if math.fmod( v, 1 ) ~= 0 then -- It's a float
|
||||
call( umsg.Char, ULib.TYPE_FLOAT )
|
||||
call( umsg.Float, v )
|
||||
else
|
||||
if v <= 127 and v >= -127 then
|
||||
call( umsg.Char, ULib.TYPE_CHAR )
|
||||
call( umsg.Char, v )
|
||||
elseif v < 32767 and v > -32768 then
|
||||
call( umsg.Char, ULib.TYPE_SHORT )
|
||||
call( umsg.Short, v )
|
||||
else
|
||||
call( umsg.Char, ULib.TYPE_LONG )
|
||||
call( umsg.Long, v )
|
||||
end
|
||||
end
|
||||
elseif tv == "boolean" then
|
||||
call( umsg.Char, ULib.TYPE_BOOLEAN )
|
||||
call( umsg.Bool, v )
|
||||
elseif tv == "Entity" or tv == "Player" then
|
||||
call( umsg.Char, ULib.TYPE_ENTITY )
|
||||
call( umsg.Entity, v )
|
||||
elseif tv == "Vector" then
|
||||
call( umsg.Char, ULib.TYPE_VECTOR )
|
||||
call( umsg.Vector, v )
|
||||
elseif tv == "Angle" then
|
||||
call( umsg.Char, ULib.TYPE_ANGLE )
|
||||
call( umsg.Angle, v )
|
||||
elseif tv == "table" then
|
||||
call( umsg.Char, ULib.TYPE_TABLE_BEGIN )
|
||||
for key, value in pairs( v ) do
|
||||
ULib.umsgSend( key, queue )
|
||||
ULib.umsgSend( value, queue )
|
||||
end
|
||||
call( umsg.Char, ULib.TYPE_TABLE_END )
|
||||
elseif tv == "nil" then
|
||||
call( umsg.Char, ULib.TYPE_NIL )
|
||||
else
|
||||
ULib.error( "Unknown type passed to umsgSend -- " .. tv )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: play3DSound
|
||||
|
||||
Plays a 3D sound, the further away from the point the player is, the softer the sound will be.
|
||||
|
||||
Parameters:
|
||||
|
||||
sound - The sound to play, relative to the sound folder.
|
||||
vector - The point to play the sound at.
|
||||
volume - *(Optional, defaults to 1)* The volume to make the sound.
|
||||
pitch - *(Optional, defaults to 1)* The pitch to make the sound, 1 = normal.
|
||||
]]
|
||||
function ULib.play3DSound( sound, vector, volume, pitch )
|
||||
volume = volume or 100
|
||||
pitch = pitch or 100
|
||||
|
||||
local ent = ents.Create( "info_null" )
|
||||
if not ent:IsValid() then return end
|
||||
ent:SetPos( vector )
|
||||
ent:Spawn()
|
||||
ent:Activate()
|
||||
ent:EmitSound( sound, volume, pitch )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: getAllReadyPlayers
|
||||
|
||||
Similar to player.GetAll(), except it only returns players that have ULib ready to go.
|
||||
|
||||
Revisions:
|
||||
|
||||
2.40 - Initial
|
||||
]]
|
||||
function ULib.getAllReadyPlayers()
|
||||
local players = player.GetAll()
|
||||
for i=#players, 1, -1 do
|
||||
if not players[ i ].ulib_ready then
|
||||
table.remove( players, i )
|
||||
end
|
||||
end
|
||||
|
||||
return players
|
||||
end
|
||||
|
||||
|
||||
ULib.repcvars = ULib.repcvars or {} -- This is used for <ULib.replicatedWithWritableCvar> in order to keep track of valid cvars and access info.
|
||||
local repcvars = ULib.repcvars
|
||||
local repCvarServerChanged
|
||||
--[[
|
||||
Function: replicatedWritableCvar
|
||||
|
||||
This function is mainly intended for use with the menus. This function is very similar to creating a replicated cvar with one caveat:
|
||||
This function also creates a cvar on the client that can be modified and will be sent back to the server.
|
||||
|
||||
Parameters:
|
||||
|
||||
sv_cvar - The string of server side cvar.
|
||||
cl_cvar - The string of the client side cvar. *THIS MUST BE DIFFERENT FROM THE sv_cvar VALUE IF YOU'RE PIGGY BACKING AN EXISTING REPLICATED CVAR (like sv_gravity)*.
|
||||
default_value - The string of the default value for the cvar.
|
||||
save - Boolean of whether or not the value is persistent across map changes.
|
||||
This uses garry's way, which has lots of issues. We recommend you watch the cvar for changes and handle saving yourself.
|
||||
notify - Boolean of whether or not value changes are announced on the server
|
||||
access - The string of the access required for a client to actually change the value.
|
||||
|
||||
Returns:
|
||||
|
||||
The server-side cvar object.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
v2.50 - Changed to not depend on the replicated cvars themselves due to Garry-breakage.
|
||||
]]
|
||||
function ULib.replicatedWritableCvar( sv_cvar, cl_cvar, default_value, save, notify, access )
|
||||
sv_cvar = sv_cvar:lower()
|
||||
cl_cvar = cl_cvar:lower()
|
||||
|
||||
local flags = 0
|
||||
if save then
|
||||
flags = flags + FCVAR_ARCHIVE
|
||||
end
|
||||
if notify then
|
||||
flags = flags + FCVAR_NOTIFY
|
||||
end
|
||||
|
||||
local cvar_obj = GetConVar( sv_cvar ) or CreateConVar( sv_cvar, default_value, flags )
|
||||
|
||||
umsg.Start( "ulib_repWriteCvar" ) -- Send to everyone connected
|
||||
umsg.String( sv_cvar )
|
||||
umsg.String( cl_cvar )
|
||||
umsg.String( default_value )
|
||||
umsg.String( cvar_obj:GetString() )
|
||||
umsg.End()
|
||||
|
||||
repcvars[ sv_cvar ] = { access=access, default=default_value, cl_cvar=cl_cvar, cvar_obj=cvar_obj }
|
||||
cvars.AddChangeCallback( sv_cvar, repCvarServerChanged )
|
||||
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, cl_cvar, nil, nil, cvar_obj:GetString() )
|
||||
|
||||
return cvar_obj
|
||||
end
|
||||
|
||||
local function repCvarOnJoin( ply )
|
||||
for sv_cvar, v in pairs( repcvars ) do
|
||||
umsg.Start( "ulib_repWriteCvar", ply )
|
||||
umsg.String( sv_cvar )
|
||||
umsg.String( v.cl_cvar )
|
||||
umsg.String( v.default )
|
||||
umsg.String( v.cvar_obj:GetString() )
|
||||
umsg.End()
|
||||
end
|
||||
end
|
||||
hook.Add( ULib.HOOK_LOCALPLAYERREADY, "ULibSendCvars", repCvarOnJoin )
|
||||
|
||||
|
||||
local function clientChangeCvar( ply, command, argv )
|
||||
local sv_cvar = argv[ 1 ]
|
||||
local newvalue = argv[ 2 ]
|
||||
|
||||
if not sv_cvar or not newvalue or not repcvars[ sv_cvar:lower() ] then -- Bad value, ignore
|
||||
return
|
||||
end
|
||||
|
||||
sv_cvar = sv_cvar:lower()
|
||||
cvar_obj = repcvars[ sv_cvar ].cvar_obj
|
||||
local oldvalue = cvar_obj:GetString()
|
||||
if oldvalue == newvalue then return end -- Agreement
|
||||
|
||||
local access = repcvars[ sv_cvar ].access
|
||||
if not ply:query( access ) then
|
||||
ULib.tsayError( ply, "You do not have access to this cvar (" .. sv_cvar .. "), " .. ply:Nick() .. "." )
|
||||
umsg.Start( "ulib_repChangeCvar", ply )
|
||||
umsg.Entity( ply )
|
||||
umsg.String( repcvars[ sv_cvar ].cl_cvar )
|
||||
umsg.String( oldvalue )
|
||||
umsg.String( oldvalue ) -- No change
|
||||
umsg.End()
|
||||
return
|
||||
end
|
||||
|
||||
repcvars[ sv_cvar ].ignore = ply -- Flag other hook not to go off. Flag will be removed at hook.
|
||||
RunConsoleCommand( sv_cvar, newvalue )
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, repcvars[ sv_cvar ].cl_cvar, ply, oldvalue, newvalue )
|
||||
end
|
||||
concommand.Add( "ulib_update_cvar", clientChangeCvar, nil, nil, FCVAR_SERVER_CAN_EXECUTE )
|
||||
-- Adding FCVAR_SERVER_CAN_EXECUTE above prevents an odd bug where if a user hosts a listen server, this command gets registered,
|
||||
-- but when they join another server they can't change any replicated cvars.
|
||||
|
||||
repCvarServerChanged = function( sv_cvar, oldvalue, newvalue )
|
||||
if not repcvars[ sv_cvar ] then -- Bad value or we need to ignore it
|
||||
return
|
||||
end
|
||||
|
||||
umsg.Start( "ulib_repChangeCvar" ) -- Tell clients to reset to new value
|
||||
umsg.Entity( repcvars[ sv_cvar ].ignore or Entity( 0 ) )
|
||||
umsg.String( repcvars[ sv_cvar ].cl_cvar )
|
||||
umsg.String( oldvalue )
|
||||
umsg.String( newvalue )
|
||||
umsg.End()
|
||||
|
||||
if repcvars[ sv_cvar ].ignore then
|
||||
repcvars[ sv_cvar ].ignore = nil
|
||||
else
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, repcvars[ sv_cvar ].cl_cvar, Entity( 0 ), oldvalue, newvalue )
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Title: Utilities
|
||||
|
||||
Has some useful server utilities
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
Function: clientRPC
|
||||
|
||||
Think of this function as if you're calling a client function directly from the server. You state who should run it, what the name of
|
||||
the function is, and then a list of parameters to pass to that function on the client. ULib handles the rest. Parameters can be any
|
||||
data type that's allowed on the network and of any size. Send huge tables or strings, it's all the same, and it all works.
|
||||
|
||||
Parameters:
|
||||
|
||||
filter - The Player object, table of Player objects for who you want to send this to, nil sends to everyone.
|
||||
fn - A string of the function to run on the client. Does *not* need to be in the global namespace, "myTable.myFunction" works too.
|
||||
... - *Optional* The parameters to pass to the function.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
]]
|
||||
function ULib.clientRPC( plys, fn, ... )
|
||||
ULib.checkArg( 1, "ULib.clientRPC", {"nil","Player","table"}, plys )
|
||||
ULib.checkArg( 2, "ULib.clientRPC", {"string"}, fn )
|
||||
|
||||
net.Start( "URPC" )
|
||||
net.WriteString( fn )
|
||||
net.WriteTable( {...} )
|
||||
if plys then
|
||||
net.Send( plys )
|
||||
else
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: umsgSend
|
||||
|
||||
Makes sending umsgs a blast. You don't have to bother knowing what type you're sending, just use ULib.umsgRcv() on the client.
|
||||
Note that while you can send tables with this function, you're limited by the max umsg size. If you're sending a large amount of data,
|
||||
consider using <clientRPC()> instead.
|
||||
|
||||
Parameters:
|
||||
|
||||
v - The value to send.
|
||||
queue - *(For use by <clientRPC()> ONLY)* A boolean of whether the messages should be queued with RPC or not.
|
||||
]]
|
||||
function ULib.umsgSend( v, queue )
|
||||
local tv = type( v )
|
||||
local function call( fn, ... )
|
||||
if queue then
|
||||
queueRPC( fn, ... )
|
||||
else
|
||||
fn( ... )
|
||||
end
|
||||
end
|
||||
|
||||
if tv == "string" then
|
||||
call( umsg.Char, ULib.TYPE_STRING )
|
||||
call( umsg.String, v )
|
||||
elseif tv == "number" then
|
||||
if math.fmod( v, 1 ) ~= 0 then -- It's a float
|
||||
call( umsg.Char, ULib.TYPE_FLOAT )
|
||||
call( umsg.Float, v )
|
||||
else
|
||||
if v <= 127 and v >= -127 then
|
||||
call( umsg.Char, ULib.TYPE_CHAR )
|
||||
call( umsg.Char, v )
|
||||
elseif v < 32767 and v > -32768 then
|
||||
call( umsg.Char, ULib.TYPE_SHORT )
|
||||
call( umsg.Short, v )
|
||||
else
|
||||
call( umsg.Char, ULib.TYPE_LONG )
|
||||
call( umsg.Long, v )
|
||||
end
|
||||
end
|
||||
elseif tv == "boolean" then
|
||||
call( umsg.Char, ULib.TYPE_BOOLEAN )
|
||||
call( umsg.Bool, v )
|
||||
elseif tv == "Entity" or tv == "Player" then
|
||||
call( umsg.Char, ULib.TYPE_ENTITY )
|
||||
call( umsg.Entity, v )
|
||||
elseif tv == "Vector" then
|
||||
call( umsg.Char, ULib.TYPE_VECTOR )
|
||||
call( umsg.Vector, v )
|
||||
elseif tv == "Angle" then
|
||||
call( umsg.Char, ULib.TYPE_ANGLE )
|
||||
call( umsg.Angle, v )
|
||||
elseif tv == "table" then
|
||||
call( umsg.Char, ULib.TYPE_TABLE_BEGIN )
|
||||
for key, value in pairs( v ) do
|
||||
ULib.umsgSend( key, queue )
|
||||
ULib.umsgSend( value, queue )
|
||||
end
|
||||
call( umsg.Char, ULib.TYPE_TABLE_END )
|
||||
elseif tv == "nil" then
|
||||
call( umsg.Char, ULib.TYPE_NIL )
|
||||
else
|
||||
ULib.error( "Unknown type passed to umsgSend -- " .. tv )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: play3DSound
|
||||
|
||||
Plays a 3D sound, the further away from the point the player is, the softer the sound will be.
|
||||
|
||||
Parameters:
|
||||
|
||||
sound - The sound to play, relative to the sound folder.
|
||||
vector - The point to play the sound at.
|
||||
volume - *(Optional, defaults to 1)* The volume to make the sound.
|
||||
pitch - *(Optional, defaults to 1)* The pitch to make the sound, 1 = normal.
|
||||
]]
|
||||
function ULib.play3DSound( sound, vector, volume, pitch )
|
||||
volume = volume or 100
|
||||
pitch = pitch or 100
|
||||
|
||||
local ent = ents.Create( "info_null" )
|
||||
if not ent:IsValid() then return end
|
||||
ent:SetPos( vector )
|
||||
ent:Spawn()
|
||||
ent:Activate()
|
||||
ent:EmitSound( sound, volume, pitch )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: getAllReadyPlayers
|
||||
|
||||
Similar to player.GetAll(), except it only returns players that have ULib ready to go.
|
||||
|
||||
Revisions:
|
||||
|
||||
2.40 - Initial
|
||||
]]
|
||||
function ULib.getAllReadyPlayers()
|
||||
local players = player.GetAll()
|
||||
for i=#players, 1, -1 do
|
||||
if not players[ i ].ulib_ready then
|
||||
table.remove( players, i )
|
||||
end
|
||||
end
|
||||
|
||||
return players
|
||||
end
|
||||
|
||||
|
||||
ULib.repcvars = ULib.repcvars or {} -- This is used for <ULib.replicatedWithWritableCvar> in order to keep track of valid cvars and access info.
|
||||
local repcvars = ULib.repcvars
|
||||
local repCvarServerChanged
|
||||
--[[
|
||||
Function: replicatedWritableCvar
|
||||
|
||||
This function is mainly intended for use with the menus. This function is very similar to creating a replicated cvar with one caveat:
|
||||
This function also creates a cvar on the client that can be modified and will be sent back to the server.
|
||||
|
||||
Parameters:
|
||||
|
||||
sv_cvar - The string of server side cvar.
|
||||
cl_cvar - The string of the client side cvar. *THIS MUST BE DIFFERENT FROM THE sv_cvar VALUE IF YOU'RE PIGGY BACKING AN EXISTING REPLICATED CVAR (like sv_gravity)*.
|
||||
default_value - The string of the default value for the cvar.
|
||||
save - Boolean of whether or not the value is persistent across map changes.
|
||||
This uses garry's way, which has lots of issues. We recommend you watch the cvar for changes and handle saving yourself.
|
||||
notify - Boolean of whether or not value changes are announced on the server
|
||||
access - The string of the access required for a client to actually change the value.
|
||||
|
||||
Returns:
|
||||
|
||||
The server-side cvar object.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
v2.50 - Changed to not depend on the replicated cvars themselves due to Garry-breakage.
|
||||
]]
|
||||
function ULib.replicatedWritableCvar( sv_cvar, cl_cvar, default_value, save, notify, access )
|
||||
sv_cvar = sv_cvar:lower()
|
||||
cl_cvar = cl_cvar:lower()
|
||||
|
||||
local flags = 0
|
||||
if save then
|
||||
flags = flags + FCVAR_ARCHIVE
|
||||
end
|
||||
if notify then
|
||||
flags = flags + FCVAR_NOTIFY
|
||||
end
|
||||
|
||||
local cvar_obj = GetConVar( sv_cvar ) or CreateConVar( sv_cvar, default_value, flags )
|
||||
|
||||
umsg.Start( "ulib_repWriteCvar" ) -- Send to everyone connected
|
||||
umsg.String( sv_cvar )
|
||||
umsg.String( cl_cvar )
|
||||
umsg.String( default_value )
|
||||
umsg.String( cvar_obj:GetString() )
|
||||
umsg.End()
|
||||
|
||||
repcvars[ sv_cvar ] = { access=access, default=default_value, cl_cvar=cl_cvar, cvar_obj=cvar_obj }
|
||||
cvars.AddChangeCallback( sv_cvar, repCvarServerChanged )
|
||||
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, cl_cvar, nil, nil, cvar_obj:GetString() )
|
||||
|
||||
return cvar_obj
|
||||
end
|
||||
|
||||
local function repCvarOnJoin( ply )
|
||||
for sv_cvar, v in pairs( repcvars ) do
|
||||
umsg.Start( "ulib_repWriteCvar", ply )
|
||||
umsg.String( sv_cvar )
|
||||
umsg.String( v.cl_cvar )
|
||||
umsg.String( v.default )
|
||||
umsg.String( v.cvar_obj:GetString() )
|
||||
umsg.End()
|
||||
end
|
||||
end
|
||||
hook.Add( ULib.HOOK_LOCALPLAYERREADY, "ULibSendCvars", repCvarOnJoin )
|
||||
|
||||
|
||||
local function clientChangeCvar( ply, command, argv )
|
||||
local sv_cvar = argv[ 1 ]
|
||||
local newvalue = argv[ 2 ]
|
||||
|
||||
if not sv_cvar or not newvalue or not repcvars[ sv_cvar:lower() ] then -- Bad value, ignore
|
||||
return
|
||||
end
|
||||
|
||||
sv_cvar = sv_cvar:lower()
|
||||
cvar_obj = repcvars[ sv_cvar ].cvar_obj
|
||||
local oldvalue = cvar_obj:GetString()
|
||||
if oldvalue == newvalue then return end -- Agreement
|
||||
|
||||
local access = repcvars[ sv_cvar ].access
|
||||
if not ply:query( access ) then
|
||||
ULib.tsayError( ply, "You do not have access to this cvar (" .. sv_cvar .. "), " .. ply:Nick() .. "." )
|
||||
umsg.Start( "ulib_repChangeCvar", ply )
|
||||
umsg.Entity( ply )
|
||||
umsg.String( repcvars[ sv_cvar ].cl_cvar )
|
||||
umsg.String( oldvalue )
|
||||
umsg.String( oldvalue ) -- No change
|
||||
umsg.End()
|
||||
return
|
||||
end
|
||||
|
||||
repcvars[ sv_cvar ].ignore = ply -- Flag other hook not to go off. Flag will be removed at hook.
|
||||
RunConsoleCommand( sv_cvar, newvalue )
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, repcvars[ sv_cvar ].cl_cvar, ply, oldvalue, newvalue )
|
||||
end
|
||||
concommand.Add( "ulib_update_cvar", clientChangeCvar, nil, nil, FCVAR_SERVER_CAN_EXECUTE )
|
||||
-- Adding FCVAR_SERVER_CAN_EXECUTE above prevents an odd bug where if a user hosts a listen server, this command gets registered,
|
||||
-- but when they join another server they can't change any replicated cvars.
|
||||
|
||||
repCvarServerChanged = function( sv_cvar, oldvalue, newvalue )
|
||||
if not repcvars[ sv_cvar ] then -- Bad value or we need to ignore it
|
||||
return
|
||||
end
|
||||
|
||||
umsg.Start( "ulib_repChangeCvar" ) -- Tell clients to reset to new value
|
||||
umsg.Entity( repcvars[ sv_cvar ].ignore or Entity( 0 ) )
|
||||
umsg.String( repcvars[ sv_cvar ].cl_cvar )
|
||||
umsg.String( oldvalue )
|
||||
umsg.String( newvalue )
|
||||
umsg.End()
|
||||
|
||||
if repcvars[ sv_cvar ].ignore then
|
||||
repcvars[ sv_cvar ].ignore = nil
|
||||
else
|
||||
hook.Call( ULib.HOOK_REPCVARCHANGED, _, sv_cvar, repcvars[ sv_cvar ].cl_cvar, Entity( 0 ), oldvalue, newvalue )
|
||||
end
|
||||
end
|
||||
|
@ -1,252 +1,252 @@
|
||||
|
||||
local gmod = gmod
|
||||
local pairs = pairs
|
||||
local isfunction = isfunction
|
||||
local isstring = isstring
|
||||
local isnumber = isnumber
|
||||
local math = math
|
||||
local IsValid = IsValid
|
||||
|
||||
--[[
|
||||
local concommand = concommand
|
||||
local print = print
|
||||
local PrintTable = PrintTable
|
||||
local tostring = tostring
|
||||
local assert = assert
|
||||
local table = table--]]
|
||||
|
||||
HOOK_MONITOR_HIGH = -2
|
||||
HOOK_HIGH = -1
|
||||
HOOK_NORMAL = 0
|
||||
HOOK_LOW = 1
|
||||
HOOK_MONITOR_LOW = 2
|
||||
|
||||
if hook.GetULibTable then return end -- Prevent autorefresh reloading this file
|
||||
|
||||
-- Grab all previous hooks from the pre-existing hook module.
|
||||
local OldHooks = hook.GetTable()
|
||||
|
||||
module( "hook" )
|
||||
|
||||
local Hooks = {}
|
||||
local BackwardsHooks = {} -- A table fully to garry's spec for aVoN
|
||||
|
||||
--
|
||||
-- For access to the Hooks table.. for some reason.
|
||||
--
|
||||
function GetTable() return BackwardsHooks end
|
||||
function GetULibTable() return Hooks end
|
||||
|
||||
--
|
||||
-- Add a hook
|
||||
--
|
||||
function Add( event_name, name, func, priority )
|
||||
|
||||
priority = priority or 0
|
||||
if ( !isfunction( func ) ) then return end
|
||||
if ( !isstring( event_name ) ) then return end
|
||||
if ( !isnumber( priority ) ) then return end
|
||||
|
||||
priority = math.floor( priority )
|
||||
if ( priority < -2 ) then priority = -2 end -- math.Clamp may not have been defined yet
|
||||
if ( priority > 2 ) then priority = 2 end
|
||||
|
||||
Remove( event_name, name ) -- This keeps the event name unique, even among the priorities
|
||||
|
||||
if (Hooks[ event_name ] == nil) then
|
||||
Hooks[ event_name ] = {[-2]={}, [-1]={}, [0]={}, [1]={}, [2]={}}
|
||||
BackwardsHooks[ event_name ] = {}
|
||||
end
|
||||
|
||||
Hooks[ event_name ][ priority ][ name ] = { fn=func, isstring=isstring( name ) }
|
||||
BackwardsHooks[ event_name ][ name ] = func -- Keep the classic style too so we won't break anything
|
||||
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Remove a hook
|
||||
--
|
||||
function Remove( event_name, name )
|
||||
|
||||
if ( !isstring( event_name ) ) then return end
|
||||
if ( !Hooks[ event_name ] ) then return end
|
||||
|
||||
for i=-2, 2 do
|
||||
Hooks[ event_name ][ i ][ name ] = nil
|
||||
end
|
||||
|
||||
BackwardsHooks[ event_name ][ name ] = nil
|
||||
|
||||
end
|
||||
|
||||
--
|
||||
-- Run a hook (this replaces Call)
|
||||
--
|
||||
function Run( name, ... )
|
||||
return Call( name, gmod and gmod.GetGamemode() or nil, ... )
|
||||
end
|
||||
|
||||
--
|
||||
-- Called by the engine
|
||||
--
|
||||
function Call( name, gm, ... )
|
||||
|
||||
--
|
||||
-- Run hooks
|
||||
--
|
||||
local HookTable = Hooks[ name ]
|
||||
if ( HookTable != nil ) then
|
||||
|
||||
for i=-2, 2 do
|
||||
|
||||
for k, v in pairs( HookTable[ i ] ) do
|
||||
|
||||
if ( v.isstring ) then
|
||||
|
||||
--
|
||||
-- If it's a string, it's cool
|
||||
--
|
||||
local a, b, c, d, e, f = v.fn( ... )
|
||||
if ( a != nil && i > -2 && i < 2 ) then
|
||||
return a, b, c, d, e, f
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
--
|
||||
-- If the key isn't a string - we assume it to be an entity
|
||||
-- Or panel, or something else that IsValid works on.
|
||||
--
|
||||
if ( IsValid( k ) ) then
|
||||
--
|
||||
-- If the object is valid - pass it as the first argument (self)
|
||||
--
|
||||
local a, b, c, d, e, f = v.fn( k, ... )
|
||||
if ( a != nil && i > -2 && i < 2 ) then
|
||||
return a, b, c, d, e, f
|
||||
end
|
||||
else
|
||||
--
|
||||
-- If the object has become invalid - remove it
|
||||
--
|
||||
HookTable[ i ][ k ] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Call the gamemode function
|
||||
--
|
||||
if ( !gm ) then return end
|
||||
|
||||
local GamemodeFunction = gm[ name ]
|
||||
if ( GamemodeFunction == nil ) then return end
|
||||
|
||||
return GamemodeFunction( gm, ... )
|
||||
|
||||
end
|
||||
|
||||
-- Bring in all the old hooks
|
||||
for event_name, t in pairs( OldHooks ) do
|
||||
for name, func in pairs( t ) do
|
||||
Add( event_name, name, func )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
local failed = false
|
||||
local shouldFail = false
|
||||
local i, t
|
||||
|
||||
-- Since the correctness of this file is so important, we've made a little test suite
|
||||
local function appendGenerator( n )
|
||||
return function( t )
|
||||
table.insert( t, n )
|
||||
end
|
||||
end
|
||||
|
||||
local function returnRange()
|
||||
return 1, 2, 3, 4, 5, 6, 7, 8
|
||||
end
|
||||
|
||||
local function noop()
|
||||
end
|
||||
|
||||
local function err()
|
||||
if shouldFail then
|
||||
error( "this error is normal!" )
|
||||
else
|
||||
error( "this error is bad!" )
|
||||
failed = true
|
||||
end
|
||||
end
|
||||
|
||||
local function doTests( ply, cmd, argv )
|
||||
print( "Being run on client: " .. tostring( CLIENT ) )
|
||||
|
||||
-- First make sure there's no return value leakage...
|
||||
Add( "LeakageA", "a", returnRange )
|
||||
t = { Call( "LeakageA", _ ) }
|
||||
assert( #t == 6 )
|
||||
for k, v in pairs( t ) do
|
||||
assert( k == v )
|
||||
end
|
||||
|
||||
Add( "LeakageB", "a", noop )
|
||||
t = { Call( "LeakageB", _ ) }
|
||||
assert( #t == 0 )
|
||||
|
||||
-- Now let's make sure errors are handled correctly...
|
||||
shouldFail = true
|
||||
Add( "ErrCheck", "a", noop )
|
||||
--Add( "ErrCheck", "b", err )
|
||||
Add( "ErrCheck", "c", noop )
|
||||
Add( "ErrCheck", "d", returnRange )
|
||||
t = { Call( "ErrCheck", _ ) }
|
||||
assert( #t == 6 )
|
||||
--assert( #Hooks.ErrCheck == 3 and Hooks.ErrCheck[4] == nil ) -- Should have been reduced so that the 'b' got removed
|
||||
|
||||
shouldFail = false
|
||||
t = { Call( "ErrCheck", _ ) }
|
||||
assert( #t == 6 )
|
||||
|
||||
-- Check for override
|
||||
Add( "ErrCheck", "d", noop, 1 ) -- Different priority, same name should still override
|
||||
t = { Call( "ErrCheck", _ ) }
|
||||
assert( #t == 0 )
|
||||
|
||||
-- Check for order and readonly'ness...
|
||||
Add( "Order", "n20a", returnRange, -2 )
|
||||
Add( "Order", "a", appendGenerator( 3 ) )
|
||||
Add( "Order", "n20a", appendGenerator( 1 ), -2 )
|
||||
Add( "Order", "n10a", appendGenerator( 2 ), -1 )
|
||||
Add( "Order", "10a", appendGenerator( 4 ), 1 )
|
||||
Add( "Order", "20a", returnRange, 2 )
|
||||
Add( "Order", "20aa", appendGenerator( 5 ), 2 )
|
||||
|
||||
t = {}
|
||||
Call( "Order", _, t )
|
||||
print( t, #t )
|
||||
PrintTable( t )
|
||||
assert( #t == 5 )
|
||||
for k, v in pairs( t ) do
|
||||
assert( k == v )
|
||||
end
|
||||
|
||||
Add( "Test", "AAA", function () print( "AAA" ) Remove( "Test", "AAA" ) end )
|
||||
Add( "Test", "BBB", function () print( "BBB" ) end)
|
||||
Run( "Test" )
|
||||
Run( "Test" )
|
||||
|
||||
if failed then
|
||||
print( "Tests failed!" )
|
||||
else
|
||||
print( "All tests passed!" )
|
||||
end
|
||||
end
|
||||
|
||||
concommand.Add( "run_hook_tests", doTests )--]]
|
||||
|
||||
|
||||
local gmod = gmod
|
||||
local pairs = pairs
|
||||
local isfunction = isfunction
|
||||
local isstring = isstring
|
||||
local isnumber = isnumber
|
||||
local math = math
|
||||
local IsValid = IsValid
|
||||
|
||||
--[[
|
||||
local concommand = concommand
|
||||
local print = print
|
||||
local PrintTable = PrintTable
|
||||
local tostring = tostring
|
||||
local assert = assert
|
||||
local table = table--]]
|
||||
|
||||
HOOK_MONITOR_HIGH = -2
|
||||
HOOK_HIGH = -1
|
||||
HOOK_NORMAL = 0
|
||||
HOOK_LOW = 1
|
||||
HOOK_MONITOR_LOW = 2
|
||||
|
||||
if hook.GetULibTable then return end -- Prevent autorefresh reloading this file
|
||||
|
||||
-- Grab all previous hooks from the pre-existing hook module.
|
||||
local OldHooks = hook.GetTable()
|
||||
|
||||
module( "hook" )
|
||||
|
||||
local Hooks = {}
|
||||
local BackwardsHooks = {} -- A table fully to garry's spec for aVoN
|
||||
|
||||
--
|
||||
-- For access to the Hooks table.. for some reason.
|
||||
--
|
||||
function GetTable() return BackwardsHooks end
|
||||
function GetULibTable() return Hooks end
|
||||
|
||||
--
|
||||
-- Add a hook
|
||||
--
|
||||
function Add( event_name, name, func, priority )
|
||||
|
||||
priority = priority or 0
|
||||
if ( !isfunction( func ) ) then return end
|
||||
if ( !isstring( event_name ) ) then return end
|
||||
if ( !isnumber( priority ) ) then return end
|
||||
|
||||
priority = math.floor( priority )
|
||||
if ( priority < -2 ) then priority = -2 end -- math.Clamp may not have been defined yet
|
||||
if ( priority > 2 ) then priority = 2 end
|
||||
|
||||
Remove( event_name, name ) -- This keeps the event name unique, even among the priorities
|
||||
|
||||
if (Hooks[ event_name ] == nil) then
|
||||
Hooks[ event_name ] = {[-2]={}, [-1]={}, [0]={}, [1]={}, [2]={}}
|
||||
BackwardsHooks[ event_name ] = {}
|
||||
end
|
||||
|
||||
Hooks[ event_name ][ priority ][ name ] = { fn=func, isstring=isstring( name ) }
|
||||
BackwardsHooks[ event_name ][ name ] = func -- Keep the classic style too so we won't break anything
|
||||
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Remove a hook
|
||||
--
|
||||
function Remove( event_name, name )
|
||||
|
||||
if ( !isstring( event_name ) ) then return end
|
||||
if ( !Hooks[ event_name ] ) then return end
|
||||
|
||||
for i=-2, 2 do
|
||||
Hooks[ event_name ][ i ][ name ] = nil
|
||||
end
|
||||
|
||||
BackwardsHooks[ event_name ][ name ] = nil
|
||||
|
||||
end
|
||||
|
||||
--
|
||||
-- Run a hook (this replaces Call)
|
||||
--
|
||||
function Run( name, ... )
|
||||
return Call( name, gmod and gmod.GetGamemode() or nil, ... )
|
||||
end
|
||||
|
||||
--
|
||||
-- Called by the engine
|
||||
--
|
||||
function Call( name, gm, ... )
|
||||
|
||||
--
|
||||
-- Run hooks
|
||||
--
|
||||
local HookTable = Hooks[ name ]
|
||||
if ( HookTable != nil ) then
|
||||
|
||||
for i=-2, 2 do
|
||||
|
||||
for k, v in pairs( HookTable[ i ] ) do
|
||||
|
||||
if ( v.isstring ) then
|
||||
|
||||
--
|
||||
-- If it's a string, it's cool
|
||||
--
|
||||
local a, b, c, d, e, f = v.fn( ... )
|
||||
if ( a != nil && i > -2 && i < 2 ) then
|
||||
return a, b, c, d, e, f
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
--
|
||||
-- If the key isn't a string - we assume it to be an entity
|
||||
-- Or panel, or something else that IsValid works on.
|
||||
--
|
||||
if ( IsValid( k ) ) then
|
||||
--
|
||||
-- If the object is valid - pass it as the first argument (self)
|
||||
--
|
||||
local a, b, c, d, e, f = v.fn( k, ... )
|
||||
if ( a != nil && i > -2 && i < 2 ) then
|
||||
return a, b, c, d, e, f
|
||||
end
|
||||
else
|
||||
--
|
||||
-- If the object has become invalid - remove it
|
||||
--
|
||||
HookTable[ i ][ k ] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Call the gamemode function
|
||||
--
|
||||
if ( !gm ) then return end
|
||||
|
||||
local GamemodeFunction = gm[ name ]
|
||||
if ( GamemodeFunction == nil ) then return end
|
||||
|
||||
return GamemodeFunction( gm, ... )
|
||||
|
||||
end
|
||||
|
||||
-- Bring in all the old hooks
|
||||
for event_name, t in pairs( OldHooks ) do
|
||||
for name, func in pairs( t ) do
|
||||
Add( event_name, name, func )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
local failed = false
|
||||
local shouldFail = false
|
||||
local i, t
|
||||
|
||||
-- Since the correctness of this file is so important, we've made a little test suite
|
||||
local function appendGenerator( n )
|
||||
return function( t )
|
||||
table.insert( t, n )
|
||||
end
|
||||
end
|
||||
|
||||
local function returnRange()
|
||||
return 1, 2, 3, 4, 5, 6, 7, 8
|
||||
end
|
||||
|
||||
local function noop()
|
||||
end
|
||||
|
||||
local function err()
|
||||
if shouldFail then
|
||||
error( "this error is normal!" )
|
||||
else
|
||||
error( "this error is bad!" )
|
||||
failed = true
|
||||
end
|
||||
end
|
||||
|
||||
local function doTests( ply, cmd, argv )
|
||||
print( "Being run on client: " .. tostring( CLIENT ) )
|
||||
|
||||
-- First make sure there's no return value leakage...
|
||||
Add( "LeakageA", "a", returnRange )
|
||||
t = { Call( "LeakageA", _ ) }
|
||||
assert( #t == 6 )
|
||||
for k, v in pairs( t ) do
|
||||
assert( k == v )
|
||||
end
|
||||
|
||||
Add( "LeakageB", "a", noop )
|
||||
t = { Call( "LeakageB", _ ) }
|
||||
assert( #t == 0 )
|
||||
|
||||
-- Now let's make sure errors are handled correctly...
|
||||
shouldFail = true
|
||||
Add( "ErrCheck", "a", noop )
|
||||
--Add( "ErrCheck", "b", err )
|
||||
Add( "ErrCheck", "c", noop )
|
||||
Add( "ErrCheck", "d", returnRange )
|
||||
t = { Call( "ErrCheck", _ ) }
|
||||
assert( #t == 6 )
|
||||
--assert( #Hooks.ErrCheck == 3 and Hooks.ErrCheck[4] == nil ) -- Should have been reduced so that the 'b' got removed
|
||||
|
||||
shouldFail = false
|
||||
t = { Call( "ErrCheck", _ ) }
|
||||
assert( #t == 6 )
|
||||
|
||||
-- Check for override
|
||||
Add( "ErrCheck", "d", noop, 1 ) -- Different priority, same name should still override
|
||||
t = { Call( "ErrCheck", _ ) }
|
||||
assert( #t == 0 )
|
||||
|
||||
-- Check for order and readonly'ness...
|
||||
Add( "Order", "n20a", returnRange, -2 )
|
||||
Add( "Order", "a", appendGenerator( 3 ) )
|
||||
Add( "Order", "n20a", appendGenerator( 1 ), -2 )
|
||||
Add( "Order", "n10a", appendGenerator( 2 ), -1 )
|
||||
Add( "Order", "10a", appendGenerator( 4 ), 1 )
|
||||
Add( "Order", "20a", returnRange, 2 )
|
||||
Add( "Order", "20aa", appendGenerator( 5 ), 2 )
|
||||
|
||||
t = {}
|
||||
Call( "Order", _, t )
|
||||
print( t, #t )
|
||||
PrintTable( t )
|
||||
assert( #t == 5 )
|
||||
for k, v in pairs( t ) do
|
||||
assert( k == v )
|
||||
end
|
||||
|
||||
Add( "Test", "AAA", function () print( "AAA" ) Remove( "Test", "AAA" ) end )
|
||||
Add( "Test", "BBB", function () print( "BBB" ) end)
|
||||
Run( "Test" )
|
||||
Run( "Test" )
|
||||
|
||||
if failed then
|
||||
print( "Tests failed!" )
|
||||
else
|
||||
print( "All tests passed!" )
|
||||
end
|
||||
end
|
||||
|
||||
concommand.Add( "run_hook_tests", doTests )--]]
|
||||
|
||||
|
@ -1,285 +1,285 @@
|
||||
--[[
|
||||
Title: Messages
|
||||
|
||||
Handles messaging like logging, debug, etc.
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
Function: tsay
|
||||
|
||||
Prints a message in talk say as well as in the user's consoles.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
wait - *(Optional, defaults to false)* Wait one frame before posting. (Useful to use from things like chat hooks)
|
||||
wasValid - *(INTERNAL USE ONLY)* This is flagged on waiting if the player *was* valid.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Initial
|
||||
]]
|
||||
function ULib.tsay( ply, msg, wait, wasValid )
|
||||
ULib.checkArg( 1, "ULib.tsay", {"nil","Player","Entity"}, ply )
|
||||
ULib.checkArg( 2, "ULib.tsay", "string", msg )
|
||||
ULib.checkArg( 3, "ULib.tsay", {"nil","boolean"}, wait )
|
||||
|
||||
if wait then ULib.namedQueueFunctionCall( "ULibChats", ULib.tsay, ply, msg, false, ply and ply:IsValid() ) return end -- Call next frame
|
||||
|
||||
if SERVER and ply and not ply:IsValid() then -- Server console
|
||||
if wasValid then -- This means we had a valid player that left, so do nothing
|
||||
return
|
||||
end
|
||||
Msg( msg .. "\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
LocalPlayer():ChatPrint( msg )
|
||||
return
|
||||
end
|
||||
|
||||
if ply then
|
||||
ply:ChatPrint( msg )
|
||||
else
|
||||
local players = player.GetAll()
|
||||
for _, player in ipairs( players ) do
|
||||
player:ChatPrint( msg )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local serverConsole = {} -- Used in the function below to identify the server console (internal use)
|
||||
|
||||
local function tsayColorCallback( ply, ... )
|
||||
if CLIENT then
|
||||
chat.AddText( ... )
|
||||
return
|
||||
end
|
||||
|
||||
if ply and ply ~= serverConsole and not ply:IsValid() then return end -- Player must have left the server
|
||||
|
||||
local args = { ... }
|
||||
|
||||
if ply == serverConsole then
|
||||
for i=2, #args, 2 do
|
||||
Msg( args[ i ] )
|
||||
end
|
||||
Msg( "\n" );
|
||||
return
|
||||
end
|
||||
|
||||
local current_chunk = { size = 0 }
|
||||
local chunks = { current_chunk }
|
||||
local max_chunk_size = 240
|
||||
while #args > 0 do
|
||||
local arg = table.remove( args, 1 )
|
||||
local typ = type( arg )
|
||||
local arg_size = typ == "table" and 4 or #arg + 2 -- Include null in strings, bool in both
|
||||
if typ == "string" and current_chunk.size + arg_size > max_chunk_size then -- Split a large string up into multiple messages
|
||||
local substr = arg:sub( 1, math.max( 1, max_chunk_size - current_chunk.size - 2 ) )
|
||||
if #substr > 0 then
|
||||
table.insert( current_chunk, substr )
|
||||
end
|
||||
table.insert( args, 1, arg:sub( #substr + 1) )
|
||||
|
||||
current_chunk = { size = 0 }
|
||||
table.insert( chunks, current_chunk )
|
||||
else
|
||||
if current_chunk.size + arg_size > max_chunk_size then
|
||||
current_chunk = { size = 0 }
|
||||
table.insert( chunks, current_chunk )
|
||||
end
|
||||
current_chunk.size = current_chunk.size + arg_size
|
||||
table.insert( current_chunk, arg )
|
||||
end
|
||||
end
|
||||
|
||||
for chunk_num=1, #chunks do
|
||||
local chunk = chunks[ chunk_num ]
|
||||
umsg.Start( "tsayc", ply )
|
||||
umsg.Bool( chunk_num == #chunks )
|
||||
umsg.Char( #chunk )
|
||||
for i=1, #chunk do
|
||||
local arg = chunk[ i ]
|
||||
if type( arg ) == "string" then
|
||||
umsg.Bool( true )
|
||||
umsg.String( arg )
|
||||
else
|
||||
umsg.Bool( false )
|
||||
umsg.Char( arg.r - 128 )
|
||||
umsg.Char( arg.g - 128 )
|
||||
umsg.Char( arg.b - 128 )
|
||||
end
|
||||
end
|
||||
umsg.End()
|
||||
end
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
local accumulator = {}
|
||||
|
||||
local function tsayColorHook( um )
|
||||
local last = um:ReadBool()
|
||||
local argn = um:ReadChar()
|
||||
for i=1, argn do
|
||||
if um:ReadBool() then
|
||||
table.insert( accumulator, um:ReadString() )
|
||||
else
|
||||
table.insert( accumulator, Color( um:ReadChar() + 128, um:ReadChar() + 128, um:ReadChar() + 128) )
|
||||
end
|
||||
end
|
||||
|
||||
if last then
|
||||
chat.AddText( unpack( accumulator ) )
|
||||
accumulator = {}
|
||||
end
|
||||
end
|
||||
usermessage.Hook( "tsayc", tsayColorHook )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: tsayColor
|
||||
|
||||
Prints a tsay message in color!
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
wait - *(Optional, defaults to false)* Wait one frame before posting. (Useful to use from things like chat hooks)
|
||||
... - color arg and text arg ad infinitum, color needs to come before the text it's coloring.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
]]
|
||||
function ULib.tsayColor( ply, wait, ... )
|
||||
if SERVER and ply and not ply:IsValid() then ply = serverConsole end -- Mark as server
|
||||
|
||||
if wait then ULib.namedQueueFunctionCall( "ULibChats", tsayColorCallback, ply, ... ) return end -- Call next frame
|
||||
tsayColorCallback( ply, ... )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: tsayError
|
||||
|
||||
Just like tsay, but prints the string in red
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
wait - *(Optional, defaults to false)* Wait one frame before posting. (Useful to use from things like chat hooks)
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
]]
|
||||
function ULib.tsayError( ply, msg, wait )
|
||||
return ULib.tsayColor( ply, wait, Color( 255, 140, 39 ), msg )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: csay
|
||||
|
||||
Prints a message in center of the screen as well as in the user's consoles.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
color - *(Optional)* The amount of red to use for the text.
|
||||
duration - *(Optional)* The amount of time to show the text.
|
||||
fade - *(Optional, defaults to 0.5)* The length of fade time
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added fade parameter. Fixed it sending the message multiple times.
|
||||
v2.40 - Changed to use clientRPC.
|
||||
]]
|
||||
function ULib.csay( ply, msg, color, duration, fade )
|
||||
if CLIENT then
|
||||
ULib.csayDraw( msg, color, duration )
|
||||
Msg( msg .. "\n" )
|
||||
return
|
||||
end
|
||||
|
||||
ULib.clientRPC( ply, "ULib.csayDraw", msg, color, duration, fade )
|
||||
ULib.console( ply, msg )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: console
|
||||
|
||||
Prints a message in the user's consoles.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
]]
|
||||
function ULib.console( ply, msg )
|
||||
if CLIENT or (ply and not ply:IsValid()) then
|
||||
Msg( msg .. "\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if ply then
|
||||
ply:PrintMessage( HUD_PRINTCONSOLE, msg .. "\n" )
|
||||
else
|
||||
local players = player.GetAll()
|
||||
for _, player in ipairs( players ) do
|
||||
player:PrintMessage( HUD_PRINTCONSOLE, msg .. "\n" )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: error
|
||||
|
||||
Gives an error to console.
|
||||
|
||||
Parameters:
|
||||
|
||||
s - The string to use as the error message
|
||||
]]
|
||||
function ULib.error( s )
|
||||
if CLIENT then
|
||||
Msg( "[LC ULIB ERROR] " .. s .. "\n" )
|
||||
else
|
||||
Msg( "[LS ULIB ERROR] " .. s .. "\n" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: debugFunctionCall
|
||||
|
||||
Prints a function call, very useful for debugging.
|
||||
|
||||
Parameters:
|
||||
|
||||
name - The name of the function called.
|
||||
... - all arguments to the function.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Now uses print instead of Msg, since Msg seems to have a low max length.
|
||||
Changed how the variable length params work so you can pass nil followed by more params
|
||||
]]
|
||||
function ULib.debugFunctionCall( name, ... )
|
||||
local args = { ... }
|
||||
|
||||
print( "Function '" .. name .. "' called. Parameters:" )
|
||||
for i=1, #args do
|
||||
local value = ULib.serialize( args[ i ] )
|
||||
print( "[PARAMETER " .. i .. "]: Type=" .. type( args[ i ] ) .. "\tValue=(" .. value .. ")" )
|
||||
end
|
||||
--[[
|
||||
Title: Messages
|
||||
|
||||
Handles messaging like logging, debug, etc.
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
Function: tsay
|
||||
|
||||
Prints a message in talk say as well as in the user's consoles.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
wait - *(Optional, defaults to false)* Wait one frame before posting. (Useful to use from things like chat hooks)
|
||||
wasValid - *(INTERNAL USE ONLY)* This is flagged on waiting if the player *was* valid.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Initial
|
||||
]]
|
||||
function ULib.tsay( ply, msg, wait, wasValid )
|
||||
ULib.checkArg( 1, "ULib.tsay", {"nil","Player","Entity"}, ply )
|
||||
ULib.checkArg( 2, "ULib.tsay", "string", msg )
|
||||
ULib.checkArg( 3, "ULib.tsay", {"nil","boolean"}, wait )
|
||||
|
||||
if wait then ULib.namedQueueFunctionCall( "ULibChats", ULib.tsay, ply, msg, false, ply and ply:IsValid() ) return end -- Call next frame
|
||||
|
||||
if SERVER and ply and not ply:IsValid() then -- Server console
|
||||
if wasValid then -- This means we had a valid player that left, so do nothing
|
||||
return
|
||||
end
|
||||
Msg( msg .. "\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
LocalPlayer():ChatPrint( msg )
|
||||
return
|
||||
end
|
||||
|
||||
if ply then
|
||||
ply:ChatPrint( msg )
|
||||
else
|
||||
local players = player.GetAll()
|
||||
for _, player in ipairs( players ) do
|
||||
player:ChatPrint( msg )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local serverConsole = {} -- Used in the function below to identify the server console (internal use)
|
||||
|
||||
local function tsayColorCallback( ply, ... )
|
||||
if CLIENT then
|
||||
chat.AddText( ... )
|
||||
return
|
||||
end
|
||||
|
||||
if ply and ply ~= serverConsole and not ply:IsValid() then return end -- Player must have left the server
|
||||
|
||||
local args = { ... }
|
||||
|
||||
if ply == serverConsole then
|
||||
for i=2, #args, 2 do
|
||||
Msg( args[ i ] )
|
||||
end
|
||||
Msg( "\n" );
|
||||
return
|
||||
end
|
||||
|
||||
local current_chunk = { size = 0 }
|
||||
local chunks = { current_chunk }
|
||||
local max_chunk_size = 240
|
||||
while #args > 0 do
|
||||
local arg = table.remove( args, 1 )
|
||||
local typ = type( arg )
|
||||
local arg_size = typ == "table" and 4 or #arg + 2 -- Include null in strings, bool in both
|
||||
if typ == "string" and current_chunk.size + arg_size > max_chunk_size then -- Split a large string up into multiple messages
|
||||
local substr = arg:sub( 1, math.max( 1, max_chunk_size - current_chunk.size - 2 ) )
|
||||
if #substr > 0 then
|
||||
table.insert( current_chunk, substr )
|
||||
end
|
||||
table.insert( args, 1, arg:sub( #substr + 1) )
|
||||
|
||||
current_chunk = { size = 0 }
|
||||
table.insert( chunks, current_chunk )
|
||||
else
|
||||
if current_chunk.size + arg_size > max_chunk_size then
|
||||
current_chunk = { size = 0 }
|
||||
table.insert( chunks, current_chunk )
|
||||
end
|
||||
current_chunk.size = current_chunk.size + arg_size
|
||||
table.insert( current_chunk, arg )
|
||||
end
|
||||
end
|
||||
|
||||
for chunk_num=1, #chunks do
|
||||
local chunk = chunks[ chunk_num ]
|
||||
umsg.Start( "tsayc", ply )
|
||||
umsg.Bool( chunk_num == #chunks )
|
||||
umsg.Char( #chunk )
|
||||
for i=1, #chunk do
|
||||
local arg = chunk[ i ]
|
||||
if type( arg ) == "string" then
|
||||
umsg.Bool( true )
|
||||
umsg.String( arg )
|
||||
else
|
||||
umsg.Bool( false )
|
||||
umsg.Char( arg.r - 128 )
|
||||
umsg.Char( arg.g - 128 )
|
||||
umsg.Char( arg.b - 128 )
|
||||
end
|
||||
end
|
||||
umsg.End()
|
||||
end
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
local accumulator = {}
|
||||
|
||||
local function tsayColorHook( um )
|
||||
local last = um:ReadBool()
|
||||
local argn = um:ReadChar()
|
||||
for i=1, argn do
|
||||
if um:ReadBool() then
|
||||
table.insert( accumulator, um:ReadString() )
|
||||
else
|
||||
table.insert( accumulator, Color( um:ReadChar() + 128, um:ReadChar() + 128, um:ReadChar() + 128) )
|
||||
end
|
||||
end
|
||||
|
||||
if last then
|
||||
chat.AddText( unpack( accumulator ) )
|
||||
accumulator = {}
|
||||
end
|
||||
end
|
||||
usermessage.Hook( "tsayc", tsayColorHook )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: tsayColor
|
||||
|
||||
Prints a tsay message in color!
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
wait - *(Optional, defaults to false)* Wait one frame before posting. (Useful to use from things like chat hooks)
|
||||
... - color arg and text arg ad infinitum, color needs to come before the text it's coloring.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
]]
|
||||
function ULib.tsayColor( ply, wait, ... )
|
||||
if SERVER and ply and not ply:IsValid() then ply = serverConsole end -- Mark as server
|
||||
|
||||
if wait then ULib.namedQueueFunctionCall( "ULibChats", tsayColorCallback, ply, ... ) return end -- Call next frame
|
||||
tsayColorCallback( ply, ... )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: tsayError
|
||||
|
||||
Just like tsay, but prints the string in red
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
wait - *(Optional, defaults to false)* Wait one frame before posting. (Useful to use from things like chat hooks)
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Initial.
|
||||
]]
|
||||
function ULib.tsayError( ply, msg, wait )
|
||||
return ULib.tsayColor( ply, wait, Color( 255, 140, 39 ), msg )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: csay
|
||||
|
||||
Prints a message in center of the screen as well as in the user's consoles.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
color - *(Optional)* The amount of red to use for the text.
|
||||
duration - *(Optional)* The amount of time to show the text.
|
||||
fade - *(Optional, defaults to 0.5)* The length of fade time
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Added fade parameter. Fixed it sending the message multiple times.
|
||||
v2.40 - Changed to use clientRPC.
|
||||
]]
|
||||
function ULib.csay( ply, msg, color, duration, fade )
|
||||
if CLIENT then
|
||||
ULib.csayDraw( msg, color, duration )
|
||||
Msg( msg .. "\n" )
|
||||
return
|
||||
end
|
||||
|
||||
ULib.clientRPC( ply, "ULib.csayDraw", msg, color, duration, fade )
|
||||
ULib.console( ply, msg )
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: console
|
||||
|
||||
Prints a message in the user's consoles.
|
||||
|
||||
Parameters:
|
||||
|
||||
ply - The player to print to, set to nil to send to everyone. (Ignores this param if called on client)
|
||||
msg - The message to print.
|
||||
]]
|
||||
function ULib.console( ply, msg )
|
||||
if CLIENT or (ply and not ply:IsValid()) then
|
||||
Msg( msg .. "\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if ply then
|
||||
ply:PrintMessage( HUD_PRINTCONSOLE, msg .. "\n" )
|
||||
else
|
||||
local players = player.GetAll()
|
||||
for _, player in ipairs( players ) do
|
||||
player:PrintMessage( HUD_PRINTCONSOLE, msg .. "\n" )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: error
|
||||
|
||||
Gives an error to console.
|
||||
|
||||
Parameters:
|
||||
|
||||
s - The string to use as the error message
|
||||
]]
|
||||
function ULib.error( s )
|
||||
if CLIENT then
|
||||
Msg( "[LC ULIB ERROR] " .. s .. "\n" )
|
||||
else
|
||||
Msg( "[LS ULIB ERROR] " .. s .. "\n" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: debugFunctionCall
|
||||
|
||||
Prints a function call, very useful for debugging.
|
||||
|
||||
Parameters:
|
||||
|
||||
name - The name of the function called.
|
||||
... - all arguments to the function.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.40 - Now uses print instead of Msg, since Msg seems to have a low max length.
|
||||
Changed how the variable length params work so you can pass nil followed by more params
|
||||
]]
|
||||
function ULib.debugFunctionCall( name, ... )
|
||||
local args = { ... }
|
||||
|
||||
print( "Function '" .. name .. "' called. Parameters:" )
|
||||
for i=1, #args do
|
||||
local value = ULib.serialize( args[ i ] )
|
||||
print( "[PARAMETER " .. i .. "]: Type=" .. type( args[ i ] ) .. "\tValue=(" .. value .. ")" )
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
@ -1,163 +1,163 @@
|
||||
--[[
|
||||
Title: Tables
|
||||
|
||||
Some table helpers.
|
||||
]]
|
||||
|
||||
-- Based off "RecursiveReadOnlyTables" by VeLoSo (http://lua-users.org/wiki/RecursiveReadOnlyTables)
|
||||
|
||||
-- cache the metatables of all existing read-only tables,
|
||||
-- so our functions can get to them, but user code can't
|
||||
local metatable_cache = setmetatable( {}, { __mode = "k" } )
|
||||
|
||||
local function make_getter( real_table )
|
||||
local function getter( dummy, key )
|
||||
local ret = real_table[ key ]
|
||||
if type( ret ) == "table" and not metatable_cache[ ret ] then
|
||||
ret = ULib.makeReadOnly( ret )
|
||||
end
|
||||
return ret
|
||||
end
|
||||
return getter
|
||||
end
|
||||
|
||||
local function setter()
|
||||
ULib.error( "Attempt to modify read-only table!" )
|
||||
end
|
||||
|
||||
local function make_pairs( real_table )
|
||||
local function pairs()
|
||||
local key, value, cur_key = nil, nil, nil
|
||||
local function nexter() -- both args dummy
|
||||
key, value = next( real_table, cur_key )
|
||||
cur_key = key
|
||||
if type( key ) == "table" and not metatable_cache[ key ] then
|
||||
key = ULib.makeReadOnly( key )
|
||||
end
|
||||
if type( value ) == "table" and not metatable_cache[ value ] then
|
||||
value = ULib.makeReadOnly( value )
|
||||
end
|
||||
return key, value
|
||||
end
|
||||
return nexter -- values 2 and 3 dummy
|
||||
end
|
||||
return pairs
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: makeReadOnly
|
||||
|
||||
Makes a table and all recursive tables read-only
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table to make read-only
|
||||
|
||||
Returns:
|
||||
|
||||
The table read-only'fied
|
||||
]]
|
||||
function ULib.makeReadOnly( t )
|
||||
local new={}
|
||||
local mt={
|
||||
__metatable = "read only table",
|
||||
__index = make_getter( t ),
|
||||
__newindex = setter,
|
||||
__pairs = make_pairs( t ),
|
||||
__type = "read-only table" }
|
||||
setmetatable( new, mt )
|
||||
metatable_cache[ new ] = mt
|
||||
return new
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: ropairs
|
||||
|
||||
The equivalent of "pairs" for a readonly table, since "pairs" won't work.
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table
|
||||
]]
|
||||
function ULib.ropairs( t )
|
||||
local mt = metatable_cache[ t ]
|
||||
if mt==nil then
|
||||
ULib.error( "bad argument #1 to 'ropairs' (read-only table expected, got " .. type(t) .. ")" )
|
||||
end
|
||||
return mt.__pairs()
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: findInTable
|
||||
|
||||
Finds a value in a table. As opposed to table.HasValue(), this function will *only* check numeric keys, and will return a number of where the value is.
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table to check
|
||||
check - The value to check if it exists in t. Can be any type.
|
||||
init - *(Optional, defaults to 1)* The value to start from.
|
||||
last - *(Optional, defaults to the length of the table)* The value to end at.
|
||||
recursive - *(Optional, default to false)* If true, it will check any subtables it comes across.
|
||||
|
||||
Returns:
|
||||
|
||||
The number of the key where check resides, false if none is found. If init > last it returns false as well.
|
||||
]]
|
||||
function ULib.findInTable( t, check, init, last, recursive )
|
||||
init = init or 1
|
||||
last = last or #t
|
||||
|
||||
if init > last then return false end
|
||||
|
||||
for i=init, last do
|
||||
if t[ i ] == check then return i end
|
||||
|
||||
if type( t[ i ] ) == "table" and recursive then return ULib.findInTable( v, check, 1, recursive ) end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: matrixTable
|
||||
|
||||
Splits a table into a number of given columns. Does not change original table.
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table to split
|
||||
columns, The number of columns to create
|
||||
|
||||
Returns:
|
||||
|
||||
The new table with the column being the first key and the row being the second key.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Initial
|
||||
]]
|
||||
function ULib.matrixTable( t, columns )
|
||||
local baserows = math.floor( #t / columns )
|
||||
local remainder = math.fmod( #t, columns )
|
||||
local nt = {} -- New table after we process
|
||||
local curn = 1 -- What value to grab next from our old table
|
||||
|
||||
for i=1, columns do
|
||||
local numtograb = baserows
|
||||
if i <= remainder then
|
||||
numtograb = baserows + 1
|
||||
end
|
||||
|
||||
nt[ i ] = {}
|
||||
for n=0, numtograb - 1 do
|
||||
table.insert( nt[ i ], t[ curn + n ] )
|
||||
end
|
||||
curn = curn + numtograb
|
||||
end
|
||||
|
||||
return nt
|
||||
end
|
||||
--[[
|
||||
Title: Tables
|
||||
|
||||
Some table helpers.
|
||||
]]
|
||||
|
||||
-- Based off "RecursiveReadOnlyTables" by VeLoSo (http://lua-users.org/wiki/RecursiveReadOnlyTables)
|
||||
|
||||
-- cache the metatables of all existing read-only tables,
|
||||
-- so our functions can get to them, but user code can't
|
||||
local metatable_cache = setmetatable( {}, { __mode = "k" } )
|
||||
|
||||
local function make_getter( real_table )
|
||||
local function getter( dummy, key )
|
||||
local ret = real_table[ key ]
|
||||
if type( ret ) == "table" and not metatable_cache[ ret ] then
|
||||
ret = ULib.makeReadOnly( ret )
|
||||
end
|
||||
return ret
|
||||
end
|
||||
return getter
|
||||
end
|
||||
|
||||
local function setter()
|
||||
ULib.error( "Attempt to modify read-only table!" )
|
||||
end
|
||||
|
||||
local function make_pairs( real_table )
|
||||
local function pairs()
|
||||
local key, value, cur_key = nil, nil, nil
|
||||
local function nexter() -- both args dummy
|
||||
key, value = next( real_table, cur_key )
|
||||
cur_key = key
|
||||
if type( key ) == "table" and not metatable_cache[ key ] then
|
||||
key = ULib.makeReadOnly( key )
|
||||
end
|
||||
if type( value ) == "table" and not metatable_cache[ value ] then
|
||||
value = ULib.makeReadOnly( value )
|
||||
end
|
||||
return key, value
|
||||
end
|
||||
return nexter -- values 2 and 3 dummy
|
||||
end
|
||||
return pairs
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: makeReadOnly
|
||||
|
||||
Makes a table and all recursive tables read-only
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table to make read-only
|
||||
|
||||
Returns:
|
||||
|
||||
The table read-only'fied
|
||||
]]
|
||||
function ULib.makeReadOnly( t )
|
||||
local new={}
|
||||
local mt={
|
||||
__metatable = "read only table",
|
||||
__index = make_getter( t ),
|
||||
__newindex = setter,
|
||||
__pairs = make_pairs( t ),
|
||||
__type = "read-only table" }
|
||||
setmetatable( new, mt )
|
||||
metatable_cache[ new ] = mt
|
||||
return new
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: ropairs
|
||||
|
||||
The equivalent of "pairs" for a readonly table, since "pairs" won't work.
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table
|
||||
]]
|
||||
function ULib.ropairs( t )
|
||||
local mt = metatable_cache[ t ]
|
||||
if mt==nil then
|
||||
ULib.error( "bad argument #1 to 'ropairs' (read-only table expected, got " .. type(t) .. ")" )
|
||||
end
|
||||
return mt.__pairs()
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Function: findInTable
|
||||
|
||||
Finds a value in a table. As opposed to table.HasValue(), this function will *only* check numeric keys, and will return a number of where the value is.
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table to check
|
||||
check - The value to check if it exists in t. Can be any type.
|
||||
init - *(Optional, defaults to 1)* The value to start from.
|
||||
last - *(Optional, defaults to the length of the table)* The value to end at.
|
||||
recursive - *(Optional, default to false)* If true, it will check any subtables it comes across.
|
||||
|
||||
Returns:
|
||||
|
||||
The number of the key where check resides, false if none is found. If init > last it returns false as well.
|
||||
]]
|
||||
function ULib.findInTable( t, check, init, last, recursive )
|
||||
init = init or 1
|
||||
last = last or #t
|
||||
|
||||
if init > last then return false end
|
||||
|
||||
for i=init, last do
|
||||
if t[ i ] == check then return i end
|
||||
|
||||
if type( t[ i ] ) == "table" and recursive then return ULib.findInTable( v, check, 1, recursive ) end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--[[
|
||||
Function: matrixTable
|
||||
|
||||
Splits a table into a number of given columns. Does not change original table.
|
||||
|
||||
Parameters:
|
||||
|
||||
t - The table to split
|
||||
columns, The number of columns to create
|
||||
|
||||
Returns:
|
||||
|
||||
The new table with the column being the first key and the row being the second key.
|
||||
|
||||
Revisions:
|
||||
|
||||
v2.10 - Initial
|
||||
]]
|
||||
function ULib.matrixTable( t, columns )
|
||||
local baserows = math.floor( #t / columns )
|
||||
local remainder = math.fmod( #t, columns )
|
||||
local nt = {} -- New table after we process
|
||||
local curn = 1 -- What value to grab next from our old table
|
||||
|
||||
for i=1, columns do
|
||||
local numtograb = baserows
|
||||
if i <= remainder then
|
||||
numtograb = baserows + 1
|
||||
end
|
||||
|
||||
nt[ i ] = {}
|
||||
for n=0, numtograb - 1 do
|
||||
table.insert( nt[ i ], t[ curn + n ] )
|
||||
end
|
||||
curn = curn + numtograb
|
||||
end
|
||||
|
||||
return nt
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user