Jump to content

table ...


Desaster

Recommended Posts

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

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

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

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

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