Jump to content

The name and price in the showroom.


dima3367

Recommended Posts

Hi all I have a problem.

I have a script to auto, and it has a natural system of buying a car, I put the ID cars and the price of them and as a result in the purchase of the player names appear standart cars from GTA San Andreas.

I want to do that to the players name appears to ask me.

Just do not know how to do it, just know about and trying to do, but it did not work, the script had stopped working, maybe someone else can help?

Here's the script without my patch

local lp = getLocalPlayer() 
  
theWindow = guiCreateWindow(x,y,width,height,"Управления автомобилем",false) 
guiWindowSetSizable(theWindow,false) 
guiSetVisible (theWindow, false) 
spawnBut = guiCreateButton(0.0604,0.120,0.4,0.2,"Спавн",true,theWindow) 
engenieBut = guiCreateButton(0.0604,0.420,0.4,0.2,"Двигатель",true,theWindow) 
lockBut = guiCreateButton(0.490,0.420,0.4,0.2,"Блок",true,theWindow) 
lightsBut = guiCreateButton(0.0604,0.720,0.4,0.2,"Фары",true,theWindow) 
  
function resourceStart () 
  bindKey ("F3", "down", menuShow) 
end 
addEventHandler ("onClientResourceStart", getResourceRootElement ( getThisResource () ), resourceStart) 
  
function menuShow () 
    visableornot = guiGetVisible (theWindow) 
    if (visableornot == true) then 
        guiSetVisible (theWindow, false) 
        showCursor (false) 
    end 
    if (visableornot == false) then 
        guiSetVisible (theWindow, true) 
        showCursor (true) 
    end 
end 
  
addEvent ("carSpawn", true) 
addEvent ("carDestroy", true) 
  
function guiClick (button, state, absoluteX, absoluteY) 
  if (source == spawnBut) then 
    triggerServerEvent ("carSpawn", lp) 
  elseif (source == destroyBut) then 
    triggerServerEvent ("carDestroy", lp) 
  elseif (source == engenieBut) then 
    triggerServerEvent ("engenieSwitch", lp)     
  elseif (source == lockBut) then 
    triggerServerEvent ("lockSwitch", lp)    
  elseif (source == lightsBut) then 
    triggerServerEvent ("lightsSwitch", lp)  
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), guiClick) 
  
  
carshopWindow = guiCreateWindow(500,200,290,440,"Автомаркет",false) 
guiSetVisible (carshopWindow, false) 
guiSetAlpha(carshopWindow,1) 
guiWindowSetSizable(carshopWindow,false) 
selectLabel = guiCreateLabel(0.0423,0.1009,0.8889,0.078,"Выберите машину",true,carshopWindow) 
guiSetAlpha(selectLabel,1) 
guiLabelSetColor(selectLabel,255,255,255) 
guiLabelSetVerticalAlign(selectLabel,"top") 
guiLabelSetHorizontalAlign(selectLabel,"left",false) 
guiSetFont(selectLabel,"default-bold-small") 
carGridList = guiCreateGridList(0.0476,0.1789,0.9048,0.6789,true,carshopWindow) 
guiGridListSetSelectionMode(carGridList,0) 
carColumn = guiGridListAddColumn(carGridList,"Автомобиль",0.5) 
costColumn = guiGridListAddColumn(carGridList,"$",0.3) 
local cars = {{492,20000},{405,23000},{404,18000},{458,24000},{445,25000},{467,28000}} 
for i,v in ipairs (cars) do 
    local carName = getVehicleNameFromModel (v[1]) 
    local row = guiGridListAddRow (carGridList) 
    guiGridListSetItemText (carGridList, row, 1, carName, false, true) 
    guiGridListSetItemText (carGridList, row, 2, tostring(v[2]), false, true) 
end 
guiSetAlpha(carGridList,1) 
buyButton = guiCreateButton(0.0476,0.8624,0.7778,0.0963,"Купить!",true,carshopWindow) 
guiSetAlpha(buyButton,1) 
closeButton = guiCreateButton(0.8571,0.8624,0.0899,0.1009,"x",true,carshopWindow) 
  
  
addEvent ("viewGUI", true) 
function viewGUI () 
  if (getLocalPlayer() == source) then 
    guiSetVisible (carshopWindow, true) 
    showCursor (true) 
  end 
end 
addEventHandler ("viewGUI", getRootElement(), viewGUI) 
  
function onClientGUIClick (button, state, absoluteX, absoluteYe) 
  if (source == buyButton) then guiSetVisible (carshopWindow, false) showCursor (false) 
    if (guiGridListGetSelectedItem (carGridList)) then 
      local carName = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 1) 
      local carID = getVehicleModelFromName (carName) 
      local carCost = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 2) 
      triggerServerEvent ("carShopCarBuy", getLocalPlayer(), carID, carCost, carName) 
    end 
  elseif (source == closeButton) then 
  guiSetVisible (carshopWindow, false) 
  showCursor (false) 
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick) 
  

Here is a line for the price of the car and going

local cars = {{492,20000},{405,23000},{404,18000},{458,24000},{445,25000},{467,28000}} 

local vehicles = {{"VW Golf", 410},{"Subaru Impreza", 551},{"Yamaha Aerox", 448}} 

But there was no work and I do not know how to register a price.

Prompt me please, I will be very grateful.

Link to comment

I didn't understand your issue, do you mean you wanna call price by vehicle ID/Name from table? You can try this:

local nameToID = { 
    ["VW Golf"] = 410, 
    ["Subaru Impreza"] = 551, 
    ["Yamaha Aerox"] = 448, 
--  ["Custom Name"] = ID From MTA SA, 
} 
  
local vehiclePrices = { 
    [410] = 25000, 
    [551] = 40000, 
    [448] = 15000, 
--  [iD From MTA SA] = Price, 
} 
  
function getIDFromCustomName(name) 
    if (not name) then return end 
    for k, v in ipairs(nameToID) do 
        if (k ~= name) then return end 
        local id = nameToID[k] 
        return id 
    end 
end 
  
function getPriceFromID(id) 
    if (not id) then return end 
    for k, v in ipairs(vehiclePrices) do 
        if (k ~= id) then return end 
        local price = vehiclePrices[k] 
        return price 
    end 
end 

Link to comment

I did so:

local screenX, screenY = guiGetScreenSize() 
local width, height = 200, 200 
local x = (screenX/2) - (width/2) 
local y = (screenY/2) - (height/2) 
local lp = getLocalPlayer() 
  
theWindow = guiCreateWindow(x,y,width,height,"Управления автомобилем",false) 
guiWindowSetSizable(theWindow,false) 
guiSetVisible (theWindow, false) 
spawnBut = guiCreateButton(0.0604,0.120,0.4,0.2,"Спавн",true,theWindow) 
engenieBut = guiCreateButton(0.0604,0.420,0.4,0.2,"Двигатель",true,theWindow) 
lockBut = guiCreateButton(0.490,0.420,0.4,0.2,"Блок",true,theWindow) 
lightsBut = guiCreateButton(0.0604,0.720,0.4,0.2,"Фары",true,theWindow) 
  
function resourceStart () 
  bindKey ("F3", "down", menuShow) 
end 
addEventHandler ("onClientResourceStart", getResourceRootElement ( getThisResource () ), resourceStart) 
  
function menuShow () 
    visableornot = guiGetVisible (theWindow) 
    if (visableornot == true) then 
        guiSetVisible (theWindow, false) 
        showCursor (false) 
    end 
    if (visableornot == false) then 
        guiSetVisible (theWindow, true) 
        showCursor (true) 
    end 
end 
  
addEvent ("carSpawn", true) 
addEvent ("carDestroy", true) 
  
function guiClick (button, state, absoluteX, absoluteY) 
  if (source == spawnBut) then 
    triggerServerEvent ("carSpawn", lp) 
  elseif (source == destroyBut) then 
    triggerServerEvent ("carDestroy", lp) 
  elseif (source == engenieBut) then 
    triggerServerEvent ("engenieSwitch", lp)     
  elseif (source == lockBut) then 
    triggerServerEvent ("lockSwitch", lp)    
  elseif (source == lightsBut) then 
    triggerServerEvent ("lightsSwitch", lp)  
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), guiClick) 
  
  
carshopWindow = guiCreateWindow(500,200,290,440,"Автомаркет",false) 
guiSetVisible (carshopWindow, false) 
guiSetAlpha(carshopWindow,1) 
guiWindowSetSizable(carshopWindow,false) 
selectLabel = guiCreateLabel(0.0423,0.1009,0.8889,0.078,"Выберите машину",true,carshopWindow) 
guiSetAlpha(selectLabel,1) 
guiLabelSetColor(selectLabel,255,255,255) 
guiLabelSetVerticalAlign(selectLabel,"top") 
guiLabelSetHorizontalAlign(selectLabel,"left",false) 
guiSetFont(selectLabel,"default-bold-small") 
carGridList = guiCreateGridList(0.0476,0.1789,0.9048,0.6789,true,carshopWindow) 
guiGridListSetSelectionMode(carGridList,0) 
carColumn = guiGridListAddColumn(carGridList,"Автомобиль",0.5) 
costColumn = guiGridListAddColumn(carGridList,"$",0.3) 
local nameToID = { 
    ["VW Golf"] = 410, 
    ["Subaru Impreza"] = 551, 
    ["Yamaha Aerox"] = 448, 
} 
  
local vehiclePrices = { 
    [410] = 25000, 
    [551] = 40000, 
    [448] = 15000, 
} 
  
function getIDFromCustomName(name) 
    if (not name) then return end 
    for k, v in ipairs(nameToID) do 
        if (k ~= name) then return end 
        local id = nameToID[k] 
        return id 
    end 
end 
  
function getPriceFromID(id) 
    if (not id) then return end 
    for k, v in ipairs(vehiclePrices) do 
        if (k ~= id) then return end 
        local price = vehiclePrices[k] 
        return price 
    end 
end 
guiSetAlpha(carGridList,1) 
buyButton = guiCreateButton(0.0476,0.8624,0.7778,0.0963,"Купить!",true,carshopWindow) 
guiSetAlpha(buyButton,1) 
closeButton = guiCreateButton(0.8571,0.8624,0.0899,0.1009,"x",true,carshopWindow) 
  
  
addEvent ("viewGUI", true) 
function viewGUI () 
  if (getLocalPlayer() == source) then 
    guiSetVisible (carshopWindow, true) 
    showCursor (true) 
  end 
end 
addEventHandler ("viewGUI", getRootElement(), viewGUI) 
  
function onClientGUIClick (button, state, absoluteX, absoluteYe) 
  if (source == buyButton) then guiSetVisible (carshopWindow, false) showCursor (false) 
    if (guiGridListGetSelectedItem (carGridList)) then 
      local carName = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 1) 
      local carID = getVehicleModelFromName (carName) 
      local carCost = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 2) 
      triggerServerEvent ("carShopCarBuy", getLocalPlayer(), carID, carCost, carName) 
    end 
  elseif (source == closeButton) then 
  guiSetVisible (carshopWindow, false) 
  showCursor (false) 
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick) 
  

But the list is empty cars.

Link to comment

Add the code i gave, then add this anywhere in code:

for i,v in ipairs (nameToID) do 
    local row = guiGridListAddRow(carGridList) 
    guiGridListSetItemText (carGridList, row, 1, i, false, true) 
    guiGridListSetItemText (carGridList, row, 2, v, false, true) 
end 

Then change onClientGUIClick() function from your script with this:

  
function onClientGUIClick (button, state, absoluteX, absoluteYe) 
  if (source == buyButton) then guiSetVisible (carshopWindow, false) showCursor (false) 
    if (guiGridListGetSelectedItem (carGridList)) then 
      local carName = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 1) 
      local carID = getIDFromCustomName(carName) 
      local carCost = getPriceFromID(carID) 
      triggerServerEvent ("carShopCarBuy", getLocalPlayer(), carID, carCost, carName) 
    end 
  elseif (source == closeButton) then 
  guiSetVisible (carshopWindow, false) 
  showCursor (false) 
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick) 

Link to comment

Did so, it is still not displayed in the list of cars, just an empty GUI

local screenX, screenY = guiGetScreenSize() 
local width, height = 200, 200 
local x = (screenX/2) - (width/2) 
local y = (screenY/2) - (height/2) 
local lp = getLocalPlayer() 
  
theWindow = guiCreateWindow(x,y,width,height,"Управления автомобилем",false) 
guiWindowSetSizable(theWindow,false) 
guiSetVisible (theWindow, false) 
spawnBut = guiCreateButton(0.0604,0.120,0.4,0.2,"Спавн",true,theWindow) 
engenieBut = guiCreateButton(0.0604,0.420,0.4,0.2,"Двигатель",true,theWindow) 
lockBut = guiCreateButton(0.490,0.420,0.4,0.2,"Блок",true,theWindow) 
lightsBut = guiCreateButton(0.0604,0.720,0.4,0.2,"Фары",true,theWindow) 
  
function resourceStart () 
  bindKey ("F3", "down", menuShow) 
end 
addEventHandler ("onClientResourceStart", getResourceRootElement ( getThisResource () ), resourceStart) 
  
function menuShow () 
    visableornot = guiGetVisible (theWindow) 
    if (visableornot == true) then 
        guiSetVisible (theWindow, false) 
        showCursor (false) 
    end 
    if (visableornot == false) then 
        guiSetVisible (theWindow, true) 
        showCursor (true) 
    end 
end 
  
addEvent ("carSpawn", true) 
addEvent ("carDestroy", true) 
  
function guiClick (button, state, absoluteX, absoluteY) 
  if (source == spawnBut) then 
    triggerServerEvent ("carSpawn", lp) 
  elseif (source == destroyBut) then 
    triggerServerEvent ("carDestroy", lp) 
  elseif (source == engenieBut) then 
    triggerServerEvent ("engenieSwitch", lp)     
  elseif (source == lockBut) then 
    triggerServerEvent ("lockSwitch", lp)    
  elseif (source == lightsBut) then 
    triggerServerEvent ("lightsSwitch", lp)  
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), guiClick) 
  
  
carshopWindow = guiCreateWindow(500,200,290,440,"Автомаркет",false) 
guiSetVisible (carshopWindow, false) 
guiSetAlpha(carshopWindow,1) 
guiWindowSetSizable(carshopWindow,false) 
selectLabel = guiCreateLabel(0.0423,0.1009,0.8889,0.078,"Выберите машину",true,carshopWindow) 
guiSetAlpha(selectLabel,1) 
guiLabelSetColor(selectLabel,255,255,255) 
guiLabelSetVerticalAlign(selectLabel,"top") 
guiLabelSetHorizontalAlign(selectLabel,"left",false) 
guiSetFont(selectLabel,"default-bold-small") 
carGridList = guiCreateGridList(0.0476,0.1789,0.9048,0.6789,true,carshopWindow) 
guiGridListSetSelectionMode(carGridList,0) 
carColumn = guiGridListAddColumn(carGridList,"Автомобиль",0.5) 
costColumn = guiGridListAddColumn(carGridList,"$",0.3) 
local nameToID = { 
    ["VW Golf"] = 410, 
    ["Subaru Impreza"] = 551, 
    ["Yamaha Aerox"] = 448, 
} 
  
local vehiclePrices = { 
    [410] = 25000, 
    [551] = 40000, 
    [448] = 15000, 
} 
  
function getIDFromCustomName(name) 
    if (not name) then return end 
    for k, v in ipairs(nameToID) do 
        if (k ~= name) then return end 
        local id = nameToID[k] 
        return id 
    end 
end 
  
function getPriceFromID(id) 
    if (not id) then return end 
    for k, v in ipairs(vehiclePrices) do 
        if (k ~= id) then return end 
        local price = vehiclePrices[k] 
        return price 
    end 
end 
for i,v in ipairs (nameToID) do 
    local row = guiGridListAddRow(carGridList) 
    guiGridListSetItemText (carGridList, row, 1, i, false, true) 
    guiGridListSetItemText (carGridList, row, 2, v, false, true) 
end 
guiSetAlpha(carGridList,1) 
buyButton = guiCreateButton(0.0476,0.8624,0.7778,0.0963,"Купить!",true,carshopWindow) 
guiSetAlpha(buyButton,1) 
closeButton = guiCreateButton(0.8571,0.8624,0.0899,0.1009,"x",true,carshopWindow) 
  
  
addEvent ("viewGUI", true) 
function viewGUI () 
  if (getLocalPlayer() == source) then 
    guiSetVisible (carshopWindow, true) 
    showCursor (true) 
  end 
end 
addEventHandler ("viewGUI", getRootElement(), viewGUI) 
  
function onClientGUIClick (button, state, absoluteX, absoluteYe) 
  if (source == buyButton) then guiSetVisible (carshopWindow, false) showCursor (false) 
    if (guiGridListGetSelectedItem (carGridList)) then 
      local carName = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 1) 
      local carID = getIDFromCustomName(carName) 
      local carCost = getPriceFromID(carID) 
      triggerServerEvent ("carShopCarBuy", getLocalPlayer(), carID, carCost, carName) 
    end 
  elseif (source == closeButton) then 
  guiSetVisible (carshopWindow, false) 
  showCursor (false) 
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick) 
  

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...