• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore WotLK Protect an area with LUA.

susumakusu

Enthusiast
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.
 

Tommy

Founder
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:

Code:
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(..)
:GetNearestPlayer(...)
:GetPlayersInRange(...)


Example:

Code:
local Trigger = { }
local triggerEntry = 1234

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

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
    end
end

RegisterCreatureEvent(triggerEntry, 5, Trigger.OnSpawn)
 
Top