[Lua] Custom Targeting Command menu

User Tag List

Results 1 to 6 of 6
  1. #1
    Vision1000's Avatar Member
    Reputation
    104
    Join Date
    Jun 2008
    Posts
    122
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Lua] Custom Targeting Command

    Well i made this script about a week ago becuase i wasn't happy with the targeting system my Lua Engine currently had. It has been quite useful since then. So i decided to share it.


    Simplified Version
    Code:
    
    function AdvancedTargeting(aCaster, aDMin, aDMax, aSpellId, aHitCount, aCastType)
    local vplr
    local iplr
    local intPlrCount = 0
    aDMin = math.pow(aDMin, 2)
    aDMax = math.pow(aDMax, 2)
    
    	if (aCastType == 0) then
    		intPlrCount = 1
    	end
    
    	if (aHitCount == 0) then
    	local irPlrCount = aCaster:GetInRangePlayersCount()
    		intPlrCount = irPlrCount
    	end
    
    	if (aCaster == nil) then
    		print("AdvancedTargeting: Arguement #1 invalid: Unit expected got nil")
    	elseif (aCaster == 0) then
    		print("AdvancedTargeting: Arguement #1 invalid: Unit expected, got 0")
    	elseif (aDMin == nil) then
    		print("AdvancedTargeting: Arguement #2 invalid: value was nil")
    	elseif (aDMax == nil) then
    		print("AdvancedTargeting: Arguement #3 invalid: value was nil")
    	elseif (aSpellId == 0) then
    		print("AdvancedTargeting: Arguement #4 invalid: a value greater than or equal to 1 expected. current value is "..aSpellId)
    	elseif (aSpellId == nil) then
    		print("AdvancedTargeting: Arguement #4 invalid: value was nil")
    	elseif (aHitCount == nil) then
    		print("AdvancedTargeting: Arguement #5 invalid: value was nil")
    	elseif (aCastType == nil) then
    		print("AdvancedTargeting: Arguement #6 invalid: value was nil")
    	elseif (aCastType >= 2) then
    		print("AdvancedTargeting: Arguement #6 invalid: value was equal to "..aInstant.." 1 or 0 expected")
    	else
    		local tblInRangePlayers = aCaster:GetInRangePlayers()
    		
    		for iplr, vplr in pairs(tblInRangePlayers) do
    			if (intPlrCount == aHitCount) then
    				break;
    			else
    				if aCaster:GetDistance(vplr) >= aDMin then
    					if aCaster:GetDistance(vplr) <= aDMax then
    						intPlrCount = intPlrCount + 1
    						aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    					end
    				end
    			end
    		end
    	end
    end
    
    Full Version

    Code:
    
    function AdvancedTargeting(aCaster, aDMin, aDMax, aSpellId, aHitCount, aCastType, aHPMin, aHPMax, aTargetType)
    local vplr
    local iplr
    local intPlrCount = 0
    aDMin = math.pow(aDMin, 2)
    aDMax = math.pow(aDMax, 2)
    
    	if (aCastType == 0) then
    		intPlrCount = 1
    	end
    
    	if (aHitCount == 0) then
    	local irPlrCount = aCaster:GetInRangePlayersCount()
    		intPlrCount = irPlrCount
    	end
    
    	if (aCaster == nil) then
    		print("AdvancedTargeting: Arguement #1 invalid: Unit expected got nil")
    	elseif (aCaster == 0) then
    		print("AdvancedTargeting: Arguement #1 invalid: Unit expected, got 0")
    	elseif (aDMin == nil) then
    		print("AdvancedTargeting: Arguement #2 invalid: value was nil")
    	elseif (aDMax == nil) then
    		print("AdvancedTargeting: Arguement #3 invalid: value was nil")
    	elseif (aSpellId == 0) then
    		print("AdvancedTargeting: Arguement #4 invalid: a value greater than or equal to 1 expected. current value is "..aSpellId)
    	elseif (aSpellId == nil) then
    		print("AdvancedTargeting: Arguement #4 invalid: value was nil")
    	elseif (aHitCount == nil) then
    		print("AdvancedTargeting: Arguement #5 invalid: value was nil")
    	elseif (aCastType == nil) then
    		print("AdvancedTargeting: Arguement #6 invalid: value was nil")
    	elseif (aCastType >= 2) then
    		print("AdvancedTargeting: Arguement #6 invalid: value was equal to "..aInstant.." 1 or 0 expected")
    	elseif (aHPMin == nil) then
    		print("AdvancedTargeting: Arguement #7 invalid: value was nil")
    	elseif (aHPMax == 0) then
    		aHPMax = 100
    	elseif (aHPMax == nil) then
    		print("AdvancedTargeting: Arguement #8 invalid: value was nil")
    	elseif (aTargetType == nil) then
    		print("AdvancedTargeting: Arguement #9 invalid: value was nil")
    	else
    		local tblInRangePlayers = aCaster:GetInRangePlayers()
    		
    		for iplr, vplr in pairs(tblInRangePlayers) do
    			if (intPlrCount == aHitCount) then
    				break;
    			else
    				local hpPct = vplr:GetHealthPct()
    				local pRange = aCaster:GetDistance(vplr)
    				local pClass = vplr:GetPlayerClass()
    				if (pRange >= aDMin) then
    					if (pRange <= aDMax) then
    						if (hpPct >= aHPMin) then
    							if (hpPct <= aHPMax) then
    								if (aTargetType == 0) then
    									intPlrCount = intPlrCount + 1
    									aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    								elseif (aTargetType == 1) then
    									if (pClass == "Warrior") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Druid") then
    										if (vplr:HasAura(9634) == true) then
    											intPlrCount = intPlrCount + 1
    											aCaster:FullCastSpellOnTarget(aSpellId, vplr)											
    										elseif (vplr:HasAura(5487) == true) then
    											intPlrCount = intPlrCount + 1
    											aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    										end
    									end
    								elseif (aTargetType == 2) then
    									if (pClass == "Mage") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    									elseif (pClass == "Hunter") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    									elseif (pClass == "Priest") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    									elseif (pClass == "Paladin") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    									elseif (pClass == "Shaman") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    									elseif (pClass == "Warlock") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    									elseif (pClass == "Druid") then
    										if (vplr:HasAura(9634) == true) then
    											-- Is in Dire bear form, has no mana.
    										elseif (vplr:HasAura(5487) == true) then
    											-- Is in Bear form, has no mana.	
    										elseif (vplr:HasAura(768) == true) then
    											-- Is in Cat form, has no mana.
    										else
    											intPlrCount = intPlrCount + 1
    											aCaster:FullCastSpellOnTarget(aSpellId, vplr)	
    										end
    											
    									end
    								elseif (aTargetType == 3) then
    									if (pClass == "Rogue") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Druid") then
    										if (vplr:HasAura(768) == true) then
    											intPlrCount = intPlrCount + 1
    											aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    										end
    									end
    								elseif (aTargetType == 4) then
    									if (pClass == "Deathknight") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									end
    								elseif (aTargetType == 5) then
    									if (pClass == "Priest") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Mage") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Warlock") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									end
    								elseif (aTargetType == 6) then
    									if (pClass == "Rogue") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Druid") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									end
    								elseif (aTargetType == 7) then
    									if (pClass == "Hunter") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Shaman") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									end
    								elseif (aTargetType == 8) then
    									if (pClass == "Deathknight") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Paladin") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									elseif (pClass == "Warrior") then
    										intPlrCount = intPlrCount + 1
    										aCaster:FullCastSpellOnTarget(aSpellId, vplr)
    									end
    								end								
    							end
    						end
    					end
    				end
    			end
    		end
    	end
    end
    
    ::::::::::::How To Use::::::::::::::

    Save one of both of these scripts in your scripts folder as <InsertNameHere>.lua Then use the function! Below are some examples.

    Simplified Version

    There are six arguements with the simplified version:

    1). Caster :The Unit casting the spell
    2). Minimum distance :The minimum distance the target must be from the Unit casting the spell
    3). Maximum distance :The maximum distance the target can be from the Unit casting the spell
    4). SpellId :SpellID of the spell Unit will be casting
    5). Hitcount :The Amount of players within the specified range the spell can hit. (Leave 0 for unlimited)
    6). Spell cast type. :The spell type (1 for instant cast, 0 for Full cast)
    AdvantedTargeting(Caster, Minimum distance, Maximum distance, SpellId, Hitcount, Spell cast type)


    Example;
    Code:
    
    function Creature_OnCombat(Unit, Event)
    	Unit:RegisterEvent("AoE_FrostboltOfAges", 5000, 0)
    end
    
    function AoE_FrostboltOfAges(Unit, Event)
    	AdvancedTargeting(Unit, 5, 50, 11, 0, 1) -- This will have Unit, cast frostbolt of the ages, on all players in a 5 to 50 yard range.
    end
    
    RegisterUnitEvent(NpcId, 1, "Creature_OnCombat")
    
    Full Version

    There are nine arguements with the full version:

    1). Caster :The Unit casting the spell
    2). Minimum distance :The minimum distance the target must be from the Unit casting the spell.
    3). Maximum distance :The maximum distance the target can be from the unit casting the spell.
    4). SpellId :The SpellID of the spell Unit will be casting.
    5). Hitcount :The amount of players within the specified conditions the spell can hit(Set to 0 for unlimited)
    6). Spell cast type :The spell type(instant/fullcast)
    Spell cast arguement flags
    • [0] Full cast spell
      [1] Instant cast spell

    7). Minimum hp percent :The minimum hp percent the target must have for them to become a valid target.
    . Maximum hp percent :The maximum amount of hp the target can have for them to become a valid target.
    Maximum hp percent:
    • [0] Set to 0 for any range

    9). Target Type :The type of target you want the spell to hit.
    Target Type arguement flags
    • [0] Anything
      [1] Has Rage
      [2] Has mana
      [3] Has Energy
      [4] Has Runic Power
      [5] Cloth wearer
      [6] Leather wearer
      [7] Mail wearer
      [8] Plate wearer

    Example;
    Code:
    
    function Creature_OnCombat(Unit, Event)
    	Unit:RegisterEvent("AoE_FrostboltOfAges", 5000, 0)   
    end
    
    function AoE_FrostboltOfAges(Unit, Event)
    	AdvancedTargeting(Unit, 5, 50, 11, 0, 1, 0, 50, 2) -- Unit will cast frostbolt of the ages on any player with mana, below 50% health within a 5-50 yard range of himself.
    end
    
    *Issues*
    - This targeting function was based around :CastSpellOnTarget() being bugged. This means only actual instant cast spells can be cast more than once, on more than one target.
    - Full version of this function can get hard to remember.


    please post back if this command doesn't work for you. I've tested it as much as i can by myself and its been working perfectly for me.

    ~all credits go to me.
    Last edited by Vision1000; 07-31-2009 at 11:11 PM.

    [Lua] Custom Targeting Command
  2. #2
    Hellgawd's Avatar Account not activated by Email
    Reputation
    710
    Join Date
    Jun 2007
    Posts
    2,480
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure why no one has looked at this yet! Looks really good, I will be using this! +7

  3. #3
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Looks good but I wouldn't use it since personly I find it easier just to do everything in each script so I know exactly whats going on and it is easier to debug if something goes wrong. +Rep x4 for the effert that went into this though and I'm sure some people will find it useful.

  4. #4
    Edude's Avatar Member
    Reputation
    98
    Join Date
    Jul 2008
    Posts
    406
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This looks amazingly epic +Rep x2 for your effort

  5. #5
    Exacute's Avatar Active Member
    Reputation
    67
    Join Date
    Mar 2008
    Posts
    337
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    surely going to use it... +Rep x2 for the great effort.. sadly i can't test it yet
    [/COLOR]

  6. #6
    TheFrostLord's Avatar Corporal
    Reputation
    1
    Join Date
    Sep 2010
    Posts
    15
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is pretty hardcore and looks really epic +rep x3 for you! Ill use it

Similar Threads

  1. [Help][Lua] Npc Targeting Another Npc
    By Zudrik in forum WoW EMU Questions & Requests
    Replies: 6
    Last Post: 03-09-2009, 07:25 PM
  2. [Help][LUA] pUnit:GetHealthPct command
    By Kiyoshi in forum World of Warcraft Emulator Servers
    Replies: 7
    Last Post: 07-03-2008, 01:42 PM
  3. [question] regarding LUA custom instance portal
    By arthars1 in forum World of Warcraft Emulator Servers
    Replies: 10
    Last Post: 06-07-2008, 05:25 PM
  4. Custom fly Command
    By snowflaker in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 03-25-2008, 03:39 AM
  5. [Release] Custom Quest Commands/Subcommands
    By wowcomputer in forum World of Warcraft Emulator Servers
    Replies: 9
    Last Post: 12-29-2007, 05:35 PM
All times are GMT -5. The time now is 02:39 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search