ThePatrik2020 Posted January 30, 2021 Share Posted January 30, 2021 (edited) The problem is that when someone starts the ATM robbery, the gui panel also appears in front of the other players. Can you help with this so that only the person who started the robbery appears? Im beginner of lua, its community script. And sorry my bad english. Client Side: local atm = {} local ATMs = { [1]={-948.37256, -335.29105, 15.55257, 0}, [2]={-940.25818, -335.28986, 15.55257, 0}, [3]={-954.92432, -328.78165, 15.55257, 0}, [4]={-947.11816, -328.76165, 15.55257, 0} } GUIEditor = { button = {}, window = {}, label = {} } GUIEditor.window[1] = guiCreateWindow(550, 287, 261, 194, "Bank Robbery", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetAlpha(GUIEditor.window[1], 1.00) guiSetVisible(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(15, 42, 117, 15, "Bank Hacking Range:", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-bold-small") GUIEditor.label[2] = guiCreateLabel(142, 42, 85, 15, "pass: 1 to 2000", false, GUIEditor.window[1]) guiLabelSetColor(GUIEditor.label[2], 230, 198, 24) GUIEditor.label[3] = guiCreateLabel(15, 72, 81, 15, "Wanted Level:", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[3], "default-bold-small") GUIEditor.label[4] = guiCreateLabel(106, 72, 85, 15, "2 stars", false, GUIEditor.window[1]) guiLabelSetColor(GUIEditor.label[4], 254, 0, 0) GUIEditor.label[5] = guiCreateLabel(15, 102, 58, 15, "Reward $:", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[5], "default-bold-small") GUIEditor.label[6] = guiCreateLabel(83, 102, 85, 15, "500,000", false, GUIEditor.window[1]) guiLabelSetColor(GUIEditor.label[6], 24, 235, 18) GUIEditor.button[1] = guiCreateButton(15, 143, 108, 35, "Hack", false, GUIEditor.window[1]) GUIEditor.button[2] = guiCreateButton(133, 143, 108, 35, "Close", false, GUIEditor.window[1]) ATM = { button = {}, window = {}, label = {}, memo = {} } ATM.window[1] = guiCreateWindow(531, 227, 298, 314, "Bank Robbery", false) guiWindowSetSizable(ATM.window[1], false) guiSetVisible(ATM.window[1], false) ATM.memo[1] = guiCreateEdit(10, 31, 221, 53, "", false, ATM.window[1]) guiEditSetReadOnly(ATM.memo[1], true) guiEditSetMaxLength ( ATM.memo[1], 7 ) ATM.label[1] = guiCreateLabel(241, 51, 41, 15, "", false, ATM.window[1]) guiSetFont(ATM.label[1], "default-bold-small") guiLabelSetColor(ATM.label[1], 255, 0, 0) ATM.label[2] = guiCreateLabel(0, 84, 284, 20, "__________________________________________________", false, ATM.window[1]) ATM.button[1] = guiCreateButton(10, 114, 44, 39, "1", false, ATM.window[1]) guiSetFont(ATM.button[1], "default-bold-small") ATM.button[2] = guiCreateButton(64, 114, 44, 39, "2", false, ATM.window[1]) guiSetFont(ATM.button[2], "default-bold-small") ATM.button[3] = guiCreateButton(118, 114, 44, 39, "3", false, ATM.window[1]) guiSetFont(ATM.button[3], "default-bold-small") ATM.button[4] = guiCreateButton(10, 163, 44, 39, "4", false, ATM.window[1]) guiSetFont(ATM.button[4], "default-bold-small") ATM.button[5] = guiCreateButton(64, 163, 44, 39, "5", false, ATM.window[1]) guiSetFont(ATM.button[5], "default-bold-small") ATM.button[6] = guiCreateButton(118, 163, 44, 39, "6", false, ATM.window[1]) guiSetFont(ATM.button[6], "default-bold-small") ATM.button[7] = guiCreateButton(10, 212, 44, 39, "7", false, ATM.window[1]) guiSetFont(ATM.button[7], "default-bold-small") ATM.button[8] = guiCreateButton(64, 212, 44, 39, "8", false, ATM.window[1]) guiSetFont(ATM.button[8], "default-bold-small") ATM.button[9] = guiCreateButton(118, 212, 44, 39, "9", false, ATM.window[1]) guiSetFont(ATM.button[9], "default-bold-small") ATM.button[10] = guiCreateButton(118, 261, 44, 39, "0", false, ATM.window[1]) guiSetFont(ATM.button[10], "default-bold-small") ATM.button[11] = guiCreateButton(10, 263, 98, 37, "Sumbit", false, ATM.window[1]) guiSetFont(ATM.button[11], "default-bold-small") ATM.button[12] = guiCreateButton(176, 116, 98, 37, "Clear All", false, ATM.window[1]) guiSetFont(ATM.button[12], "default-bold-small") ATM.button[13] = guiCreateButton(176, 163, 98, 37, "Give Up", false, ATM.window[1]) guiSetFont(ATM.button[13], "default-bold-small") for k,v in ipairs (ATMs) do local marker = createMarker(v[1], v[2], v[3], "cylinder", 2, 255, 255,255,0) atm[marker] = k --local obj = createObject(2942, v[1], v[2], v[3], 0, 0, v[4]) -- exports.customblips:createCustomBlip ( v[1], v[2], 10, 10, "atm.png", 300 ) end function MKH_OPEN () if not atm[source] then return false end if guiGetVisible(GUIEditor.window[1]) == true then guiSetVisible(GUIEditor.window[1], false) showCursor(false) else guiSetVisible(GUIEditor.window[1], true) showCursor(true) end end addEventHandler("onClientMarkerHit", root, MKH_OPEN) function MKH_CLOSE () if (source == GUIEditor.button[2]) then guiSetVisible(GUIEditor.window[1], false) showCursor(false) end end addEventHandler("onClientGUIClick", root, MKH_CLOSE) function MKH_OPENHACK () if (source == GUIEditor.button[1]) then guiSetVisible(GUIEditor.window[1], false) guiSetVisible(ATM.window[1], true) end end addEventHandler("onClientGUIClick", root, MKH_OPENHACK) function MKH_CLOSEHACK () if (source == ATM.button[13]) then guiSetVisible(ATM.window[1], false) showCursor(false) end end addEventHandler("onClientGUIClick", root, MKH_CLOSEHACK) function MKH_SETNUMBERS () local text = guiGetText(ATM.memo[1]) if (source == ATM.button[1]) then guiSetText(ATM.memo[1], text.."1") elseif (source == ATM.button[2]) then guiSetText(ATM.memo[1], text.."2") elseif (source == ATM.button[3]) then guiSetText(ATM.memo[1], text.."3") elseif (source == ATM.button[4]) then guiSetText(ATM.memo[1], text.."4") elseif (source == ATM.button[5]) then guiSetText(ATM.memo[1], text.."5") elseif (source == ATM.button[6]) then guiSetText(ATM.memo[1], text.."6") elseif (source == ATM.button[7]) then guiSetText(ATM.memo[1], text.."7") elseif (source == ATM.button[8]) then guiSetText(ATM.memo[1], text.."8") elseif (source == ATM.button[9]) then guiSetText(ATM.memo[1], text.."9") elseif (source == ATM.button[10]) then guiSetText(ATM.memo[1], text.."0") elseif (source == ATM.button[12]) then guiSetText(ATM.memo[1], "") end end addEventHandler("onClientGUIClick", root, MKH_SETNUMBERS) function MKH_SUMBIT () if (source == ATM.button[11]) then local text = guiGetText(ATM.memo[1]) triggerServerEvent ( "MKH:ATM_sumbit", localPlayer, localPlayer, text) end end addEventHandler("onClientGUIClick", root, MKH_SUMBIT) function MKH_LOWER ( message ) guiSetText(ATM.label[1], "LOWER") guiSetText(ATM.memo[1], "") end addEvent( "MKH:LOWER", true ) addEventHandler( "MKH:LOWER", localPlayer, MKH_LOWER ) function MKH_HIGHER ( message ) guiSetText(ATM.label[1], "HIGHER") guiSetText(ATM.memo[1], "") end addEvent( "MKH:HIGHER", true ) addEventHandler( "MKH:HIGHER", localPlayer, MKH_HIGHER ) function MKH_WON ( message ) guiSetText(ATM.label[1], "WON !") guiSetText(ATM.memo[1], "") guiSetVisible(ATM.window[1], false) showCursor(false) end addEvent( "MKH:WON", true ) addEventHandler( "MKH:WON", localPlayer, MKH_WON ) Server Side: function onResourceStart () local randomNumber = math.random(1000, 1999) executeSQLQuery("DROP TABLE ATMRobbery" ) executeSQLQuery("CREATE TABLE IF NOT EXISTS ATMRobbery (ATM TEXT, theNumber INT)") executeSQLQuery( "INSERT INTO ATMRobbery(ATM, theNumber) VALUES(?,?)", "ATMs", randomNumber) outputDebugString ("Bankrablás: SQL Tábla létrehozva!") outputDebugString ("Bankrablás: Ez a generált szám: "..randomNumber) outputChatBox("#f195ac[Bank-Robbery]#ffffff Bank Robbery is now available, try to hack it", root, 255, 255, 255, true) ATM_ROBBERY = true end addEventHandler("onResourceStart", resourceRoot, onResourceStart) function MKH_onsumbit (player, text) if ATM_ROBBERY == false then return outputChatBox("#f195ac[Bank-Robbery]#ffffff is not available now. Come see next time.", player, 255, 255, 255, true) end local query = executeSQLQuery("SELECT * FROM ATMRobbery") for k,v in ipairs(query) do if tonumber(text) < tonumber(v["theNumber"]) then result = "LOWER" triggerClientEvent ( player, "MKH:LOWER", player, result ) elseif tonumber(text) > tonumber(v["theNumber"]) then result = "HIGHER" triggerClientEvent ( player, "MKH:HIGHER", player, result ) elseif tonumber(text) == tonumber(v["theNumber"]) then result = "WON" outputChatBox("#f195ac[Bank-Robbery] #b28bc0"..getPlayerName(player).."#ffffff has hacked the Bank Safe, the number was "..text, root, 255, 255, 255, true) outputChatBox("#f195ac[Bank-Robbery] #ffffffYou got #bb9b65$500,000 #ffffff and #b0bb652 stars", player, 255, 255, 255, true) setPlayerMoney(player, getPlayerMoney(player) + 500000) setPlayerHudComponentVisible ( source, "wanted", true ) setPlayerWantedLevel(player, 2) setElementModel(player, 13) setPedArmor(player, 0) triggerClientEvent ( player, "MKH:WON", player, result ) executeSQLQuery("DROP TABLE ATMRobbery" ) ATM_ROBBERY = false setTimer ( onResourceStart, 1800000 , 1) end end end addEvent( "MKH:ATM_sumbit", true ) addEventHandler( "MKH:ATM_sumbit", getRootElement(), MKH_onsumbit ) Edited January 30, 2021 by Patlik Bad edited post. Link to comment
Discord Moderators Zango Posted February 1, 2021 Discord Moderators Share Posted February 1, 2021 addEventHandler("onClientMarkerHit", root, MKH_OPEN) If you bind this event handler to the local player instead addEventHandler("onClientMarkerHit", localPlayer, MKH_OPEN) The GUI should only open when you hit the marker. 1 Link to comment
Moderators Citizen Posted February 1, 2021 Moderators Share Posted February 1, 2021 @Zango Nope, it will just stop working now (will never open) because the source of onClientMarkerHit is the marker which got hit, not the element hitting the marker. @Patlik You have to check if the hitPlayer (provided as 1st parameter of the handler function) is equal to the localPlayer element (and checking matchingDimenssion is a best practice too): function MKH_OPEN (element, matchingDimension) if element ~= localPlayer or not matchingDimension then return end if not atm[source] then return end if guiGetVisible(GUIEditor.window[1]) then -- I've also removed `== true` there as it is redundant guiSetVisible(GUIEditor.window[1], false) showCursor(false) else guiSetVisible(GUIEditor.window[1], true) showCursor(true) end end addEventHandler("onClientMarkerHit", root, MKH_OPEN) 1 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