SHARE
TWEET

Untitled

a guest Jul 17th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function OnEnterCombat(pUnit, Event) -- Ok event has started
  3.     pUnit:RegisterEvent("X", 2500, 0) -- Register the event 'x' to happen every 2.5 seconds forever
  4. end
  5.  
  6. function X(pUnit) -- Function x has been called and we still have pUnit
  7.     if pUnit:GetHealthPct() < 2 then -- if health percentage is less than 2 (less than 2%)
  8.         pUnit:CastSpellOnTarget(36877,pUnit:GetMainTank()) -- Get the main tank and cast spell 36877 on him, without normal effects (add full to make it normal - FullCastSpellOnTarget), cast spell ignores mana cost/cast time etc
  9.     end
  10. end
  11.  
  12. RegisterUnitEvent(npcid,1,"OnEnterCombat") -- This is our hook that makes the script start working, 1 is for on enter combat and a unit
  13.  
  14.  
  15. --[[
  16.  
  17. The above script would now work fine
  18. However you could do the following to get a random target etc that may return nil
  19.  
  20. function x(pUnit)
  21.     if pUnit:GetHealthPct() < 2 then
  22.         local plr = pUnit:GetRandomPlayer(0)
  23.         if plr ~= nil then
  24.         pUnit:CastSpellOnTarget(36877, plr)
  25.         end
  26.     end
  27. end
  28.  
  29. so the script you just made, it will make that if the player has under 2% health left, it gets that spell on him/her? Aye, read my commentsAh great. And the second script?
  30. ta da, finished it basicly
  31.  
  32. ]]
  33.  
  34. -- This one is A LOT more complicated
  35.  
  36. function OnChatMessage(event, plr, message, type, language) -- Our function and parameters
  37.     local message = string.lower(message) -- change it all to lower caps so it could have been #DiE before but now it is #die
  38.     if message == "#die" then -- Check for the message we want
  39.         local target = plr:GetTarget() -- Get the target of the player
  40.         if target ~= nil -- Check we have a target
  41.             if target:GetHealthPct() < 1 -- If he has less than 1% HP
  42.                 target:CastSpell(5) -- I doubt spell 5 will work, there are alternate spells to use to kill him if needed
  43.             else
  44.                 player:SendBroadcastMessage("That player is not hurt enough!")
  45.             end
  46.         else
  47.             player:SendBroadcastMessage("You have no target!")
  48.         end
  49.     end
  50.     return 0 -- Makes the message not display in chat
  51. end
  52.  
  53. RegisterServerHook(16, "OnChatMessage") -- Our hook for when sending messages
RAW Paste Data
Top