Jump to content

Search in by table


JluHeuKa

Recommended Posts

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)
Link to comment

I decided in this way, is it possible to somehow simplify and add a filter to prohibit repetitions?

    c=0
function sveh (id)
	for k,v in pairs(carTable)do
    random = math.random(1,#carTable)
    if k == random then
        c=c+1
        table.insert(carSP,v[1])
        if c <= #carTable then
            setTimer(function()
            createVehicle(v[1],v[3]+15,v[4],v[5],0,0,v[6]+180)
            end,5000,1)
        return 
        end    
end  
end
    end

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...