SerialKiller
20-02-10, 07:35 AM
I DID NOT DO THIS ALL CREDITS GO TO VISION1000
If anything is wrong with this guide, or information is incorrect, please post back and I'll correct it, Be aware I'm not an Lua expert, i learned by looking at many Lua guides, and by messing around and testing out stuff in-game. These are the concepts i feel i have a pretty good understanding of so far. If there is anything i'm missing in this guide, also post and i'll add it in. (Also say if any of the examples / sections of this guide are unclear, i'll try my best to fix them Edit: I've been learning C++, and well... if you have the time, its definitely worth learning over lua.)
After reading through all the other guides that are vague and leave out very basic information that you are expected to know,
but do not.
i decided to make a very very thorough one.
[Table of Contents]
[1.0]: General
[1.1]: Functions & Registering Events
[1.2]: Variables
[1.3]: The If Statement
[1.4]: Command List & Usage
[2.0] Creature Events
[2.1]: Most Common Creature Commands & Usage
[2.5]: Combat and General Events
[2.9]: Creature Summary and Tips
[3.0] Gameobject Events.
[3.1] Most Common Gameobject Commands & Usage
[3.5] Gameobject Events
[3.9] Gameobject Summary and Tips
[5.0] Generalized Gossip Events.
[$.#]3x7r4 1Nf0rNm471on
.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: .:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: .:.:.:.:.:.:.:.:.:.:.:.:.
[1.0]General
[1.1]Functions & Registering Events
Functions are blocks of code created to be called upon and do a specific task when your script is executed. The only way to initially call on a function is by having a certain Event happen to the scripted Unit(Whether it be a Creature, Gameobject, or Item)
These triggering events are;
-Accepting a Quest
-Completing a Quest
-Canceling a Quest
-Activating a Quest Gameobject
-Killing a Creature Required for a Quest
-Exploring an Area for a quest
-Picking up an Item for a Quest
-Creature Entering Combat
-Creature Leaving Combat
-Creature Killing an Enemy
-Creature Dieing
-Creature being Parried
-Creature being Dodged
-Creature being Blocked
-Creature being Critically Hit
-Creature Parrying
-Creature Dodging
-Creature Blocking??
-Creature Critically Hitting
-Creature Hitting
-Creature Feared
-Creature Flee
-Creature Loading
-Creature Reaching a Waypoint
-Creature having loot taken from it
-Creature Emoting
-Gameobject being Created
-Gameobject Spawning
-Gameobject having loot taken from it
-Gameobject being clicked/used
-Gameobject Despawning
-Talking to a Gossip Unit
-Selecting an option from a Gossip Unit
-Closing a Gossip Window / Ending it
The Skeleton if you will, of a function must always look like this;
function FunctionName(Unit, Event)
endWhen this function is called it will execute what is between the Skeleton. As stated above, it can only be initially called by a trigger event. To have a function called when a specific event happens
you must register that function to do so. Below is the syntax used to register different types of Events.
RegisterUnitEvent(NPCID, FLAG, "FunctionName")
RegisterUnitGossipEvent(NPCID, FLAG, "FunctionName")
RegisterItemGossipEvent(ItemID, FLAG, "Item_Trigger")
RegisterGameObjectEvent(GoID, FLAG, "FunctionName")
Replacing the NPC/item/Go Id's with the ones you will spawn in the world and use. the 'FLAG' is a number that indicates the event that the registered function will trigger on. Here is a breakdown of how to register an event.
[NOTE]When Registering Events, you type it at the bottom or top of the script.
Please remember that no function has to have any particular name. Not having "OnCombat" in the function name, won't affect if it gets triggered on combat, as long as its function name matches the name your registering, and you have the correct flag.
function Creature_OnCombat(Unit, Event)
end
RegisterUnitEvent(6, 1,"Creature_OnCombat")
6: Is the NPCID of a Kobold Vermin, Change it to the NPCID you want to script.
1: Is the Flag of the type of event you want this registered function to get triggered on.
"Creature_OnCombat": Is the name of the function your registering to be executed when the Kobold enters combat.
RegisterUnitEvent: Is used to Register a Unit/Creature Event.
NPCID was 6 (For Kobold Vermin)
EventFlag was 1 (To Register the function Creature_OnCombat when the kobold vermin enters combat
FunctionName "Creature_OnCombat"
Below is a Complete List of EventFlags you can use when registering an event.
[QUEST EVENTS]
QUEST_EVENT_ON_ACCEPT = 1,
QUEST_EVENT_ON_COMPLETE = 2,
QUEST_EVENT_ON_CANCEL = 3,
QUEST_EVENT_GAMEOBJECT_ACTIVATE = 4,
QUEST_EVENT_ON_CREATURE_KILL = 5,
QUEST_EVENT_ON_EXPLORE_AREA = 6,
QUEST_EVENT_ON_PLAYER_ITEMPICKUP = 7,
QUEST_EVENT_COUNT,
[CREATURE EVENTS]
CREATURE_EVENT_ON_ENTER_COMBAT = 1,
CREATURE_EVENT_ON_LEAVE_COMBAT = 2,
CREATURE_EVENT_ON_TARGET_DIED = 3,
CREATURE_EVENT_ON_DIED = 4,
CREATURE_EVENT_ON_TARGET_PARRIED = 5,
CREATURE_EVENT_ON_TARGET_DODGED = 6,
CREATURE_EVENT_ON_TARGET_BLOCKED = 7,
CREATURE_EVENT_ON_TARGET_CRIT_HIT = 8,
CREATURE_EVENT_ON_PARRY = 9,
CREATURE_EVENT_ON_DODGED = 10,
CREATURE_EVENT_ON_BLOCKED = 11,
CREATURE_EVENT_ON_CRIT_HIT = 12,
CREATURE_EVENT_ON_HIT = 13,
CREATURE_EVENT_ON_ASSIST_TARGET_DIED = 14,
CREATURE_EVENT_ON_FEAR = 15,
CREATURE_EVENT_ON_FLEE = 16,
CREATURE_EVENT_ON_CALL_FOR_HELP = 17,
CREATURE_EVENT_ON_LOAD = 18,
CREATURE_EVENT_ON_REACH_WP = 19,
CREATURE_EVENT_ON_LOOT_TAKEN = 20,
CREATURE_EVENT_ON_AIUPDATE = 21,
CREATURE_EVENT_ON_EMOTE = 22,
CREATURE_EVENT_COUNT,
[GAMEOBJECT EVENTS]
GAMEOBJECT_EVENT_ON_CREATE = 1,
GAMEOBJECT_EVENT_ON_SPAWN = 2,
GAMEOBJECT_EVENT_ON_LOOT_TAKEN = 3,
GAMEOBJECT_EVENT_ON_USE = 4,
GAMEOBJECT_EVENT_AIUPDATE = 5,
GAMEOBJECT_EVENT_ON_DESPAWN = 6,
GAMEOBJECT_EVENT_COUNT,
[GOSSIP EVENTS]
GOSSIP_EVENT_ON_TALK = 1,
GOSSIP_EVENT_ON_SELECT_OPTION = 2,
GOSSIP_EVENT_ON_END = 3,
GOSSIP_EVENT_COUNT,
[RANDOM FLAGS]
RANDOM_ANY = 0,
RANDOM_IN_SHORTRANGE = 1,
RANDOM_IN_MIDRANGE = 2,
RANDOM_IN_LONGRANGE = 3,
RANDOM_WITH_MANA = 4,
RANDOM_WITH_RAGE = 5,
RANDOM_WITH_ENERGY = 6,
RANDOM_NOT_MAINTANK = 7,
RANDOM_COUNT,
[NOTE]: 'RandomFlags' are generally used for creature targeting. hers an example.
Unit:GetRandomPlayer(7)That will get a random player that is not the main tank. (Replacing the the 7 with a different flag when changing it of course).
When creating the meat of a function, every Lua command must have a prefix before the command that tells what will be executing the command(Gameobject/Creature/Item)
For example, when you want a Creature to cast a spell on a random target. it would need a prefix telling who is casting the spell;
function Creature_OnCombat(Unit, Event)
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(7))
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
Above, tells the Unit, To cast spell 11 (Frost bolt of the Ages) on a random player that isn't the main tank. Since it was registed "OnCombat", it will only cast this spell once as the unit enters combat, To make it cast periodically, you Register an event from inside a function.
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("FunctionName", Interval, IntervalCount)
end
function Frostbolt(Unit, Event)
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(7)
end
FunctionName is the name of the function your calling/registering (the name must match the name of the function you are calling), the interval is the amount of time it will take for the event to get registered, and the IntervalCount is the amount of times the function will be registered (Leave it at 0 for infinite)
Now if you make the interval 1000, and the invervalcount 0. It will cast Frostbolt at a random target that isn't the main tank every second, But say your group wipes. He will still register the event when not in combat, and when he enters combat again he will cast frostbolt twice a second. Which is why you need to use the command
Unit:RemoveEvents() which clears all events from the unit. You do this by creating a new function and registering it with the flag "2" for 'CREATURE_EVENT_ON_LEAVE_COMBAT' and "4" for "CREATURE_EVENT_ON_DIED", Then inserting Unit:RemoveEvents(), clearing all events when the NPC Leaves combat / your group wipes.
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("FrostboltSpam", 1000, 0)
end
function FrostboltSpam(Unit, Event)
Unit:FullCastSpellOnTarget(11, Unit:GetClosestPlayer())
end
function Creature_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Creature_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
RegisterUnitEvent(NPCID, 2, "Creature_OnLeaveCombat")
RegisterUnitEvent(NPCID, 4, "Creature_OnDied")
You can only Register events with Creatures/NPC's. From inside Combat Events / Gossip Events, gameobjects and items cannot register events..
[1.2]Variables
Variables are a value stored in memory that can be called upon or modified at a later point in your script. Just like in grade 1 where you have to find out what goes in the box with a equation like so 1 + 2 = [ ]. The Box being the variable, would end up being 3. However we don't use boxes, It is easiest to name your variable after what the variable will be used for, especially when making large scripts. Now there are 2 types of Variables. Global variables, and local variables. Global variables are variables used throughout your entire script. Local variables are variables used within a function. When creating local variables, they need to be declared (Making the Lua engine realize they are local variables). they are declared by using the term 'local' behind the variable your declaring.
function Creature_OnCombat(Unit, Event)
local intVariable = 0
endGlobal variables do not need declaration and can be created the same way as local variables, except without the usage of the term 'local'
function Creature_OnCombat(Unit, Event)
intVariable = 0
end[NOTE]You can have the same local and global variable names as long as you do not use both of them inside the same function.
[NOTE]I'm Not sure about this haven't ever tried it, But i believe Global variables, can be used throughout all your scripts in the scripts folder. So if you want a variable to be relative to just one of your scripts, declare the variable as a local variable at the top of the script:
local intEnteredCombat = 0
function Creature_OnCombat(Unit, Event)
intEnteredCombat = intEnteredCombat + 1
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
[1.3]The If Statement
When scripting with Lua, One of the most handy things to understand is an If statement. How it works is, IF <this happens / is true> then <this will happen>. Example below:
local intVariable = 0
function Creature_OnCombat(Unit, Event)
intVariable = 0
if (intVariable == 0) then -- If intVariable is equal to something other than 0, nothing will happen when the creature enters combat.
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(7)) -- Otherwise it will cast spell 11 (frostbolt of the ages, on a random target that isn't the tank)
end
end
An if statement must always start with If, and end with end. when checking the variables value in a statement, you must use two equals signs, as opposed to one. This indicates you are checking the variables value, rather than modifying/setting it. Within an If statement you can have a few basic substatements (which are not limited to); Elseif, and Else. These statements do what they say.
function Creature_OnCombat(Unit, Event)
if (intVariable == 0) then
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(0))
intVariable = 1
elseif (intVariable == 1) then
Unit:CastSpellOnTarget(5, Unit:GetRandomplayer(0))
else
Unit:SendChatMessage(14, 0, "intVariable has no value!)
intVariable = 0
end
end
Whats happening in the function above, is when the NPC enters combat for the first time, since intVariable was not given a value at any other point in the script, it is 'null' (nothing, no value). Which is not 0 or 1, thus executing what is in the 'else' statement, setting intVariable to 0, and sending a chat message. The 2nd time the creautre enters combat, they will cast frostbolt, and the third time and all times after that, they will cast death touch.
A good trick you can use with If statements, when timing scripts. is the use of a variable that equals itself + 1, take a look;
local intVariable = 0
function Creature_OnCombat(Unit, Event)
intVariable = 0 -- Setting a value so it isn't null.
Unit:RegisterEvent("Timer", 1000, 1)
end
function Timer(Unit, Event)
intVariable = intVariable + 1
if (intVariable == 1) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 1")
elseif (intVariable == 2) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 2")
elseif (intVariable == 3) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 3")
elseif (intVariable == 4) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 4")
elseif (intVariable == 5) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 5")
else
Unit:SendChatMessage(14, 0, "intVariable is another value aside from 1, 2, 3, 4, 5")
end
end
Now with the script above, since it's only getting registered once, (IntervalCount is 1) the function Timer, will only be executed once. we need to either set the intervalcount to 0, or create a Stop Variabe while looping the function.
local intVariable = 0
function Creature_OnCombat(Unit, Event)
intVariable = 0
intStop = 0 -- New Stop Variable
Unit:RegisterEvent("Timer", 1000, 1)
end
function Timer(Unit, Event)
intVariable = intVariable + 1
if (intVariable == 1) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 1")
elseif (intVariable == 2) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 2")
elseif (intVariable == 3) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 3")
elseif (intVariable == 4) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 4")
elseif (intVariable == 5) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 5")
else
Unit:SendChatMessage(14, 0, "intVariable is another value aside from 1, 2, 3, 4, 5")
end
if (intStop == 1) then
-- nothing
elseif (intStop == 0) then
Unit:RegisterEvent("Timer", 1000, 1) -- Loops the Timer function unless intStop == 1, in which case it stops.
end
end
creating a stop variable can be useful for when you want to have a certain NPC's death trigger an event to temporarily stop, or prevent an NPC from spawning if one already spawned. And it is a lot safer as when you have intervalcount set to 0, if you spawn more than 1 NPC, you can have an event registered more often than you want.
[1.4]Command List & Usage
[NOTE]:Some of these Commands may not work with some Lua Engines
math.random(min, max) -- returns a random number between min and max. Best used as a variable
Ex.______________________
Choice=math.random(1,5)
if (choice == 5) then
player:SendAreaTriggerMessage("You just won the lottery")
end
_________________________
Gossip Commands
Item:GossipCreateMenu(textid, player, 0)
Item:GossipMenuAddItem(iconid, "name", intid, type);
Item:GossipSendMenu(player);
Item:GossipComplete(player);
Item:GossipSendPOI(player, Xcoord, Ycoord, icon, flags, data, nameofPOI);
Unit:GossipCreateMenu(textid, player, 0);
Unit:GossipMenuAddItem(iconid, "name" intid, type);
Unit:GossipSendMenu(player);
Unit:GossipComplete(player);
Unit:GossipSendPOI(player, Xcoord, Ycoord, icon, flags, data, nameofPOI);
GameObject:GossipCreateMenu(textid, player, 0);
GameObject:GossipMenuAddItem(iconid, "name", intid, type);
GameObject:GossipSendMenu(player);
GameObject:GossipComplete(player);
GameObject:GossipSendPOI(player, Xcoord, Ycoord, icon, flags, data, nameofPOI);
[NOTE] for GossipCreateMenu: textid, is the same id used in npc_textid, however you cannot have the same textid for 2 different menus.
[NOTE] iconid = Icon next to the text in the menu list ingame. intid is a variable used in GossipSubMenu, type - 0 is regular, 1 = code(A prompt box pops up and you have to enter a new value for the variable 'code', doesn't work that good.)
GET COMMANDS
Unit:GetPlayerRace(); -- returns number based on race. [1=Human][2=Orc][3=Dwarf][4=NightElf][5=Undead][6=Tauren][7=Gnome][8=Troll][10=BloodElf][11=Draenei]
Unit:GetCurrentSpellId(); -- Returns spell ID the target is currently casting
Unit:GetStanding(lua_State * L, Unit * ptr);
Unit:GetMainTank(lua_State * L, Unit * ptr);
Unit:GetAddTank(lua_State * L, Unit * ptr);
Unit:GetX(); -- Returns X Coordinate
Unit:GetY(); -- Returns Y Coordinate
Unit:GetZ(); -- Returns Z Coordinate
Unit:GetO(); -- Returns Orientation
Unit:GetTauntedBy(); -- returns player who taunted
Unit:GetSoulLinkedWith(lua_State * L, Unit * ptr);
Unit:GetItemCount(itemid); -- returns amount
Unit:GetName(); -- returns Unit Name
Unit:GetHealthPct(); -- Returns Units health betweeen 1 and 100
Unit:GetManaPct(); -- Returns Units Mana between 1 and 100
Unit:GetInstanceID(); -- returns instance id
Unit:GetClosestPlayer(RandomFlag); -- Gets closest player; use Random Flags.
Unit:GetRandomPlayer(RandomFlag); -- Gets random player; use Random Flags.
Unit:GetRandomFriend(); -- Gets Random friend / player; use Random flags?.
Unit:GetUnitBySqlId(); -- Gets another NPC by their SQLID
Unit:GetPlayerClass(); -- Returns number based on class. [Warrior=1][Paladin=2][Hunter=3][Rogue=4][Priest=5][Deathknight=6][Shaman=7][Mage=8][Warlock=9][Druid=11]
Unit:GetHealth(); -- Returns Units Current health
Unit:GetMaxHealth(); -- Returns units Max health
Unit:GetCreatureNearestCoords(x, y, z, NPCID);
Unit:GetGameObjectNearestCoords(x, y, z, GOID);
Unit:GetDistance(); -- Returns Distance. .debug rangecheck (Uses distance2dsq, 2 distance only.)
Unit:GetGUID(); -- Returns GUID
Unit:GetZoneId(); -- Returns GUID
Unit:GetMaxMana(Value); -- Sets Max Mana
Unit:GetMana(); -- Returns Current Mana
Unit:GetCurrentSpell(); -- returns current spell id?
Unit:GetSpawnO(); -- Returns Orientation of original Spawn
Unit:GetSpawnZ(); -- Returns Z Coordinate of original Spawn
Unit:GetSpawnY(); -- Returns Y Coordinate of original Spawn
Unit:GetSpawnX(); -- Returns X coordinate of Original Spanw
Unit:GetInRangePlayersCount(); -- Returns number based on amount of in range players.
Unit:GetUInt32Value(lua_State * L, Unit * ptr);
Unit:GetUInt64Value(lua_State * L, Unit * ptr);
Unit:GetFloatValue(lua_State * L, Unit * ptr);
Unit:GetAIState(lua_State * L, Unit * ptr);
Unit:GetCurrentSpell(); -- same as others?
Unit:GetInRangeGameObjects(); -- Returns Gameobjects in range in a Table (Cannot be used as a target)--\_____ Will get error "Unit Expected, got Nil"
Unit:GetInRangePlayers(); -- Returns In range Players in a Table (Cannot be used as a target)----------/
Unit:GetAITargets(lua_State * L, Unit * ptr);
Unit:GetUnitByGUID(); -- Returns Unit by their Guid
Unit:GetInRangeObjectsCount(); -- Returns a number based on amount of in range gameobjects
Unit:GetAITargetsCount(lua_State * L, Unit * ptr);
Unit:GetUnitToFollow(lua_State * L, Unit * ptr);
Unit:GetNextTarget(); -- Gets next highest threat target.
Unit:GetPetOwner(lua_State * L, Unit * ptr);
Unit:GetEntry(); -- Returns npc entryid?
Unit:GetFaction(); -- Returns NPC's faction
Unit:GetThreatByPtr(lua_State * L, Unit * ptr);
Unit:GetInRangeFriends(lua_State * L, Unit * ptr);
Unit:GetPowerType(lua_State * L, Unit * ptr);
Unit:GetMapId(); -- Returns Mapid
Unit:GetFactionStanding(lua_State * L, Unit * ptr);
Unit:GetPlayerLevel(); -- Returns playerlevel
IS COMMANDS -- Will returns '1' or 'true' if true. Not sure what one.
Unit:IsPlayerAttacking();
Unit:IsPlayerMoving();
Unit:IsPlayerAtWar(factionID);
Unit:IsPlayer();
Unit:IsCreature();
Unit:IsInCombat();
Unit:IsAlive();
Unit:IsDead(l);
Unit:IsInWorld();
Unit:IsCreatureMoving();
Unit:IsFlying();
Unit:IsInFront();
Unit:IsInBack();
Unit:IsPacified();
Unit:IsFeared();
Unit:IsStunned();
Unit:HasInRangeObjects();
Unit:IsInWater();
Unit:IsInArc();
Unit:IsPet();
Unit:MoveFly();
Unit:NoRespawn();
Unit:HasItem();
Unit:FlyCheat();
OTHER COMMANDS
Unit:AdvanceSkill(skillid, amount);
Unit:AddSkill(skillid);
Unit:RemoveSkill(skillid);
Unit:PlaySpellVisual(lua_State * L, Unit * ptr);
Unit:RemoveThreatByPtr(lua_State * L, Unit * ptr);
Unit:EventCastSpell(lua_State * L, Unit * ptr);
Unit:AttackReaction(lua_State * L, Unit * ptr);
Unit:DismissPet(lua_State * L, Unit * ptr);
Unit:HandleEvent(lua_State * L, Unit * ptr);
Unit:SetMoveRunFlag(lua_State * L, Unit * ptr);
Unit:SendChatMessage(Language, Type, "Message"); -- Langage; what language message is in, type = what form message is in (say/yell/whisper), "message" = duh
Unit:MoveTo(x, y, z, o); -- Once NPC gets to position i reccomend using Unit:SetFacing(Orientation) if O coordinate doesn't work.
Unit:SetMovementType(lua_State * L, Unit * ptr);
Unit:CastSpell(SpellID); -- Casts spell on Itself
Unit:CastSpellOnTarget(spellID, target); -- Casts spell ID on a target with no casttime, mights till be bugged and cast on itself
Unit:FullCastSpell(spellid); -- Fully casts a spell on itself / aoe spell
Unit:FullCastSpellOnTarget(spellid, target); -- Full casts a spell on a target.
Unit:SpawnGameObject(GOID, x, y, z, o, duration); -- self explanitory (set duration to 0 to keep gameobject spawned until server restart/shutdown
Unit:SpawnCreature(NPCID, x, y, z, o, faction, duration); -- self explanitory (set duration to 0 to keep creatued spawned forever until server restart/shutdown)
Unit:RegisterEvent("Event", Interval, IntervalCount); -- "Event"; event name, Interval; amount of time between registering the event again, IntervalCount; Amount of times to register the event.
Unit:RemoveEvents(); -- Removes all events from the Unit
Unit:SendBroadcastMessage("Text"); -- player only command, sends to chat box (player:SendBroadcastMessage("BroadcastMessageAppearsInTextBox"))
Unit:SendAreaTriggerMessage(lua_State * L, Unit * ptr); -- player only command, sends across screen (player:SendAreaTriggerMessage("AreaTriggerMessageAppearsAcrossScreen"))
Unit:KnockBack(dx, dy, affect1, affect2); -- Not sure, distancex, distancey, affects might be spell ID's?
Unit:MarkQuestObjectiveAsComplete(lua_State * L, Unit * ptr); -- no clue
Unit:LearnSpell(SpelLID); -- learns spellid, may be player only command
Unit:UnlearnSpell(SpellID); -- Unlearns spellid, may be player only command
Unit:HasFinishedQuest(QuestID); -- Returns true / 1 if true
Unit:ClearThreatList(); -- Drops all agro, may even leave combat
Unit:ChangeTarget(lua_State * L, Unit * ptr);
Unit:Emote(emoteid, time);
Unit:Despawn(despawntime, respawntime); -- despawntime = despawns in x miliseconds, respawntime = respawns in x miliseconds. (To Permanantly remove a creature spawned by another creature with no SQLID, use :RemoveFromWorld()
Unit:PlaySoundToSet(SoundID);
Unit:RemoveAura(SpellID);
Unit:StopMovement(Time); -- time = Time in miliseconds
Unit:AddItem(itemid, itemcount); -- playeronly command
Unit:RemoveItem(itemid, itemcount); -- playeronly command
Unit:CreateCustomWaypointMap(lua_State * L, Unit * ptr);
Unit:CreateWaypoint(lua_State * L, Unit * ptr);
Unit:DestroyCustomWaypointMap(lua_State * L, Unit * ptr);
Unit:MoveToWaypoint(lua_State * L, Unit * ptr);
Unit:TeleportUnit(map, x, y, z); -- Teleports player that clicked to location, not sure~ might teleport the Unit.
Unit:ClearHateList(); -- Resets threat list, gets random target
Unit:WipeHateList(); -- clears hate list, might leave combat
Unit:WipeTargetList(lua_State * L, Unit * ptr);
Unit:WipeCurrentTarget(lua_State * L, Unit * ptr);
Unit:CastSpellAoF x, y, z, spellid); -- self explanitory
Unit:RemoveAllAuras(); -- removes all auras, hostile and friendly
Unit:StopChannel(); -- stops channeling
Unit:ChannelSpell(spellid, target); -- channels spell on target?
Unit:ReturnToSpawnPoint(); -- returns to spawn point
Unit:HasAura(spellid); -- returns true or 1 if true.
Unit:Land(); -- Unit removes 1024 flag of flying.
Unit:CancelSpell(spellid); -- stops casting spell?
Unit:Root(target); -- self
Unit:Unroot(target); -- explanitory?
Unit:CalcDistance(target); -- returns value based in yards?
Unit:ModUInt32Value(lua_State * L, Unit * ptr);
Unit:ModFloatValue(lua_State * L, Unit * ptr);
Unit:SendData(lua_State * L, Unit * ptr);
Unit:InitPacket(lua_State * L, Unit * ptr);
Unit:AddDataToPacket(lua_State * L, Unit * ptr);
Unit:AddGuidDataToPacket(lua_State * L, Unit * ptr);
Unit:AdvanceQuestObjective(lua_State * L, Unit * ptr);
Unit:Heal(lua_State * L, Unit * ptr);
Unit:Energize(lua_State * L, Unit * ptr);
Unit:SendChatMessageAlternateEntry(lua_State * L, Unit * ptr);
Unit:SendChatMessageToPlayer(lua_State * L, Unit * ptr);
Unit:Strike(lua_State * L, Unit * ptr);
Unit:Kill(target);
Unit:DealDamage(lua_State * L, Unit * ptr);
Unit:CreateGuardian(lua_State * L, Unit * ptr);
Unit:CalcToDistance(lua_State * L, Unit * ptr);
Unit:CalcAngle(lua_State * L, Unit * ptr);
Unit:CalcRadAngle(lua_State * L, Unit * ptr);
Unit:IsInvisible(lua_State * L, Unit * ptr);
Unit:IsInvincible(lua_State * L, Unit * ptr);
Unit:ResurrectPlayer(player); -- player only command
Unit:KickPlayer(lua_State * L, Unit * ptr);
Unit:CanCallForHelp(lua_State * L, Unit * ptr);
Unit:CallForHelpHp(lua_State * L, Unit * ptr);
Unit:RemoveFromWorld(); -- Removes Unit From World (useful for npcs not saved to the Db {NPC spawned by other NPCS with no GUID})
Unit:SpellNonMeleeDamageLog(lua_State * L, Unit * ptr);
Unit:ModThreat(lua_State * L, Unit * ptr);
Unit:AddAssistTargets(lua_State * L, Unit * ptr);
Unit:RemoveAurasByMechanic(lua_State * L, Unit * ptr);
Unit:RemoveAurasType(lua_State * L, Unit * ptr);
Unit:AddAuraVisual(lua_State * L, Unit * ptr);
SET COMMANDS
Unit:SetPlayerStanding(lua_State * L, Unit * ptr);
Unit:SetPlayerLevel(level); -- might not work
Unit:SetPlayerAtWar(lua_State * L, Unit * ptr);
Unit:SetCreatureName(lua_State * L, Unit * ptr);
Unit:SetDeathState(lua_State * L, Unit * ptr);
Unit:SetPowerType(lua_State * L, Unit * ptr);
Unit:SetAttackTimer(time, duration);
Unit:SetMana(Value); -- sets currnet mana
Unit:SetMaxMana(Value);
Unit:SetHealth(Value); -- sets current health
Unit:SetMaxHealth(Value);
Unit:SetFlying(); -- Sets NPC to fly.
Unit:SetCombatCapable(1); --------\
Unit:SetCombatMeleeCapable(1); ----\
Unit:SetCombatRangedCapable(1); ----\_________ Set to 1 for Disableing Capableness, set to 0 to enable it again.
Unit:SetCombatSpellCapable(1); -----/
Unit:SetCombatTargetingCapable(1);-/
Unit:SetNPCFlags(NPCFLAGS); -- sets npc flags
Unit:SetModel(displayid); -- displayid
Unit:SetScale(Scale); -- size
Unit:SetFaction(faction); -- faction id
Unit:SetStandState(lua_State * L, Unit * ptr);
Unit:SetTauntedBy(lua_State * L, Unit * ptr);
Unit:SetSoulLinkedWith(lua_State * L, Unit * ptr);
Unit:SetInFront(lua_State * L, Unit * ptr);
Unit:SetHealthPct(%); -- sets health Percent
Unit:SetOutOfCombatRange(lua_State * L, Unit * ptr);
Unit:ModifyRunSpeed(lua_State * L, Unit * ptr);
Unit:ModifyWalkSpeed(lua_State * L, Unit * ptr);
Unit:ModifyFlySpeed(lua_State * L, Unit * ptr);
Unit:SetRotation(Orientation);
Unit:SetOrientation(Orientation);
Unit:SetUInt32Value(lua_State * L, Unit * ptr);
Unit:SetUInt64Value(lua_State * L, Unit * ptr);
Unit:SetFloatValue(lua_State * L, Unit * ptr);
Unit:SetUnitToFollow(lua_State * L, Unit * ptr);
Unit:SetNextTarget(lua_State * L, Unit * ptr);
Unit:SetPetOwner(lua_State * L, Unit * ptr);
Unit:SetFacing(lua_State * L, Unit * ptr);
GAMEOBJECT LIST
GET COMMANDS
GameObject:GetName(lua_State * L, GameObject * ptr);
GameObject:GetMapId(lua_State * L, GameObject * ptr);
GameObject:GetCreatureNearestCoords(lua_State * L, GameObject * ptr);
GameObject:GetGameObjectNearestCoords(lua_State *L, GameObject * ptr);
GameObject:GetAreaID(lua_State * L, GameObject * ptr);
GameObject:GetClosestPlayer(lua_State * L, GameObject * ptr);
GameObject:GetZoneId(lua_State *L, GameObject * ptr);
GameObject:GetItemCount(lua_State * L, GameObject * ptr);
GameObject:GetSpawnX(lua_State * L, GameObject * ptr);
GameObject:GetSpawnY(lua_State * L, GameObject * ptr);
GameObject:GetSpawnZ(lua_State * L, GameObject * ptr);
GameObject:GetSpawnO(lua_State * L, GameObject * ptr);
GameObject:GetInRangePlayersCount(lua_State * L, GameObject * ptr);
GameObject:GetEntry(lua_State * L, GameObject * ptr);
GameObject:GetX(lua_State * L, GameObject * ptr);
GameObject:GetY(lua_State * L, GameObject * ptr);
GameObject:GetZ(lua_State * L, GameObject * ptr);
GameObject:GetO(lua_State * L, GameObject * ptr);
GameObject:GetInRangePlayers(lua_State * L, GameObject * ptr);
GameObject:GetInRangeGameObjects(lua_State * L, GameObject * ptr);
GameObject:GetInstanceID(lua_State * L, GameObject * ptr);
GameObject:GetUInt64Value(lua_State * L, GameObject * ptr);
GameObject:GetUInt32Value(lua_State * L, GameObject * ptr);
GameObject:GetFloatValue(lua_State * L, GameObject * ptr);
GameObject:GetGUID(lua_State * L, GameObject* ptr);
OTHER COMMANDS
GameObject:Teleport(lua_State * L, GameObject * ptr); -- player command, player:Teleport(map, x, y, z)
GameObject:AddItem(lua_State * L, GameObject * ptr); -- player command, player:AddItem(itemid, itemcount)
GameObject:Despawn(lua_State * L, GameObject * ptr);
GameObject:IsInWorld(lua_State * L, GameObject * ptr);
GameObject:IsInBack(lua_State * L, GameObject * ptr);
GameObject:IsInFront(lua_State * L, GameObject * ptr);
GameObject:PlaySoundToSet(lua_State * L, GameObject * ptr);
GameObject:SpawnCreature(lua_State * L, GameObject * ptr);
GameObject:SpawnGameObject(lua_State * L, GameObject * ptr);
GameObject:CalcDistance(lua_State * L, GameObject * ptr);
GameObject:SetOrientation(lua_State * L, GameObject * ptr);
GameObject:RemoveFromWorld(lua_State * L, GameObject * ptr);
GameObject:CalcRadAngle(lua_State * L, GameObject * ptr);
GameObject:SetUInt32Value(lua_State * L, GameObject * ptr);
GameObject:SetUInt64Value(lua_State * L, GameObject * ptr);
GameObject:SetFloatValue(lua_State * L, GameObject * ptr);
GameObject:ModUInt32Value(lua_State * L, GameObject * ptr);
GameObject:CastSpell(lua_State * L, GameObject * ptr);
GameObject:FullCastSpell(lua_State * L, GameObject * ptr);
GameObject:CastSpellOnTarget(lua_State * L, GameObject * ptr);
GameObject:FullCastSpellOnTarget(lua_State * L, GameObject * ptr);
GameObjectvEventCastSpell(lua_State * L, GameObject * ptr);
GameObject:GossipObjectCreateMenu(lua_State * L, GameObject * ptr);
GameObject:GossipObjectMenuAddItem(lua_State * L, GameObject * ptr);
GameObject:GossipObjectSendMenu(lua_State * L, GameObject * ptr);
GameObject:GossipObjectComplete(lua_State * L, GameObject * ptr);
GameObject:GossipObjectSendPOI(lua_State * L, GameObject * ptr);
GameObject:ModUInt32Value(lua_State * L, GameObject * ptr);
GameObject:ModFloatValue(lua_State * L, GameObject * ptr);
GameObject:GetFloatValue(lua_State * L, GameObject * ptr);
GameObject:InitPacket(lua_State * L, GameObject * ptr);
GameObject:AddDataToPacket(lua_State * L, GameObject * ptr);
GameObject:AddGuidDataToPacket(lua_State * L, GameObject * ptr);
GameObject:SendData(lua_State * L, GameObject * ptr);
[1.5]Commenting
Thought i'd add this in here real quick. Commenting code is done by using two '-' followed by a space and text of your choice for reminders or tags for certain lines of code. heres an example;
function Creature_OnLoad(Unit, Event)
Unit:RegisterEvent("Timer", 1000, 1)
end
function Timer(Unit, Event)
Unit:FullCastSpellOnTarget(35853, Unit:GetRandomPlayer(7)) -- [SPELLID:35853 = Chain Fireball]
end
another example is encasing a large paragraph of text using --[[ & -- ]. Heres an example
-- [[
################################################## #############
# #
# #
# #
# Dumb Header For scripting Teams? #
# #
# #
# #
################################################## ############# -- ]]
function Creature_OnLoad(Unit, Event)
Unit:RegisterEvent("SendChatMessage", 1000, 0)
end
function SendChatMessage(Unit, Event)
Unit:SendChatMessage(12, 0, "Im an annoying spammer NPC...")
Unit:SetFaction(14)
Unit:CastSpell(5) -- Deathtouches himself
end
[2.0] Creature Events
Most Common Creature Commands & Usage[2.1]
The most common commands when scripting a boss fight of creature are;
Unit:RegisterEvent("EventName", Interval, IntervalCount)
Unit:CastSpell(Spellid)
Unit:CastSpellOnTarget(SpellId, target)
Unit:FullCastSpellOnTarget(SpellId, target)
Unit:FullCastSpell(SpellID)
Unit:GetHealthPct()
Unit:SetModel(DisplayID)
Unit:GetRandomPlayer(FLAG)
[RANDOM FLAGS]
RANDOM_ANY = 0,
RANDOM_IN_SHORTRANGE = 1,
RANDOM_IN_MIDRANGE = 2,
RANDOM_IN_LONGRANGE = 3,
RANDOM_WITH_MANA = 4,
RANDOM_WITH_RAGE = 5,
RANDOM_WITH_ENERGY = 6,
RANDOM_NOT_MAINTANK = 7,
Unit:GetClosestPlayer()
Unit:SpawnCreature(creatureID, x, y, z, o, faction, duration) -- duration = 0 for infinite.
Unit:SendChatMessage(language, channeltype, "Message")
Unit:RemoveEvents()
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("WatchHealth", 1000, 1)
end
function WatchHealth(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RemoveEvents() -- Removes constant Registering event from OnCombat
Unit:RegisterEvent("Phase2", 1000, 1) -- Registers Phase2.
Unit:FullCastSpellOnTarget(11, Unit:GetRandomPlayer(7))
Unit:SendChatMessage(41, 0, "Creature begins to transform!, and his minion appears!")
Unit:SetModel(28090)
Unit:SpawnCreature(6, 1234, 432, 42, 0, 14, 10000) -- Spawns creature 6(Kobold vermin), at x1234, y 432, z 42, and its orientation facing north. its faction is 14, and it will despawn 10 seconds after it is spawned.
else
Unit:RegisterEvent("WatchHealth", 5000, 1)
end
end
Languages and Channeltypes for SendChatMessage
[Language ID
0 = Universal
1 = Orcish
2 = Darnassian
3 = Tauron
6 = Dwarfs
7 = Common
8 = Demonic
9 = Titans
13 = Gnomish
14 = Troll language
33 = Gutterspeak
35 = Draenei
[ChannelTypes
12 = Say
14 = Yell
13 = Whisper
16 = Emote
41 = Area Broadcast with sound \__________ ex: "The lava around sarthiron begins to churn" then the bell noise.
42 = Area Broadcast with sound /
[2.3]Combat and General Events
Bosses are where you can really let your imagination run wild. A Boss must be fun. But no matter how simple it is, you must make sure it is a unique and entertaining fight, Otherwiset, The fight will get boring, no one will attempt the boss as much, everyone will have the same loot. So i'm here to hopefully show you how to make a good fun boss fight. However, your scripts are only as good as your imagination.
But before i start, any new Commands i use in the examples below will be explained and they will also have an example for them. Also, i will be using Kobold Vermins entry ID for the boss, rawr.
To start, I will show you how to create phases, There is a few different ways;
1). This takes a bit more work, but is generally easier to handle.
function Creature_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "rawr its my first phase")
Unit:RegisterEvent("Creature_FirstPhase", 1000, 1)
end
function Creature_FirstPhase(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RegisterEvent("Creature_SecondPhase", 1000, 1) -- The boss is below 80% hp, registering 2nd phase.
Unit:SendChatMessage(14, 0, "Rawr entering second phase") -- This is where you will input any spells or chat messages you only want to be said ONCE when your npc enters their next phase.
else
Unit:RegisterEvent("Creature_FirstPhase", 1000, 1) -- If the boss isn't below 80% hp, it will register the event and check again every 1 second.
end
end
function Creature_SecondPhase(Unit, Event)
-- Second phase code.
end
RegisterUnitEvent(6, 1, "Creature_OnCombat")
2). This requires the least work, but sometimes can cause problems
function Creature_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "rawr its my first phase")
Unit:RegisterEvent("Creature_FirstPhase", 1000, 0)
end
function Creature_FirstPhase(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RemoveEvents() -- Removing this event , so it stops registering since its interval count is set to infinite.
Unit:RegisterEvent("Creature_SecondPhase", 1000, 0)
end
end
function Creature_SecondPhase(Unit, Event)
-- Second phase code.
end
[NOTE]: Unit:RemoveEvents() must be before Unit:RegisterEvent("Creature_SecondPhase", 1000,0) otherwise, Creature_SecondPhase event, will be removed.
3). This way, is similar to the first one, except your phases aren't based on the bosses health, there based on if, for example - There add dies, and we have a stoptrigger get set to 1. I added in another variable to count how many seconds goesby so you can time spells or events you want to happen at certain points in phase one.
local intCreatureAddDeadTrigger = 0
local intPhaseOneCount = 0
function Creature_OnCombat(Unit, Event)
Unit:SendChatMessage(41, 0, "The creature awakens.")
Unit:RegisterEvent("Creature_PhaseOne", 1000, 1)
Unit:SpawnCreature(NPCID, x, y, z, o, 14, 0)
end
function Creature_PhaseOne(Unit, Event)
intPhaseOneCount = intPhaseOneCount + 1
if (intPhaseOneCount == 15) then
-- After 15 seconds he'll do this and so on...
elseif (intPhaseOneCount == 30) then
-- and so on...
elseif (intPhaseOneCount == 35) then
-- ... and so on...
elseif (intPhaseOneCount == 50) then
-- On your last event you want to happen, set intPhaseOneCount back to 0 so it will continue to loop the events above.
end
if (intCreatureAddDeadTrigger == 1) then
Unit:RegisterEvent("Creature_PhaseTwo", 1000, 1)
else
Unit:RegisterEvent("Creature_PhaseOne", 1000, 1)
end
end
function Creature_PhaseTwo(Unit, Event)
-- awmahgawd phase 2.
end
function CreatureAdd_OnDied(Unit, Event)
intCreatureAddDeadTrigger = 1
end
RegisterUnitEvent(NPCID, 4, "CreatureAdd_OnDied")
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
At first, i was surprised about how short this section was, but then i realized, After you know about what you can do with variables and if statements, and then how to make phases, you can do whatever you want.
[2.9]Creature Summary and Tips
There is a few things i know to make your life much much easier. The first thing is making an NPC as a whole, a variable, Meaning NPCs can cast spells on each other, Say things, all in the same function.. (Thanks Stoneharry)
function Creature_OnLoad(Unit, Event)
-- Say the bosses name is Fresca (Courtesy of the leaning tower of pop cans on my desk)
Fresca = Unit -- What this does, is makes the "Unit" from this function into the variable of "Fresca"
end
RegisterUnitEvent(NPCID, 18, "Creature_OnLoad")
The reason this is insanely useful is due to being able to have two different creatures being able to do something in the same function. And when your timing an even where two different npcs talk to eachother, ect ect. You can do that without making a parralell function line and trying to get the timing right. heres an example.
local TalkStartCount = 0
function CreatureOne_OnLoad(Unit, Event)
COne = Unit
end
function CreatureTwo_OnLoad(Unit, Event)
CTwo = Unit
end
function CreatureOne_OnCombat(Unit, Event)
COne:RegisterEvent("Talk_Start", 1000, 15)
COne:SetCombatMeleeCapable(1) -- All this just makes them friendly, and stand still / not attackable
CTwo:SetCombatMeleeCapable(1) -- Whlie there talking to each other before
COne:SetFaction(35) -- the actual event happens and
CTwo:SetFaction(35) -- you have to fight them
end
function Talk_Start(Unit, Event)
TalkStartCount = TalkStartCount + 1
if (TalkStartCount == 1) then
COne:SendChatMessage(14, 0, "Hey, how are you doing")
elseif (TalkStartCount == 5) then
CTwo:SendChatMessage(14, 0, "Good... and yourself")
elseif (TalkStartCount == 10) then
COne:SendChatMessage(14, 0, "I'm going to kill you")
elseif (TalkStartCount == 15) then
CTwo:SendChatMessage(14, 0, "gasp.")
CTwo:SetFaction(84)
COne:SetFaction(106)
CTwo:SetCombatMeleeCapable(0)
COne:SetCombatMeleeCapable(0)
end
end
RegisterUnitEvent(NPCID, 18, "CreatureTwo_OnLoad")
RegisterUnitEvent(NPCID, 18, "CreatureOne_OnLoad")
RegisterUnitEvent(NPCID, 1, "CreatureOne_OnCombat")
This instead of...
local TalkStartCountTwo = 0
local TalkStartCountOne = 0
function CreatureTwo_OnCombat(Unit, Event)
Unit:RegisterEvent("TalkTwo_Start", 1000, 15)
Unit:SetCombatMeleeCapable(1)
Unit:SetFaction(35)
end
function TalkTwo_Start(Unit, Event)
TalkStartCountTwo = TalkStartCountTwo + 1
if (TalkStartCountTwo == 1) then
COne:SendChatMessage(14, 0, "Hey, how are you doing")
elseif (TalkStartCountTwo == 10) then
COne:SendChatMessage(14, 0, "I'm going to kill you")
Unit:SetFaction(84)
Unit:SetCombatMeleeCapable(0)
end
end
function CreatureOne_OnCombat(Unit, Event)
Unit:RegisterEvent("TalkOne_Start", 1000, 15)
Unit:SetCombatMeleeCapable(1)
Unit:SetFaction(35)
end
function TalkOne_Start(Unit, Event)
TalkStartCountOne = TalkStartCountOne + 1
if (TalkStartCountOne == 5) then
CTwo:SendChatMessage(14, 0, "Good... and yourself")
elseif (TalkStartCountOne == 15) then
Unit:SendChatMessage(14, 0, "Gasp")
Unit:SetFaction(106)
Unit:SetCombatMeleeCapable(0)
end
end
RegisterUnitEvent(NPCID, 18, "CreatureTwo_OnLoad")
RegisterUnitEvent(NPCID, 18, "CreatureOne_OnLoad")
RegisterUnitEvent(NPCID, 1, "CreatureOne_OnCombat")
RegisterUnitEvent(NPCID, 1, "CraetureTwo_OnCombat")
Red highlights indicate what doesn't need to be there if we used the first method.
You can probably imagine how much more usefull this will become once your scripts get larger, and you have more than 2 NPC's.
Another tip is keeping you code clean, there is proper coding edicate i believe, but if its your own script. using Tabs instead of 5 spaces isn't going to hurt anything. Space your codes lines out appropriately so its easy to read through the code, or if you realase you scripts its easy for people to re-read them and modify them to their liking.
Sometimes you'll see code with no spaces, and some with plenty of spaces, heres an example.
No Spaces
local intCount = 0
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("OmgWhatAMess", 1000, 1)
Unit:SendChatMessage(14, 0, "Hello everyone")
end
function OmgWhatAMess(Unit, Event)
intCount = intCount + 1
if (intCount == 1) then
Unit:SendChatMessage(12, 0, "intcount is equal to 1)
elseif (intCount == 2) then
UnitSendChatMessage(12, 0, "intCount is equal to 2
Unit:FullCastSpellOnTarget(11, Unit:GetClosestPlayer())
else
Unit:SendChatMessage(14, 0, "whats going on")
intCount = 0
end
if Unit:GetHealthPct() <= 80 then
Unit:RegisterEvent("phasetwo", 1000, 1)
else
Unit:RegisterEvent(OmgWhatAMess", 1000, 1)
end
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
With Spaces
local intCount = 0
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("OmgWhatAMess", 1000, 1)
Unit:SendChatMessage(14, 0, "Hello everyone")
end
function OmgWhatAMess(Unit, Event)
intCount = intCount + 1
if (intCount == 1) then
Unit:SendChatMessage(12, 0, "intcount is equal to 1)
elseif (intCount == 2) then
UnitSendChatMessage(12, 0, "intCount is equal to 2
Unit:FullCastSpellOnTarget(11, Unit:GetClosestPlayer())
else
Unit:SendChatMessage(14, 0, "whats going on")
intCount = 0
end
if Unit:GetHealthPct() <= 80 then
Unit:RegisterEvent("phasetwo", 1000, 1)
else
Unit:RegisterEvent(OmgWhatAMess", 1000, 1)
end
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
With spaces, it becomes much clearer where If statements start and end, and in general whats actually happening in the script.
==============================================\/ Continued \/=============================================
If anything is wrong with this guide, or information is incorrect, please post back and I'll correct it, Be aware I'm not an Lua expert, i learned by looking at many Lua guides, and by messing around and testing out stuff in-game. These are the concepts i feel i have a pretty good understanding of so far. If there is anything i'm missing in this guide, also post and i'll add it in. (Also say if any of the examples / sections of this guide are unclear, i'll try my best to fix them Edit: I've been learning C++, and well... if you have the time, its definitely worth learning over lua.)
After reading through all the other guides that are vague and leave out very basic information that you are expected to know,
but do not.
i decided to make a very very thorough one.
[Table of Contents]
[1.0]: General
[1.1]: Functions & Registering Events
[1.2]: Variables
[1.3]: The If Statement
[1.4]: Command List & Usage
[2.0] Creature Events
[2.1]: Most Common Creature Commands & Usage
[2.5]: Combat and General Events
[2.9]: Creature Summary and Tips
[3.0] Gameobject Events.
[3.1] Most Common Gameobject Commands & Usage
[3.5] Gameobject Events
[3.9] Gameobject Summary and Tips
[5.0] Generalized Gossip Events.
[$.#]3x7r4 1Nf0rNm471on
.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: .:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: .:.:.:.:.:.:.:.:.:.:.:.:.
[1.0]General
[1.1]Functions & Registering Events
Functions are blocks of code created to be called upon and do a specific task when your script is executed. The only way to initially call on a function is by having a certain Event happen to the scripted Unit(Whether it be a Creature, Gameobject, or Item)
These triggering events are;
-Accepting a Quest
-Completing a Quest
-Canceling a Quest
-Activating a Quest Gameobject
-Killing a Creature Required for a Quest
-Exploring an Area for a quest
-Picking up an Item for a Quest
-Creature Entering Combat
-Creature Leaving Combat
-Creature Killing an Enemy
-Creature Dieing
-Creature being Parried
-Creature being Dodged
-Creature being Blocked
-Creature being Critically Hit
-Creature Parrying
-Creature Dodging
-Creature Blocking??
-Creature Critically Hitting
-Creature Hitting
-Creature Feared
-Creature Flee
-Creature Loading
-Creature Reaching a Waypoint
-Creature having loot taken from it
-Creature Emoting
-Gameobject being Created
-Gameobject Spawning
-Gameobject having loot taken from it
-Gameobject being clicked/used
-Gameobject Despawning
-Talking to a Gossip Unit
-Selecting an option from a Gossip Unit
-Closing a Gossip Window / Ending it
The Skeleton if you will, of a function must always look like this;
function FunctionName(Unit, Event)
endWhen this function is called it will execute what is between the Skeleton. As stated above, it can only be initially called by a trigger event. To have a function called when a specific event happens
you must register that function to do so. Below is the syntax used to register different types of Events.
RegisterUnitEvent(NPCID, FLAG, "FunctionName")
RegisterUnitGossipEvent(NPCID, FLAG, "FunctionName")
RegisterItemGossipEvent(ItemID, FLAG, "Item_Trigger")
RegisterGameObjectEvent(GoID, FLAG, "FunctionName")
Replacing the NPC/item/Go Id's with the ones you will spawn in the world and use. the 'FLAG' is a number that indicates the event that the registered function will trigger on. Here is a breakdown of how to register an event.
[NOTE]When Registering Events, you type it at the bottom or top of the script.
Please remember that no function has to have any particular name. Not having "OnCombat" in the function name, won't affect if it gets triggered on combat, as long as its function name matches the name your registering, and you have the correct flag.
function Creature_OnCombat(Unit, Event)
end
RegisterUnitEvent(6, 1,"Creature_OnCombat")
6: Is the NPCID of a Kobold Vermin, Change it to the NPCID you want to script.
1: Is the Flag of the type of event you want this registered function to get triggered on.
"Creature_OnCombat": Is the name of the function your registering to be executed when the Kobold enters combat.
RegisterUnitEvent: Is used to Register a Unit/Creature Event.
NPCID was 6 (For Kobold Vermin)
EventFlag was 1 (To Register the function Creature_OnCombat when the kobold vermin enters combat
FunctionName "Creature_OnCombat"
Below is a Complete List of EventFlags you can use when registering an event.
[QUEST EVENTS]
QUEST_EVENT_ON_ACCEPT = 1,
QUEST_EVENT_ON_COMPLETE = 2,
QUEST_EVENT_ON_CANCEL = 3,
QUEST_EVENT_GAMEOBJECT_ACTIVATE = 4,
QUEST_EVENT_ON_CREATURE_KILL = 5,
QUEST_EVENT_ON_EXPLORE_AREA = 6,
QUEST_EVENT_ON_PLAYER_ITEMPICKUP = 7,
QUEST_EVENT_COUNT,
[CREATURE EVENTS]
CREATURE_EVENT_ON_ENTER_COMBAT = 1,
CREATURE_EVENT_ON_LEAVE_COMBAT = 2,
CREATURE_EVENT_ON_TARGET_DIED = 3,
CREATURE_EVENT_ON_DIED = 4,
CREATURE_EVENT_ON_TARGET_PARRIED = 5,
CREATURE_EVENT_ON_TARGET_DODGED = 6,
CREATURE_EVENT_ON_TARGET_BLOCKED = 7,
CREATURE_EVENT_ON_TARGET_CRIT_HIT = 8,
CREATURE_EVENT_ON_PARRY = 9,
CREATURE_EVENT_ON_DODGED = 10,
CREATURE_EVENT_ON_BLOCKED = 11,
CREATURE_EVENT_ON_CRIT_HIT = 12,
CREATURE_EVENT_ON_HIT = 13,
CREATURE_EVENT_ON_ASSIST_TARGET_DIED = 14,
CREATURE_EVENT_ON_FEAR = 15,
CREATURE_EVENT_ON_FLEE = 16,
CREATURE_EVENT_ON_CALL_FOR_HELP = 17,
CREATURE_EVENT_ON_LOAD = 18,
CREATURE_EVENT_ON_REACH_WP = 19,
CREATURE_EVENT_ON_LOOT_TAKEN = 20,
CREATURE_EVENT_ON_AIUPDATE = 21,
CREATURE_EVENT_ON_EMOTE = 22,
CREATURE_EVENT_COUNT,
[GAMEOBJECT EVENTS]
GAMEOBJECT_EVENT_ON_CREATE = 1,
GAMEOBJECT_EVENT_ON_SPAWN = 2,
GAMEOBJECT_EVENT_ON_LOOT_TAKEN = 3,
GAMEOBJECT_EVENT_ON_USE = 4,
GAMEOBJECT_EVENT_AIUPDATE = 5,
GAMEOBJECT_EVENT_ON_DESPAWN = 6,
GAMEOBJECT_EVENT_COUNT,
[GOSSIP EVENTS]
GOSSIP_EVENT_ON_TALK = 1,
GOSSIP_EVENT_ON_SELECT_OPTION = 2,
GOSSIP_EVENT_ON_END = 3,
GOSSIP_EVENT_COUNT,
[RANDOM FLAGS]
RANDOM_ANY = 0,
RANDOM_IN_SHORTRANGE = 1,
RANDOM_IN_MIDRANGE = 2,
RANDOM_IN_LONGRANGE = 3,
RANDOM_WITH_MANA = 4,
RANDOM_WITH_RAGE = 5,
RANDOM_WITH_ENERGY = 6,
RANDOM_NOT_MAINTANK = 7,
RANDOM_COUNT,
[NOTE]: 'RandomFlags' are generally used for creature targeting. hers an example.
Unit:GetRandomPlayer(7)That will get a random player that is not the main tank. (Replacing the the 7 with a different flag when changing it of course).
When creating the meat of a function, every Lua command must have a prefix before the command that tells what will be executing the command(Gameobject/Creature/Item)
For example, when you want a Creature to cast a spell on a random target. it would need a prefix telling who is casting the spell;
function Creature_OnCombat(Unit, Event)
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(7))
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
Above, tells the Unit, To cast spell 11 (Frost bolt of the Ages) on a random player that isn't the main tank. Since it was registed "OnCombat", it will only cast this spell once as the unit enters combat, To make it cast periodically, you Register an event from inside a function.
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("FunctionName", Interval, IntervalCount)
end
function Frostbolt(Unit, Event)
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(7)
end
FunctionName is the name of the function your calling/registering (the name must match the name of the function you are calling), the interval is the amount of time it will take for the event to get registered, and the IntervalCount is the amount of times the function will be registered (Leave it at 0 for infinite)
Now if you make the interval 1000, and the invervalcount 0. It will cast Frostbolt at a random target that isn't the main tank every second, But say your group wipes. He will still register the event when not in combat, and when he enters combat again he will cast frostbolt twice a second. Which is why you need to use the command
Unit:RemoveEvents() which clears all events from the unit. You do this by creating a new function and registering it with the flag "2" for 'CREATURE_EVENT_ON_LEAVE_COMBAT' and "4" for "CREATURE_EVENT_ON_DIED", Then inserting Unit:RemoveEvents(), clearing all events when the NPC Leaves combat / your group wipes.
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("FrostboltSpam", 1000, 0)
end
function FrostboltSpam(Unit, Event)
Unit:FullCastSpellOnTarget(11, Unit:GetClosestPlayer())
end
function Creature_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Creature_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
RegisterUnitEvent(NPCID, 2, "Creature_OnLeaveCombat")
RegisterUnitEvent(NPCID, 4, "Creature_OnDied")
You can only Register events with Creatures/NPC's. From inside Combat Events / Gossip Events, gameobjects and items cannot register events..
[1.2]Variables
Variables are a value stored in memory that can be called upon or modified at a later point in your script. Just like in grade 1 where you have to find out what goes in the box with a equation like so 1 + 2 = [ ]. The Box being the variable, would end up being 3. However we don't use boxes, It is easiest to name your variable after what the variable will be used for, especially when making large scripts. Now there are 2 types of Variables. Global variables, and local variables. Global variables are variables used throughout your entire script. Local variables are variables used within a function. When creating local variables, they need to be declared (Making the Lua engine realize they are local variables). they are declared by using the term 'local' behind the variable your declaring.
function Creature_OnCombat(Unit, Event)
local intVariable = 0
endGlobal variables do not need declaration and can be created the same way as local variables, except without the usage of the term 'local'
function Creature_OnCombat(Unit, Event)
intVariable = 0
end[NOTE]You can have the same local and global variable names as long as you do not use both of them inside the same function.
[NOTE]I'm Not sure about this haven't ever tried it, But i believe Global variables, can be used throughout all your scripts in the scripts folder. So if you want a variable to be relative to just one of your scripts, declare the variable as a local variable at the top of the script:
local intEnteredCombat = 0
function Creature_OnCombat(Unit, Event)
intEnteredCombat = intEnteredCombat + 1
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
[1.3]The If Statement
When scripting with Lua, One of the most handy things to understand is an If statement. How it works is, IF <this happens / is true> then <this will happen>. Example below:
local intVariable = 0
function Creature_OnCombat(Unit, Event)
intVariable = 0
if (intVariable == 0) then -- If intVariable is equal to something other than 0, nothing will happen when the creature enters combat.
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(7)) -- Otherwise it will cast spell 11 (frostbolt of the ages, on a random target that isn't the tank)
end
end
An if statement must always start with If, and end with end. when checking the variables value in a statement, you must use two equals signs, as opposed to one. This indicates you are checking the variables value, rather than modifying/setting it. Within an If statement you can have a few basic substatements (which are not limited to); Elseif, and Else. These statements do what they say.
function Creature_OnCombat(Unit, Event)
if (intVariable == 0) then
Unit:CastSpellOnTarget(11, Unit:GetRandomPlayer(0))
intVariable = 1
elseif (intVariable == 1) then
Unit:CastSpellOnTarget(5, Unit:GetRandomplayer(0))
else
Unit:SendChatMessage(14, 0, "intVariable has no value!)
intVariable = 0
end
end
Whats happening in the function above, is when the NPC enters combat for the first time, since intVariable was not given a value at any other point in the script, it is 'null' (nothing, no value). Which is not 0 or 1, thus executing what is in the 'else' statement, setting intVariable to 0, and sending a chat message. The 2nd time the creautre enters combat, they will cast frostbolt, and the third time and all times after that, they will cast death touch.
A good trick you can use with If statements, when timing scripts. is the use of a variable that equals itself + 1, take a look;
local intVariable = 0
function Creature_OnCombat(Unit, Event)
intVariable = 0 -- Setting a value so it isn't null.
Unit:RegisterEvent("Timer", 1000, 1)
end
function Timer(Unit, Event)
intVariable = intVariable + 1
if (intVariable == 1) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 1")
elseif (intVariable == 2) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 2")
elseif (intVariable == 3) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 3")
elseif (intVariable == 4) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 4")
elseif (intVariable == 5) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 5")
else
Unit:SendChatMessage(14, 0, "intVariable is another value aside from 1, 2, 3, 4, 5")
end
end
Now with the script above, since it's only getting registered once, (IntervalCount is 1) the function Timer, will only be executed once. we need to either set the intervalcount to 0, or create a Stop Variabe while looping the function.
local intVariable = 0
function Creature_OnCombat(Unit, Event)
intVariable = 0
intStop = 0 -- New Stop Variable
Unit:RegisterEvent("Timer", 1000, 1)
end
function Timer(Unit, Event)
intVariable = intVariable + 1
if (intVariable == 1) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 1")
elseif (intVariable == 2) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 2")
elseif (intVariable == 3) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 3")
elseif (intVariable == 4) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 4")
elseif (intVariable == 5) then
Unit:SendChatMessage(14, 0, "intVariable is equal to 5")
else
Unit:SendChatMessage(14, 0, "intVariable is another value aside from 1, 2, 3, 4, 5")
end
if (intStop == 1) then
-- nothing
elseif (intStop == 0) then
Unit:RegisterEvent("Timer", 1000, 1) -- Loops the Timer function unless intStop == 1, in which case it stops.
end
end
creating a stop variable can be useful for when you want to have a certain NPC's death trigger an event to temporarily stop, or prevent an NPC from spawning if one already spawned. And it is a lot safer as when you have intervalcount set to 0, if you spawn more than 1 NPC, you can have an event registered more often than you want.
[1.4]Command List & Usage
[NOTE]:Some of these Commands may not work with some Lua Engines
math.random(min, max) -- returns a random number between min and max. Best used as a variable
Ex.______________________
Choice=math.random(1,5)
if (choice == 5) then
player:SendAreaTriggerMessage("You just won the lottery")
end
_________________________
Gossip Commands
Item:GossipCreateMenu(textid, player, 0)
Item:GossipMenuAddItem(iconid, "name", intid, type);
Item:GossipSendMenu(player);
Item:GossipComplete(player);
Item:GossipSendPOI(player, Xcoord, Ycoord, icon, flags, data, nameofPOI);
Unit:GossipCreateMenu(textid, player, 0);
Unit:GossipMenuAddItem(iconid, "name" intid, type);
Unit:GossipSendMenu(player);
Unit:GossipComplete(player);
Unit:GossipSendPOI(player, Xcoord, Ycoord, icon, flags, data, nameofPOI);
GameObject:GossipCreateMenu(textid, player, 0);
GameObject:GossipMenuAddItem(iconid, "name", intid, type);
GameObject:GossipSendMenu(player);
GameObject:GossipComplete(player);
GameObject:GossipSendPOI(player, Xcoord, Ycoord, icon, flags, data, nameofPOI);
[NOTE] for GossipCreateMenu: textid, is the same id used in npc_textid, however you cannot have the same textid for 2 different menus.
[NOTE] iconid = Icon next to the text in the menu list ingame. intid is a variable used in GossipSubMenu, type - 0 is regular, 1 = code(A prompt box pops up and you have to enter a new value for the variable 'code', doesn't work that good.)
GET COMMANDS
Unit:GetPlayerRace(); -- returns number based on race. [1=Human][2=Orc][3=Dwarf][4=NightElf][5=Undead][6=Tauren][7=Gnome][8=Troll][10=BloodElf][11=Draenei]
Unit:GetCurrentSpellId(); -- Returns spell ID the target is currently casting
Unit:GetStanding(lua_State * L, Unit * ptr);
Unit:GetMainTank(lua_State * L, Unit * ptr);
Unit:GetAddTank(lua_State * L, Unit * ptr);
Unit:GetX(); -- Returns X Coordinate
Unit:GetY(); -- Returns Y Coordinate
Unit:GetZ(); -- Returns Z Coordinate
Unit:GetO(); -- Returns Orientation
Unit:GetTauntedBy(); -- returns player who taunted
Unit:GetSoulLinkedWith(lua_State * L, Unit * ptr);
Unit:GetItemCount(itemid); -- returns amount
Unit:GetName(); -- returns Unit Name
Unit:GetHealthPct(); -- Returns Units health betweeen 1 and 100
Unit:GetManaPct(); -- Returns Units Mana between 1 and 100
Unit:GetInstanceID(); -- returns instance id
Unit:GetClosestPlayer(RandomFlag); -- Gets closest player; use Random Flags.
Unit:GetRandomPlayer(RandomFlag); -- Gets random player; use Random Flags.
Unit:GetRandomFriend(); -- Gets Random friend / player; use Random flags?.
Unit:GetUnitBySqlId(); -- Gets another NPC by their SQLID
Unit:GetPlayerClass(); -- Returns number based on class. [Warrior=1][Paladin=2][Hunter=3][Rogue=4][Priest=5][Deathknight=6][Shaman=7][Mage=8][Warlock=9][Druid=11]
Unit:GetHealth(); -- Returns Units Current health
Unit:GetMaxHealth(); -- Returns units Max health
Unit:GetCreatureNearestCoords(x, y, z, NPCID);
Unit:GetGameObjectNearestCoords(x, y, z, GOID);
Unit:GetDistance(); -- Returns Distance. .debug rangecheck (Uses distance2dsq, 2 distance only.)
Unit:GetGUID(); -- Returns GUID
Unit:GetZoneId(); -- Returns GUID
Unit:GetMaxMana(Value); -- Sets Max Mana
Unit:GetMana(); -- Returns Current Mana
Unit:GetCurrentSpell(); -- returns current spell id?
Unit:GetSpawnO(); -- Returns Orientation of original Spawn
Unit:GetSpawnZ(); -- Returns Z Coordinate of original Spawn
Unit:GetSpawnY(); -- Returns Y Coordinate of original Spawn
Unit:GetSpawnX(); -- Returns X coordinate of Original Spanw
Unit:GetInRangePlayersCount(); -- Returns number based on amount of in range players.
Unit:GetUInt32Value(lua_State * L, Unit * ptr);
Unit:GetUInt64Value(lua_State * L, Unit * ptr);
Unit:GetFloatValue(lua_State * L, Unit * ptr);
Unit:GetAIState(lua_State * L, Unit * ptr);
Unit:GetCurrentSpell(); -- same as others?
Unit:GetInRangeGameObjects(); -- Returns Gameobjects in range in a Table (Cannot be used as a target)--\_____ Will get error "Unit Expected, got Nil"
Unit:GetInRangePlayers(); -- Returns In range Players in a Table (Cannot be used as a target)----------/
Unit:GetAITargets(lua_State * L, Unit * ptr);
Unit:GetUnitByGUID(); -- Returns Unit by their Guid
Unit:GetInRangeObjectsCount(); -- Returns a number based on amount of in range gameobjects
Unit:GetAITargetsCount(lua_State * L, Unit * ptr);
Unit:GetUnitToFollow(lua_State * L, Unit * ptr);
Unit:GetNextTarget(); -- Gets next highest threat target.
Unit:GetPetOwner(lua_State * L, Unit * ptr);
Unit:GetEntry(); -- Returns npc entryid?
Unit:GetFaction(); -- Returns NPC's faction
Unit:GetThreatByPtr(lua_State * L, Unit * ptr);
Unit:GetInRangeFriends(lua_State * L, Unit * ptr);
Unit:GetPowerType(lua_State * L, Unit * ptr);
Unit:GetMapId(); -- Returns Mapid
Unit:GetFactionStanding(lua_State * L, Unit * ptr);
Unit:GetPlayerLevel(); -- Returns playerlevel
IS COMMANDS -- Will returns '1' or 'true' if true. Not sure what one.
Unit:IsPlayerAttacking();
Unit:IsPlayerMoving();
Unit:IsPlayerAtWar(factionID);
Unit:IsPlayer();
Unit:IsCreature();
Unit:IsInCombat();
Unit:IsAlive();
Unit:IsDead(l);
Unit:IsInWorld();
Unit:IsCreatureMoving();
Unit:IsFlying();
Unit:IsInFront();
Unit:IsInBack();
Unit:IsPacified();
Unit:IsFeared();
Unit:IsStunned();
Unit:HasInRangeObjects();
Unit:IsInWater();
Unit:IsInArc();
Unit:IsPet();
Unit:MoveFly();
Unit:NoRespawn();
Unit:HasItem();
Unit:FlyCheat();
OTHER COMMANDS
Unit:AdvanceSkill(skillid, amount);
Unit:AddSkill(skillid);
Unit:RemoveSkill(skillid);
Unit:PlaySpellVisual(lua_State * L, Unit * ptr);
Unit:RemoveThreatByPtr(lua_State * L, Unit * ptr);
Unit:EventCastSpell(lua_State * L, Unit * ptr);
Unit:AttackReaction(lua_State * L, Unit * ptr);
Unit:DismissPet(lua_State * L, Unit * ptr);
Unit:HandleEvent(lua_State * L, Unit * ptr);
Unit:SetMoveRunFlag(lua_State * L, Unit * ptr);
Unit:SendChatMessage(Language, Type, "Message"); -- Langage; what language message is in, type = what form message is in (say/yell/whisper), "message" = duh
Unit:MoveTo(x, y, z, o); -- Once NPC gets to position i reccomend using Unit:SetFacing(Orientation) if O coordinate doesn't work.
Unit:SetMovementType(lua_State * L, Unit * ptr);
Unit:CastSpell(SpellID); -- Casts spell on Itself
Unit:CastSpellOnTarget(spellID, target); -- Casts spell ID on a target with no casttime, mights till be bugged and cast on itself
Unit:FullCastSpell(spellid); -- Fully casts a spell on itself / aoe spell
Unit:FullCastSpellOnTarget(spellid, target); -- Full casts a spell on a target.
Unit:SpawnGameObject(GOID, x, y, z, o, duration); -- self explanitory (set duration to 0 to keep gameobject spawned until server restart/shutdown
Unit:SpawnCreature(NPCID, x, y, z, o, faction, duration); -- self explanitory (set duration to 0 to keep creatued spawned forever until server restart/shutdown)
Unit:RegisterEvent("Event", Interval, IntervalCount); -- "Event"; event name, Interval; amount of time between registering the event again, IntervalCount; Amount of times to register the event.
Unit:RemoveEvents(); -- Removes all events from the Unit
Unit:SendBroadcastMessage("Text"); -- player only command, sends to chat box (player:SendBroadcastMessage("BroadcastMessageAppearsInTextBox"))
Unit:SendAreaTriggerMessage(lua_State * L, Unit * ptr); -- player only command, sends across screen (player:SendAreaTriggerMessage("AreaTriggerMessageAppearsAcrossScreen"))
Unit:KnockBack(dx, dy, affect1, affect2); -- Not sure, distancex, distancey, affects might be spell ID's?
Unit:MarkQuestObjectiveAsComplete(lua_State * L, Unit * ptr); -- no clue
Unit:LearnSpell(SpelLID); -- learns spellid, may be player only command
Unit:UnlearnSpell(SpellID); -- Unlearns spellid, may be player only command
Unit:HasFinishedQuest(QuestID); -- Returns true / 1 if true
Unit:ClearThreatList(); -- Drops all agro, may even leave combat
Unit:ChangeTarget(lua_State * L, Unit * ptr);
Unit:Emote(emoteid, time);
Unit:Despawn(despawntime, respawntime); -- despawntime = despawns in x miliseconds, respawntime = respawns in x miliseconds. (To Permanantly remove a creature spawned by another creature with no SQLID, use :RemoveFromWorld()
Unit:PlaySoundToSet(SoundID);
Unit:RemoveAura(SpellID);
Unit:StopMovement(Time); -- time = Time in miliseconds
Unit:AddItem(itemid, itemcount); -- playeronly command
Unit:RemoveItem(itemid, itemcount); -- playeronly command
Unit:CreateCustomWaypointMap(lua_State * L, Unit * ptr);
Unit:CreateWaypoint(lua_State * L, Unit * ptr);
Unit:DestroyCustomWaypointMap(lua_State * L, Unit * ptr);
Unit:MoveToWaypoint(lua_State * L, Unit * ptr);
Unit:TeleportUnit(map, x, y, z); -- Teleports player that clicked to location, not sure~ might teleport the Unit.
Unit:ClearHateList(); -- Resets threat list, gets random target
Unit:WipeHateList(); -- clears hate list, might leave combat
Unit:WipeTargetList(lua_State * L, Unit * ptr);
Unit:WipeCurrentTarget(lua_State * L, Unit * ptr);
Unit:CastSpellAoF x, y, z, spellid); -- self explanitory
Unit:RemoveAllAuras(); -- removes all auras, hostile and friendly
Unit:StopChannel(); -- stops channeling
Unit:ChannelSpell(spellid, target); -- channels spell on target?
Unit:ReturnToSpawnPoint(); -- returns to spawn point
Unit:HasAura(spellid); -- returns true or 1 if true.
Unit:Land(); -- Unit removes 1024 flag of flying.
Unit:CancelSpell(spellid); -- stops casting spell?
Unit:Root(target); -- self
Unit:Unroot(target); -- explanitory?
Unit:CalcDistance(target); -- returns value based in yards?
Unit:ModUInt32Value(lua_State * L, Unit * ptr);
Unit:ModFloatValue(lua_State * L, Unit * ptr);
Unit:SendData(lua_State * L, Unit * ptr);
Unit:InitPacket(lua_State * L, Unit * ptr);
Unit:AddDataToPacket(lua_State * L, Unit * ptr);
Unit:AddGuidDataToPacket(lua_State * L, Unit * ptr);
Unit:AdvanceQuestObjective(lua_State * L, Unit * ptr);
Unit:Heal(lua_State * L, Unit * ptr);
Unit:Energize(lua_State * L, Unit * ptr);
Unit:SendChatMessageAlternateEntry(lua_State * L, Unit * ptr);
Unit:SendChatMessageToPlayer(lua_State * L, Unit * ptr);
Unit:Strike(lua_State * L, Unit * ptr);
Unit:Kill(target);
Unit:DealDamage(lua_State * L, Unit * ptr);
Unit:CreateGuardian(lua_State * L, Unit * ptr);
Unit:CalcToDistance(lua_State * L, Unit * ptr);
Unit:CalcAngle(lua_State * L, Unit * ptr);
Unit:CalcRadAngle(lua_State * L, Unit * ptr);
Unit:IsInvisible(lua_State * L, Unit * ptr);
Unit:IsInvincible(lua_State * L, Unit * ptr);
Unit:ResurrectPlayer(player); -- player only command
Unit:KickPlayer(lua_State * L, Unit * ptr);
Unit:CanCallForHelp(lua_State * L, Unit * ptr);
Unit:CallForHelpHp(lua_State * L, Unit * ptr);
Unit:RemoveFromWorld(); -- Removes Unit From World (useful for npcs not saved to the Db {NPC spawned by other NPCS with no GUID})
Unit:SpellNonMeleeDamageLog(lua_State * L, Unit * ptr);
Unit:ModThreat(lua_State * L, Unit * ptr);
Unit:AddAssistTargets(lua_State * L, Unit * ptr);
Unit:RemoveAurasByMechanic(lua_State * L, Unit * ptr);
Unit:RemoveAurasType(lua_State * L, Unit * ptr);
Unit:AddAuraVisual(lua_State * L, Unit * ptr);
SET COMMANDS
Unit:SetPlayerStanding(lua_State * L, Unit * ptr);
Unit:SetPlayerLevel(level); -- might not work
Unit:SetPlayerAtWar(lua_State * L, Unit * ptr);
Unit:SetCreatureName(lua_State * L, Unit * ptr);
Unit:SetDeathState(lua_State * L, Unit * ptr);
Unit:SetPowerType(lua_State * L, Unit * ptr);
Unit:SetAttackTimer(time, duration);
Unit:SetMana(Value); -- sets currnet mana
Unit:SetMaxMana(Value);
Unit:SetHealth(Value); -- sets current health
Unit:SetMaxHealth(Value);
Unit:SetFlying(); -- Sets NPC to fly.
Unit:SetCombatCapable(1); --------\
Unit:SetCombatMeleeCapable(1); ----\
Unit:SetCombatRangedCapable(1); ----\_________ Set to 1 for Disableing Capableness, set to 0 to enable it again.
Unit:SetCombatSpellCapable(1); -----/
Unit:SetCombatTargetingCapable(1);-/
Unit:SetNPCFlags(NPCFLAGS); -- sets npc flags
Unit:SetModel(displayid); -- displayid
Unit:SetScale(Scale); -- size
Unit:SetFaction(faction); -- faction id
Unit:SetStandState(lua_State * L, Unit * ptr);
Unit:SetTauntedBy(lua_State * L, Unit * ptr);
Unit:SetSoulLinkedWith(lua_State * L, Unit * ptr);
Unit:SetInFront(lua_State * L, Unit * ptr);
Unit:SetHealthPct(%); -- sets health Percent
Unit:SetOutOfCombatRange(lua_State * L, Unit * ptr);
Unit:ModifyRunSpeed(lua_State * L, Unit * ptr);
Unit:ModifyWalkSpeed(lua_State * L, Unit * ptr);
Unit:ModifyFlySpeed(lua_State * L, Unit * ptr);
Unit:SetRotation(Orientation);
Unit:SetOrientation(Orientation);
Unit:SetUInt32Value(lua_State * L, Unit * ptr);
Unit:SetUInt64Value(lua_State * L, Unit * ptr);
Unit:SetFloatValue(lua_State * L, Unit * ptr);
Unit:SetUnitToFollow(lua_State * L, Unit * ptr);
Unit:SetNextTarget(lua_State * L, Unit * ptr);
Unit:SetPetOwner(lua_State * L, Unit * ptr);
Unit:SetFacing(lua_State * L, Unit * ptr);
GAMEOBJECT LIST
GET COMMANDS
GameObject:GetName(lua_State * L, GameObject * ptr);
GameObject:GetMapId(lua_State * L, GameObject * ptr);
GameObject:GetCreatureNearestCoords(lua_State * L, GameObject * ptr);
GameObject:GetGameObjectNearestCoords(lua_State *L, GameObject * ptr);
GameObject:GetAreaID(lua_State * L, GameObject * ptr);
GameObject:GetClosestPlayer(lua_State * L, GameObject * ptr);
GameObject:GetZoneId(lua_State *L, GameObject * ptr);
GameObject:GetItemCount(lua_State * L, GameObject * ptr);
GameObject:GetSpawnX(lua_State * L, GameObject * ptr);
GameObject:GetSpawnY(lua_State * L, GameObject * ptr);
GameObject:GetSpawnZ(lua_State * L, GameObject * ptr);
GameObject:GetSpawnO(lua_State * L, GameObject * ptr);
GameObject:GetInRangePlayersCount(lua_State * L, GameObject * ptr);
GameObject:GetEntry(lua_State * L, GameObject * ptr);
GameObject:GetX(lua_State * L, GameObject * ptr);
GameObject:GetY(lua_State * L, GameObject * ptr);
GameObject:GetZ(lua_State * L, GameObject * ptr);
GameObject:GetO(lua_State * L, GameObject * ptr);
GameObject:GetInRangePlayers(lua_State * L, GameObject * ptr);
GameObject:GetInRangeGameObjects(lua_State * L, GameObject * ptr);
GameObject:GetInstanceID(lua_State * L, GameObject * ptr);
GameObject:GetUInt64Value(lua_State * L, GameObject * ptr);
GameObject:GetUInt32Value(lua_State * L, GameObject * ptr);
GameObject:GetFloatValue(lua_State * L, GameObject * ptr);
GameObject:GetGUID(lua_State * L, GameObject* ptr);
OTHER COMMANDS
GameObject:Teleport(lua_State * L, GameObject * ptr); -- player command, player:Teleport(map, x, y, z)
GameObject:AddItem(lua_State * L, GameObject * ptr); -- player command, player:AddItem(itemid, itemcount)
GameObject:Despawn(lua_State * L, GameObject * ptr);
GameObject:IsInWorld(lua_State * L, GameObject * ptr);
GameObject:IsInBack(lua_State * L, GameObject * ptr);
GameObject:IsInFront(lua_State * L, GameObject * ptr);
GameObject:PlaySoundToSet(lua_State * L, GameObject * ptr);
GameObject:SpawnCreature(lua_State * L, GameObject * ptr);
GameObject:SpawnGameObject(lua_State * L, GameObject * ptr);
GameObject:CalcDistance(lua_State * L, GameObject * ptr);
GameObject:SetOrientation(lua_State * L, GameObject * ptr);
GameObject:RemoveFromWorld(lua_State * L, GameObject * ptr);
GameObject:CalcRadAngle(lua_State * L, GameObject * ptr);
GameObject:SetUInt32Value(lua_State * L, GameObject * ptr);
GameObject:SetUInt64Value(lua_State * L, GameObject * ptr);
GameObject:SetFloatValue(lua_State * L, GameObject * ptr);
GameObject:ModUInt32Value(lua_State * L, GameObject * ptr);
GameObject:CastSpell(lua_State * L, GameObject * ptr);
GameObject:FullCastSpell(lua_State * L, GameObject * ptr);
GameObject:CastSpellOnTarget(lua_State * L, GameObject * ptr);
GameObject:FullCastSpellOnTarget(lua_State * L, GameObject * ptr);
GameObjectvEventCastSpell(lua_State * L, GameObject * ptr);
GameObject:GossipObjectCreateMenu(lua_State * L, GameObject * ptr);
GameObject:GossipObjectMenuAddItem(lua_State * L, GameObject * ptr);
GameObject:GossipObjectSendMenu(lua_State * L, GameObject * ptr);
GameObject:GossipObjectComplete(lua_State * L, GameObject * ptr);
GameObject:GossipObjectSendPOI(lua_State * L, GameObject * ptr);
GameObject:ModUInt32Value(lua_State * L, GameObject * ptr);
GameObject:ModFloatValue(lua_State * L, GameObject * ptr);
GameObject:GetFloatValue(lua_State * L, GameObject * ptr);
GameObject:InitPacket(lua_State * L, GameObject * ptr);
GameObject:AddDataToPacket(lua_State * L, GameObject * ptr);
GameObject:AddGuidDataToPacket(lua_State * L, GameObject * ptr);
GameObject:SendData(lua_State * L, GameObject * ptr);
[1.5]Commenting
Thought i'd add this in here real quick. Commenting code is done by using two '-' followed by a space and text of your choice for reminders or tags for certain lines of code. heres an example;
function Creature_OnLoad(Unit, Event)
Unit:RegisterEvent("Timer", 1000, 1)
end
function Timer(Unit, Event)
Unit:FullCastSpellOnTarget(35853, Unit:GetRandomPlayer(7)) -- [SPELLID:35853 = Chain Fireball]
end
another example is encasing a large paragraph of text using --[[ & -- ]. Heres an example
-- [[
################################################## #############
# #
# #
# #
# Dumb Header For scripting Teams? #
# #
# #
# #
################################################## ############# -- ]]
function Creature_OnLoad(Unit, Event)
Unit:RegisterEvent("SendChatMessage", 1000, 0)
end
function SendChatMessage(Unit, Event)
Unit:SendChatMessage(12, 0, "Im an annoying spammer NPC...")
Unit:SetFaction(14)
Unit:CastSpell(5) -- Deathtouches himself
end
[2.0] Creature Events
Most Common Creature Commands & Usage[2.1]
The most common commands when scripting a boss fight of creature are;
Unit:RegisterEvent("EventName", Interval, IntervalCount)
Unit:CastSpell(Spellid)
Unit:CastSpellOnTarget(SpellId, target)
Unit:FullCastSpellOnTarget(SpellId, target)
Unit:FullCastSpell(SpellID)
Unit:GetHealthPct()
Unit:SetModel(DisplayID)
Unit:GetRandomPlayer(FLAG)
[RANDOM FLAGS]
RANDOM_ANY = 0,
RANDOM_IN_SHORTRANGE = 1,
RANDOM_IN_MIDRANGE = 2,
RANDOM_IN_LONGRANGE = 3,
RANDOM_WITH_MANA = 4,
RANDOM_WITH_RAGE = 5,
RANDOM_WITH_ENERGY = 6,
RANDOM_NOT_MAINTANK = 7,
Unit:GetClosestPlayer()
Unit:SpawnCreature(creatureID, x, y, z, o, faction, duration) -- duration = 0 for infinite.
Unit:SendChatMessage(language, channeltype, "Message")
Unit:RemoveEvents()
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("WatchHealth", 1000, 1)
end
function WatchHealth(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RemoveEvents() -- Removes constant Registering event from OnCombat
Unit:RegisterEvent("Phase2", 1000, 1) -- Registers Phase2.
Unit:FullCastSpellOnTarget(11, Unit:GetRandomPlayer(7))
Unit:SendChatMessage(41, 0, "Creature begins to transform!, and his minion appears!")
Unit:SetModel(28090)
Unit:SpawnCreature(6, 1234, 432, 42, 0, 14, 10000) -- Spawns creature 6(Kobold vermin), at x1234, y 432, z 42, and its orientation facing north. its faction is 14, and it will despawn 10 seconds after it is spawned.
else
Unit:RegisterEvent("WatchHealth", 5000, 1)
end
end
Languages and Channeltypes for SendChatMessage
[Language ID
0 = Universal
1 = Orcish
2 = Darnassian
3 = Tauron
6 = Dwarfs
7 = Common
8 = Demonic
9 = Titans
13 = Gnomish
14 = Troll language
33 = Gutterspeak
35 = Draenei
[ChannelTypes
12 = Say
14 = Yell
13 = Whisper
16 = Emote
41 = Area Broadcast with sound \__________ ex: "The lava around sarthiron begins to churn" then the bell noise.
42 = Area Broadcast with sound /
[2.3]Combat and General Events
Bosses are where you can really let your imagination run wild. A Boss must be fun. But no matter how simple it is, you must make sure it is a unique and entertaining fight, Otherwiset, The fight will get boring, no one will attempt the boss as much, everyone will have the same loot. So i'm here to hopefully show you how to make a good fun boss fight. However, your scripts are only as good as your imagination.
But before i start, any new Commands i use in the examples below will be explained and they will also have an example for them. Also, i will be using Kobold Vermins entry ID for the boss, rawr.
To start, I will show you how to create phases, There is a few different ways;
1). This takes a bit more work, but is generally easier to handle.
function Creature_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "rawr its my first phase")
Unit:RegisterEvent("Creature_FirstPhase", 1000, 1)
end
function Creature_FirstPhase(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RegisterEvent("Creature_SecondPhase", 1000, 1) -- The boss is below 80% hp, registering 2nd phase.
Unit:SendChatMessage(14, 0, "Rawr entering second phase") -- This is where you will input any spells or chat messages you only want to be said ONCE when your npc enters their next phase.
else
Unit:RegisterEvent("Creature_FirstPhase", 1000, 1) -- If the boss isn't below 80% hp, it will register the event and check again every 1 second.
end
end
function Creature_SecondPhase(Unit, Event)
-- Second phase code.
end
RegisterUnitEvent(6, 1, "Creature_OnCombat")
2). This requires the least work, but sometimes can cause problems
function Creature_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "rawr its my first phase")
Unit:RegisterEvent("Creature_FirstPhase", 1000, 0)
end
function Creature_FirstPhase(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RemoveEvents() -- Removing this event , so it stops registering since its interval count is set to infinite.
Unit:RegisterEvent("Creature_SecondPhase", 1000, 0)
end
end
function Creature_SecondPhase(Unit, Event)
-- Second phase code.
end
[NOTE]: Unit:RemoveEvents() must be before Unit:RegisterEvent("Creature_SecondPhase", 1000,0) otherwise, Creature_SecondPhase event, will be removed.
3). This way, is similar to the first one, except your phases aren't based on the bosses health, there based on if, for example - There add dies, and we have a stoptrigger get set to 1. I added in another variable to count how many seconds goesby so you can time spells or events you want to happen at certain points in phase one.
local intCreatureAddDeadTrigger = 0
local intPhaseOneCount = 0
function Creature_OnCombat(Unit, Event)
Unit:SendChatMessage(41, 0, "The creature awakens.")
Unit:RegisterEvent("Creature_PhaseOne", 1000, 1)
Unit:SpawnCreature(NPCID, x, y, z, o, 14, 0)
end
function Creature_PhaseOne(Unit, Event)
intPhaseOneCount = intPhaseOneCount + 1
if (intPhaseOneCount == 15) then
-- After 15 seconds he'll do this and so on...
elseif (intPhaseOneCount == 30) then
-- and so on...
elseif (intPhaseOneCount == 35) then
-- ... and so on...
elseif (intPhaseOneCount == 50) then
-- On your last event you want to happen, set intPhaseOneCount back to 0 so it will continue to loop the events above.
end
if (intCreatureAddDeadTrigger == 1) then
Unit:RegisterEvent("Creature_PhaseTwo", 1000, 1)
else
Unit:RegisterEvent("Creature_PhaseOne", 1000, 1)
end
end
function Creature_PhaseTwo(Unit, Event)
-- awmahgawd phase 2.
end
function CreatureAdd_OnDied(Unit, Event)
intCreatureAddDeadTrigger = 1
end
RegisterUnitEvent(NPCID, 4, "CreatureAdd_OnDied")
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
At first, i was surprised about how short this section was, but then i realized, After you know about what you can do with variables and if statements, and then how to make phases, you can do whatever you want.
[2.9]Creature Summary and Tips
There is a few things i know to make your life much much easier. The first thing is making an NPC as a whole, a variable, Meaning NPCs can cast spells on each other, Say things, all in the same function.. (Thanks Stoneharry)
function Creature_OnLoad(Unit, Event)
-- Say the bosses name is Fresca (Courtesy of the leaning tower of pop cans on my desk)
Fresca = Unit -- What this does, is makes the "Unit" from this function into the variable of "Fresca"
end
RegisterUnitEvent(NPCID, 18, "Creature_OnLoad")
The reason this is insanely useful is due to being able to have two different creatures being able to do something in the same function. And when your timing an even where two different npcs talk to eachother, ect ect. You can do that without making a parralell function line and trying to get the timing right. heres an example.
local TalkStartCount = 0
function CreatureOne_OnLoad(Unit, Event)
COne = Unit
end
function CreatureTwo_OnLoad(Unit, Event)
CTwo = Unit
end
function CreatureOne_OnCombat(Unit, Event)
COne:RegisterEvent("Talk_Start", 1000, 15)
COne:SetCombatMeleeCapable(1) -- All this just makes them friendly, and stand still / not attackable
CTwo:SetCombatMeleeCapable(1) -- Whlie there talking to each other before
COne:SetFaction(35) -- the actual event happens and
CTwo:SetFaction(35) -- you have to fight them
end
function Talk_Start(Unit, Event)
TalkStartCount = TalkStartCount + 1
if (TalkStartCount == 1) then
COne:SendChatMessage(14, 0, "Hey, how are you doing")
elseif (TalkStartCount == 5) then
CTwo:SendChatMessage(14, 0, "Good... and yourself")
elseif (TalkStartCount == 10) then
COne:SendChatMessage(14, 0, "I'm going to kill you")
elseif (TalkStartCount == 15) then
CTwo:SendChatMessage(14, 0, "gasp.")
CTwo:SetFaction(84)
COne:SetFaction(106)
CTwo:SetCombatMeleeCapable(0)
COne:SetCombatMeleeCapable(0)
end
end
RegisterUnitEvent(NPCID, 18, "CreatureTwo_OnLoad")
RegisterUnitEvent(NPCID, 18, "CreatureOne_OnLoad")
RegisterUnitEvent(NPCID, 1, "CreatureOne_OnCombat")
This instead of...
local TalkStartCountTwo = 0
local TalkStartCountOne = 0
function CreatureTwo_OnCombat(Unit, Event)
Unit:RegisterEvent("TalkTwo_Start", 1000, 15)
Unit:SetCombatMeleeCapable(1)
Unit:SetFaction(35)
end
function TalkTwo_Start(Unit, Event)
TalkStartCountTwo = TalkStartCountTwo + 1
if (TalkStartCountTwo == 1) then
COne:SendChatMessage(14, 0, "Hey, how are you doing")
elseif (TalkStartCountTwo == 10) then
COne:SendChatMessage(14, 0, "I'm going to kill you")
Unit:SetFaction(84)
Unit:SetCombatMeleeCapable(0)
end
end
function CreatureOne_OnCombat(Unit, Event)
Unit:RegisterEvent("TalkOne_Start", 1000, 15)
Unit:SetCombatMeleeCapable(1)
Unit:SetFaction(35)
end
function TalkOne_Start(Unit, Event)
TalkStartCountOne = TalkStartCountOne + 1
if (TalkStartCountOne == 5) then
CTwo:SendChatMessage(14, 0, "Good... and yourself")
elseif (TalkStartCountOne == 15) then
Unit:SendChatMessage(14, 0, "Gasp")
Unit:SetFaction(106)
Unit:SetCombatMeleeCapable(0)
end
end
RegisterUnitEvent(NPCID, 18, "CreatureTwo_OnLoad")
RegisterUnitEvent(NPCID, 18, "CreatureOne_OnLoad")
RegisterUnitEvent(NPCID, 1, "CreatureOne_OnCombat")
RegisterUnitEvent(NPCID, 1, "CraetureTwo_OnCombat")
Red highlights indicate what doesn't need to be there if we used the first method.
You can probably imagine how much more usefull this will become once your scripts get larger, and you have more than 2 NPC's.
Another tip is keeping you code clean, there is proper coding edicate i believe, but if its your own script. using Tabs instead of 5 spaces isn't going to hurt anything. Space your codes lines out appropriately so its easy to read through the code, or if you realase you scripts its easy for people to re-read them and modify them to their liking.
Sometimes you'll see code with no spaces, and some with plenty of spaces, heres an example.
No Spaces
local intCount = 0
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("OmgWhatAMess", 1000, 1)
Unit:SendChatMessage(14, 0, "Hello everyone")
end
function OmgWhatAMess(Unit, Event)
intCount = intCount + 1
if (intCount == 1) then
Unit:SendChatMessage(12, 0, "intcount is equal to 1)
elseif (intCount == 2) then
UnitSendChatMessage(12, 0, "intCount is equal to 2
Unit:FullCastSpellOnTarget(11, Unit:GetClosestPlayer())
else
Unit:SendChatMessage(14, 0, "whats going on")
intCount = 0
end
if Unit:GetHealthPct() <= 80 then
Unit:RegisterEvent("phasetwo", 1000, 1)
else
Unit:RegisterEvent(OmgWhatAMess", 1000, 1)
end
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
With Spaces
local intCount = 0
function Creature_OnCombat(Unit, Event)
Unit:RegisterEvent("OmgWhatAMess", 1000, 1)
Unit:SendChatMessage(14, 0, "Hello everyone")
end
function OmgWhatAMess(Unit, Event)
intCount = intCount + 1
if (intCount == 1) then
Unit:SendChatMessage(12, 0, "intcount is equal to 1)
elseif (intCount == 2) then
UnitSendChatMessage(12, 0, "intCount is equal to 2
Unit:FullCastSpellOnTarget(11, Unit:GetClosestPlayer())
else
Unit:SendChatMessage(14, 0, "whats going on")
intCount = 0
end
if Unit:GetHealthPct() <= 80 then
Unit:RegisterEvent("phasetwo", 1000, 1)
else
Unit:RegisterEvent(OmgWhatAMess", 1000, 1)
end
end
RegisterUnitEvent(NPCID, 1, "Creature_OnCombat")
With spaces, it becomes much clearer where If statements start and end, and in general whats actually happening in the script.
==============================================\/ Continued \/=============================================