Dimos7 Posted October 4, 2017 Share Posted October 4, 2017 (edited) 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(-2410.39, 2313.69, 4, "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 local carShopwindow = guiCreateWindow(left, top, windowW, windowH, "Carshop", false) guiWindowSetMovable(carShopwindow, false) guiWindowSetSizable(carShopwindow, false) local carGridList = guiCreateGridList(33, 29, 502, 333, false, carShopwindow) local columnName = guiGridListAddColumn(carGridList, "Name", 0.8) local 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 if getVehicleType(v[1]) ~= "Plane" or getVehicleType(v[1]) ~= "Helicopter" or getVehicleType(v[1]) ~= "Boat" then local row = guiGridListAddRow(carGridList) local name = getVehicleNameFromModel(v[1]) guiGridListSetItemText(carGridList, row, columnName, name, false, false) guiGridListSetItemData(carGridList, row, columnName, name) 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 if getVehicleType(v[1]) ~="Automobile" or getVehicleType(v[1]) ~="Bike" or getVehicleType(v[1])~= "Boat" then local row = guiGridListAddRow(carGridList) local name = getVehicleNameFromModel(v[1]) guiGridListSetItemText(carGridList, row, columnName, name, false, false) guiGridListSetItemData(carGridList, row, columnName, name) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) end elseif isElementWithinMarker(localPlayer, baysidecarShop) then if getVehicleType(v[1]) ~="Automobile" or getVehicleType(v[1]) ~="Bike" or getVehicleType(v[1]) ~= "Plane" or getVehicleType(v[1]) ~="Helicopter" then local row = guiGridListAddRow(carGridList) local name = getVehicleNameFromModel(v[1]) guiGridListSetItemText(carGridList, row, columnName, name, false, false) guiGridListSetItemData(carGridList, row, columnName, name) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) end end end local buy = guiCreateButton(43, 407, 96, 49, "Buy", false, carShopwindow) local preview = guiCreateButton(224, 407, 96, 49, "Preview", false, carShopwindow) local 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) function carshop_buyvehicle() 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 = tonumber(guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 2)) triggerServerEvent("buyCar", root, localPlayer, 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 ptimer = setTimer(function() local x, y, z = getElementPosition(localPlayer) local vehicle = createVehicle(modelID, x, y, z - 10) end, 5000, 1) if isTimer(ptimer) then destoryElement(vehicle) elseif source == cancel then guiSetVisible(carShopwindow,false) showCursor(false) end end addEventHandler("onClientGUIClick", root, carshop_buyvehicle) 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) the window show up put say the chat An error has been ocuiped please help me also appear they vehicle types i don't want to apear in that markers Edited October 4, 2017 by Dimos7 Link to comment
Moderators IIYAMA Posted October 4, 2017 Moderators Share Posted October 4, 2017 function createcarShopwindow() --... local carShopwindow = guiCreateWindow(left, top, windowW, windowH, "Carshop", false) --... return carShopwindow end local values can't just leave the function block. They are stuck in their scope. The return statement can return any values to the place where you called the function. local carShopwindow = createcarShopwindow() Calling the function createcarShopwindow and receiving returned values. Please follow this tutorial for a better understanding about local scopes. http://lua-users.org/wiki/ScopeTutorial Link to comment
Dimos7 Posted October 4, 2017 Author Share Posted October 4, 2017 (edited) on markers apear the vehicle type i don't want to apear but still there be Edited October 4, 2017 by Dimos7 Link to comment
Moderators IIYAMA Posted October 5, 2017 Moderators Share Posted October 5, 2017 Appear as what? Link to comment
Dimos7 Posted October 5, 2017 Author Share Posted October 5, 2017 apear the model i don't want it in that marker for exacle i made it so when a vehicle is plane dont add row but still have it Link to comment
Moderators IIYAMA Posted October 5, 2017 Moderators Share Posted October 5, 2017 if getVehicleType(v[1]) ~= "Plane" or getVehicleType(v[1]) ~= "Helicopter" or getVehicleType(v[1]) ~= "Boat" then if getVehicleType(v[1]) ~= "Plane" and getVehicleType(v[1]) ~= "Helicopter" and getVehicleType(v[1]) ~= "Boat" then For improved performance: (199% faster) local vehicleType = getVehicleType(v[1]) if vehicleType ~= "Plane" and vehicleType ~= "Helicopter" and vehicleType ~= "Boat" then And even faster: local notAcceptableVehicles = {Plane = true, Helicopter = true, Boat = true} -- function () -- ... local vehicleType = getVehicleType(v[1]) if not notAcceptableVehicles[vehicleType] then -- ... -- end Link to comment
Dimos7 Posted October 5, 2017 Author Share Posted October 5, 2017 (edited) 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(-2410.39, 2313.69, 4, "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, name) 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, name) 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, name) 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) triggerServerEvent("buyCar", root, tonumber(modelID), tonumber(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 x, y, z = getElementPosition(localPlayer) local vehicle = createVehicle(tonumber(modelID), x, y, z - 10) 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) ty mate for advice now i have another problem when try to create the Vehicle say it take nil not number Edited October 5, 2017 by Dimos7 Link to comment
Moderators IIYAMA Posted October 5, 2017 Moderators Share Posted October 5, 2017 First you have to figure out why it is a nil. Check if the data is correctly set to the correct element. Please debug also at the place where you set the data. But to make you do not receive that warning: modelID = tonumber(modelID) -- You already declared it as a local, so you don't have to re-do that. if modelID then --... create the vehicle here else iprint("modelID is a", modelID) end Link to comment
Dimos7 Posted October 6, 2017 Author Share Posted October 6, 2017 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(-2410.39, 2313.69, 4, "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, name) 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, name) 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, name) 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 modelID = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 1) price = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 2) triggerServerEvent("buyCar", root, tonumber(modelID), tonumber(price)) guiSetVisible(carShopwindow, false) showCursor(false) elseif source == preview then if guiGridListGetSelectedItem(carGridList) == -1 then outputChatBox("Select one vehicle!", 255, 0, 0) return end modelID=tonumber(modelID) if modelID then x, y, z = getElementPosition(localPlayer) vehicle = createVehicle(modelID, x, y, z - 10) else iprint("modelID is a",modelID) 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) it print the modelID is a and nothing else Link to comment
Moderators IIYAMA Posted October 6, 2017 Moderators Share Posted October 6, 2017 -- ... elseif source == preview then if guiGridListGetSelectedItem(carGridList) == -1 then outputChatBox("Select one vehicle!", 255, 0, 0) return end -- Retrieve data local modelID = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 1) local price = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 2) -- modelID = tonumber(modelID) if modelID then local x, y, z = getElementPosition(localPlayer) local vehicle = createVehicle(modelID, x, y, z - 10) local ptimer = setTimer(function(vehicle) if isElement(vehicle) then destroyElement(vehicle) end end, 45000, 1, vehicle) else iprint("modelID is a",modelID) end elseif source == cancel then -- ... You might want to receive the data at the right place. Link to comment
Moderators IIYAMA Posted October 6, 2017 Moderators Share Posted October 6, 2017 7 hours ago, Dimos7 said: still the same No it is not, we came one step closer to a fix, because it solved multiple issues. Did you debug the place of creation (of the data)? Please show me your debug skills. Link to comment
Dimos7 Posted October 7, 2017 Author Share Posted October 7, 2017 (edited) --client 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(-2410.39, 2313.69, 4, "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, name) 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, name) 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, name) 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) if modelID and price then triggerServerEvent("buyCar", root, modelID, price) guiSetVisible(carShopwindow, false) showCursor(false) else iprint("modelID is a", modelID, "price is a", price) end 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) if modelID then x, y, z = getElementPosition(localPlayer) vehicle = createVehicle(modelID, x, y, z - 10) else iprint("modelID is a",modelID) end local ptimer = setTimer(function(vehicle) if isElement(vehicle) then destroyElement(vehicle) end 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) --server function buyCar(modelID, price) if isElement(source) and source == client then local money = getPlayerMoney(source) if modelID and price then if money >= price then local x, y, z = getElementPosition(source) takePlayerMoney(source, price) createVehicle(x, y, z-10) else outputChatBox("You don't have enough money to buy this vehicle!", source, 255, 0, 0) end else iprint("modelID is a", modelID, "price is a", price) end end end addEvent("buyCar", true) addEventHandler("buyCar", root, buyCar) when try press button buy nothing happend only clsoe the window when pres preview say modelID is a nothing else Edited October 7, 2017 by Dimos7 Link to comment
Moderators IIYAMA Posted October 7, 2017 Moderators Share Posted October 7, 2017 At the place of creation > GUI, not when you click the button. Link to comment
Dimos7 Posted October 7, 2017 Author Share Posted October 7, 2017 (edited) hmm okay i will try to see but i think when create the gui and modelID is place in and didn't understand where exalcy to put it Edited October 7, 2017 by Dimos7 Link to comment
Dimos7 Posted October 7, 2017 Author Share Posted October 7, 2017 can you give me a example please Link to comment
Moderators IIYAMA Posted October 7, 2017 Moderators Share Posted October 7, 2017 No example required. You have to start making your code visible in order to understand it. Just fill up your entire code with debug lines. Run the code View in which order the lines show up. View the values of the variables. And you got your answer. Link to comment
Dimos7 Posted October 8, 2017 Author Share Posted October 8, 2017 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(-2410.39, 2313.69, 4, "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, name) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) iprint("modelID ia", guiGridListGetItemData(carGridList,guiGridListGetSelectedItem(carGridList), 1), "prices is a", guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 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, name) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) iprint("modelID ia", guiGridListGetItemData(carGridList,guiGridListGetSelectedItem(carGridList), 1), "prices is a", guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 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, name) guiGridListSetItemText(carGridList, row, columnPrice, v[2].." $", false, false) guiGridListSetItemData(carGridList, row, columnPrice, v[2]) iprint("modelID ia", guiGridListGetItemData(carGridList,guiGridListGetSelectedItem(carGridList), 1), "prices is a", guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 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) if modelID and price then triggerServerEvent("buyCar", root, modelID, price) guiSetVisible(carShopwindow, false) showCursor(false) else iprint("modelID is a", modelID, "price is a", price) end 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) if modelID then x, y, z = getElementPosition(localPlayer) vehicle = createVehicle(modelID, x, y, z - 10) else iprint("modelID is a",modelID) end local ptimer = setTimer(function(vehicle) if isElement(vehicle) then destroyElement(vehicle) end 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) when try to debug it like this say modelID is a after modelID is [DUP X40 and X80] 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