Entity hooks, without the scripted entities/entities directories.

So, I need to modify some entities when a map spawns. Specifically, entities in the map itself: func_door, func_button and func_movelinear. For what I need to do, I’ll be needing KeyValues, and Touch/EndTouch hooking. I’ve found much of what I need for setting/getting entdata, but it seems the hooks I need aren’t as straight forward as others. There’s no explanation of how I might go about hooking these functions. I noticed the ENT:Hook appears in SENT code I’ve seen in the sandbox source. My question is can I access these hooks without creating a SENT? A SENT seems impractical for what I need, which are 3 entities that need to be altered based on OTHER entities in the map. They also need to interact (touch/endtouch) with players through my main server script. Besides, I don’t quite understand SENTs, and can’t find a decent explanation/tutorial for them, except for the obviously useful wiki page. Ideas/suggestions/further reading appreciated! Thanks again.

I must be doing scripted entities wrong.

garrysmod/gamemodes/mygamemode/entities/entities/func_door/init.lua



ENT.Type = "brush"

function ENT:Initialize()
    Msg("Ent Init Test
")
end

Msg("File Init Test
")


Nothing happens on map change. I’m only interested in getting information from entities and using entity hooks, nothing more. ARGH.

I don’t think you’ll be able to do that. These entities are already defined and you may not change their behavior directly with such a script. What you can use are gamemode hooks to detect when a player tries to interact with these entities (touch, damage, use…).

Hmm, I’ve seen the exact thing I’m trying to do on a GMod server before, and also the same on CS:S through http://www.sourcemod.net/. I don’t think what I need can be done any other way than accessing keyvalues, and hooking Touch/EndTouch (I should hope Touch/EndTouch works with existing entites, as this functionality is even working in old school CS1.6/HL1 through scripting).

Could you please explain what it is you want to do? Certainly you would then receive more adequate help.

[editline]04:08PM[/editline]

Also : **[Entity.GetKeyValues

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.GetKeyValues)**

OK. I’ll explain exactly what I want to do. I’ll start from the beginning since it’s a bit obscure.

“Bhop” or “Bunny Hopping” (lame as it sounds) is a type of gameplay where players jump from brush to brush trying not to fall. There’s usually a limited amount of time a player can stay on the brush before it falls. The brush entities usually used in maps are: func_doors, func_buttons, or func_movelinears. The brushes move down when touched, and as you can imagine, if you have many players on a server, and the brushes are falling down each time they are touched, it can get very frustrating to play.

So what I’m trying to do here, is to re-create a multi-player friendly bhop addon from CS:S. (http://forums.alliedmods.net/showthread.php?p=808724)

The goal is to stop the brushes moving when players jump on them, while still teleporting them from the brushes they stayed on for too long (by tracing a teleport trigger from the brushes original movement patterns, origins, mins, maxs, etc.)

Here’s some pseudo code as an example of what I believe needs to be done (and what is done in the original mpbhops addon).



on map start
  find all func_doors, func_buttons, func_movelinears
  if they look like bhop brushes (moving down, not too big etc.)
    look for teleport triggers overlapping either their highest, or lowest position
    if we found a teleport trigger for the brush
      remember the brush is a bhop, store value of the trigger_teleports destination/location
      edit the brush (no sounds, no movements etc.)
end

on entity touch (func_doors, func_buttons, func_movelinears)
  if we saved a teleport destination for this entity
    allow the player to stay touching the entity for x seconds
    if the player has stayed too long
      teleport the player to the destination relative to the entity
end


So, yeah. Basically I’ll be needing to retrieve and set entdata for the brushes (all the data I need seem to be listed as keyvalues on the wiki pages for the brush entities). Other than that, I’ve already noted the functions I’ll be needing from the GMod wiki (OBBMins/OBBMaxs/GetPos, etc.). And of course, I’ll be needing those Touch hooks too D:

I looked at that function, but this really put me off using it:

I tried the hook too, but it didn’t seem to do anything, I just assumed it was for entities that have keyvalues set after the map has loaded.

Here’s a couple of posts trying to do similar things with keyvalues that I havn’t managed to get anything useful from:

http://www.facepunch.com/showthread.php?t=580281
http://www.facepunch.com/showthread.php?t=753241

And a quote which seems to be the exact thing I want to do, but it’s through scripted entities (ENT:KeyValue) which I have no idea about!

Mk. That’s all I have!

bump this is useful

Mmk. I just checked some capture point code from the recent fretta contest entry called battlesource. They used a func_capturepoint brush SENT for the capture points. So, I stripped the code so it would be usable for my func_door test:



ENT.Type = "brush"
ENT.Active = true

function ENT:Initialize()
    Msg("

Capture Init

")
end

function ENT:StartTouch( ent )
    Msg("

Capture Start Touch

")
end

function ENT:EndTouch( ent )
    Msg("

Capture End Touch

")
end


And… It worked for func_capturepoint but not for func_door (in the exact same circumstances).

Is there a workaround, or something I can do?

Also,

Is there a gamemode hook for touch? I don’t see one.

No there is no gamemode hook for touch and no, there is no work-around. Their func_capturepoint entity is not defined in the game so when looking for something to spawn there the game found their lua version. In your case the doors already exist and there is nothing you can do about it.

Thanks.