Jump to content

car slots


Recommended Posts

hi, im genting problems making a second car slot in my car system, i cant find what is the error in the code, maybe someone can give me a hand :roll: , here is my code:

server-side

carShopMarker = createMarker (-1953.68, 304.57, 34.46875, "cylinder", 3, 255, 0, 0, 127)
addEvent ("viewGUI", true)
function markerHit (hitPlayer, matchingDimension)
if (source == carShopMarker) then
triggerClientEvent ("viewGUI", hitPlayer)
outputChatBox ("Welcome to the vehicleshop!", hitPlayer, 255, 0, 0)
end
end
addEventHandler ("onMarkerHit", getRootElement(), markerHit)
 
addEvent ("carShopCarBuy", true)
addEventHandler ("carShopCarBuy", getRootElement(), 
function(id, cost, name)
if (getPlayerMoney (source) >= tonumber(cost)) then
outputChatBox ("Bought a " .. name, source, 255, 0, 0, false)
outputChatBox ("ID: " .. id, source, 255, 0, 0, false)
outputChatBox ("Cost: " .. cost, source, 255, 0, 0, false)
takePlayerMoney (source, tonumber (cost))
setAccountData (getPlayerAccount (source), "funmodev2-car", tonumber(id))
setAccountData (getPlayerAccount (source), "funmodev2-paintjob", 3)
setAccountData (getPlayerAccount (source), "funmodev2-carupg", 0)
else
outputChatBox ("You are too poor!", source, 255, 0, 0, false)
end
end)
 
addEvent ("carShopCarBuy2", true)
addEventHandler ("carShopCarBuy2", getRootElement(), 
function(id2, cost2, name2,slot2)
if (getPlayerMoney (source) >= tonumber(cost2)) then
outputChatBox ("Bought a " .. name2, source, 255, 0, 0, false)
outputChatBox ("ID: " .. id2, source, 255, 0, 0, false)
outputChatBox ("Cost: " .. cost2, source, 255, 0, 0, false)
takePlayerMoney (source, tonumber (cost2))
setAccountData (getPlayerAccount (source), "funmode2-car", tonumber(id2))
setAccountData (getPlayerAccount (source), "funmode2-paintjob", 3)
setAccountData (getPlayerAccount (source), "funmode2-carupg", 0)
else
outputChatBox ("You are too poor!", source, 255, 0, 0, false)
end
end)

client-side

carshopWindow = guiCreateWindow(12,120,289,325,"City Car Shop",false)
guiSetVisible (carshopWindow, false)
guiSetAlpha(carshopWindow,1)
guiWindowSetSizable(carshopWindow,false)
selectLabel = guiCreateLabel(10,20,257,25,"Select your car",false,carshopWindow)
guiSetAlpha(selectLabel,1)
guiLabelSetColor(selectLabel,255,255,255)
guiLabelSetVerticalAlign(selectLabel,"top")
guiLabelSetHorizontalAlign(selectLabel,"left",false)
guiSetFont(selectLabel,"default-bold-small")
slot1 = guiCreateRadioButton(188,72,90,21," Slot 1",false,carshopWindow)
slot2 = guiCreateRadioButton(188,101,90,21," Slot 2",false,carshopWindow)
slotLabel = guiCreateLabel(191,34,91,20,"Select car slot",false,carshopWindow)
carGridList = guiCreateGridList(9,39,171,213,false,carshopWindow)
guiGridListSetSelectionMode(carGridList,0)
carColumn = guiGridListAddColumn(carGridList,"Car",0.5)
costColumn = guiGridListAddColumn(carGridList,"$",0.3)
 
local cars = {{579,60000},{400,60000},{404,28000},{489,65000},{505,65000},{479,45000},{442,45000},{458,45000},{602,100000},{496,42500},{401,41000},{518,60000},{527,75000},{589,75000},{419,45000},{533,75000},{526,50000},{474,55000},{545,50000},{517,45000},{410,41000},{600,50000},{436,41000},{580,50000},{439,75000},{549,75000},{491,45000},{445,45000},{507,45000},{585,45000},{587,100000},{466,55000},{492,50000},{546,45000},{551,45000},{516,45000},{467,45000},{426,47500},{547,45000},{405,55000},{409,75000},{550,45000},{566,45000},{540,45000},{421,50000},{529,45000},{402,250000},{542,65000},{603,150000},{475,75000},{562,175000},{565,95000},{559,125000},{561,50000},{560,125000},{558,100000},{429,150000},{541,150000},{415,150000},{480,95000},{434,100000},{494,200000},{502,200000},{503,200000},{411,300000},{506,150000},{451,300000},{555,95000},{477,95000},{499,25000},{498,25000},{578,50000},{486,70000},{406,500000},{573,250000},{455,75000},{588,50000},{403,75000},{423,1000000},{414,50000},{443,75000},{515,75000},{514,75000},{531,12000},{456,45000},{422,45000},{482,95000},{530,12000},{418,45000},{572,12000},{582,50000},{413,50000},{440,50000},{543,65000},{583,12000},{478,35000},{554,50000},{536,75000},{575,75000},{534,75000},{567,75000},{535,75000},{576,75000},{412,75000},{568,75000},{457,12000},{483,45000},{508,40000},{571,10000},{500,55000},{444,250000},{556,250000},{557,250000},{495,100000},{539,75000},{485,12000},{431,60000},{438,45000},{437,60000},{574,12000},{420,45000},{525,75000},{408,50000},{428,65000}}
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(30,274,124,34,"BUY CAR",false,carshopWindow)
guiSetAlpha(buyButton,1)
closeButton = guiCreateButton(240,277,33,30,"X",false,carshopWindow)
 
if (guiRadioButtonGetSelected(slot1)) then
_carSlot=1
elseif (guiRadioButtonGetSelected(slot2)) then
_carSlot=2
end
 
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, carSlot)
if (source == buyButton) then 
guiSetVisible (carshopWindow, false) 
showCursor (false,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,false)
end
if (source == buyButton) and _carSlot2 then 
guiSetVisible (carshopWindow, false) 
showCursor (false,false)
if (guiGridListGetSelectedItem (carGridList)) then
local carName2 = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 1)
local carID2 = getVehicleModelFromName (carName)
local carCost2 = guiGridListGetItemText (carGridList, guiGridListGetSelectedItem (carGridList), 2)
triggerServerEvent ("carShopCarBuy2", getLocalPlayer(), carID2, carCost2, carName2, carSlot2 )
end
elseif (source == closeButton) then guiSetVisible (carshopWindow, false) showCursor (false)
end
end
addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick)

Link to comment
Well what exactly isn't happening. You can't just give us a whole script to look through and diagnose all on our own. You could help us a bit with it.

Okay, the problem is, i want to buy a car and detect what slot is selected, as you see im using radio buttons to select slot, but when i click buy only buys for slot 1.

i hope u understand a bit more now :)

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