Spawn NPCs Near a Player menu

User Tag List

Results 1 to 3 of 3
  1. #1
    choweyiii's Avatar Contributor
    Reputation
    91
    Join Date
    Aug 2010
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Spawn NPCs Near a Player

    I've been trying for some time now to spawn NPCs near players for some time now, sure spawning them directly on top of players is easy using this code:

    Code:
    plr:SpawnCreature(900042, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), 2212, 0, 0, 0, 0, plr:GetPhase(), save)
    But the problem is, that causes several NPCs to stack on top of each other, which makes targeting difficult, and I would love to see them spawn just a few yards away. I've tried some things with the math function and desperately just adding +'s to the GetCords but it appears I have no idea what I'm doing. Any help would be greatly appreciated and I'll reward rep for any helpful comment. Thank you.

    Spawn NPCs Near a Player
  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)
    North, East, South and West is represented as -X, -Y, +X, +Y.

    Note, it may be +X, +Y, -X, -Y, cannot remember.

    This is similar to sin, cos, -sin, -cos in calculus. The same rules apply: You can calculate angles and distances between different points to create what you want. For example:

    Code:
    function ZG.VAR.FireballExplode(pUnit)
    
    	local x2 = pUnit:GetX()
    	local y2 = pUnit:GetY()
    	
    	pUnit:CastSpell(76010) -- visual
    	pUnit:RemoveAura(71706) -- main visual
    	
    	for _,plr in pairs(pUnit:GetInRangePlayers()) do
    		local distance = plr:GetDistanceYards(pUnit)
    		if plr:GetPhase() == 2 and distance < 20 then
    		
    			local minimum = distance*40
    			local maximum = distance*50
    			
    			pUnit:Strike(plr, 2, 72134, minimum, maximum, 0.1)		
    		
    			local x1 = plr:GetX()
    			local y1 = plr:GetY()
    
    			local x = x2 - x1
    			local y = y2 - y1
    			
    			local angle = math.pi + math.atan2(-y, -x)
    
    			local x = x1 - ((math.random(25,30)-distance) * math.cos(angle))
    			local y = y1 - ((math.random(25,30)-distance) * math.sin(angle))
    			
    			local z = pUnit:GetLandHeight(x, y)
    			if z > 200 or z < 20 then
    				z = plr:GetZ()
    			end
    			
    			plr:MoveKnockback(x, y, z, 2, 9)
    			
    		end
    	end
    end
    I use this code to get the point between the npc and the player, then calculate a location based on the distance following that line:



    You could use a similar formula to get a location slightly further away each time. Or you can just add/take away to X and Y and use the following function to get land height:

    unit:GetLandHeight(x,y) -- returns Z at location of X, Y if maps and vmaps are enabled.

  3. #3
    choweyiii's Avatar Contributor
    Reputation
    91
    Join Date
    Aug 2010
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, stoneharry. I'll try to make sense of this in the coming days :P

Similar Threads

  1. Npc models as player model?
    By Almgandi in forum WoW Memory Editing
    Replies: 4
    Last Post: 08-23-2008, 05:39 AM
  2. Help needed - I cannot talk to spawned NPCs
    By ADAMZY in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 11-23-2007, 08:02 AM
  3. custom/spawned npc wont save when i spawned them
    By bjorn11 in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 11-19-2007, 10:04 AM
  4. Spawn NPC not working..
    By Volcomchamp in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 10-01-2007, 04:27 AM
  5. Removing spawned NPC's for good?
    By lazboy in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 08-31-2007, 09:14 AM
All times are GMT -5. The time now is 06:14 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