PDA

View Full Version : Learning Lua Inside and Out



xepher
19-01-09, 11:13 AM
Registering the events
The events I have listed are here for your Convenience. All you have to do is change The “Npc spawn ID” to the id that spawns The npc you want this script for As well as The “Name” Needs to be changed to the name of the creature. This part of the LUA Must be placed at the bottom.

CREDIT GOES TO RUINKER.


RegisterUnitEvent (Npc Spawn ID, 1, "Name_Entercombat")
Using this will make the event happen when the player enters combat with the Npc that has this script enabled.

RegisterUnitEvent (Npc Spawn ID, 2, "Name_Leavecombat")
Using this will make the event happen when the player leaves combat with the Npc that has this script enabled.

RegisterUnitEvent(Npc Spawn ID, 3, "Name_Killtarget")
Using this will make the event happen when the Npc who has this script kills its target

RegisterUnitEvent (Npc Spawn ID, 4, "Name_Died")T
his event will happen when the npc has died

RegisterUnitEvent (Npc Spawn ID, 5, "Name_AItick")
Not sure yet???

RegisterUnitEvent (Npc Spawn ID, 6, "Name_Spawn")
This will happen when the npc is spawned

RegisterUnitEvent (Npc Spawn ID, 7, "Name_Gossip")
Not sure yet??

RegisterUnitEvent (Npc Spawn ID, 8, "Name_waypoint")
This will happen when player reaches waypoint

RegisterUnitEvent (Npc Spawn ID, 9, "Name_leavelimbo")
Not sure yet

RegisterUnitEvent (Npc Spawn ID, 10, "Name_playerenter")
This will happen when player reachs waypoint.

RegisterGossipEvent(Npc Id , 1, "On_Gossip")(Npc Id, 2,"Gossip_Submenus")
Makes a menu for those who know how to make a teleporter.


RegisterGameObjectEvent (PORTALGUID, 2, "Nameofportal_onUse")
Used for teleporting a player using a game object.

---note you will need at least one per event you would like to do
so if you wanted to make the npc do something on waypoint AND
combat you would need to make two making the bottom look like this


RegisterUnitEvent (Npc Spawn ID, 1, "Name_Entercombat")
RegisterUnitEvent (Npc Spawn ID, 8, "Name_waypoint")

The events themselves

pUnit:SendChatMessage(<type>, <language>, message)
The npc will say the message (look at type and/or language codes to change)

pUnit:MoveTo(x, y, z, o)
This will move the npc to the xyzo location (look at the xyz part of the guide)

pUnit:CastSpell(spellID)
This will make the npc cast the spell with the spell id (look at thottbot for more spell ids)

pUnit:FullCastSpell(spellID)
Makes the npc cast a spell with full casting time (look at thottbot for more spell ids)

pUnit:SpawnGameObject(entryID, x, y, z, o, duration)
This will spawn a game object then despawn it after the time time is in milliseconds. (look at the xyz part of the guide)

pUnit:SpawnCreature(entryID, x, y, z, o, faction, duration)
This will spawn a npc then despawn it after the time, time is in milliseconds. (look at the xyz part of the guide)

pUnit:PlaySoundToSet(soundID)
This will play a sound to the area

pUnit:SetMovementType(movementType)
This will tell the npc how to move (movement types are fly and walk)

pUnit:SetHealthPct(value)
This will make the npcs health at specified percent

pUnit:SetNPCFlags(flags)
This will mark a flag on npc

pUnit:SetModel(modelID)
This will change the display of the npc

pUnit:SetScale(scale)
This will change the scale of npc

pUnit:SetFaction(factionID)
This will change the faction of the npc

pUnit:SetModel(Display id)
This will change the display of the npc

pUnit:SendAreaTriggerMessage(message)

pUnit:KnockBack(dx, dy, affect1, affect2)

pUnit:MarkQuestObjectiveAsComplete(questID, objective)
Marks an objective of a quest as complete.

pUnit:LearnSpell(spellID)
Adds a spell to a unit.

pUnit:UnlearnSpell(spellID)
Removes a spell from a unit.

pUnitespawn(delay, respawn)
Despawns a unit after delay milliseconds and respawns it after respawn milliseconds.

pUnit:PlaySoundToSet(soundID)
Plays a sound to the surrounding area.

pUnit:RemoveAura(auraID)
Removes an aura from a unit.

pUnit:StopMovement(time)
Stops a unit from moving for time milliseconds.

pMisc:AddItem(itemID, count)
Adds a quantity of items to a unit.

pUnit:RemoveItem(itemID, count)
Removes a quantity of items from a unit.

pUnit:CreateCustomWaypointMap()
Creates a custom waypoint map.

pUnit:CreateWaypoint(x, y, z, o, waitTime, flags, modelID)
Adds a waypoint to the custom waypoint map.

pUnitestroyCustomWaypointMap()
Destroys a created custom waypoint map.

pUnit:MoveToWaypoint(waypointID)
Tells a unit to move to a particular waypoint.

pUnit:SetCombatCapable(value)
If value is 1 the unit cannot attack.

pUnit:SetHealthPct(value)
Sets the unit's health percentage.

pUnit:SetNPCFlags(flags)
Sets the NPC flags of a unit.

pUnit:SetModel(modelID)
Sets the model (display ID) of a unit.

pUnit:SetScale(scale)
Sets the scale (size) of a unit.

pUnit:SetFaction(factionID)
Sets the faction of a unit.

pUnit:SetTauntedBy(unit)
Sets the unit that taunted the current unit.

pUnit:SetSoulLinkedWith(unit)
Sets the unit that is soul linked with this unit.

pUnit:SendBroadcastMessage(message)
This will broadcast the message across the whole server

pUnit:Emote(emoteID)
Tells a unit to perform an emote.

pUnit:FullCastSpellOnTarget(spellID, unitTarget)
Makes npc cast a spell on target. (look at thottbot for more spell ids)

pUnit:CastSpellOnTarget(spellID, unitTarget)
Cast spell on target (look at thottbot for more spell ids)

pMisc:Teleport (MAPID, X, Y, Z)
Teleports player to the map with x, y, z

pUnit:GossipCreateMenu(100, player)
Creates the menu itself

pUnit:GossipMenuAddItem(player, 0, "Horde Cities", 1, 0)
Add an item to the menu

pUnit:GossipSendMenu(player)
Sends player to this part of the menu

Changing the red to what you need

Spell-this can be found on thottbot or Wowhead it’s the last numbers of the page of spell
Type-use the premade table I have made below
Language-use the premade table I have made below
Scale-this is how big you want it to get by multiplying it
Modelid-this is the display id of the mob
Flag-this can be found on *******
Value-% at wich you would like the npc’s health
Momenttype-you can pick fly or walk
Soundid-you can find on *******
Entryid- this is the same as the number used to spawn it
Duration-how long until this is undone
Faction- what faction would you like it
Message-enter your message here
X,Y,Z,O- these are found by typing .gps inside the server itself at the location you want.]
Emoteid- The id of the emote search ******* for these
Displayid- display id of what you want it to look like
Time- Time is in milliseconds

The Advanced if commands Use these commands if you want
Whatever is between the then and the end Tags to work
only when it is a yes.


GetName()
This will return the units name

GetX()
This will return the units X position.

GetY()
This will return the units Y position.

GetZ()
This will return the units Z position.

GetO()
This will return the units orientation.

IsPlayer() then
This will make the commands below it work only If the target is a player

IsCreature() then
This will make the commands below work if the target is a creature

☼HasFinishedQuest(questID) then
This will work only if the target has finished quest id

☼GetItemCount(itemID)<#then
This will tell if how many of the items player has

☼GetHealthPct()<%then
This will tell it to only do it if the health is at a percent

☼GetUnitBySqlId(sqlID)then
Returns a unit from the sql ID.

☼GetClosestPlayer() then
This will target the nearest player

☼GetRandomPlayer(flags)
Returns a random in-range unit that is a player.
The flag is to check what type of random
- GetRandomPlayer(0) = Random Player
- GetRandomPlayer(1) = Random in Short-Range
- GetRandomPlayer(2) = Random in Mid-Range
- GetRandomPlayer(3) = Random in Long-Range
- GetRandomPlayer(4) = Random with Mana
- GetRandomPlayer(5) = Random with Rage
- GetRandomPlayer(6) = Random With Energy
- GetRandomPlayer(7) = Random NOT Main-Tank

☼GetRandomFriend()
Returns a random in-range unit that is a player and is friendly towards the current player.

☼GetMainTank()
Returns the main tank (most hated).


☼GetAddTank()
Returns the add tank (second most hated).

☼GetTauntedBy()
Returns the player that taunted the unit.

☼GetSoulLinkedWith()
Returns the unit that is set as the soul link for this unit.




Registering events inside events

RegisterUnitEvent(225501, 1, "Vanity_OnCombat")
Is to register the event itself but if you wanted to make
Events inside an event you would use
Unit:RegisterEvent("Vanity_Phase1",1000, 0)
And then for the sub event you would use
function Vanity_Phase1(Unit, event)lets put them all together to show
you what I mean. Hope this helps out people wondering about two part
events.

---code----
function Vanity_Phase1(Unit, event)
if Unit:GetHealthPct() < 95 then
Unit:RemoveEvents()
Unit:SendChatMessage(11, 0, "You think you can beat me")
Unit:RegisterEvent("Vanity_Phase2",1000, 0)
end
end



function Vanity_Phase2(Unit, event)
if Unit:GetHealthPct() < 80 then
Unit:RemoveEvents()
Unit:CastSpell(22436)
end
end


function Vanity_OnCombat(Unit, event)
Unit:SendChatMessage(11, 0, "Do i have to kill you are no equal?")
Unit:RegisterEvent("Vanity_Phase1",1000, 0)
Unit:RegisterEvent("Vanity_Phase2",1000, 0)
end

QQrofl
19-01-09, 11:15 AM
Nice work! +rep

xepher
19-01-09, 11:16 AM
thanks qq :D

Avidgamer
19-01-09, 02:23 PM
Nice work indeed.
+Rep

xepher
19-01-09, 06:23 PM
why thank you kind sir :D

runiker
19-01-09, 08:52 PM
If you would like to see it in color please visit
http://www.mmopro.net/forums/lua-scripting/384-lua-made-easy.html

xepher
19-01-09, 08:54 PM
sorry runiker got this off of the site me and you are part of, darkwowabyss didnt realize you had posted it already :S

runiker
19-01-09, 11:14 PM
Ah thats fine you gave credit around mmo forums that is rare so you got +1 rep for credits :P