Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Base hooks

Alessio Malato edited this page Apr 25, 2016 · 20 revisions

There's some hooks that you don't really want to touch to keep the functionality of the predicted entity base, so here we will only cover the ones that are supposed to be overridden.

πŸ”· ENT:OnAttach( ply , forced )

Called when this entity is finally attached to a player, you should use this function to prepare your variables for player use, of course, you want to keep the ones that should be persistent across players intact ( such as the fuel or ammo ).

The default behavior of this function is to do nothing.

πŸ”· ENT:OnDrop( ply , forced )

Called when this entity is finally dropped from a player, you should reset your per-player variables here. The player parameter might be NULL. In the case of the jetpack, the entity keeps flying when the player dies while using it or if it was a forced drop.

The default behavior of this function is to do nothing.

πŸ”· ENT:CanPlayerEditVariable( ply , key , val , editor )

Called when the player wants to edit any datatable variable ( that are exposed, of course ) with sandbox's edit menu. Key and Val arguments are both strings, and editor is the table that was assigned during DefineNWVar ( if there was one ).

You can return false to not allow the player to edit the specified key, in case your logic says that is not a valid operation.

The default behavior of this function is to do nothing.

πŸ”· ENT:CanEditKey( ply , val , editor )

Same as above, but only called when "Key" is modified, which is the button on the keyboard ( or mouse or gamepad ) that should be pressed to trigger the "InButton".

This function is not called if the button is deemed not allowed in the first place ( used by ENT.KeyAllowedFlags )

The default behavior of this function is to only allow editing by the owning player or by anyone when not carried.

πŸ”· ENT:CanAttach( ply )

Called when the player wants to pickup this entity, return false to stop the pickup.

This is not called when the pickup is forced, which is why this function does not have that argument.

The default behavior of this function is to do nothing.

πŸ”· ENT:CanDrop( ply )

Called when the player wants to drop this entity, return false to stop the drop.

This is not called when the drop is forced, which is why this function does not have that argument.

The default behavior of this function is to do nothing.

πŸ”· ENT:OnInitPhysics( physobj )

Called after the physics object has been intialized, and you want to modify some parameters such as mass or collision group.

The default behavior of this function is to do nothing.

πŸ”· ENT:OnRemovePhysics( physobj )

Called before the physics object is removed.

The default behavior of this function is to do nothing.

πŸ”Ά ENT:HandleLoopingSounds()

Called during prediction or normal entity hook, but never for both at the same time.

You should play your looping sounds here, based on your networked variables.

The default behavior of this function is to do nothing.

πŸ”Ά ENT:DrawOnViewModel( ply , vm , hands )

Called when the viewmodel is drawn, useful when you want to show something on the player's viewmodel.

The default behavior of this function is to do nothing.

πŸ”Ά ENT:DrawFirstPerson( ply )

Similar to the viewmodel drawing hook, this uses the same depth modifiers as to not clip anything that is drawn here trough objects.

This function is ideal if you want to show something like a shoulder mounted cannon without having to rely on a viewmodel to be present ( and also to ignore the viewmodel's view bobbing )

The default behavior of this function is to do nothing.

πŸ”Ά ENT:Draw( flags )

You should know what this function does, regardless, this function is called both when the entity is not picked up and when it's attached to the player.

The default behaviour of this function is to call self:DrawModel()

πŸ”Ά πŸ”· ENT:Think()

Called when the entity thinks on its own, you should call your non-player equipped logic here.

You should always call the baseclass function here as it does some important checks.

The default behavior of this function is to do some internal checks about prediction and the looping sounds function.

πŸ”Ά πŸ”· ENT:HandleMainActivityOverride( ply , velocity )

Called when the main activity of the player needs to be configured, return the ideal ACTIVITY and ideal SEQUENCE.

The default behavior of this function is to do nothing.

πŸ”Ά πŸ”· ENT:HandleUpdateAnimationOverride( ply , velocity , maxseqgroundspeed )

Called after HandleMainActivityOverride to configure the movement parameters and other gestures.

Return true to override the default behavior from the main hook.

The default behavior of this function is to do nothing.

πŸ”Ά πŸ”· ENT:HandleAnimationEventOverride( ply , event , data )

Called when an animation event has been triggered, return the ACTIVITY you want to be played instead, or just play the gesture here yourself.

Return ACT_INVALID when you find your event and data to stop other hooks from handling it.

The default behavior of this function is to do nothing.

πŸ”Ά πŸ”· ENT:PredictedStartCommand( ply , cmd )

πŸ”Ά πŸ”· ENT:PredictedPlayerButtonPress( ply , btn , pressed )

πŸ”Ά πŸ”· ENT:PredictedSetupMove( ply , mv , cmd )

πŸ”Ά πŸ”· ENT:PredictedMove( ply , mv )

πŸ”Ά πŸ”· ENT:PredictedThink( ply , mv )

πŸ”Ά πŸ”· ENT:PredictedFinishMove( ply , mv )

πŸ”Ά πŸ”· ENT:PredictedHitGround( ply , inwater , onfloater , speed )

Clone this wiki locally