Jump to content

carshop system with token


HuskLV

Recommended Posts

Hey, i make carshop system new button "token" with buy car.

If you have token you can buy car with him, please help with this.

client side:

if itemID == 300 then
  gui["btnCoin"] = guiCreateButton(232, 140, 105, 41, "Redeem token", false, gui["_root"])
  addEventHandler("onClientGUIClick", gui["btnCoin"], carshop_buyCar_click, false)
  guiSetEnabled(gui["btnCoin"], coinEnabled)
 else
  gui["btnCash"] = guiCreateButton(10, 140, 105, 41, "Pay by cash", false, gui["_root"])
  addEventHandler("onClientGUIClick", gui["btnCash"], carshop_buyCar_click, false)
  guiSetEnabled(gui["btnCash"], cashEnabled)
 end

function carshop_buyCar_click()
 if exports.global:hasSpaceForItem(getLocalPlayer(), 3, 1) then
  local sourcestr = "cash"
  if (source == gui["btnBank"]) then
   sourcestr = "bank"
  elseif (source == gui["btnCoin"]) then
   sourcestr = "coin"
  end
  triggerServerEvent("carshop:buyCar", theVehicle, sourcestr)
 else
  outputChatBox("You don't have space in your inventory for a key", 0, 255, 0)
 end
 carshop_buyCar_close()
end

server side:

elseif (paymentMethod == "coin") then
  if itemID == 300 and costCar < 15000 then
   if isOverlayDisabled then
    outputChatBox("Token 15'000$ you dont have token with up to 15'000$!", client, 0, 255, 0)
   else
    exports.hud:sendBottomNotification(client, "Wrong token - 15'000$", "Token 15'000$ you dont have token with up to 15'000$!")
   end
  else
   takeItemFromSlot(client, 300)
  end

 

Please help me! :)

  • Like 1
Link to comment
--CLIENT SIDE
if itemID == 300 then
  gui["btnCoin"] = guiCreateButton(232, 140, 105, 41, "Redeem token", false, gui["_root"])
  addEventHandler("onClientGUIClick", gui["btnCoin"], carshop_buyCar_click, false)
  guiSetEnabled(gui["btnCoin"], coinEnabled)
 else
  gui["btnCash"] = guiCreateButton(10, 140, 105, 41, "Pay by cash", false, gui["_root"])
  addEventHandler("onClientGUIClick", gui["btnCash"], carshop_buyCar_click, false)
  guiSetEnabled(gui["btnCash"], cashEnabled)
 end 
function carshop_buyCar_click()
 if exports.global:hasSpaceForItem(getLocalPlayer(), 3, 1) then
  local sourcestr = "cash"
  if (source == gui["btnBank"]) then
   sourcestr = "bank"
  elseif (source == gui["btnCoin"]) then
   sourcestr = "coin"
  end
  triggerServerEvent("carshop:buyCar", theVehicle, sourcestr)
 else
  outputChatBox("You don't have space in your inventory for a key", 0, 255, 0)
 end
 carshop_buyCar_close()
end 

--SERVER SIDE

elseif (paymentMethod == "coin") then
  if itemID == 300 and costCar < 15000 then
   if isOverlayDisabled then
    outputChatBox("Token 15'000$ you dont have token with up to 15'000$!", client, 0, 255, 0)
   else
    exports.hud:sendBottomNotification(client, "Wrong token - 15'000$", "Token 15'000$ you dont have token with up to 15'000$!")
   end
  else
   takeItemFromSlot(client, 300)
  end 

 

Link to comment

Whats above this?

 

elseif (paymentMethod == "coin") then
  if itemID == 300 and costCar < 15000 then
    if isOverlayDisabled then
      outputChatBox("Token 15'000$ you dont have token with up to 15'000$!", client, 0, 255, 0)
    else
      exports.hud:sendBottomNotification(client, "Wrong token - 15'000$", "Token 15'000$ you dont have token with up to 15'000$!")
    end
  else
    takeItemFromSlot(client, 300)
  end

 

Link to comment
local costCar = getElementData(source, "carshop:cost")
	if (paymentMethod == "cash") then
		if not exports.global:hasMoney(client, costCar) or costCar == 0 then
			if isOverlayDisabled then
				outputChatBox("You don't have enough money on hand for this pal..", client, 0, 255, 0)
			else
				exports.hud:sendBottomNotification(client, "Money is always a problem..", "You don't have enough money on hand for this pal..")
			end
			return false
		else
			exports.global:takeMoney(client, costCar)
		end
	elseif (paymentMethod == "bank") then
		local money = getElementData(client, "bankmoney") - costCar
		if money < 0 or costCar == 0 then
			if isOverlayDisabled then 
				outputChatBox("You don't have enough money in your bank account for this pal..", client, 0, 255, 0)
			else
				exports.hud:sendBottomNotification(client, "Money is always a problem..", "You don't have enough money in your bank account for this pal..")
			end
		else
			exports.anticheat:changeProtectedElementDataEx(client, "bankmoney", money, false)
			mysql:query_free("UPDATE characters SET bankmoney=" .. mysql:escape_string((tonumber(money) or 0)) .. " WHERE id=" .. mysql:escape_string(getElementData( client, "dbid" )))
		end
	elseif (paymentMethod == "coin") then
		if itemID == 300 and costCar < 15000 then
			if isOverlayDisabled then
				outputChatBox("Jūs nevarat iegādāties dārgāku par 15'000$ caur šo kuponu!", client, 0, 255, 0)
			else
				exports.hud:sendBottomNotification(client, "Nederīgs kupons - 15'000$", "Jūs nevarat iegādāties dārgāku par 15'000$ caur šo kuponu!")
			end
		else
			takeItemFromSlot(client, 300)--HUSKLV
		end
	else
		if isOverlayDisabled then 
			outputChatBox("No.", client, 0, 255, 0)
		else
			exports.hud:sendBottomNotification(client, "No!", "Just no...")
		end
		return false
	end

 

Link to comment
7 minutes ago, NeXuS™ said:

Can you search for this in your code?


setElementData(source, "carshop:cost", ...)

 

carshop:cost work! Because with cash and bank i can buy, but i make token and that's not working. Error not shows.

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