Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. local npcList = {3100, 3101, 3102};
  2. local range = 40; -- Range that will trigger / stop the npc from announcing.
  3. local delay = 1*10*1000; -- Delay between the announcements.
  4. local subDelay = 1*2*1000; -- Time between linked announcements.
  5.  
  6. -- {Statement, stated, linked, emote, spellid,{spawn type, spawn id},},
  7. -- statement :: in quotes "blah blah"
  8. -- stated :: say = 0 // yell = 1
  9. -- linked :: table key id if your using multiple statements  for one announcement i.e.(yell THEN say)
  10. -- emote :: talk = 1 // yell = 5// Question = 6 // Dance = 10 // Rude = 14 // shout = 22 //
  11. -- spellid :: spell id
  12. -- http://collab.kpsn.org/display/tc/Emote
  13. -- spawn type :: 0 none, 1 npc // 2 gob
  14. -- spawn id :: id of what to spawn
  15.  
  16. local annTable = { ["Says"] = {
  17.     [1] = {"Yo, I heard you liked boars!", 1, 0, 6, 58837},
  18.     [2] = {"What's up dawg?", 0, 100, 1, 0},
  19.     [100] = {"Yo, you good dawg", 0, 101, 1, 0},
  20.     [101] = {"Hey, I am talking to you!", 1, 0, 1, 0},
  21. }};
  22.  
  23. local reqData = 5;
  24.  
  25. local function announce(id, pUnit)
  26.     local sayTable = annTable["Says"][id];
  27.     -- Are we missing data? We don't want any nil values ...
  28.     if #sayTable ~= reqData then
  29.         return;
  30.     end
  31.     -- Putting the data from the table into local variables,
  32.     -- to prevent a lot of table indexing.
  33.     local msg, msgType, linkId, emoteId, spellId --[[, spawnType, spawnId]] = table.unpack(sayTable);
  34.     -- Checking the data for events that should occur, if so
  35.     -- let it happen.
  36.     if msgType == 0 then pUnit:SendUnitSay(msg, 0); else pUnit:SendUnitYell(msg, 0); end
  37.     if emoteId ~= 0 then pUnit:Emote(emoteId); end
  38.     if linkId ~= 0 then
  39.         -- Does the table exist?
  40.         if annTable["Says"][linkId] == nil then
  41.             return;
  42.         end
  43.         -- Recursive call to announce, we want the same result right?
  44.         CreateLuaEvent(function() announce(linkId, pUnit); end, subDelay, 1);
  45.     end
  46.     if spellId ~= 0 then pUnit:CastSpell(pUnit, spellId); end
  47. end
  48.    
  49. local function timedSay(_, _, _, pUnit)
  50.     announce(math.random(#annTable["Says"]), pUnit);
  51. end
  52.  
  53. local function stopAnnounce(pUnit)
  54.     if #pUnit:GetPlayersInRange(range) == 0 then
  55.         annTable[pUnit:GetGUIDLow()] = false;
  56.         return pUnit:RemoveEvents();
  57.     end
  58.     CreateLuaEvent(function() return stopAnnounce(pUnit); end, delay, 1);
  59. end
  60.  
  61. local function onMotion(_, pUnit, plr)
  62.     -- If we stop announcing if there are no players
  63.     -- in a certain range, we shouldn't start either.
  64.     if #pUnit:GetPlayersInRange(range) == 0 then
  65.         return;
  66.     end
  67.    
  68.     local lGuid = pUnit:GetGUIDLow();
  69.     local unitTable = annTable[lGuid];
  70.     -- Are we announcing?
  71.     if unitTable == nil or unitTable == false then
  72.         annTable[lGuid] = true; -- We are now ...
  73.         pUnit:RegisterEvent(timedSay, delay, 0);
  74.         -- Registering the check to see if we should continue
  75.         -- to announce or not.
  76.         CreateLuaEvent(function() return stopAnnounce(pUnit); end, delay-1, 1);
  77.     end
  78. end
  79.        
  80. for index=1, #npcList do
  81.     RegisterCreatureEvent(npcList[index], 27, onMotion);
  82. end
  83.  
  84. math.randomseed(os.time());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement