kusanagy

sc_default

Dec 29th, 2017
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. --
  2. -- Cooldown Methods by Foereaper
  3. --
  4. -- player:SetLuaCooldown(seconds[, opt_id]) -- Sets the cooldown timer to X seconds, optionally a specific cooldown ID can be set. Default ID: 1
  5. -- player:GetLuaCooldown([opt_id])          -- Returns cooldown or 0 if none, default cooldown checked is ID 1, unless other is specified.
  6. --
  7.  
  8. local cooldowns = {};
  9.  
  10. function Player:SetLuaCooldown(seconds, opt_id)
  11.     assert(type(self) == "userdata");
  12.     seconds = assert(tonumber(seconds));
  13.     opt_id = opt_id or 1;
  14.     local guid = self:GetGUIDLow();
  15.  
  16.     if (not cooldowns[guid]) then
  17.         cooldowns[guid] = {};
  18.     end
  19.  
  20.     cooldowns[guid][opt_id] = os.time() + seconds;
  21. end
  22.  
  23. function Player:GetLuaCooldown(opt_id)
  24.     assert(type(self) == "userdata");
  25.     local guid = self:GetGUIDLow();
  26.     opt_id = opt_id or 1;
  27.  
  28.     if (not cooldowns[guid]) then
  29.         cooldowns[guid] = {};
  30.     end
  31.  
  32.     local cd = cooldowns[guid][opt_id];
  33.     if (not cd or cd < os.time()) then
  34.         cooldowns[guid][opt_id] = 0
  35.         return 0;
  36.     else
  37.         return cooldowns[guid][opt_id] - os.time();
  38.     end
  39. end
  40.  
  41. --
  42. -- GossipSetText Methods by Rochet2
  43. --
  44. -- player:GossipMenuAddItem(0, "Text", 0, 0)
  45. -- player:GossipMenuAddItem(0, "Text", 0, 0)
  46. -- player:GossipSetText("Text")
  47. -- player:GossipSendMenu(0x7FFFFFFF, creature)
  48. --
  49.  
  50. local SMSG_NPC_TEXT_UPDATE = 384
  51. local MAX_GOSSIP_TEXT_OPTIONS = 8
  52.  
  53. function Player:GossipSetText(text)
  54.     data = CreatePacket(SMSG_NPC_TEXT_UPDATE, 100);
  55.     data:WriteULong(0x7FFFFFFF)
  56.     for i = 1, MAX_GOSSIP_TEXT_OPTIONS do
  57.         data:WriteFloat(0)     -- Probability
  58.         data:WriteString(text) -- Text
  59.         data:WriteString(text) -- Text
  60.         data:WriteULong(0)     -- language
  61.         data:WriteULong(0)     -- emote
  62.         data:WriteULong(0)     -- emote
  63.         data:WriteULong(0)     -- emote
  64.         data:WriteULong(0)     -- emote
  65.         data:WriteULong(0)     -- emote
  66.         data:WriteULong(0)     -- emote
  67.     end
  68.     self:SendPacket(data)
  69. end
  70.  
  71. --
  72. -- WorldState methods by Foereaper
  73. --
  74. -- player:InitializeWorldState(Map, Zone, StateID, Value)
  75. -- player:UpdateWorldState(StateID, Value)
  76. --
  77.  
  78. local SMSG_INIT_WORLD_STATES = 0x2C2
  79. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  80.  
  81. function Player:InitializeWorldState(Map, Zone, StateID, Value)
  82.     local data = CreatePacket(SMSG_INIT_WORLD_STATES, 18);
  83.     data:WriteULong(Map);
  84.     data:WriteULong(Zone);
  85.     data:WriteULong(0);
  86.     data:WriteUShort(1);
  87.     data:WriteULong(StateID);
  88.     data:WriteULong(Value);
  89.     self:SendPacket(data)
  90. end
  91.  
  92. function Player:UpdateWorldState(StateID, Value)
  93.     local data = CreatePacket(SMSG_UPDATE_WORLD_STATE, 8);
  94.     data:WriteULong(StateID);
  95.     data:WriteULong(Value);
  96.     self:SendPacket(data)
  97. end
  98.  
  99. function ChatMsg(type)
  100.     if (type == 0x00) then
  101.         return("System")
  102.     elseif (type == 0x01) then
  103.         return("Says")
  104.     elseif (type == 0x02) then
  105.         return("Party")
  106.     elseif (type == 0x03) then
  107.         return("Raid")
  108.     elseif (type == 0x04) then
  109.         return("Guild["..pg.."]")
  110.     elseif (type == 0x05) then
  111.         return("Guild Officer["..pg.."]")
  112.     elseif (type == 0x06) then
  113.         return("Yells")
  114.     elseif (type == 0x07) then
  115.         return("Whisper")
  116.     elseif (type == 0x11) then
  117.         return("(General/Trade/Local Defense/LFG/Custom)")
  118.     elseif (type == 0x2C) then
  119.         return("Battleground")
  120.     elseif (type == 0x2D) then
  121.         return("Battleground Leader")
  122.     else
  123.         return(type)
  124.     end
  125. end
  126.  
  127. function CreateQueue()
  128.     local Queue = {Queue = {}}
  129.  
  130.     function Queue:Set(index)
  131.         if (self:Has(index)) then
  132.             return false
  133.         end
  134.         self.Queue[index] = true
  135.         return true
  136.     end
  137.  
  138.     function Queue:Remove(index)
  139.         if (not self:Has(index)) then
  140.             return false
  141.         end
  142.         self.Queue[index] = nil
  143.         return true
  144.     end
  145.  
  146.     function Queue:Has(index)
  147.         return self.Queue[index] ~= nil
  148.     end
  149.  
  150.     function Queue:Get()
  151.         return self.Queue
  152.     end
  153.  
  154.     local pairs = pairs
  155.     function Queue:Count()
  156.         local count = 0
  157.         for k,v in pairs(self.Queue) do
  158.             count = count + 1
  159.         end
  160.         return count
  161.     end
  162.  
  163.     return Queue
  164. end
Advertisement
Add Comment
Please, Sign In to add comment