Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------
- -- Variable setup
- --------------------------------------------------------
- OBJECT_END = 0x0006
- UNIT_FIELD_FLAGS = OBJECT_END + 0x0035 -- Size: 1, Type: INT, Flags: PUBLIC
- UNIT_FLAG_NOT_SELECTABLE = 0x02000000 -- 26 33554432 cannot select the unit
- local gameInProgress = false
- local grid_npc = {}
- local grid_obj = {}
- local a_npcs = {}
- local h_npcs = {}
- -- Format entry Id's: Castle, Bishop, Knight, Queen, King, Knight, Bishop, Castle
- local alliance_creatures = {32561, 32561, 32561, 32561, 32561, 32561, 32561, 32561}
- local horde_creatures = {32561, 32561, 32561, 32561, 32561, 32561, 32561, 32561}
- -- Creature entry ID's and what they are
- local creature_index = {[32561] = "a_castle",
- [32561] = "h_castle",
- [32561] = "a_bishop",
- [32561] = "h_bishop",
- [32561] = "a_knight",
- [32561] = "h_knight",
- [32561] = "a_queen",
- [32561] = "h_queen",
- [32561] = "a_king",
- [32561] = "h_king"}
- --------------------------------------------------------
- -- Event triggering (toggle)
- --------------------------------------------------------
- function chesschat(event, plr, message, mtype, language)
- if message == "#chess" then
- if gameInProgress then
- plr:SendBroadcastMessage("Ending chess.")
- DespawnChess()
- else
- plr:SendBroadcastMessage("Starting chess.")
- SpawnChess(plr)
- end
- return false
- end
- end
- RegisterServerHook(16, "chesschat")
- --------------------------------------------------------
- -- Spawn/Despawn grid
- --------------------------------------------------------
- function SpawnChess(pUnit)
- if pUnit == nil then
- return
- end
- if gameInProgress then
- pUnit:SendBroadcastMessage("Game is in progress - try again later.")
- return
- end
- gameInProgress = true
- local x = pUnit:GetX()
- local y = pUnit:GetY()
- local z = pUnit:GetZ()
- local i, j
- local a = 0
- local b = 0
- for i=0,35,5 do
- a = a + 1
- table.insert(a_npcs, pUnit:SpawnCreature(alliance_creatures[a], x+i, y, z+0.1, 1.5, 35, 0))
- for j=0,35,5 do
- if j == 35 then
- b = b + 1
- local npc = pUnit:SpawnCreature(horde_creatures[b], x+i, y+j, z+0.1, 4.7, 35, 0)
- npc:RegisterEvent("Chess_Piece_Move", 1000, 0)
- table.insert(h_npcs, npc)
- end
- table.insert(grid_npc, pUnit:SpawnCreature(28816, x+i, y+j, z, 0, 35, 0))
- table.insert(grid_obj, pUnit:SpawnGameObject(185301, x+i, y+j, z-0.21, 0, 0, 100))
- end
- end
- for _,v in ipairs(grid_npc) do
- v:SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE)
- end
- for _,v in ipairs(a_npcs) do
- v:RegisterEvent("Chess_Piece_Move", 1000, 0)
- end
- for _,v in ipairs(h_npcs) do
- v:RegisterEvent("Chess_Piece_Move", 1000, 0)
- end
- end
- function DespawnChess()
- for _,v in ipairs(grid_npc) do
- if v then
- v:Despawn(1,0)
- end
- end
- for _,v in ipairs(grid_obj) do
- if v then
- v:Despawn(1,0)
- end
- end
- for _,v in ipairs(a_npcs) do
- if v then
- v:Despawn(1,0)
- end
- end
- for _,v in ipairs(h_npcs) do
- if v then
- v:Despawn(1,0)
- end
- end
- grid_npc = {}
- grid_obj = {}
- a_npcs = {}
- h_npcs = {}
- gameInProgress = false
- end
- --------------------------------------------------------
- -- Moving a piece
- --------------------------------------------------------
- function Chess_Piece_Move(pUnit)
- local plr = pUnit:GetClosestPlayer()
- if not plr then
- return
- end
- if plr:GetDistanceYards(pUnit) > 3 then
- if v:HasAura(50236) then
- v:RemoveAura(50236) -- light beam visual
- end
- return
- end
- pUnit:CastSpell(50236) -- light beam visual
- ------------------------------------------------
- -- Handle where this unit can move
- ------------------------------------------------
- local piece = creature_index[pUnit:GetEntry()]
- if not piece then
- pUnit:SendChatMessage(12,0,"ERROR: I am not handled.")
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment