[LUA] NPC Channeling Question ! menu

User Tag List

Results 1 to 3 of 3
  1. #1
    ~ Sh3ll's Avatar Member
    Reputation
    1
    Join Date
    Dec 2016
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [LUA] NPC Channeling Question !

    Hey there OwnedCore community.
    I would like to make two NPCs , one of em channel a spell on another one , But the script doesnt work for some reasons :
    Actually the script works since the channeler npc yells a text as its intended but it just doesnt channel the spell :

    here is the script :

    PHP Code:

    local target 
    nil 
    local Channeler 
    100006 
    local ChannelerTarget 
    100007 

    function Channel_NPC(pUnitEvent)
        
    pUnit:SendChatMessage(140"Test Text")
        
    pUnit:RegisterEvent("Check"25000)
    end

    function Check(pUnitEvent)
        if 
    target ~= nil then
        pUnit
    :ChannelSpell(689target)
        
    pUnit:RemoveEvents()
        
    end
    end

    RegisterUnitEvent
    (Channeler1"Channel_NPC")

    function 
    target_on_load(pUnitEvent)
        
    target pUnit
    end

    RegisterUnitEvent
    (ChannelerTarget18"target_on_load"

    Any help will be appreciated.

    Thanks.

    [LUA] NPC Channeling Question !
  2. #2
    ~ Sh3ll's Avatar Member
    Reputation
    1
    Join Date
    Dec 2016
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bump !

    Anyone ?

  3. #3
    stoneharry's Avatar Moderator Harry


    Reputation
    1618
    Join Date
    Sep 2007
    Posts
    4,564
    Thanks G/R
    151/150
    Trade Feedback
    0 (0%)
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    So what Lua engine are you using? I'm going to answer this post assuming Eluna. ArcEmu is far behind because it has been dead for years now and is unstable and full of bugs in core areas of game functionality.

    There are not methods for this available in the Eluna engine, or at least not in the version I am on. I am quite out of date. You could implement some, or I made some utility Lua functions to help with this sort of thing.

    File name: Utility.ext
    Code:
    function Creature:IsCasting()
    	return self:HasUnitState(0x00008000)
    end
    
    function Player:IsCasting()
    	return self:HasUnitState(0x00008000)
    end
    
    function Creature:ChannelSpell(target, id)
    	self:SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, target:GetGUID());
    	self:SetUInt32Value(UNIT_CHANNEL_SPELL, id);
    end
    
    function Creature:StopChannel()
    	self:SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, 0);
    	self:SetUInt32Value(UNIT_CHANNEL_SPELL, 0);
    end
    
    function Creature:GetCreature(range, id)
    	return GetCreature(range, id, self)
    end
    
    function GetCreature(range, id, pUnit)
    	local t = pUnit:GetCreaturesInRange(range, id)
    	if not t or #t == 0 then
    		return nil
    	end
    	if #t > 1 then
    		for _,v in pairs(t) do
    			if v:GetPhaseMask() == pUnit:GetPhaseMask() then
    				return v
    			end
    		end
    	end
    	return t[1]
    end
    
    function Creature:IsFacing(target, compareAngle)
    	local x = target:GetX() - self:GetX()
    	local y = target:GetY() - self:GetY()
    	
    	local angle = math.atan2(y, x)
    	if (angle < 0.0) then
    		angle = 2.0 * math.pi + angle
    	end
    	angle = angle - self:GetO()
    	
    	while (angle > math.pi) do
    		angle = angle - 2.0 * math.pi
    	end
    	while (angle < -math.pi) do
    		angle = angle + 2.0 * math.pi
    	end
    	
    	-- reduce or increase angle
    	--local compareAngle = (60 * math.pi) / 180 --math.pi
    	
    	local left = -1.0 * (compareAngle / 2.0)
    	local right = (compareAngle / 2.0)
    	
    	return (angle >= left) and (angle <= right)
    end
    
    function sendAddonMessage(plr, msg, packet)
    	local splitLength = 240
    	local splits = math.ceil(msg:len() / splitLength)
    	local send
    	local counter = 1
    	for i=1, msg:len(), splitLength do
    		send = string.format("%03d", packet)
    		send = send .. string.format("%02d", counter)
    		send = send .. string.format("%02d", splits)
    		if ((i + splitLength) > msg:len()) then
    			send = send .. msg:sub(i, msg:len())
    		else
    			send = send .. msg:sub(i, i + splitLength)
    		end
    		counter = counter + 1
    
    		if _DEBUG then print("[SENT] " .. send) end
    		plr:SendAddonMessage(send, "", 7, plr)
    	end
    end
    
    function scen_split(str)
    	local b = {}
    	local c = 1
    	local d = {}
    	string.gsub(str, "[%w%s-]", function(a)
    		if (a == "-") then
    			c = c + 1
    		else
    			if (not b[c]) then
    				b[c] = {}
    			end
    			table.insert(b[c], a)
    		end
    	end)
    	for k, v in pairs (b) do
    		table.insert(d, table.concat(v))
    	end
    	return d
    end
    Then in your other Lua scripts you can call:

    Code:
    local spellId = 11
    local target = creature -- target can be self or any other unit reference
    creature:ChannelSpell(target, spellId)
    ...
    creature:StopChannel()
    The script actually calls variables that need to be defined. I have a Constants.ext file but you can put it at the top of the same script if you want to.

    Code:
    OBJECT_END 						= 0x0006
    UNIT_NPC_EMOTESTATE 			= OBJECT_END + 0x004D
    UNIT_FIELD_BYTES_1 				= OBJECT_END + 0x0044
    UNIT_FIELD_BYTES_2 				= OBJECT_END + 0x0074
    UNIT_FIELD_FLAGS 				= OBJECT_END + 0x0035
    UNIT_FIELD_FLAG_UNTARGETABLE	= 33554434
    UNIT_FIELD_FLAG_UNATTACKABLE	= 2
    UNIT_FIELD_FLAG_C_UNATTACKABLE	= 770
    UNIT_FIELD_CHANNEL_OBJECT 		= OBJECT_END + 0x000E
    UNIT_CHANNEL_SPELL 				= OBJECT_END + 0x0010
    GAMEOBJECT_BYTES_1				= OBJECT_END + 0x000B
    There are more flags than this in the game, these are just the ones I have used so far on something I am working on.

    Oh and you cannot store references to objects in member variables like that. You have to obtain the reference when you need it and not pass it between functions. Eluna will now actually detect you doing this and warn you from doing it while disabling the functionality. Other game engines had the potential to crash.

    One way would be to use a function from my utility script:
    Code:
    function Creature:GetCreature(range, id)
    Code:
    local creature = unit:GetCreature(40, 10811)
    But I am, pretty sure there's a better way (like storing the GUID and then getting creature by GUID) but I cannot find the method from a quick scan.
    Last edited by stoneharry; 12-04-2016 at 11:22 AM.

Similar Threads

  1. Lua Npc's healing each other?
    By anything in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 12-05-2008, 02:08 PM
  2. Replies: 40
    Last Post: 11-04-2008, 04:03 PM
  3. NPC Spawn Question
    By Devilsadvocate in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 08-07-2008, 04:47 PM
  4. [Lua] NPC Announcer
    By Maven01 in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 06-19-2008, 03:34 PM
  5. Lua Scripting, a question on mob targeting
    By adarant_dru in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 06-08-2008, 07:28 PM
All times are GMT -5. The time now is 07:22 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search