
Results 1 to 5 of 5
Hybrid View
-
17-03-10, 09:43 PM #1
- Rep Power
- 0
- Reputation
- 87
Code:if (intid == 1) then
Code:player:Teleport(MapID, x, y, z)
Code:MapID: 1 X: -9101.980469 Y: 1612.902832 Z: 21
Code:player:Teleport(1, -9101.980469, 1612.902832, 21)
Code:end
Wait, we have two ends? Yes, we do, well done, you can count. The 'if' statement requires an end, since it is a loop, and Lua cannot determine when it has ended on it's own.
Let's see what our function looks like now;
Code:function exampleGossipOnSelect(Unit, Event, player, id, intid, code, pMisc) if (intid == 1) then player:Teleport(1, -9101.980469, 1612.902832, 21) player:GossipComplete() end end
Code:function exampleGossipOnSelect(Unit, Event, player, id, intid, code, pMisc) if (intid == 1) then player:Teleport(1, -9101.980469, 1612.902832, 21) player:GossipComplete() end if (intid == 2) then end end
Code:function exampleGossipOnSelect(Unit, Event, player, id, intid, code, pMisc) if (intid == 1) then player:Teleport(1, -9101.980469, 1612.902832, 21) player:GossipComplete() end if (intid == 2) then if (player:HasAura(15007) == true) then player:SendBroadcastMessage("Resurrection Sickness has been removed. Be careful next time!") player:RemoveAura(15007) player:GossipComplete() else player:SendBroadcastMessage("You do not have Resurrection Sickness!") player:GossipComplete() end end end
Well, I thought it would be self explanatory, but there we go. OK, I'll guide you through it.
Code::HasAura(SpellID) :RemoveAura(SpellID)
Code::SendBroadcastMessage("message")
Code:else
Code:If the value of intid is 2, and the player has the aura '15007', then do this. If he doesn't have that aura, then do this.
So, now we have two intids, lets look at our function now, and add the last one.
Code:function exampleGossipOnSelect(Unit, Event, player, id, intid, code, pMisc) if (intid == 1) then player:Teleport(1, -9101.980469, 1612.902832, 21) player:GossipComplete() end if (intid == 2) then if (player:HasAura(15007) == true) then player:SendBroadcastMessage("Resurrection Sickness has been removed. Be careful next time!") player:RemoveAura(15007) player:GossipComplete() else player:SendBroadcastMessage("You do not have Resurrection Sickness!") player:GossipComplete() end end if (intid == 3) then player:GossipComplete() end end
The complete script:
Code:--[[ My First Gossip Script! Tutorial by Neglected ]] -- Variables local NPC_ID = 133713 -- On Triggers function exampleGossipOnTalk(Unit, Event, player) Unit:GossipCreateMenu(100, player, 0) Unit:GossipMenuAddItem(0, "Teleport me to the mall.", 1, 0) Unit:GossipMenuAddItem(0, "Remove Resurrection Sickness.", 2, 0) Unit:GossipMenuAddItem(0, "Never mind.", 3, 0) Unit:GossipSendMenu(player) end function exampleGossipOnSelect(Unit, Event, player, id, intid, code, pMisc) if (intid == 1) then player:Teleport(1, -9101.980469, 1612.902832, 21) player:GossipComplete() end if (intid == 2) then if (player:HasAura(15007) == true) then player:SendBroadcastMessage("Resurrection Sickness has been removed. Be careful next time!") player:RemoveAura(15007) player:GossipComplete() else player:SendBroadcastMessage("You do not have Resurrection Sickness!") player:GossipComplete() end end if (intid == 3) then player:GossipComplete() end end -- RegisterUnitEvents RegisterUnitGossipEvent(NPC_ID, 1, "exampleGossipOnTalk") RegisterUnitGossipEvent(NPC_ID, 2, "exampleGossipOnSelect")
Well done! You've created your first ever functioning script. Or at least, using this tutorial. Save it as TeleporterNPC.lua and place it in your /scripts/ folder. Spawn your mob and restart your server (Or type in #reload if you are using Alvanaar's Reload Chat Command script), and enjoy talking to your first script!
Ifs and Elseifs.
So you know how to use ifs and elses.. but, using the following is quite hard to read and monotonous;
Code:if (var == true) then Weee() end if (var == false) then Awww() end if (var == nil) then WTFITSHOULDNTBENIL() end
Code:if (var == true) then Wee() elseif (var == false) then Awww() elseif (var == nil) then WTFITSHOULDNTBENIL() end