Desaster Posted October 27, 2013 Share Posted October 27, 2013 hello , I am trying to sell a car by finding the first value of the table and to find the matching one with the car's ID and then to take the second value wish is the price and to give the half of it to the player I had some problems to make it could you help me what I made : local cars = {{519,250000},{460,80000},{593,65000},{511,125000},{513,70000},{447,180000},{563,200000},{497,350000},{488,70000},{487,300000},{520,4000000},{417,160000}} function guiClick6 (button, state, absoluteX, absoluteY) if (source == FirstSlotSell) then triggerServerEvent ("carSellShop",getLocalPlayer(),3) guiSetVisible (CarSellWindow, false) showCursor (false) for i,v in ipairs (cars) do carID = getElementData (source, "hisCar1") if carID == v[1] then givePlayerMoney ( v[2] ) end end end end addEventHandler ("onClientGUIClick", getRootElement(), guiClick6) Link to comment
tosfera Posted October 27, 2013 Share Posted October 27, 2013 Oke, so you're trying to create a script that allows people to sell their car for 50% of the price? Just create a list of all the vehicle's that the user owns ( if you saved them in a database ). Then whenever the player selects a vehicle and presses; 'sell'. Search for the vaue in the cars3 ( your array ). Giving the player the money and removing the record out of the database. Link to comment
Desaster Posted October 27, 2013 Author Share Posted October 27, 2013 I am saving them into setAccoutData but I don't get what you mean Link to comment
tosfera Posted October 27, 2013 Share Posted October 27, 2013 Oke, so one user can have 1 vehicle? Link to comment
Desaster Posted October 27, 2013 Author Share Posted October 27, 2013 nop every car have it's slot in total there are 3 Link to comment
Desaster Posted October 27, 2013 Author Share Posted October 27, 2013 maybe this function guiClick6 (button, state, absoluteX, absoluteY) if (source == FirstSlotSell) then triggerServerEvent ("carSellShop",getLocalPlayer(),3) guiSetVisible (CarSellWindow, false) showCursor (false) for i,v in ipairs (cars) do carID = getElementData (source, "hisCar1") value = table.concat(cars, carID) givePlayerMoney ( value + 1 ) end elseif (source == SecondSlotSell) then elseif (source == ThirdSlotSell) then elseif (source == cancel123) then guiSetVisible (CarSellWindow, false) showCursor (false) end end addEventHandler ("onClientGUIClick", getRootElement(), guiClick6) but won't work Link to comment
tosfera Posted October 27, 2013 Share Posted October 27, 2013 What doesn't work, is your gui not showing, you can't sell your vehicle, what's going wrong. Link to comment
Desaster Posted October 28, 2013 Author Share Posted October 28, 2013 I can sell them but I don't get the price the sell function is triggered from server Link to comment
Markeloff Posted October 28, 2013 Share Posted October 28, 2013 I think he wanted to get the price from the table whenever the player wants to sell his car, that means he get the id and the price from the table and give him the money of his car. Link to comment
Castillo Posted October 28, 2013 Share Posted October 28, 2013 Well, your code makes no sense. You must loop the table and see if the ID matches the one you're trying to sell, then break the loop, then you must trigger the price to the server side using triggerServerEvent for then give the player the money, since if you give it client side, it'll not be synced with the server. 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