View Full Version : TrinityCore WotLK Protect an area with LUA.

05-06-2016, 09:52 PM
Is It possible to create an "imaginary" area surround an NPC so when a player go inside this area he gets teleported out if he hasn't got an item?

I know you can protect AreaId and MApsId but I want to protect a range in exact coordinates where an NPC is spawned, is that possible?

If It is possible what functions I should use?

Sorry my bad english.

05-06-2016, 10:27 PM
Yeah, you can do this. Depends on how much radius you wanna cover though.

I would suggest creating a trigger or use the npc itself as a trigger.

You could use:

CREATURE_EVENT_ON_MOVE_IN_LOS = 27, // (event, creature, unit)

Hook, but I don't know how big you want your radius. To solve that you could create an event (or use AI Update hook) and call one of these methods:

:GetNearObjects(..) (http://eluna.emudevs.com/WorldObject/GetNearObjects.html)
:GetNearestPlayer(...) (http://eluna.emudevs.com/WorldObject/GetNearestPlayer.html)
:GetPlayersInRange(...) (http://eluna.emudevs.com/WorldObject/GetPlayersInRange.html)


local Trigger = { }
local triggerEntry = 1234

function Trigger.OnSpawn(event, creature)
creature:RegisterEvent(Trigger.YouShallNotPass, 1000, 0)

function Trigger.YouShallNotPass(event, delay, repeats, creature)
local nearestPlayer = creature:GetNearestPlayer(30) -- 30 = radius (somewhat of a decent radius)
if (nearestPlayer ~= nil) then -- If we found a player, teleport them!
nearestPlayer:Teleport(1, 1, 1, 1, 0) -- Map, x, y, z, o

RegisterCreatureEvent(triggerEntry, 5, Trigger.OnSpawn)

05-07-2016, 01:46 AM
there is also:


where the range is in game yards I think.
it will return a table of all the players within x game yards.


use the (MovementLineOfSight event or the AIUpdate event) and get all players within range and check for x then do y. :)

05-07-2016, 08:21 AM
Thank you I will check it as soon as possible.