-- client.lua ---
Try this:
GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Grid = {}
GUIEditor_Window[1] = guiCreateWindow(270,216,449,476,"Panel",false)
guiWindowSetSizable(GUIEditor_Window[1],false)
GUIEditor_Grid[1] = guiCreateGridList(9,20,431,394,false,GUIEditor_Window[1])
guiGridListSetSelectionMode(GUIEditor_Grid[1],2)
guiGridListAddColumn(GUIEditor_Grid[1],"maps",1.2)
GUIEditor_Button[1] = guiCreateButton(12,419,190,46,"Refresh MapList",false,GUIEditor_Window[1])
GUIEditor_Button[2] = guiCreateButton(258,419,182,46,"Buy Map!",false,GUIEditor_Window[1])
guiSetVisible( GUIEditor_Window[1], false )
showCursor ( false )
function getMaps()
setTimer(callServerFunction,500,1,"getServerMaps",getLocalPlayer())
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getMaps)
--maps tab
function loadMaps(gamemodeMapTable, gamemode, map)
guiGridListClear(GUIEditor_Grid[1])
if gamemodeMapTable then
aGamemodeMapTable = gamemodeMapTable
for id,gamemode in pairs (gamemodeMapTable) do
if (gamemode.name == "Race") then
for id,map in ipairs (gamemode.maps) do
local row = guiGridListAddRow(GUIEditor_Grid[1])
guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, map.name, false, false )
end
end
end
end
end
function callClientFunction(funcname, ...)
local arg = { ... }
if (arg[1]) then
for key, value in next, arg do arg[key] = tonumber(value) or value end
end
loadstring("return "..funcname)()(unpack(arg))
end
addEvent("onServerCallsClientFunction", true)
addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction)
--
-- Call server function
--
function callServerFunction(funcname, ...)
local arg = { ... }
if (arg[1]) then
for key, value in next, arg do
if (type(value) == "number") then arg[key] = tostring(value) end
end
end
triggerServerEvent("onClientCallsServerFunction", resourceRoot , funcname, unpack(arg))
end
function oppenz()
if guiGetVisible ( GUIEditor_Window[1] ) then
guiSetVisible ( GUIEditor_Window[1], false )
showCursor(false)
guiSetInputEnabled(false)
else
guiSetVisible ( GUIEditor_Window[1], true )
showCursor(true)
guiSetInputEnabled(true)
end
end
bindKey("F6","down",oppenz)
server.lua
Try this:
function callServerFunction(funcname, ...)
local arg = { ... }
if (arg[1]) then
for key, value in next, arg do arg[key] = tonumber(value) or value end
end
loadstring("return "..funcname)()(unpack(arg))
end
addEvent("onClientCallsServerFunction", true)
addEventHandler("onClientCallsServerFunction", getRootElement() , callServerFunction)
function callClientFunction(client, funcname, ...)
local arg = { ... }
if (arg[1]) then
for key, value in next, arg do
if (type(value) == "number") then arg[key] = tostring(value) end
end
end
triggerClientEvent(client, "onServerCallsClientFunction", getRootElement(), funcname, unpack(arg or {}))
end
function getServerMaps (loadList)
local tableOut
if loadList then
tableOut = {}
local gamemodes = {}
gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes")
for id,gamemode in ipairs (gamemodes) do
tableOut[id] = {}
tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode)
tableOut[id].resname = getResourceName(gamemode)
tableOut[id].maps = {}
local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode)
for _,map in ipairs (maps) do
table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map) })
end
table.sort(tableOut[id]["maps"], sortCompareFunction)
end
table.sort((tableOut), sortCompareFunction)
table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}})
local countGmodes = #tableOut
local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode")
for id,map in ipairs (maps) do
table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map) })
end
table.sort(tableOut[countGmodes]["maps"], sortCompareFunction)
end
local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap")
local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode")
gamemode = gamemode and getResourceName(gamemode) or "N/A"
map = map and getResourceName(map) or "N/A"
callClientFunction(loadList,"loadMaps", tableOut, gamemode, map)
end
function sortCompareFunction(s1, s2)
if type(s1) == "table" and type(s2) == "table" then
s1, s2 = s1.name, s2.name
end
s1, s2 = s1:lower(), s2:lower()
if s1 == s2 then
return false
end
local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1))
if not byte1 then
return true
elseif not byte2 then
return false
elseif byte1 < byte2 then
return true
elseif byte1 == byte2 then
return sortCompareFunction(s1:sub(2), s2:sub(2))
else
return false
end
end
function callGetMaps()
for i,player in ipairs(getElementsByType("player")) do
triggerClientEvent(player,"getMaps")
end
end
addCommandHandler("rebuildMaps",callGetMaps)
i've tested,its work