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

[SOLVED] Checking if players around

Status
Not open for further replies.

EmuNoob

Exalted Member
Hello, struggling with a script for creature to check if there are any players around.. if there are none cast aura upon it self
 
Last edited:

Rochet2

Moderator / Eluna Dev
So what part of the script are you having a problem with?
What is difficult in making the script? Why and what is it that you cant get?

Have you already made/tried something?
 

EmuNoob

Exalted Member
The whole thing, I just don't know how to do it. I tried with IsWithinDistInMap but when the player is in the area it blinks out and in from the aura (stealth)......
Just ran out of ideas..

The basic idea was that NPC stays in the stealth mode, player come close and the NPC will reveal itself and ofcourse if player leaves it goes back into stealth.. Last part seems to be the biggest problem :RpS_sad:

Or just to make the npc half visible but can't find the way how to make it, sadly. (can't find a proper aura, or a spell just makes the npc totally invisible)
 
Last edited:

Grandelf

Esteemed Member
By the lack of info I assumed that the creature attacks the player.
The easiest way of doing such a thing, would be something like this:
Code:
local npc_id = 24575;
-- Aura
local SPELL_STEALTH = 1784;
-- Events
local CREATURE_EVENT_ON_AIUPDATE = 7;

local function onAIUpdate(_, creature)
	if not creature:IsInCombat() and not creature:HasAura(SPELL_STEALTH) then
		creature:CastSpell(creature, SPELL_STEALTH, true);
	-- Uncomment this part if the stealth spell isn't automatically removed.
	--[[elseif creature:IsInCombat() and creature:HasAura(SPELL_STEALTH) then
		creature:RemoveAura(SPELL_STEALTH);]]
	end
end
RegisterCreatureEvent(npc_id, CREATURE_EVENT_ON_AIUPDATE, onAIUpdate);
This script makes the creature enter stealth, when the creature attacks it will automatically remove stealth.
If the npc leaves combat he will enter stleath again.

For future support threads, you should consider posting the script that you have made so far.
This just makes it easier to help you, because right now I am not sure what you want to use this script for.
 
Last edited:

EmuNoob

Exalted Member
Yeah the thing is it's not about combat, if it would I'd already done that. Thing is that the NPC stays hidden in stealth, and when player comes around he pops out for interaction , and when player leaves he should disappear again. The dissapear thing is the biggest problem for me since I have no idea how to handle that, and yeah sorry I will be more precise next time in my support requests, sorry !
 

Grandelf

Esteemed Member
Alright well, the method you are probably looking for is: :GetPlayersInRange(range)
Modifying my other script would result in something like this:
Code:
local npc_id = 24575;
-- Range in yards for the creature to appear / dissapear.
local RANGE = 10;
-- Aura (Uber Stealth, makes the creature completely invisible).
local SPELL_STEALTH = 10032;
-- Events
local CREATURE_EVENT_ON_AIUPDATE = 7;

local function onAIUpdate(_, creature)
	local players = creature:GetPlayersInRange(RANGE);
	if #players > 0 and creature:HasAura(SPELL_STEALTH) then
		creature:RemoveAura(SPELL_STEALTH);
	elseif #players == 0 and not creature:HasAura(SPELL_STEALTH) then
		creature:CastSpell(creature, SPELL_STEALTH, false);
	end
end
RegisterCreatureEvent(npc_id, CREATURE_EVENT_ON_AIUPDATE, onAIUpdate);
 
Last edited:
Status
Not open for further replies.
Top