Sign in to follow this  
ezzzyxs

Help. givePlayerMoney

Recommended Posts

 
Sorry for the clumsy English

 

 
Help is needed. I wrote a script to transfer money. The visual part works, but the amount does not transfer. Help, where is the error?

Client:

addEvent("UI.click", false)
addEventHandler("UI.click", resourceRoot, function (widget)
	if widget == ui.playersList then
		local items = exports.UI:getItems(ui.playersList)
		local selectedItem = exports.UI:getActiveItem(ui.playersList)
		Panel.showPlayerInfo(items[selectedItem].player)
	elseif widget == ui.CanelButton then
		Panel.hide()
	elseif widget == ui.SendButton then
		local reason = UI:getText(ui.reasonInput)
		if client:getData("money") < reason then
			exports.UI:showMessageBox("Error", "Недостаточно средств")
		else
			triggerServerEvent("SendMoney", localPlayer, selectedPlayer, reason)
			Panel.hide()
		end
	end
end)

Server:

addEvent("SendMoney",true)
addEventHandler("SendMoney", localPlayer, function(selectedPlayer, reason)
	if not isElement(selectedPlayer) then
		return false
	end
	if type(reason) ~= "number" then
		return false
	end
	if client:getData("money") < reason then
		return
	end
	if not exports.Core:givePlayerMoney(client, -reason) then
		return false
	end
	if isElement(selectedPlayer) then
		exports.Core:givePlayerMoney(selectedPlayer, reason)
	end
end)

 

Edited by ezzzyxs

Share this post


Link to post
addEvent("UI.click", false)
addEventHandler("UI.click", resourceRoot, function (widget)
	if widget == ui.playersList then
		local items = exports.UI:getItems(ui.playersList)
		local selectedItem = exports.UI:getActiveItem(ui.playersList)
		Panel.showPlayerInfo(items[selectedItem].player)
	elseif widget == ui.CanelButton then
		Panel.hide()
	elseif widget == ui.SendButton then
		local reason = UI:getText(ui.reasonInput)
		if client:getData("money") < reason then
			exports.UI:showMessageBox("Error", "Недостаточно средств")
		else
			triggerServerEvent("SendMoney", localPlayer, Panel.showPlayerInfo(items[selectedItem].player), reason)
			Panel.hide()
		end
	end
end)
addEvent("SendMoney",true)
addEventHandler("SendMoney", root, function(selectedPlayer, reason)
	if not isElement(selectedPlayer) then
		return false
	end
	if type(reason) ~= "number" then
		return false
	end
	if client:getData("money") < reason then
		return
	end
	if not exports.Core:givePlayerMoney(client, -reason) then
		return false
	end
	if isElement(selectedPlayer) then
		exports.Core:givePlayerMoney(selectedPlayer, reason)
	end
end)

Try this one.

Share this post


Link to post
17 minutes ago, Dzsozi (h03) said:

addEvent("UI.click", false)
addEventHandler("UI.click", resourceRoot, function (widget)
	if widget == ui.playersList then
		local items = exports.UI:getItems(ui.playersList)
		local selectedItem = exports.UI:getActiveItem(ui.playersList)
		Panel.showPlayerInfo(items[selectedItem].player)
	elseif widget == ui.CanelButton then
		Panel.hide()
	elseif widget == ui.SendButton then
		local reason = UI:getText(ui.reasonInput)
		if client:getData("money") < reason then
			exports.UI:showMessageBox("Error", "Недостаточно средств")
		else
			triggerServerEvent("SendMoney", localPlayer, Panel.showPlayerInfo(items[selectedItem].player), reason)
			Panel.hide()
		end
	end
end)

addEvent("SendMoney",true)
addEventHandler("SendMoney", root, function(selectedPlayer, reason)
	if not isElement(selectedPlayer) then
		return false
	end
	if type(reason) ~= "number" then
		return false
	end
	if client:getData("money") < reason then
		return
	end
	if not exports.Core:givePlayerMoney(client, -reason) then
		return false
	end
	if isElement(selectedPlayer) then
		exports.Core:givePlayerMoney(selectedPlayer, reason)
	end
end)

Try this one.

Did not help. Clicked to transfer, the button does not work and does not display the message "Insufficient Funds"

Button "Send" does not work

Edited by ezzzyxs

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.