Search the Community
Showing results for tags 'pairs'.
-
how to create any one vehicle that is listed in the table, with a delay per minute and a filter for re-creating the transport and the maximum number (car dealership)? server carTable = { -- id price x y z rz {475,5000,-2149,-775.5,32,-90}, {411,5000,-2149,-769.5,32,-90}, {416,5000,-2149,-763.5,32,-90}, {466,5000,-2149,-757.5,32,-90}, } icon = { {1239,3,-2137,-746,32} } function sveh (id) for k,v in pairs(carTable)do createVehicle(v[1],v[3],v[4],v[5],0,0,v[6]) end end addEventHandler('onResourceStart',resourceRoot,sveh) function pick () for k,v in pairs(icon) do local sicon = createPickup(v[3],v[4],v[5],v[2],v[1],0) end end addEventHandler('onResourceStart',resourceRoot,pick) addEventHandler('onPickupHit',resourceRoot, function(e) if isElement(e)then triggerClientEvent('visibleSalonWindow',e,e) end end) client carTable = { {475,5000,-2149,-775.5,32,-90}, {411,5000,-2149,-769.5,32,-90}, {416,5000,-2149,-763.5,32,-90}, {466,5000,-2149,-757.5,32,-90},} function drawTextOnPosition(x,y,z,price,id,number) if (getDistanceBetweenPoints3D(x,y,z,getElementPosition(localPlayer))) < 5 then local coords = {getScreenFromWorldPosition(x,y,z)} if coords[1] and coords[2] then dxDrawText("Транспорт продается",coords[1],coords[2],coords[1],coords[2], tocolor(0,0,0), 1.01, "default-bold", 'center', 'center') dxDrawText("Транспорт продается",coords[1],coords[2],coords[1],coords[2], tocolor(156,98,40), 1, "default-bold", 'center', 'center') dxDrawText("Модель: "..getVehicleNameFromModel( id )..'('..id..')',coords[1],coords[2]+20,coords[1],coords[2]+20, tocolor(0,0,0), 1.01, "default-bold", 'center', 'center') dxDrawText("Модель: "..getVehicleNameFromModel( id )..'('..id..')',coords[1],coords[2]+20,coords[1],coords[2]+20, tocolor(176,180,176), 1, "default-bold", 'center', 'center') dxDrawText("Стоимость "..price..'$.',coords[1],coords[2]+40,coords[1],coords[2]+40, tocolor(0,0,0), 1.01, "default-bold", 'center', 'center') dxDrawText("Стоимость "..price..'$.',coords[1],coords[2]+40,coords[1],coords[2]+40, tocolor(176,180,176), 1, "default-bold", 'center', 'center') end end end addEventHandler('onClientRender',root,function() for k,v in pairs(carTable) do drawTextOnPosition(v[3],v[4],v[5]+1,v[2],v[1]) end end) GUIEditor = { button = {}, window = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(0.36, 0.18, 0.27, 0.64, "Атосалон Эконом-класса", true) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.button[1] = guiCreateButton(0.39, 0.93, 0.22, 0.05, "Закрыть", true, GUIEditor.window[1]) guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") GUIEditor.label[1] = guiCreateLabel(0.05, 0.03, 0.92, 0.03, "В данном автосалоне вы сможете купить ато Эконом класса :", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-bold-small") guiLabelSetHorizontalAlign(GUIEditor.label[1], "center", false) guiLabelSetVerticalAlign(GUIEditor.label[1], "center") GUIEditor.label[2] = guiCreateLabel(0.05, 0.10, 0.92, 0.14, "Infernus, Sabre, Glendale, Sabre Turbo", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[2], "default-bold-small") GUIEditor.label[3] = guiCreateLabel(0.05, 0.61, 0.92, 0.03, "Авто добовляется из-за рубежа каждые 2 часа", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[3], "default-bold-small") GUIEditor.label[4] = guiCreateLabel(0.05, 0.76, 0.92, 0.03, "На данный момент ожидаем поставку ", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[4], "default-bold-small") GUIEditor.label[5] = guiCreateLabel(0.05, 0.79, 0.92, 0.03, "До прибытя осталось: \"\"", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[5], "default-bold-small") GUIEditor.label[6] = guiCreateLabel(0.05, 0.83, 0.92, 0.03, "Стоимость: $\"\"", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[6], "default-bold-small") guiSetVisible(GUIEditor.window[1],false) end ) bindKey( "x", "down", function( ) local state = not guiGetVisible(GUIEditor.window[1] ) guiSetVisible(GUIEditor.window[1], state ) showCursor( state ) end ) function visible () if guiGetVisible(GUIEditor.window[1]) then guiSetVisible(GUIEditor.window[1],false) showCursor(false) else guiSetVisible(GUIEditor.window[1],true) showCursor(true) end end addEvent('visibleSalonWindow',true) addEventHandler('visibleSalonWindow',localPlayer,visible) addEventHandler('onClientGUIClick',resourceRoot,function(button,state) if button == "left" and state == "up" then if source == GUIEditor.button[1] then guiSetVisible(GUIEditor.window[1],false) showCursor(false) end end end)
-
I have this: -- 2 points on each city. local spawnCoords = { {1125, -2036, 69.89, -90}, {2504, -1686, 13.55, 45}, {-1972, 643, 46.57, -45}, {-2720, -317, 7.85, 45}, {2023, 1008, 10.83, -90}, {1298, 2084, 12.83, -90}, } -- all skins. local validSkins = {0, 1, 2, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312} function spawnPoints (player) local x,y,z,r = unpack(spawnCoords[math.random(1,#spawnCoords)]) spawnPlayer(source, x, y, z, r, validSkins[math.random(1,#validSkins)]) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerJoin", getRootElement(), spawnPoints) Althought it works, after giving it several tests, I realized the spawn locations where always in the same order, as well as the skins. Coincidentally, I've reached the tables subject in the MTA's tutorial, and I learned about <for key, value in pairs(table) do>. Contrary to "ipairs", "pairs" is supposed to give you a random reading throughout the table everytime the script is ran. I used 'broph.Lua' as a way to understand the process, and to make sure that if I do the same, it'll work. My small knowledge told me that, by adding <for key, value in pairs(spawnCoords) do> right after the beginning of the function, I would get the random effect of the table reading. However, the result is far from what I expected: it destroys the function, and the player doesn't spawn at all (black screen). I'm continuing the tutorial, but 'in pairs' is the last thing NanoBob mentions about the tables. This time, I'd like a bit of a challenge, so if you could give me the hints and point me in the right direction, I would appreciate that.