--Some vars
--Author TwiX [[Don't Remove This Line]]
local sW,sH = guiGetScreenSize ( );
local gUtils = { };
gUtils.guiW,gUtils.guiH = 398, 410;
gUtils.posX,gUtils.posY = sW / 2 - gUtils.guiW / 2, sH / 2 - gUtils.guiH / 2; --Center of screen for all resolutions
local gLabels = { };
local gButtons = { };
function createGui ( )
gWindow = guiCreateWindow ( gUtils.posX, gUtils.posY, gUtils.guiW, gUtils.guiH, "Mini Map Shop v0.7", false );
gLabels[1] = guiCreateLabel ( 206, 30, 161, 19, "Money:", false, gWindow );
gLabels[2] = guiCreateLabel ( 206, 49, 100, 16, "Map Costs 5000$", false, gWindow );
gLabels[3] = guiCreateLabel ( 206, 66, 82, 15, "Selected Map:", false, gWindow );
gLabels[4] = guiCreateLabel ( 206, 145, 188, 22, "Buy Maps Shop by TwiX", false, gWindow );
gLabels[5] = guiCreateLabel ( 206,165,67,22, "Search Map:", false, gWindow );
gLabels[6] = guiCreateLabel ( 206,215,188,22, "Top 1: ", false, gWindow );
gLabels[7] = guiCreateLabel ( 206,235,188,22, "Top 2: ", false, gWindow );
gLabels[8] = guiCreateLabel ( 206,255,188,22, "Top 3: ", false, gWindow );
gUtils[1] = guiCreateLabel ( 206, 86, 188, 16, "Please select any map", false, gWindow );
gUtils[2] = guiCreateLabel ( 206, 106, 188, 16, "Played: N/A", false, gWindow );
gUtils[3] = guiCreateLabel ( 206, 125, 188, 16, "Rating: N/A", false, gWindow );
for _, label in ipairs ( gUtils ) do guiLabelSetColor ( label, 171, 205, 239 ); guiSetFont ( label, "default-bold-small" ); end
for _, label in ipairs ( gLabels ) do
guiSetFont ( label, "default-bold-small" );
if label == gLabels[3] then
guiLabelSetColor ( gLabels[3], 0, 255, 0 );
end
end
gButtons[1] = guiCreateButton ( 206, 366, 182, 35, "Buy as next map", false, gWindow );
gButtons[2] = guiCreateButton ( 206, 277, 68, 21, "[DM]", false, gWindow );
gButtons[3] = guiCreateButton ( 322, 277, 68, 21, "[DD]", false ,gWindow );
gButtons[4] = guiCreateButton ( 206, 301, 68, 21, "[FUN]", false, gWindow );
gButtons[5] = guiCreateButton ( 322, 301, 68, 21, "[TRIALS]", false, gWindow );
gButtons[6] = guiCreateButton ( 260, 335, 68, 21, "[ALL]", false, gWindow );
gGridList = guiCreateGridList ( 11, 32, 191, 395, false, gWindow );
guiGridListSetSelectionMode ( gGridList, 2 );
gColumn = guiGridListAddColumn ( gGridList, "Name:", 0.85 );
guiWindowSetSizable ( gWindow, false );
pEdit = guiCreateEdit ( 206, 185, 153, 26, "", false, gWindow );
guiSetVisible ( gWindow, false );
addEventHandler ( "onClientGUIClick", getResourceRootElement ( getThisResource ( ) ), somethingFromClick );
addCommandHandler("dshop",showPanel)
end
addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), createGui )
function showPanel ( )
if guiGetVisible ( gWindow ) then
guiSetVisible ( gWindow, false );
showCursor ( false );
removeEventHandler ( "onClientGUIChanged", pEdit, startSearchMap );
else
triggerServerEvent ( "doRefreshMapList", localPlayer, localPlayer );
addEventHandler ( "onClientGUIChanged", pEdit, startSearchMap );
guiSetVisible ( gWindow, true );
showCursor ( true );
local playerMoney = getPlayerMoney ( );
guiSetText ( gLabels[1], "Money: [ " .. playerMoney .. " ]" );
end
end
function somethingFromClick ( button, state )
local row = guiGridListGetSelectedItem ( gGridList );
if row == -1 then
guiSetText ( gUtils[1], "Error! Please Select any map" );
guiSetText ( gUtils[2], "Played: N/A" );
guiSetText ( gUtils[3], "Rating: N/A" );
guiSetText ( gLabels[6], "Top 1: N/A" );
guiSetText ( gLabels[7], "Top 2: N/A" );
guiSetText ( gLabels[8], "Top 3: N/A" );
end
if source == gButtons[1] then
local mName = guiGridListGetItemText ( gGridList, row, gColumn );
triggerServerEvent ( "doBuyMap", localPlayer, localPlayer, mName );
elseif source == gGridList then
local mapName = guiGridListGetItemText ( gGridList, row, gColumn );
guiSetText ( gUtils[1], mapName );
triggerServerEvent ( "doGetResultFormap", localPlayer, localPlayer, mapName );
elseif source == gButtons[2] then
filterForMaps ( 1 );
elseif source == gButtons[3] then
filterForMaps ( 2 );
elseif source == gButtons[4] then
filterForMaps ( 3 );
elseif source == gButtons[5] then
filterForMaps ( 4 );
elseif source == gButtons[6] then
filterForMaps ( 5 );
end
end
function setMapNameInGrid ( gamemodeMapTable, gamemode, map, s )
guiGridListClear ( gGridList );
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
if s then
if string.find ( string.lower ( map.name ), string.lower ( s ) ) then
local row = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, row, gColumn, map.name, false, false );
end
else
local row = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, row, gColumn, map.name, false, false );
end
end
end
end
end
end
addEvent ( "refreshCompleted", true )
addEventHandler ( "refreshCompleted", root, setMapNameInGrid )
function startSearchMap ( )
if not source == pEdit then return end
guiGridListClear ( gGridList );
if guiGetText ( pEdit ) ~= "" then
local found = 0;
for id, gamemode in pairs ( aGamemodeMapTable ) do
if ( gamemode.name == "Race" ) then
for id, map in ipairs ( gamemode.maps ) do
if string.find ( string.lower ( map.name ), string.lower ( guiGetText(pEdit):lower ( ) ), 0, true ) ~= nil then
local row = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, row, 1, map.name, false, false );
found = found + 1;
end
end
end
end
if found == 0 then
local row = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, row, 1, "Map not found", false, false );
guiGridListSetItemColor ( gGridList, row, 1, 255, 0, 0 );
end
else
for id, gamemode in pairs ( aGamemodeMapTable ) do
if ( gamemode.name == "Race" ) then
for id, map in ipairs ( gamemode.maps ) do
local row = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, row, 1, map.name, false, false );
end
end
end
end
end
function filterForMaps ( mode ) -- Bad function will loop all maps. I don't recommend, only if you want this
local mode = tonumber ( mode );
guiGridListClear ( gGridList );
for id, gamemode in pairs ( aGamemodeMapTable ) do
if ( gamemode.name == "Race" ) then
for id, map in ipairs ( gamemode.maps ) do
if mode == 1 then
if string.find ( map.name, "[DM]", 1, true ) then
local gRow = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, gRow, gColumn, map.name, false, false );
end
elseif mode == 2 then
if string.find ( map.name, "[DD]", 1, true ) then
local gRow = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, gRow, gColumn, map.name, false, false );
end
elseif mode == 3 then
if string.find ( map.name, "[FUN]", 1, true ) then
local gRow = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, gRow, gColumn, map.name, false, false );
end
elseif mode == 4 then
if string.find ( map.name, "[TRIALS]", 1, true ) then
local gRow = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, gRow, gColumn, map.name, false, false );
end
elseif mode == 5 then
local gRow = guiGridListAddRow ( gGridList );
guiGridListSetItemText ( gGridList, gRow, gColumn, map.name, false, false );
end
end
end
end
end
function guiSetMapText ( played, rating, count, name1, theTime1, name2, theTime2, name3, theTime3 )
if played == 1 then
p = "Played: First time";
else
p = "Played: ["..played.." times]";
end
guiSetText ( gUtils[2], p );
if count == 1 then prefix = ""; else prefix = "'s"; end
if rating then
text = "Rating: [" .. rating .. "/10] by ( " .. count .. " ) player" .. prefix;
else
text = "Not Rated Yet";
end
guiSetText ( gUtils[3], text );
if name1 and theTime1 then
guiSetText ( gLabels[6], "Top 1: " .. name1 .. " - " .. theTime1 );
else
guiSetText ( gLabels[6], "Top 1: N/A" );
end
if name2 and theTime2 then
guiSetText ( gLabels[7], "Top 2: " .. name2 .. " - " .. theTime2 );
else
guiSetText ( gLabels[7], "Top 2: N/A" );
end
if name3 and theTime3 then
guiSetText ( gLabels[8], "Top 3: " .. name3 .. " - " .. theTime3 );
else
guiSetText ( gLabels[8], "Top 3: N/A" );
end
end
addEvent ( "doUpdateLabels", true )
addEventHandler ( "doUpdateLabels", root, guiSetMapText )
fileDelete ( "tx_mapsShop_c.lua" );
Please Replace This Code On This File : tx_mapsShop_c.lua
and change the command @ line @ 43