1 Replies - 364 Views - Last Post: 27 February 2019 - 10:22 AM Rate Topic: -----

#1 Brycie   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-February 19

Help with .LUA Script

Posted 27 February 2019 - 10:03 AM

Hi, I am currently trying to learn to code in .LUA for a game server I am hosting. I thought I would try somthing simple to start. I have added an Item BankCard to the database, I then added a check to my shop script to say if players has bank card item, use bank balance, else use cash. Tried to keep it simple for now, eventually id have it give u the option to use bank balance or cash balance. Anyway long story short it doesn't work lol, It skips to the end of the loop and somehow messes up the math, Saying I have im short the price by -$947 (I have 1k in both bank and on hand balance). I have pasted the code bellow, Maybe someone can point me in the right direction.

	-- can the player afford this item? --Extra check for bank balance
	if xPlayer.getMoney() >= price or xPlayer.getBank() >= price then
		-- can the player carry the said amount of x item?
		if sourceItem.limit ~= -1 and (sourceItem.count + amount) > sourceItem.limit then
			TriggerClientEvent('esx:showNotification', _source, _U('player_cannot_hold'))
			--Does player have a Bank Card --Added by Brycie 27/02/2019
		if xItem.count >= 1 then
			xPlayer.addInventoryItem(itemName, amount)
			TriggerClientEvent('esx:showNotification', _source, _U('Paid from bank balance', amount, itemLabel, ESX.Math.GroupDigits(price)))
			xPlayer.addInventoryItem(itemName, amount)
			TriggerClientEvent('esx:showNotification', _source, _U('bought', amount, itemLabel, ESX.Math.GroupDigits(price)))
		local missingMoney = price - xPlayer.getMoney() or - xPlayer.getBank()
		TriggerClientEvent('esx:showNotification', _source, _U('not_enough', ESX.Math.GroupDigits(missingMoney)))

Is This A Good Question/Topic? 0
  • +

Replies To: Help with .LUA Script

#2 modi123_1   User is online

  • Suitor #2
  • member icon

Reputation: 15506
  • View blog
  • Posts: 62,082
  • Joined: 12-June 08

Re: Help with .LUA Script

Posted 27 February 2019 - 10:22 AM

Yeah your logic seems hinky.

I would divide the problem in to sections. First - card or no card.

No card is an easy check.. is your cash value greater or equal to the price.

With a card you have four scenarios.

1. card balance is greater than or equal to price
2. cash balance is greater than or equal to price
3. card plus cash are greater than or equal to price.
4. None of the above.

You may want to rework what you have to fit that break down.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1