So basically last night I started work on a Proof-of-Concept for an auto-teleport whenever a player enters a pre-defined vector box. It requires separate functions to run in two different states: one constantly and another only once. I’ll do the part with ents.FindInBox on my own. But I need to know which hook to use outside of that HUDPaint hook to trigger the separate teleporter hook itself? I need to execute the teleporter hook only once when a condition is met. Something like:
function getplayerposition() <if player is in vector box then shouldteleport = true end> end hook.Add("HUDPaint", "getplayerposition", getplayerposition) function teleport(ply) ply:SetPos(Vector(10,10,50)) ply:SetAngles(Angle(0,0,0)) end --//THIS IS THE HOOK I NEED hook.Add("???", "teleport", teleport)
I’ve tried so many different hooks for that teleport section and none of them will execute when called from the HUDPaint function. I can get the teleport hook to work if it’s attached to something like ShowSpare1 when the F3 key is pressed. But trying to run the hook otherwise does not function. Nor does attaching it to a concommand.
Is there any type of single-execution hook that I can call at any time the instant a boolean variable becomes true? I’m not asking anyone to write this out for me, I really just need the name of the hook(s) to use. I cannot for the life of me identify any single hook that will function the way I need it to.
The problem with this entire concept for me is that I can’t get the two execution states to co-exist. I need part of the code that runs constantly (the position checking) and another part (the teleport) that runs only once. So far my attempts result with the teleport never being executed because the hook was idle when the vector conditions were met, or the teleport runs constantly (or not at all) because the trigger is executed over and over in a HUDPaint hook.
Ideas and suggestions please?
[editline]22nd December 2014[/editline]
Nevermind guys, lol. Figured it out on my own. I saw a tutorial by AceCool about a “drowning system” which lead me to the CalcMainActivity hook, and as a shot in the dark I tried it and it worked.
So if you guys want a system that can, all in one function, detect a player’s position and teleport them elsewhere based on a detected box, use this:
hook.Add("CalcMainActivity", "teleport", teleport)