Code:
local VERSION = "1.1"
--[[====================================--
-- Easy-Creature-Combat --
-- [ Fully Made by Claiver ] --
-- REPORT FEEDBACK AT MMOWNED.COM --
--======================================]]
--[[============================================================================================
=========== ( General Settings ) ===============================================================
==============================================================================================]]
--| Is Debug Enabled? If Enabled, detailed information will be printed to console.
local DEBUG = true
--[[============================================================================================
=========== ( Creature Settings ) ==============================================================
================================================================================================
All of the following options are bound to the creature, and will
scale to the creature in the server! ]]
--| Please Enter the ENTRYID of the Creature.
local ENTRYID = 103103103
--| Please Enter the NAME of the Creature.
local NAME = "Your Creature Namezzz"
--| Please Enter the SUBNAME (GuildName) of the Creature.
local SUBNAME = "Your Creature SubName"
--| Please Enter the LEVEL of the Creature.
local LEVEL = 80
--| Please Enter the HEALTHPOINTS (HP) of the Creature.
local HP = 90000
--| Please Enter the MANA of the Creature.
local MANA = 0
--| Please Enter the FACTION of the Creature.
local FACTION = 14 -- Default: 14
--| Please Enter the DISPLAYID (MODEL) of the Creature.
local DISPLAYID = 24352
--| Please Enter the ATTACKSPEED (In Seconds!) of the Creature.
local ATTACKSPEED = 2 -- Default: 2
--| Please Enter the MINIMUM DAMAGE of the Creature.
local MIN_DAMAGE = 1100
--| Please Enter the MAXIMUM DAMAGE of the Creature.
local MAX_DAMAGE = 1400
--| Please Enter the ARMOR of the Creature.
local ARMOR = 0 -- Default: 0
--[[============================================================================================
=========== ( Attack Settings ) ================================================================
==============================================================================================]]
--[[-----------------------------------------------------------------------------------------------------|
Define the spells the creature will cast.
Follow the following values when adding spells, you must not remove the ValueName (it's between [" "])
Add one line below to the list 'local Creature_CastSpells'. Just look at the current spells for an example.
{ ["SPELLID"]=spellID,["SPELLNAME"]="spellname",["TARGET"]="target",["CAST-TIME"]=casttime,["COOLDOWN"]=cooldown,["CAST-COUNT"]=count,["CAST-MODE"]="castmode" },
__| LEGEND |_____________________________________________________
o ["SPELLID"] --> This is the ID of the Spell.
o ["SPELLNAME"] --> This is the Name of the Spell.
o ["TARGET"] --> This is the Target the spell is casted on. You can choose between:
Self (only buffs); Random; Tank; ShortRange; MidRange; LongRange; Mana; Rage; Energy; AnyoneButTank
o ["CAST-TIME"] --> This is the exact casttime of the Spell, in seconds.
o ["COOLDOWN"] --> This is the average time in seconds between each cast of the Spell (not precise!)
o ["CAST-COUNT"] --> This is the amount of casts of the Spell that will be casted. 0 for infinite.
o ["CAST-MODE"] --> This is the mode of how the spell is casted. Choose between 'FullCast' or 'InstantCast'.
[NOTE] The list below is just an example. You may use/modify/delete the list to your needs!
## THE SPELLS #################################################################################################]]
local Creature_CastSpells =
{
{ ["SPELLID"]=48461,["SPELLNAME"]="Wrath",["TARGET"]="Tank",["CAST-TIME"]=2.0,["COOLDOWN"]=5.0,["CAST-COUNT"]=0,["CAST-MODE"]="FullCast" },
{ ["SPELLID"]=59172,["SPELLNAME"]="Chaos Bolt",["TARGET"]="Tank",["CAST-TIME"]=2.5,["COOLDOWN"]=3.0,["CAST-COUNT"]=0,["CAST-MODE"]="FullCast" },
{ ["SPELLID"]=47864,["SPELLNAME"]="Curse of Agony",["TARGET"]="Tank",["CAST-TIME"]=0,["COOLDOWN"]=4.5,["CAST-COUNT"]=0,["CAST-MODE"]="FullCast" },
{ ["SPELLID"]=47893,["SPELLNAME"]="Fel Armor",["TARGET"]="Self",["CAST-TIME"]=0,["COOLDOWN"]=1.0,["CAST-COUNT"]=1,["CAST-MODE"]="FullCast" },
{ ["SPELLID"]=28271,["SPELLNAME"]="Polymorph",["TARGET"]="Tank",["CAST-TIME"]=1.5,["COOLDOWN"]=4.0,["CAST-COUNT"]=3,["CAST-MODE"]="FullCast" },
}
--[[---------------------------------------------------------------------------------------------------|
After you have defined the spells to be casted above, you have to do one more thing.
You will have to create a new line and add it below at the bottom of the function-list.
The new line will look like this: (change everything between !!!)
Follow the following values when adding spells, you must not remove the ValueName (it's between [" "]):
function CS_!!!spellquickname!!! (pUnit,Event) local SpellName = "!!!spellname!!!" SimpleCast(pUnit,SpellName) end
That's only two things! However, you have to note the following. (Everything is Case-Sensitive!)
o Change !!!spellquickname!!! to the spellname without spaces and in CAPS!
Example: Chaos Bolt will be CHAOSBOLT and Curse of Agony will be CURSEOFAGONY
o Change !!!spellname!!! to the ["SPELLNAME"] you have defined earlier (must be the same!)
Example: If you have put in ["SPELLNAME"] = "Curse of Agony" above,
then you replace !!!spellname!!! with 'Curse of Agony'.
[NOTE] The list below is just an example. You may use/modify/delete the list to your needs!
## THE FUNCTION LIST #########################################################################################]]
function CS_WRATH (pUnit,Event) local SpellName = "Wrath" SimpleCast(pUnit,SpellName) end
function CS_CHAOSBOLT (pUnit,Event) local SpellName = "Chaos Bolt" SimpleCast(pUnit,SpellName) end
function CS_CURSEOFAGONY (pUnit,Event) local SpellName = "Curse of Agony" SimpleCast(pUnit,SpellName) end
function CS_FELARMOR (pUnit,Event) local SpellName = "Fel Armor" SimpleCast(pUnit,SpellName) end
function CS_POLYMORPH (pUnit,Event) local SpellName = "Polymorph" SimpleCast(pUnit,SpellName) end
--[[-----------------------------------------------------------------------------------------------------|
Here we can add some weapons.
If you would like a slot (MAINHAND,OFFHAND,WAND/RANGED) to be empty, then fill in 0.
[NOTE] It seems like this function is currently not working with GuaEngine (not for me!)
## WEAPONS #################################################################################################]]
local Creature_EquipWeapons = {
["MAINHAND"] = 40703,
["OFFHAND"] = 44311,
["RANGED"] = 0, }
--###############################################################################################################################
--#################################[ DO NOT EDIT BELOW THIS LINE ]###############################################################
--###############################################################################################################################
--------------------------------------------------------------------------------------|
--\ BaseFunction: OnCombat | Execute this when Creature enters Combat.
--------------------------------------------------------------------------------------|
function Creature_OnCombat(pUnit,Event)
for k,v in pairs(Creature_CastSpells) do
C_T = (v["COOLDOWN"]+v["CAST-TIME"]+v["SPELLID"]/100000)*1000
pUnit:RegisterEvent("CS_"..string.upper(string.gsub(v["SPELLNAME"],"%s","")),C_T,v["CAST-COUNT"])
DebugSendMSG(string.upper(string.gsub(v["SPELLNAME"],"%s","")).." - Will cast every ".. C_T .." ms, for "..v["CAST-COUNT"].." times (0=infinite).")
end
Creature_StopCasting()
end
--------------------------------------------------------------------------------------|
--\ BaseFunction: OnLeave | Execute this when Creature leaves Combat.
--------------------------------------------------------------------------------------|
function Creature_OnLeave(pUnit,Event)
pUnit:RemoveEvents()
Creature_StopCasting()
end
--------------------------------------------------------------------------------------|
--\ BaseFunction: OnDeath | Execute this when Creature dies.
--------------------------------------------------------------------------------------|
function Creature_OnDeath(pUnit,Event)
pUnit:RemoveEvents()
Creature_StopCasting()
end
--------------------------------------------------------------------------------------|
--\ BaseFunction: OnSpawn | Execute this when Creature spawns.
--------------------------------------------------------------------------------------|
function Creature_OnSpawn(pUnit,Event)
CreatureSetStatistics(pUnit)
Creature_StopCasting()
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: GetTarget
--------------------------------------------------------------------------------------|
function GetTarget(_unit,_t)
if (_t == "Self") then return _unit end
if (_t == "Tank") then return _unit:GetMainTank() end
if (_t == "Random") then return _unit:GetRandomPlayer(0) end
if (_t == "ShortRange") then return _unit:GetRandomPlayer(1) end
if (_t == "MidRange") then return _unit:GetRandomPlayer(2) end
if (_t == "LongRange") then return _unit:GetRandomPlayer(3) end
if (_t == "Mana") then return _unit:GetRandomPlayer(4) end
if (_t == "Rage") then return _unit:GetRandomPlayer(5) end
if (_t == "Energy") then return _unit:GetRandomPlayer(6) end
if (_t == "AnyoneButTank") then return _unit:GetRandomPlayer(7) end
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: SimpleCast
--------------------------------------------------------------------------------------|
function SimpleCast(_unit,_spell)
for k,v in pairs(Creature_CastSpells) do DoCastSpell(_unit,v,_spell) end
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: DoCastSpell
--------------------------------------------------------------------------------------|
function DoCastSpell(_unit,_v,_spell)
if (_v["SPELLNAME"] == _spell) and (Creature_CastSpells[1][ENTRYID] ~= true) then
--| ACQUIRE CASTTIME
if (_v["CAST-TIME"] >= 1) and (_v["CAST-MODE"] == "FullCast") then Creature_CastSpells[1][ENTRYID] = true -- (_v["CAST-TIME"] >= 1) and
_unit:RegisterEvent("Creature_StopCasting", (_v["CAST-TIME"]*1000)+1, 1)
_unit:StopMovement((_v["CAST-TIME"]*1000)+1)
end
--| ACQUIRE TARGET
CT = GetTarget(_unit,_v["TARGET"])
if (CT == _unit) then T_NAME = "Self" if (_unit:HasAura(_v["SPELLID"]) == false) then
DebugSendMSG("Casted ".._v["SPELLNAME"].." on '"..T_NAME.."'.")
if (string.upper(_v["CAST-MODE"]) == "INSTANTCAST") then _unit:CastSpell(_v["SPELLID"]) end
if (string.upper(_v["CAST-MODE"]) == "FULLCAST") then _unit:FullCastSpell(_v["SPELLID"]) end end
else T_NAME = CT:GetName()
DebugSendMSG("Casted ".._v["SPELLNAME"].." on '"..T_NAME.."'.")
if (string.upper(_v["CAST-MODE"]) == "INSTANTCAST") then _unit:CastSpellOnTarget(_v["SPELLID"], CT) end
if (string.upper(_v["CAST-MODE"]) == "FULLCAST") then _unit:FullCastSpellOnTarget(_v["SPELLID"], CT) end
end
end
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: CreatureSetStatistics
--------------------------------------------------------------------------------------|
function CreatureSetStatistics(_unit)
DebugSendMSG("Setting Creature Statistics...")
_unit:SetHealth(HP) DebugSendMSG("HP: "..string.format("%s",HP))
_unit:SetMana(MANA) DebugSendMSG("MANA: "..string.format("%s",MANA))
_unit:SetFaction(FACTION) DebugSendMSG("FACTION: "..string.format("%s",FACTION))
_unit:SetModel(DISPLAYID) local v=Creature_EquipWeapons
_unit:EquipWeapons(v["MAINHAND"],v["OFFHAND"],v["RANGED"])
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: DebugSendMSG
--------------------------------------------------------------------------------------|
function DebugSendMSG(_d)
if (DEBUG == true) then print("[DEBUG] "..string.format("%s",_d).."") end
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: Creature_StopCasting
--------------------------------------------------------------------------------------|
function Creature_StopCasting(pUnit, Event)
if (Creature_CastSpells[1][ENTRYID] ~= false) then Creature_CastSpells[1][ENTRYID] = false end
end
--------------------------------------------------------------------------------------|
--\ AdvFunction: InsertDataToSQL
--------------------------------------------------------------------------------------|
function InsertDataToSQL()
Execute(2, "DELETE FROM `creature_proto` WHERE `entry`="..ENTRYID..";")
Execute(2, "DELETE FROM `creature_names` WHERE `entry`="..ENTRYID..";")
Execute(2, "INSERT INTO creature_names (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `unk4`, `spelldataid`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `civilian`, `leader`) VALUES ("..ENTRYID..", '"..NAME.."', '"..SUBNAME.."', '', 0, 0, 0, 1, 0, 0, "..DISPLAYID..", 0, 0, 0, 1, 1, NULL, 0); ")
Execute(2, "INSERT INTO creature_proto (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `death_state`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`) VALUES ("..ENTRYID..", "..LEVEL..", "..LEVEL..", "..FACTION..", "..HP..", "..HP..", 0, 1, 0, ".. ATTACKSPEED*1000 ..", 0, "..MIN_DAMAGE..", "..MAX_DAMAGE..", 0, 0, 0, 0, 360000, "..ARMOR..", 0, 0, 0, 0, 0, 0, 2, 1, '0', 0, 0, 0, 0, 2.5, 8, 14, 0, 0, 0, 0, 0, 0, 0);")
end InsertDataToSQL()
--------------------------------------------------------------------------------------|
--\ AdvFunction: PrintToConsole
--------------------------------------------------------------------------------------|
function PrintToConsole()
print("\n\n\n******************************************************************************")
print(" \t\t Loaded AI for "..NAME..".")
print(" \tAI created with 'Easy-Creature-Combatscript (V"..VERSION..") by Claiver'")
print("******************************************************************************\n\n\n")
end PrintToConsole()
--------------------------------------------------------------------------------------|
--\ Register Unit Events
--------------------------------------------------------------------------------------|
RegisterUnitEvent(ENTRYID, 1, "Creature_OnCombat")
RegisterUnitEvent(ENTRYID, 2, "Creature_OnLeave")
RegisterUnitEvent(ENTRYID, 4, "Creature_OnDeath")
RegisterUnitEvent(ENTRYID, 18, "Creature_OnSpawn")