Garry's Mod

Garry's Mod

151 ratings
Long Use Entity Base
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Tool
Addon Tags: Fun, Realism
File Size
Posted
Updated
7.553 KB
Jul 2, 2020 @ 8:32pm
Apr 16, 2023 @ 3:44pm
13 Change Notes ( view )

Subscribe to download
Long Use Entity Base

In 1 collection by SweptThr.one
SweptThrone Catalogue
135 items
Description
Make entities that take time to use.

//

This addon is more for DEVELOPERS who are making their OWN ENTITIES that they want to have hold-to-use functionality. If you are a REGULAR USER, it is likely you will have NO REASON to use this addon unless another addon requires it.

Long Use Entity Base gives you an entity (long_use_base) that grants you the power to make "hold-to-use" entities.

To use this entity base, set your custom entity's ENT.Base to "long_use_base" and then make sure you take the following steps to make your entity utilize this base properly:
• In your ENT:Initialize function, set your use type to continuous via self:SetUseType( CONTINUOUS_USE ).
• Rename your ENT:Use function to ENT:OnUseFinish. This new function only has one argument: the player using the entity.
• Set ENT.TimeToUse to however many seconds you want your players to have to hold your entity for. This must be shared.
• Optionally ENT:SetDrawKeyPrompt( false ) if you don't want the E key to show on screen.
• Optionally ENT:SetDrawProgress( false ) if you don't want the progress ring to show on screen.
• Create a server function ENT:OnUseStart( ply ) that gets called when a player starts holding E on the entity. This can be empty, but it should be there.
• Create a server function ENT:OnUseCancel( ply ) that gets called when a player releases E early. This can be empty, but it should be there.
• Optionally create a shared ENT.PartialUses table with values being tables with a number "prog" as the whole-number percentage of use to call the function "func" to do at the respective step (with the entity as its only argument).
And that's all! Your long-use entity should be ready to go!

If you need a custom SetupDataTables hook, you must do the following:
• Add the line DEFINE_BASECLASS( ENT.Base ) somewhere near the top of the file, but under your definition of ENT.Base.
• Add your NetworkVars. If you need a Float and/or an Entity, start at 1 for each instead of 0, and for Bool, start at 2! This base uses Float and Entity slot 0 and Bool slots 0 and 1 to work!
• Do all of the rest of your SetupDataTables code.
• As the last line of your SetupDataTables hook, add the line BaseClass.SetupDataTables( self ).

If you need a custom Think hook, you must do the following:
• Add the line DEFINE_BASECLASS( ENT.Base ) somewhere near the top of the file, but under your definition of ENT.Base.
• Do all of your Think code.
• As the last line of your Think hook, add the line BaseClass.Think( self ).

This entity adds a server function unique to it and derived entities, ENT:CancelUse( b ), which will successfully cancel use if called. Passing true into this function will call the entity's OnUseCancel hook, otherwise it will not.

Better documentation for this addon's custom hooks and functions can be found here[docs.sweptthr.one].

If you decide to use this addon, please add it as a required addon to your addon, instead of packaging this addon's code within your own. This may get updated in the future.

This requires the newest version of Garry's Mod to function! It uses a new function that doesn't seem to be supported in the Chromium branch, which is outdated!

If you find any problems with this addon, please report them immediately either in the comments or on my Discord server.

I made this just to do something during this quarantine.


[sweptthr.one]

Credits:
theawesomecoder61 - Reuploading arc-drawing code[gist.github.com]
Me - The rest of the code
16 Comments
lambups Mar 20, 2021 @ 3:20am 
finally i can eat boorgers
lambups Feb 24, 2021 @ 2:19am 
actually, i think it'd be possible to recreate payday 2 using this
Drunk Headcrab Jan 31, 2021 @ 8:30pm 
Guys, the thermal drill, go get it
SweptThr.one  [author] Oct 1, 2020 @ 7:06pm 
no
stevensky Oct 1, 2020 @ 3:25pm 
works on doors?
SweptThr.one  [author] Aug 3, 2020 @ 7:01pm 
speaking of, apparently this doesn't work if you just subscribe to it, and i don't get how, which is why it's on github
SweptThr.one  [author] Aug 3, 2020 @ 7:01pm 
there isn't because it's kinda a hackjob when it comes to releasing. it's on github if you wanna fuck around with it lol
Darsu Jul 27, 2020 @ 7:30am 
Is there a function for use key release? Or how can I write this function?
80Hg Jul 4, 2020 @ 11:42am 
time to steal this code for if i ever decide to finish my l4d hud
80Hg Jul 4, 2020 @ 11:37am 
now this is actually based