[Guide][LUA] Make a mob speak/use spell on a %! -
01-10-2008
Okay, I've found a way how to make a mob do something on a certain % with LUA.
Many people said that we need C++ for that, but that FALSE!
Here's the script!
This will make a mob speak at 75%.
You have to change the red words in it.
Code:
buffer = 0
function testmob_phase(unit)
local percento = unit:GetHealthPct()
if buffer == 0 then
if (percento <= 75) then
buffer = 1
unit:SendChatMessage(12, 0, "Speak something")
--You can insert random other commands here, such as Castspell and etc, what you want your mob to do.
end
end
end
function testmob_entercombat(unit)
buffer = 0
unit:RegisterEvent("testmob_phase",3000, 0)
end
function testmob_LeaveCombat(unit)
buffer = 0
end
RegisterUnitEvent(12345, 1, "testmob_entercombat")
RegisterUnitEvent(12345, 2, "testmob_leavecombat")
Looks a bit difficult? Let me help.
testmob = the name of the function, name it whatever you want, but name it on every place. 75 = the precent of when the mob should do the action. Speak something = The text you want the mob to say. 3000 = Important! This is the delay of checking if his hp is below the current precent or not. Don't change it, I will explain this further.
=====FAQ=====
Q: Please tell me how is this working!
A: This checks the mob's hp's precent within a delay, which is now for 3000 example
Q: Why can't we use AI_Tick?
A: I couldn't get that work, besides this would not lag the server that much since it's not trying to check it continously.
Q: What does "buffer" mean?
A: The function is being checked every 3000 (=3 sec), and let's say you're doing the boss, it gets below the HP and it would trigger the function always, meaning it would continously do the function (Speak for example).
"buffer" variable makes that it will trigger only one time, and resetting it if the mob gets out of combat/gets in combat.
I know this full thing is a bit hard-to-understand, so if you have any problem, post it in this section, I will help.
You can change the 3000 to something lower, like 1000 (so the delay would be 1sec) if you're killing a low hp mob or whatsoever, it's up to you
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 2
Reputation: 3
Posts: 30
Join Date: May 2007
01-10-2008
would :
buffer = 2
function testmob_phase(unit)
local percento = unit:GetHealthPct()
if buffer == 2 then
if (percento <= 75) then
buffer = 1
unit:SendChatMessage(12, 0, "Speak something")
if buffer == 2 then if (percento <= 40) then buffer = 1 unit:SendChatMessage(12, 0, "Speak something ELSE")
end
end
end
function testmob_entercombat(unit)
buffer = 0
unit:RegisterEvent("testmob_phase",3000, 0)
end
buffer = 2
function testmob_phase(unit)
local percento = unit:GetHealthPct()
if buffer == 2 then
if (percento <= 75) then
buffer = 1
unit:SendChatMessage(12, 0, "Speak something")
if buffer == 2 then if (percento <= 40) then buffer = 1 unit:SendChatMessage(12, 0, "Speak something ELSE")
end
end
end
function testmob_entercombat(unit) buffer = 2
unit:RegisterEvent("testmob_phase",3000, 0)
end
function testmob_LeaveCombat(unit) buffer = 2
end
Now it would work. But I don't advise you to change the value of the buffer since it's clearly not neccesary, also it can easily make the whole script don't work properly.
Quote:
Originally Posted by Dee2001
uuhhh in this code if u change the unit:SendChatMessage(12, 0, "Speak something")
too unit:castspell()
would that work ??
Yes, it would work. That is the point, you can add your own code!
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 2
Reputation: 3
Posts: 30
Join Date: May 2007
01-10-2008
can u help me out???? i can seem to get it to work.... can u set up an example? lets say with ILLidaN? ID 22917..... thnks ( and possible make him cast healing spell???? thnkx
No offense, but you totally stole my idea :P Anyway, this is a pretty bad way of making phases between bosses. Using this method, any called functions in phase one would persist through phase 2 and so on. Using "Buffer" or "didthat" is bound to fail.
I recommend looking at my new guide and using Unit:RemoveEvents()
And the emulators shall tremble.
[Only registered and activated users can see links. ]
You are responsible for any broken rule, regardless if you "didn't know" or not.
1. You are wrong, totally, using that is variable is like a switch, which you turn off when the spell was used 1time. "Unit:RemoveEvents()" is needed after every phase, that's true 2. Stole "your" idea? Since when do you think I'd steal anybody's work or anything else? EVEN I posted this a little faster then you as I know. I'm offended because of the statement.