Dimos7 Posted October 11, 2017 Share Posted October 11, 2017 (edited) Hello guys i want ask a question for be sure before do it i want when i click a gui button i know that event name but i want make it so when someone click a button need wait some time i need getTickCount or setTimer for that? Edited October 11, 2017 by Dimos7 Link to comment
koragg Posted October 11, 2017 Share Posted October 11, 2017 You can use each of those things. For me setTimer is easier but getTickCount() can do the same job, sometimes even better. Link to comment
Dimos7 Posted October 11, 2017 Author Share Posted October 11, 2017 (edited) i tried make it like that local lscarShop = createMarker(552, -1266.90, 15.69, "cylinder", 3, 0, 70, 0, 255) local sfcarShop = createMarker(-1649, 1203.90, 6.3, "cylinder", 3, 0, 70, 0, 255) local lvcarShop = createMarker(2171.69, 1410.19, 10.19, "cylinder", 3, 0, 70, 0, 255) local lsapcarShop = createMarker(1924.5, -2242.30, 12.5, "cylinder", 3, 0, 70, 0, 255) local sfapcarShop = createMarker(-1350.19, -516.40, 13.19, "cylinder", 3, 0, 70, 0, 255) local lvapcarShop = createMarker(1292, 1359.69, 9.6, "cylinder", 3, 0, 70, 0 , 255) local baysidecarShop = createMarker(-2329, 2292.8, 3.5, "cylinder", 3, 0, 70, 0, 255) local vehiclePrices ={{445,100000}, {602,150000},{429,210000}, {536,200000}, {496,100000}, {402,2600000},{541,3000000}, {415,2500000},{589,100000}, {480, 1500000},{562, 2000000},{587,700000},{533, 700000}, {434, 500000}, {494, 2000000}, {503, 2000000}, {502, 2000000}, {579, 1200000}, {411, 2500000}, {559, 1500000}, {400, 2000000}, {500, 500000}, {603, 1000000}, {475, 400000}, {495, 700000}, {405, 1300000}, {535, 1000000}, {409, 1700000}, {560, 1500000},{506, 3000000}, {451, 3200000}, {558, 2000000}, {555, 1500000}, {477, 1000000}, {482, 1000000}, {581, 70000}, {521, 100000}, {463, 80000},{522, 200000}, {461, 100000}, {468, 80000},{592, 5000000}, {577, 4000000}, {511, 500000}, {512, 500000}, {593, 300000}, {553, 3000000}, {476, 3500000}, {519, 2000000}, {460, 1500000}, {513, 2000000}, {417, 800000},{487, 1500000},{469, 800000},{473, 200000}, {493, 500000}, {452, 700000}, {454, 200000}} function createcarShopwindow() local screenW, screenH = guiGetScreenSize() local windowW, windowH = 714, 556 local left, top = (screenW-windowW)/2, (screenH-windowH)/2 carShopwindow = guiCreateWindow(left, top, windowW, windowH, "Carshop", false) guiWindowSetMovable(carShopwindow, false) guiWindowSetSizable(carShopwindow, false) carGridList = guiCreateGridList(33, 29, 502, 333, false, carShopwindow) columnName = guiGridListAddColumn(carGridList, "Name", 0.8) columnPrice = guiGridListAddColumn(carGridList, "Price", 0.8) for i , v in ipairs (vehiclePrices) do if isElementWithinMarker(localPlayer, lscarShop) or isElementWithinMarker(localPlayer, sfcarShop) or isElementWithinMarker(localPlayer, lvcarShop) then local notAcceptableVehicles = {Plane = true, Helicopter = true, Boat = true} local vehicleType = getVehicleType(v[1]) if not notAcceptableVehicles[vehicleType] then local row = guiGridListAddRow(carGridList) local name = getVehicleNameFromModel(v[1]) guiGridListSetItemText(carGridList, row, columnName, name, false, false) guiGridListSetItemData(carGridList, row, columnName, v[1]) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) end elseif isElementWithinMarker(localPlayer, lsapcarShop) or isElementWithinMarker(localPlayer, sfapcarShop) or isElementWithinMarker(localPlayer, lvapcarShop) then local notAcceptableVehicles = {Automobile = true, Bike = true, Boat = true} local vehicleType = getVehicleType(v[1]) if not notAcceptableVehicles[vehicleType] then local row = guiGridListAddRow(carGridList) local name = getVehicleNameFromModel(v[1]) guiGridListSetItemText(carGridList, row, columnName, name, false, false) guiGridListSetItemData(carGridList, row, columnName, v[1]) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) end elseif isElementWithinMarker(localPlayer, baysidecarShop) then local notAcceptableVehicles = {Plane = true, Helicopter = true, Automobile = true, Bike= true} local vehicleType = getVehicleType(v[1]) if not notAcceptableVehicles[vehicleType] then local row = guiGridListAddRow(carGridList) local name = getVehicleNameFromModel(v[1]) guiGridListSetItemText(carGridList, row, columnName, name, false, false) guiGridListSetItemData(carGridList, row, columnName, v[1]) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) end end end buy = guiCreateButton(43, 407, 96, 49, "Buy", false, carShopwindow) preview = guiCreateButton(224, 407, 96, 49, "Preview", false, carShopwindow) cancel = guiCreateButton(373, 407, 96, 49, "Cancel", false, carShopwindow) end function showcarShopWindow() createcarShopwindow() if carShopwindow ~= nil then guiSetVisible(carShopwindow, true) else outputChatBox("An error has been ocupited!", 255, 0 , 0) end showCursor(true) end addEventHandler("onClientMarkerHit", root, showcarShopWindow) addEventHandler("onClientGUIClick", root, function() if not carShopwindow or not guiGetVisible(carShopwindow) then return end if source == buy then if guiGridListGetSelectedItem(carGridList) == -1 then outputChatBox("Select one vehicle!", 255, 0, 0) return end local modelID = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 1) local price = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 2) local modelID = tonumber(modelID) local price = tonumber(price) triggerServerEvent("buyCar", root, modelID, price) guiSetVisible(carShopwindow, false) showCursor(false) elseif source == preview then if guiGridListGetSelectedItem(carGridList) == -1 then outputChatBox("Select one vehicle!", 255, 0, 0) return end local modelID = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 1) local modelID = tonumber(modelID) x, y, z = getElementPosition(localPlayer) vehicle = createVehicle(modelID, x+10, y, z - 10) if not getTickCount() < 45000 then outputChatBox("You need wait 45 seconds to see another vehicle!", 255, 0, 0) end local ptimer = setTimer(function() destroyElement(vehicle) end, 45000, 1) elseif source == cancel then guiSetVisible(carShopwindow,false) showCursor(false) end end ) function resourceStart() createBlipAttachedTo(lsapcarShop, 55, 2) createBlipAttachedTo(sfapcarShop, 55, 2) createBlipAttachedTo(lvapcarShop, 55, 2) createBlipAttachedTo(lscarShop, 55, 2) createBlipAttachedTo(sfcarShop, 55, 2) createBlipAttachedTo(lvcarShop, 55, 2) createBlipAttachedTo(baysidecarShop, 55, 2) end addEventHandler("onClientResourceStart", resourceRoot, resourceStart) that i want is when a player click preview button for 45 seocnds he can't press it again and apear a message say that you need wait seconds for see another vehicle but a get error i try compare bollen with a number Edited October 11, 2017 by Dimos7 Link to comment
koragg Posted October 11, 2017 Share Posted October 11, 2017 Sorry, can you tell at which line you get that boolean error, please? Link to comment
koragg Posted October 11, 2017 Share Posted October 11, 2017 10 minutes ago, Dimos7 said: 92 Oh, you can't use it like that. Read what the wiki says: https://wiki.multitheftauto.com/wiki/GetTickCount This function returns amount of time that your system has been running in milliseconds. So you can't compare it like that as it will always be a lot higher than 45000. You can compare two variables which you've assigned to getTickCount(). For example: 1. You make "local startTime = getTickCount()" when the resource starts. 2. You make "local currentTime = getTickCount()" when some condition is met (not when the resource starts) 3. Now you can check it like this somewhere else in your code: "if currentTime - startTime < 60000 then". Link to comment
Dimos7 Posted October 12, 2017 Author Share Posted October 12, 2017 the thing is i want to make it so when press the button to have wait for 45 seconds how to do that Link to comment
kieran Posted October 12, 2017 Share Posted October 12, 2017 What you might want to consider is setting players data with setElementData and then using a timer to remove there data after 45 seconds, just create an event that sets the data to false, this means the data would be removed, when the player clicks the button, get there element data, if there element data is true, then output a message, otherwise spawn a vehicle or whatever you are doing and then set there element data to true. I would suggest not using a timer as you'd be setting it outside of your function, unfortunately I have no idea how to declare a timer as a global variable to use it across functions, but you could set it, then check if it exists AFTER near the top of your button click event... I would personally use the first approach, set their data, set a timer to remove their data, then check their data (NOT THE TIMER) and if it's that data do nothing, else do something, then when timer hits 0, it would go to an event to remove there data, simple! Link to comment
Rockyz Posted October 12, 2017 Share Posted October 12, 2017 Well, i'm not sure what are you trying to do, but that's an example : playerTick, Seconds = { }, 3; addCommandHandler ( 'allowed', function ( plr, cmd ) if ( playerTick [ plr ] and playerTick [ plr ] + ( Seconds * 1000 ) > getTickCount ( ) ) then outputChatBox ( 'Please Wait', plr, 255, 0, 0, true ) else outputChatBox ( 'Every Thing is Okay', plr, 0, 255, 0, true ) playerTick [ plr ] = getTickCount ( ) end end ); 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