stoneharry

Untitled

May 30th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.83 KB | None | 0 0
  1. --------------------------------------------------------
  2. -- Variable setup
  3. --------------------------------------------------------
  4.  
  5. OBJECT_END = 0x0006
  6. UNIT_FIELD_FLAGS = OBJECT_END + 0x0035 -- Size: 1, Type: INT, Flags: PUBLIC
  7. UNIT_FLAG_NOT_SELECTABLE = 0x02000000 -- 26    33554432  cannot select the unit
  8.  
  9. local gameInProgress = false
  10. local grid_npc = {}
  11. local grid_obj = {}
  12. local a_npcs = {}
  13. local h_npcs = {}
  14.  
  15. -- Format entry Id's: Castle, Bishop, Knight, Queen, King, Knight, Bishop, Castle
  16. local alliance_creatures = {32561, 32561, 32561, 32561, 32561, 32561, 32561, 32561}
  17. local horde_creatures = {32561, 32561, 32561, 32561, 32561, 32561, 32561, 32561}
  18. -- Creature entry ID's and what they are
  19. local creature_index = {[32561] = "a_castle",
  20.                         [32561] = "h_castle",
  21.                         [32561] = "a_bishop",
  22.                         [32561] = "h_bishop",
  23.                         [32561] = "a_knight",
  24.                         [32561] = "h_knight",
  25.                         [32561] = "a_queen",
  26.                         [32561] = "h_queen",
  27.                         [32561] = "a_king",
  28.                         [32561] = "h_king"}
  29.  
  30. --------------------------------------------------------
  31. -- Event triggering (toggle)
  32. --------------------------------------------------------
  33.  
  34. function chesschat(event, plr, message, mtype, language)
  35.     if message == "#chess" then
  36.         if gameInProgress then
  37.             plr:SendBroadcastMessage("Ending chess.")
  38.             DespawnChess()
  39.         else
  40.             plr:SendBroadcastMessage("Starting chess.")
  41.             SpawnChess(plr)
  42.         end
  43.         return false
  44.     end
  45. end
  46.  
  47. RegisterServerHook(16, "chesschat")
  48.  
  49. --------------------------------------------------------
  50. -- Spawn/Despawn grid
  51. --------------------------------------------------------
  52.  
  53. function SpawnChess(pUnit)
  54.     if pUnit == nil then
  55.         return
  56.     end
  57.     if gameInProgress then
  58.         pUnit:SendBroadcastMessage("Game is in progress - try again later.")
  59.         return
  60.     end
  61.     gameInProgress = true
  62.     local x = pUnit:GetX()
  63.     local y = pUnit:GetY()
  64.     local z = pUnit:GetZ()
  65.     local i, j
  66.     local a = 0
  67.     local b = 0
  68.     for i=0,35,5 do
  69.         a = a + 1
  70.         table.insert(a_npcs, pUnit:SpawnCreature(alliance_creatures[a], x+i, y, z+0.1, 1.5, 35, 0))
  71.         for j=0,35,5 do
  72.             if j == 35 then
  73.                 b = b + 1
  74.                 local npc = pUnit:SpawnCreature(horde_creatures[b], x+i, y+j, z+0.1, 4.7, 35, 0)
  75.                 npc:RegisterEvent("Chess_Piece_Move", 1000, 0)
  76.                 table.insert(h_npcs, npc)
  77.             end
  78.             table.insert(grid_npc, pUnit:SpawnCreature(28816, x+i, y+j, z, 0, 35, 0))
  79.             table.insert(grid_obj, pUnit:SpawnGameObject(185301, x+i, y+j, z-0.21, 0, 0, 100))
  80.         end
  81.     end
  82.     for _,v in ipairs(grid_npc) do
  83.         v:SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE)
  84.     end
  85.     for _,v in ipairs(a_npcs) do
  86.         v:RegisterEvent("Chess_Piece_Move", 1000, 0)
  87.     end
  88.     for _,v in ipairs(h_npcs) do
  89.         v:RegisterEvent("Chess_Piece_Move", 1000, 0)
  90.     end
  91. end
  92.  
  93. function DespawnChess()
  94.     for _,v in ipairs(grid_npc) do
  95.         if v then
  96.             v:Despawn(1,0)
  97.         end
  98.     end
  99.     for _,v in ipairs(grid_obj) do
  100.         if v then
  101.             v:Despawn(1,0)
  102.         end
  103.     end
  104.     for _,v in ipairs(a_npcs) do
  105.         if v then
  106.             v:Despawn(1,0)
  107.         end
  108.     end
  109.     for _,v in ipairs(h_npcs) do
  110.         if v then
  111.             v:Despawn(1,0)
  112.         end
  113.     end
  114.     grid_npc = {}
  115.     grid_obj = {}
  116.     a_npcs = {}
  117.     h_npcs = {}
  118.     gameInProgress = false
  119. end
  120.  
  121. --------------------------------------------------------
  122. -- Moving a piece
  123. --------------------------------------------------------
  124.  
  125. function Chess_Piece_Move(pUnit)
  126.     local plr = pUnit:GetClosestPlayer()
  127.     if not plr then
  128.         return
  129.     end
  130.     if plr:GetDistanceYards(pUnit) > 3 then
  131.         if v:HasAura(50236) then
  132.             v:RemoveAura(50236) -- light beam visual
  133.         end
  134.         return
  135.     end
  136.     pUnit:CastSpell(50236) -- light beam visual
  137.     ------------------------------------------------
  138.     -- Handle where this unit can move
  139.     ------------------------------------------------
  140.     local piece = creature_index[pUnit:GetEntry()]
  141.     if not piece then
  142.         pUnit:SendChatMessage(12,0,"ERROR: I am not handled.")
  143.         return
  144.     end
  145.  
  146. end
Advertisement
Add Comment
Please, Sign In to add comment