summaryrefslogtreecommitdiffstats
path: root/Plugins/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/Core')
-rw-r--r--Plugins/Core/onblockplace.lua69
-rw-r--r--Plugins/Core/playerlist.lua20
-rw-r--r--Plugins/Core/web_playerlist.lua26
3 files changed, 61 insertions, 54 deletions
diff --git a/Plugins/Core/onblockplace.lua b/Plugins/Core/onblockplace.lua
index ba75bf5c2..45d9a082e 100644
--- a/Plugins/Core/onblockplace.lua
+++ b/Plugins/Core/onblockplace.lua
@@ -1,3 +1,5 @@
+local BlockData = {}
+
function OnBlockPlace( Block, Player )
-- dont check if the direction is in the air
@@ -11,50 +13,47 @@ function OnBlockPlace( Block, Player )
return true
end
- local collision = false
- local World = Player:GetWorld()
- local PlayerList = World:GetAllPlayers()
-
- -- check if a player occupies the placement location
- for i, Player in ipairs( PlayerList ) do
-
- -- drop the decimals, we only care about the full block X,Y,Z
- local PlayerX = math.floor(Player:GetPosX(), 0)
- local PlayerY = math.floor(Player:GetPosY(), 0)
- local PlayerZ = math.floor(Player:GetPosZ(), 0)
-
- local BlockX = Block.m_PosX
- local BlockY = Block.m_PosY
- local BlockZ = Block.m_PosZ
+ BlockData = Block
+ if( Player:GetWorld():ForEachPlayer( CheckCollision ) == false ) then
+ return true
+ else
+ return false
+ end
- -- player height is 2 blocks, so we check the position and then offset it up one
- -- so they can't place a block on there face
+ end
- if Block.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
- if Block.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
+ return false
- if Block.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
- if Block.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
+end
- if Block.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
- if Block.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
+function CheckCollision( Player )
+ -- drop the decimals, we only care about the full block X,Y,Z
+ local PlayerX = math.floor(Player:GetPosX(), 0)
+ local PlayerY = math.floor(Player:GetPosY(), 0)
+ local PlayerZ = math.floor(Player:GetPosZ(), 0)
- if Block.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
- if Block.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
+ local BlockX = BlockData.m_PosX
+ local BlockY = BlockData.m_PosY
+ local BlockZ = BlockData.m_PosZ
- if Block.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
- if Block.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
+ -- player height is 2 blocks, so we check the position and then offset it up one
+ -- so they can't place a block on there face
- end
+ local collision = false
+ if BlockData.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
+ if BlockData.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
- if collision then
- return true
- else
- return false
- end
+ if BlockData.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
+ if BlockData.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
- end
+ if BlockData.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
+ if BlockData.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
- return false
+ if BlockData.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
+ if BlockData.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
+ if BlockData.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
+ if BlockData.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
+
+ return collision
end \ No newline at end of file
diff --git a/Plugins/Core/playerlist.lua b/Plugins/Core/playerlist.lua
index c120f068f..63990e825 100644
--- a/Plugins/Core/playerlist.lua
+++ b/Plugins/Core/playerlist.lua
@@ -1,16 +1,16 @@
+local PlayerTable = {}
+
function HandlePlayerListCommand( Split, Player )
- local World = Player:GetWorld()
- local PlayerList = World:GetAllPlayers()
+ PlayerTable = {}
+ Player:GetWorld():ForEachPlayer( AppendToTable )
- local Message = cChatColor.Green .. "Connected players: (".. cChatColor.White.. #PlayerList .. cChatColor.Green .. ")"
+ local Message = cChatColor.Green .. "Connected players: (".. cChatColor.White.. #PlayerTable .. cChatColor.Green .. ")"
Player:SendMessage( Message )
-
- local PlayerTable = {}
- for i, TempPlayer in ipairs( PlayerList ) do
- local PlayerName = TempPlayer:GetName()
- table.insert(PlayerTable, PlayerName )
- end
-
+
Player:SendMessage( table.concat(PlayerTable, " ") )
return true
+end
+
+function AppendToTable( Player )
+ table.insert(PlayerTable, Player:GetName() )
end \ No newline at end of file
diff --git a/Plugins/Core/web_playerlist.lua b/Plugins/Core/web_playerlist.lua
index 6c736ce3c..62ccb1d44 100644
--- a/Plugins/Core/web_playerlist.lua
+++ b/Plugins/Core/web_playerlist.lua
@@ -1,3 +1,6 @@
+local PlayerHTML = ""
+local PlayerNum = 0
+
function HandleRequest_PlayerList( Request )
local World = cRoot:Get():GetWorld()
local Content = ""
@@ -16,20 +19,25 @@ function HandleRequest_PlayerList( Request )
Content = Content .. "<p>Connected Players: <b>" .. World:GetNumPlayers() .. "</b></p>"
Content = Content .. "<table>"
+ PlayerNum = 0
+ PlayerHTML = ""
+ World:ForEachPlayer( CreatePlayerList )
- local PlayerList = World:GetAllPlayers()
- if( #PlayerList > 0 ) then
- for i, Player in ipairs( PlayerList ) do
- Content = Content .. "<tr>"
- Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
- Content = Content .. "<td>" .. Player:GetName() .. "</td>"
- Content = Content .. "<td><a href='?playerlist-kick=" .. Player:GetName() .. "'>Kick</a></td>"
- Content = Content .. "</tr>"
- end
+ if( PlayerHTML ~= "" ) then
+ Content = Content .. PlayerHTML
else
Content = Content .. "<tr><td>None</td></tr>"
end
Content = Content .. "</table>"
Content = Content .. "<br>"
return Content
+end
+
+function CreatePlayerList( Player, Data )
+ PlayerNum = PlayerNum + 1
+ PlayerHTML = PlayerHTML .. "<tr>"
+ PlayerHTML = PlayerHTML .. "<td style='width: 10px;'>" .. PlayerNum .. ".</td>"
+ PlayerHTML = PlayerHTML .. "<td>" .. Player:GetName() .. "</td>"
+ PlayerHTML = PlayerHTML .. "<td><a href='?playerlist-kick=" .. Player:GetName() .. "'>Kick</a></td>"
+ PlayerHTML = PlayerHTML .. "</tr>"
end \ No newline at end of file