Ranged npc (normal fire) problem. menu

User Tag List

Results 1 to 3 of 3
  1. #1
    BurnDownTheSystem's Avatar Private
    Reputation
    1
    Join Date
    Jun 2012
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ranged npc (normal fire) problem.

    Hi there im working on a project but got stuck once I tried to make an npc ranged, I want it to cast the normal shoot spell (301 or just shoot an arrow out of a bow that deals dmg, doesnt make a difference to me.

    So the question ~ how do I make an npc shoot in range creatures & players?

    Currently I got this which doesnt work:

    Code:
    local ArcherEntryID = 60607
    
    function Arch(pUnit, event)
    	Archer = pUnit
    end
    
    RegisterUnitEvent(ArcherEntryID, 18, "Arch")
    
    function Archer_OnCombat(pUnit, event)
    		Archer:Root()
    		Archer:RegisterEvent("Shoot", 500, 1)
    end
    
    RegisterUnitEvent(60607, 1, "Archer_OnCombat")
    
    function Shoot(pUnit, event)
    	Archer:CastSpell(3018)
    	Archer:RegisterEvent("ShootAgain", 500, 1)
    end
    
    function ShootAgain(pUnit, event)
    	Archer:CastSpell(3018)
    	Archer:RegisterEvent("Shoot", 500, 1)
    end
    Would appriciate it if someone could help me out

    Ranged npc (normal fire) problem.
  2. #2
    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)
    Here, this code snippet should help:

    Code:
    function AntiAirTowerSpawn(pUnit, Event)
    	if Event == 18 then
    		-- If a npc spawns, make it check for nearby units every 1.5 seconds
    		pUnit:RegisterEvent("AntiAirTowerShoot", 1500, 0)
    	else
    		-- If it dies, remove events
    		pUnit:RemoveEvents()
    	end
    end
    
    function AntiAirTowerShoot(pUnit)
    	local found = false
    	-- Get all units
    	for _, unit in pairs(pUnit:GetInRangeUnits()) do
    		if unit:IsAlive() then
    			-- This just makes us face who we are shooting
    			local x, y, z = pUnit:GetLocation()
    			pUnit:SetPosition(x, y, z, pUnit:CalcRadAngle(x, y, unit:GetX(), unit:GetY()))
    			-- This deals damage - in combat log it will show spell 61647 being used (can be any spell)
    			-- It is dealing 100 damage
    			-- On critical strike, it will do double damage (1)
    			pUnit:Strike(unit, 2, 61647, 100, 100, 1)
    			pUnit:CastSpellOnTarget(61647, unit) -- shoot bow
    			-- Mark we have found somebody
    			found = true
    			-- Stop searching if we found somebody
    			break
    		end
    	end
    	-- If no creature was found
    	if not found then
    		-- Search players
    		for _, plr in pairs(pUnit:GetInRangePlayers()) do
    			if plr:IsAlive() then
    				-- This just makes us face who we are shooting
    				local x, y, z = pUnit:GetLocation()
    				pUnit:SetPosition(x, y, z, pUnit:CalcRadAngle(x, y, plr:GetX(), plr:GetY()))
    				-- This deals damage - in combat log it will show spell 61647 being used (can be any spell)
    				-- It is dealing 100 damage
    				-- On critical strike, it will do double damage (1)
    				pUnit:Strike(plr, 2, 61647, 100, 100, 1)
    				pUnit:CastSpellOnTarget(61647, plr) -- shoot bow
    				-- Mark we have found somebody
    				found = true
    				-- Stop searching if we found somebody
    				break
    			end			
    		end
    	end
    end
    
    RegisterUnitEvent(485211, 18, "AntiAirTowerSpawn") -- 485211 = npc id
    RegisterUnitEvent(485211, 4, "AntiAirTowerSpawn")

  3. #3
    BurnDownTheSystem's Avatar Private
    Reputation
    1
    Join Date
    Jun 2012
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot stoneharry also thanks for pointing out what everything is, you've been a great help would love to +rep you but wont let me :s will do it as soon as I can give it

Similar Threads

  1. [Selling] Selling Great 1 Def Pure ! 60 Atk / 97 Str / 85 Range ! Mithril Gloves & Fire Cape
    By RobertoRusso in forum Runescape Buy Sell Trade
    Replies: 2
    Last Post: 10-18-2015, 04:47 PM
  2. [Lua Script] Ranged NPC problems.
    By bendaferi in forum WoW EMU Questions & Requests
    Replies: 9
    Last Post: 03-15-2012, 12:07 PM
  3. [Trinity] [C++] NPC Gossip Option Problem
    By 4BOLTMAIN in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 08-23-2011, 05:32 PM
  4. Arcane to Fire problem
    By xozyc in forum WoW ME Questions and Requests
    Replies: 5
    Last Post: 08-01-2008, 05:33 PM
  5. How do you make a ranged npc?
    By justsum1 in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 01-28-2008, 08:37 PM
All times are GMT -5. The time now is 07:46 AM. 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