I'm having multiple problems with Lua on my server.
The first, and most important is my innkeeper script. I've turned off health regeneration on my server and multiplied the base HP by 10. The Innkeeper is a very important part, as I'm planning on placing buildings with innkeepers all over the game world.
I've created a script which will sell you a room at an inn and heal you to full health for a price based on your level. My server's max level is set to 120, which is why it goes up to that.
The problem I run into is that when I click either of the options, "Make this Inn your home", "How much for a room" or "I'd like to purchase a room", nothing happens.
"Make this Inn your home" should make the npc cast "Bind" on you. I taught myself the spell and cast it on myself, and it worked. But the npc won't cast it.
I've tried countless things and have looked over my script at least 20 times. It doesn't work for me or anyone else who plays on my server. I'm ready for it to be some stupid tiny detail I missed.. but please. If anyone thinks they can solve my problem, look over my script:
Code:
local NPCID = 60004
function Inn_Gossip(Unit, event, player)
Unit:GossipCreateMenu(60002, player, 0)
Unit:GossipMenuAddItem(5, "Make this Inn your home", 1, 0)
Unit:GossipMenuAddItem(7, "How much for a room?", 2, 0)
Unit:GossipMenuAddItem(6, "I'd like to purchase a room.", 3, 0)
Unit:GossipMenuAddItem(0, "Nevermind.", 4, 0)
Unit:GossipSendMenu(player)
end
function Inn_Gossip_SubMenus(Unit, event, player, id, intid, code)
if (intid == 1) then
Unit:FullCastSpellOnTarget(3286, player)
player:GossipComplete()
player:SendBroadcastMessage("If this worked for you, and the innkeeper casts Bind, TELL ME!")
end
if (intid == 2) then
Unit:RegisterEvent("CheckLevel", 1000, 1)
Unit:GossipCreateMenu(60003, player, 0)
Unit:GossipMenuAddItem(6, "I'd like to purchase a room.", 3, 0)
Unit:GossipMenuAddItem(0, "Nevermind.", 4, 0)
Unit:GossipSendMenu(player)
end
if (intid == 3) then
player:GossipComplete()
Unit:RegisterEvent("Purchase", 1000, 1)
end
if (intid == 4) then
player:GossipComplete()
end
end
function CheckLevel(Unit, event, player)
local level = Unit:GetPlayerLevel()
if (level <= 9) then
Unit:SendChatMessage(12, 0, "I could give you a room for only 30 copper, how's that?")
elseif (level <= 19) and (level >= 10) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 2 silver, 40 copper. How's that?")
elseif (level <= 29) and (level >= 20) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 20 silver, 40 copper. How's that?")
elseif (level <= 39) and (level >= 30) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 36 silver, 10 copper. How's that?")
elseif (level <= 49) and (level >= 40) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 64 silver, 10 copper. How's that?")
elseif (level <= 59) and (level >= 50) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 86 silver, 90 copper. How's that?")
elseif (level <= 69) and (level >= 60) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 1 gold, 20 silver, 40 copper. How's that?")
elseif (level <= 79) and (level >= 70) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 2 gold. How's that?")
elseif (level <= 89) and (level >= 80) then
Unit:SendChatMessage(12, 0, "I could give you a room for 2 gold, 54 silver, 50 copper. How's that?")
elseif (level <= 99) and (level >= 90) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 12 gold, 18 silver, 90 copper. How's that?")
elseif (level <= 109) and (level >= 100) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 32 gold, 98 silver, 90 copper. How's that?")
elseif (level <= 119) and (level >= 110) then
Unit:SendChatMessage(12, 0, "I could give you a room for about 40 gold, 98 silver, 90 copper. How's that?")
elseif (level >= 120) then
Unit:SendChatMessage(12, 0, "I could give you a room for 50 gold. How's that?")
end
end
function Purchase(Unit, event, player)
local level = Unit:GetPlayerLevel()
local money = player:GetCoinage()
if (level <= 9) then
if (money >= 30) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(30)
elseif (money < 30) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 19) and (level >= 10) then
if (money >= 240) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(240)
elseif (money < 240) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 29) and (level >= 20) then
if (money >= 2040) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(2040)
elseif (money < 2040) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 39) and (level >= 30) then
if (money >= 3610) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(3610)
elseif (money < 3610) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 49) and (level >= 40) then
if (money >= 6410) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(6410)
elseif (money < 6410) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 59) and (level >= 50) then
if (money >= 8690) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(8690)
elseif (money < 8690) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 69) and (level >= 60) then
if (money >= 12040) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(12040)
elseif (money < 12040) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 79) and (level >= 70) then
if (money >= 20000) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(20000)
elseif (money < 20000) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 89) and (level >= 80) then
if (money >= 25450) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(25450)
elseif (money < 25450) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 99) and (level >= 90) then
if (money >= 121890) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(121890)
elseif (money < 121890) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 109) and (level >= 100) then
if (money >= 329890) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(329890)
elseif (money < 329890) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level <= 119) and (level >= 110) then
if (money >= 409890) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(409890)
elseif (money < 409890) then
player:SendAreaTriggerMessage("Not enough gold.")
end
elseif (level >= 120) then
if (money >= 500000) then
Unit:FullCastSpellOnTarget(25840, player)
player:AddItem(89001, 1)
player:DealGoldCost(500000)
elseif (money < 500000) then
player:SendAreaTriggerMessage("Not enough gold.")
end
end
end
function On_Gossip_Complete(Unit, event, player)
Unit:RemoveEvents()
end
RegisterUnitGossipEvent(60004, 1, "Inn_Gossip")
RegisterUnitGossipEvent(60004, 2, "Inn_Gossip_SubMenus")
RegisterUnitGossipEvent(60004, 3, "On_Gossip_Complete")
The other problem I run into is with two separate Lua scripts, and two separate NPCs.
The first NPC's entryid: 60010
The second's entryid: 60012
Now, NPC #1 is supposed to just fight enemies like so:
Code:
local NPCID = 60010
function EquipWepsOnLoad_60010(pUnit, event)
local equipchance = math.random(1,3)
if (equipchance == 1) then
pUnit:EquipWeapons(38632, 0, 0)
end
if (equipchance == 2) then
pUnit:EquipWeapons(40491, 45287, 34334)
pUnit:SetCombatRangedCapable(true)
end
if (equipchance == 3) then
pUnit:EquipWeapons(40491, 30314, 0)
end
end
function Guard_OnCombat_60010(pUnit, event)
local taunt = math.random(1,5)
if (taunt == 1) then
pUnit:SendChatMessage(14, 0, "Die scum!")
end
if (taunt == 2) then
pUnit:SendChatMessage(14, 0, "Your existence is pointless! You will be eliminated!")
end
if (taunt == 3) then
pUnit:SendChatMessage(14, 0, "Back to hell with you!")
end
if (taunt == 4) then
pUnit:SendChatMessage(14, 0, "You dare challenge the order?")
end
if (taunt == 5) then
pUnit:SendChatMessage(14, 0, "I shall bring death upon you!")
end
pUnit:FullCastSpell(54043)
pUnit:RegisterEvent("SpellChoosing_60010", 4000, 0)
pUnit:RegisterEvent("CombatTalk_60010", 8000, 0)
end
function Guard_OnLeaveCombat_60010(pUnit, event)
local modelchance = pUnit:GetNativeDisplay()
pUnit:SetModel(modelchance)
pUnit:SendChatMessage(12, 0, "Disgusting.")
pUnit:RemoveEvents()
end
function CombatTalk_60010(pUnit, event)
local say = math.random(1,4)
if (say == 1) then
pUnit:SendChatMessage(12, 0, "You shall perish.")
end
if (say == 2) then
pUnit:SendChatMessage(12, 0, "Your persistence will mean the death of you!")
end
if (say == 4) then
pUnit:SendChatMessage(12, 0, "Give up the fight.")
end
end
function SpellChoosing_60010(pUnit, event)
if pUnit:GetHealthPct() <= 30 then
pUnit:RegisterEvent("PhSpellChoosing_60010", 3000, 0)
local spell = math.random(1,4)
if (spell == 1) then
pUnit:FullCastSpell(66003)
end
if (spell == 2) then
pUnit:FullCastSpell(66007)
end
if (spell == 4) then
pUnit:FullCastSpell(67251)
end
end
function PhSpellChoosing_60010(pUnit, event)
local phspell = math.random(1,2)
local phtarget = pUnit:GetPrimaryCombatTarget()
pUnit:SendChatMessage(14, 10, "I will not fall! Not here, not now!")
pUnit:SetModel(19682)
if (phspell == 1) then
pUnit:FullCastSpell(75419, phtarget)
end
if (phspell == 2) then
pUnit:FullCastSpell(75413, phtarget)
end
end
RegisterUnitEvent(60010, 1, "Guard_OnCombat_60010")
RegisterUnitEvent(60010, 2, "Guard_OnLeaveCombat_60010")
RegisterUnitEvent(60010, 18, "EquipWepsOnLoad_60010")
And NPC #2 is actually an NPC summoned via a gossip script with another NPC. This NPC defends you from enemies for 90 seconds. Anyways, the problem isn't that.
The problem is that both NPCs cast Divine shield every 31 seconds. Only NPC #2 should do that. It's as if the two scripts were merged or something. Here's the second script:
Code:
local NPCID = 60012
function EquipWepsOnLoad_60012(pUnit, event)
local equipchance = math.random(1,3)
if (equipchance == 1) then
pUnit:EquipWeapons(38632, 0, 0)
end
if (equipchance == 2) then
pUnit:EquipWeapons(40491, 45287, 34334)
pUnit:SetCombatRangedCapable(true)
end
if (equipchance == 3) then
pUnit:EquipWeapons(40491, 30314, 0)
end
end
function Protect_Player_60012(pUnit, event)
local player = pUnit:GetClosestPlayer()
if(player ~= nil) then
pUnit:FullCastSpellOnTarget(10278, player)
pUnit:RegisterEvent("Protect_Player_Repeats", 31000, 0)
else
end
end
function Protect_Player_Repeats_60012(pUnit, event)
local cplayer = pUnit:GetClosestPlayer()
if(player ~= nil) then
pUnit:FullCastSpellOnTarget(10278, cplayer)
else
end
end
function Guard_OnCombat_60012(pUnit, event)
local cplayer = pUnit:GetClosestPlayer()
pUnit:SendChatMessageToPlayer(13, 0, "Wait here, ".. pUnit:GetPlayerClass() ..". I'll take care of this mongrel..", cplayer)
pUnit:SendChatMessage(14, 10, "Die scum! For Lord Amun!!")
pUnit:FullCastSpell(54043)
pUnit:RegisterEvent("Protect_Player_60012", 1000, 1)
end
function Guard_Combat_Actions_60012(pUnit, event)
pUnit:RegisterEvent("SpellChoosing_60012", 3500, 0)
end
function SpellChoosing_60012(pUnit, event)
local spell = math.random(1,4)
local target = pUnit:GetPrimaryCombatTarget()
if pUnit:GetHealthPct() <=30 then
pUnit:RemoveEvents()
pUnit:RegisterEvent("PhSpellChoosing_60012", 3000, 0)
end
if (spell == 1) then
pUnit:FullCastSpellOnTarget(66003, target)
end
if (spell == 2) then
pUnit:FullCastSpellOnTarget(66007, target)
end
if (spell == 4) then
pUnit:FullCastSpellOnTarget(67251, target)
end
end
function PhSpellChoosing_60012(pUnit, event)
local phspell = math.random(1,2)
local phtarget = pUnit:GetPrimaryCombatTarget()
pUnit:SendChatMessage(14, 10, "I will not fall! Not here, not now!")
pUnit:SetModel(19682)
if (phspell == 1) then
pUnit:FullCastSpellOnTarget(75419, phtarget)
end
if (phspell == 2) then
pUnit:FullCastSpellOnTarget(75413, phtarget)
end
end
function Reset_OnExit_60012(pUnit, event)
pUnit:RemoveEvents()
local modelchance = pUnit:GetNativeDisplay()
pUnit:SetModel(modelchance)
pUnit:RegisterEvent("Speak_Player", 2500, 1)
end
function Speak_Player_60012(pUnit, event, player)
pUnit:SendChatMessage(12, 0, "Enemy eliminated. Sorry for that, let us continue on. I need to get you to the gate.")
end
RegisterUnitEvent(60012, 18, "EquipWepsOnLoad_60012")
RegisterUnitEvent(60012, 23, "Guard_Combat_Actions_60012")
RegisterUnitEvent(60012, 1, "Guard_OnCombat_60012")
RegisterUnitEvent(60012, 2, "Reset_OnExit_60012")