Files
ashlar/scripts/guiHelper.lua
T
David Cernat 6684326e5e [General] Rename BaseWorld's loadedRegions into storedRegions
There was a discrepancy in the meaning of "loaded" between the LoadedCells table and BaseWorld's loadedRegions table. The former contained only currently loaded cells, while the latter contained all the regions that had ever been loaded since the start of the server. To remove the inconsistency, the latter has been renamed.
2018-08-27 23:16:01 +03:00

157 lines
4.1 KiB
Lua

tableHelper = require("tableHelper")
guiHelper = {}
guiHelper.ID = tableHelper.enum({"LOGIN", "REGISTER", "PLAYERSLIST", "CELLSLIST"})
guiHelper.ShowLogin = function(pid)
tes3mp.PasswordDialog(pid, guiHelper.ID.LOGIN, "Enter your password:", "")
end
guiHelper.ShowRegister = function(pid)
tes3mp.PasswordDialog(pid, guiHelper.ID.REGISTER, "Create new password:",
"Warning: the server owner will be able to read your password, so you should use a unique one for each server.")
end
local GetConnectedPlayerList = function()
local lastPid = tes3mp.GetLastPlayerId()
local list = ""
local divider = ""
for playerIndex = 0, lastPid do
if playerIndex == lastPid then
divider = ""
else
divider = "\n"
end
if Players[playerIndex] ~= nil and Players[playerIndex]:IsLoggedIn() then
list = list .. tostring(Players[playerIndex].name) .. " (pid: " .. tostring(Players[playerIndex].pid) ..
", ping: " .. tostring(tes3mp.GetAvgPing(Players[playerIndex].pid)) .. ")" .. divider
end
end
return list
end
local GetLoadedCellList = function()
local list = ""
local divider = ""
local cellCount = logicHandler.GetLoadedCellCount()
local cellIndex = 0
for key, value in pairs(LoadedCells) do
cellIndex = cellIndex + 1
if cellIndex == cellCount then
divider = ""
else
divider = "\n"
end
list = list .. key .. " (auth: " .. LoadedCells[key]:GetAuthority() .. ", loaded by " ..
LoadedCells[key]:GetVisitorCount() .. ")" .. divider
end
return list
end
local GetLoadedRegionList = function()
local list = ""
local divider = ""
local regionCount = logicHandler.GetLoadedRegionCount()
local regionIndex = 0
for key, value in pairs(WorldInstance.storedRegions) do
local visitorCount = WorldInstance:GetRegionVisitorCount(key)
if visitorCount > 0 then
regionIndex = regionIndex + 1
if regionIndex == regionCount then
divider = ""
else
divider = "\n"
end
list = list .. key .. " (auth: " .. WorldInstance:GetRegionAuthority(key) .. ", loaded by " ..
visitorCount .. ")" .. divider
end
end
return list
end
local GetPlayerInventoryList = function(pid)
local list = ""
local divider = ""
local lastItemIndex = tableHelper.getCount(Players[pid].data.inventory)
for index, currentItem in ipairs(Players[pid].data.inventory) do
if index == lastItemIndex then
divider = ""
else
divider = "\n"
end
list = list .. index .. ": " .. currentItem.refId .. " (count: " .. currentItem.count .. ")" .. divider
end
return list
end
guiHelper.ShowPlayerList = function(pid)
local playerCount = logicHandler.GetConnectedPlayerCount()
local label = playerCount .. " connected player"
if playerCount ~= 1 then
label = label .. "s"
end
tes3mp.ListBox(pid, guiHelper.ID.PLAYERSLIST, label, GetConnectedPlayerList())
end
guiHelper.ShowCellList = function(pid)
local cellCount = logicHandler.GetLoadedCellCount()
local label = cellCount .. " loaded cell"
if cellCount ~= 1 then
label = label .. "s"
end
tes3mp.ListBox(pid, guiHelper.ID.CELLSLIST, label, GetLoadedCellList())
end
guiHelper.ShowRegionList = function(pid)
local regionCount = logicHandler.GetLoadedRegionCount()
local label = regionCount .. " loaded region"
if regionCount ~= 1 then
label = label .. "s"
end
tes3mp.ListBox(pid, guiHelper.ID.CELLSLIST, label, GetLoadedRegionList())
end
guiHelper.ShowInventoryList = function(menuId, pid, inventoryPid)
local inventoryCount = tableHelper.getCount(Players[pid].data.inventory)
local label = inventoryCount .. " item"
if inventoryCount ~= 1 then
label = label .. "s"
end
tes3mp.ListBox(pid, menuId, label, GetPlayerInventoryList(inventoryPid))
end
return guiHelper