Memory Posted October 7, 2012 Share Posted October 7, 2012 Hi, Can you are help me with maps shop for race? With what to begin first? Link to comment
Callum Posted October 7, 2012 Share Posted October 7, 2012 First make the GUI, ensure it all works correctly, and then make the GUI usable by linking it to a command, event, or whatever. Link to comment
Memory Posted October 7, 2012 Author Share Posted October 7, 2012 Worked outputChatBox("Maps Shop Loaded",255,255,0) GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Label = {} GUIEditor_Edit = {} GUIEditor_Grid = {} GUIEditor_Image = {} GUIEditor_Window[1] = guiCreateWindow(701,328,584,394,"Map Shop",false) GUIEditor_Image[1] = guiCreateStaticImage(11,19,564,366,"back.png",false,GUIEditor_Window[1]) GUIEditor_Label[1] = guiCreateLabel(273,13,289,21,"Money:",false,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[1],0,0,0) guiSetFont(GUIEditor_Label[1],"default-bold-small") GUIEditor_Label[2] = guiCreateLabel(270,75,284,70,"A Map Costs 5000$",false,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[2],0,0,0) guiSetFont(GUIEditor_Label[2],"default-bold-small") GUIEditor_Button[1] = guiCreateButton(280,264,265,91,"Buy Map [ -5000 ]",false,GUIEditor_Image[1]) GUIEditor_Label[3] = guiCreateLabel(272,36,252,19,"Map Status:",false,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[3],0,0,0) guiSetFont(GUIEditor_Label[3],"default-bold-small") GUIEditor_Edit[1] = guiCreateEdit(286,211,252,45,"Map",false,GUIEditor_Image[1]) GUIEditor_Label[4] = guiCreateLabel(293,170,233,37,"Selected Map:",false,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[4],0,255,0) guiLabelSetVerticalAlign(GUIEditor_Label[4],"center") guiLabelSetHorizontalAlign(GUIEditor_Label[4],"center",false) guiSetFont(GUIEditor_Label[4],"default-bold-small") mapGridList = guiCreateGridList(3,5,254,357,false,GUIEditor_Image[1]) guiGridListSetSelectionMode(mapGridList,2) mapsColumn = guiGridListAddColumn(mapGridList,"Maps",0.85) guiGridListSetSelectionMode(mapGridList,2) guiSetVisible (GUIEditor_Window[1], false) guiSetVisible (GUIEditor_Image[1], false) function onresourceStart () bindKey ("F1", "down", showPanel) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onresourceStart) function showPanel () getVisible = guiGetVisible (GUIEditor_Window[1]) playerName = getPlayerName ( getLocalPlayer() ) if (getVisible == true) then guiSetVisible (GUIEditor_Window[1], false) guiSetVisible (GUIEditor_Image[1], false) showCursor (false) end if (getVisible == false) then triggerServerEvent ( "dannyevent", getRootElement()) guiSetVisible (GUIEditor_Window[1], true) guiSetVisible (GUIEditor_Image[1], true) showCursor (true) local playerMoney = getPlayerMoney(source) guiSetText ( GUIEditor_Label[1], "Money: [ " .. playerMoney .. " ]" ) end end Link to comment
TwiX! Posted October 10, 2012 Share Posted October 10, 2012 (edited) Client --Some vars --Author TwiX [[Don't Remove This Line]] local sW,sH = guiGetScreenSize(); local gUtils = {}; gUtils.guiW,gUtils.guiH = 398,341; gUtils.posX,gUtils.posY = sW/2-gUtils.guiW/2,sH/2-gUtils.guiH/2; --Center of screen for all resolutions local gLabels = {}; function onresourceStart() gWindow = guiCreateWindow(gUtils.posX,gUtils.posY,gUtils.guiW,gUtils.guiH,"Map Shop",false); gLabels[1] = guiCreateLabel(206,30,161,19,"Money:",false,gWindow); gLabels[2] = guiCreateLabel(206,49,100,16,"A Map Costs 5000$",false,gWindow); gLabels[3] = guiCreateLabel(206,66,82,15,"Selected Map:",false,gWindow); gLabels[4] = guiCreateLabel(206,106,188,22,"Buy Maps Shop by TwiX",false,gWindow); gUtils[1] = guiCreateLabel(206,86,188,22,"Please select any map",false,gWindow); guiLabelSetColor(gUtils[1],171,205,239) for _,label in ipairs (gLabels) do guiSetFont(label,"default-bold-small"); if label == gLabels[3] then guiLabelSetColor(gLabels[3],0,255,0); end end gButton = guiCreateButton(207,291,182,35,"Buy as next map",false,gWindow); gGridList = guiCreateGridList(11,32,191,395,false,gWindow); guiGridListSetSelectionMode(gGridList,2); gColumn = guiGridListAddColumn(gGridList,"Name:",0.85); guiSetVisible (gWindow,false); addEventHandler ("onClientGUIClick",getResourceRootElement(getThisResource()),somethingFromClick); bindKey ("F1","down",showPanel); end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),onresourceStart) function showPanel() if guiGetVisible(gWindow) then guiSetVisible(gWindow,false); showCursor(false); else triggerServerEvent ("doRefreshMapList",localPlayer,localPlayer); guiSetVisible (gWindow,true); showCursor(true); local playerMoney = getPlayerMoney(); guiSetText(gLabels[1],"Money: [ "..playerMoney.." ]"); end end function somethingFromClick(button,state) if source == gButton then local row = guiGridListGetSelectedItem(gGridList); local mapName = guiGridListGetItemText(gGridList,row,gColumn); triggerServerEvent("doBuyMap",localPlayer,localPlayer,mapName); elseif source == gGridList then local selectedMap = guiGridListGetSelectedItem(gGridList); local row = guiGridListGetSelectedItem(gGridList); local mapName = guiGridListGetItemText(gGridList,row,gColumn); if selectedMap == -1 then guiSetText(gUtils[1],"Error! Please Select any map"); return end guiSetText(gUtils[1],mapName); 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); guiGridListSetItemData (gGridList,row,gColumn,map.resname); end else local row = guiGridListAddRow (gGridList); guiGridListSetItemText (gGridList,row,gColumn,map.name,false,false); guiGridListSetItemData (gGridList,row,gColumn,map.resname); end end end end end end addEvent("refreshCompleted",true) addEventHandler( "refreshCompleted",getRootElement(),setMapNameInGrid) --fileDelete ('YOUR SCRIPT NAME HERE.lua') Server --Vars local price = 5000; function rStart() pHasBought = false; end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),rStart) function buyNextMap(player,mapName) if not player or not mapName then return end if (isGuestAccount(getPlayerAccount(player)) == false) then if pHasBought == false then local money = tonumber(getPlayerMoney(player)); if money >= price then executeCommandHandler("bm",player,mapName); --This function need admin rights pHasBought = true else outputChatBox("* You #abcdefdon't #ffffffhave enough #abcdefmoney #ffffffto buy the map!",player,255,255,255,true); end else outputChatBox("* A #abcdefmap #ffffffis already bought at the moment! Please #abcdeftry #ffffffagain later",player,255,255,255,true); end else outputChatBox("* You should be #abcdeflogged in to buy the map!",player,255,255,255,true); end end addEvent("doBuyMap",true) addEventHandler("doBuyMap",getRootElement(),buyNextMap) addEvent("onMapStarting") addEventHandler("onMapStarting",getRootElement(), function(mapInfo,mapOptions,gameOptions) pHasBought = false end ) --Functions by Admin Panel (lil_Toady) function getAllMaps(loadList,s) 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"; triggerClientEvent("refreshCompleted",loadList,tableOut,gamemode,map,s); end addEvent("doRefreshMapList",true) addEventHandler( "doRefreshMapList",getRootElement(),getAllMaps) 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 Add in racevoting_server.lua code: addCommandHandler('bm', function(player,command,...) local query = #{...} > 0 and table.concat({...},' ') or nil if not query then if g_ForcedNextMap then outputDebugString('Next map is '..getMapName(g_ForcedNextMap )); else outputDebugString('Next map is not set'); end return end local map,errormsg = findMap(query); if not map then outputRace( errormsg,player); return end if (isGuestAccount(getPlayerAccount(player)) == false) then g_ForcedNextMap = map; outputChatBox('* '..getPlayerName(player)..' #ffffffhas bought as next map - #ABCDEF'..getMapName(g_ForcedNextMap),g_Root,0,240,0,true); takePlayerMoney(player,5000); else outputChatBox("* Please #abcdefLogin #ffffffor #abcdefRegister!",player,255,255,255,true); end end ) You can find it there: /resources/[gamemodes]/[race]/race Don't forget add admin rights for this resource or https://community.multitheftauto.com/ind ... ls&id=5801 Edited October 10, 2012 by Guest Link to comment
TwiX! Posted October 10, 2012 Share Posted October 10, 2012 Big thank you you are welcome Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now