Jump to content

Checking Player Money


dima3367

Recommended Posts

Hello! I have such a problem, it's impossible to check the player's money.

I have a game mod that uses its own money system. And for example, that the player would give the money to the resource, I have to use the export.
Example:

exports["tws-main"]:givePlayerMoney

I need to do something by analogy to check the player's amount of money.

For example, in this function:

function StartStudyBtn ()
    if source == StartLessonBtn then
		local playerLesson = guiGridListGetItemData ( VehicleLessons, guiGridListGetSelectedItem ( VehicleLessons ), 2 )
		local Money = guiGridListGetItemText ( VehicleLessons, guiGridListGetSelectedItem ( VehicleLessons ), 3 )
		local StudyLevel = getElementData(localPlayer, "VehLevel")+1
			if playerLesson and guiGetEnabled(StartLessonBtn) == true then
				if getPlayerMoney () < tonumber(Money) then
					outputChatBox("У вас недостаточно денег")
				else
					if tonumber(playerLesson) > tonumber(StudyLevel) then
						outputChatBox("Вы не прошли предыдуший курс")
					elseif tonumber(playerLesson) < tonumber(StudyLevel) then
						outputChatBox("Вы уже прошли этот курс")
					else 
						if (getElementData ( localPlayer, "working") == "1") then
							setElementModel ( localPlayer, tonumber(getElementData ( localPlayer, "skinback")))
							setElementData ( localPlayer, "working", "0" )
						end
						guiSetVisible(LicensePanel,false)
						showCursor(false)
						removeEventHandler ( "onClientGUIClick", getRootElement(), ByLicense ,false )
						removeEventHandler ( "onClientGUIClick", getRootElement(), StartStudyBtn ,false )
						triggerServerEvent("TakePlayerMoney", getRootElement(), localPlayer,Money)
						setLesson(playerLesson)
					end
				end
			end
	end
end

In line 7 there is a check whether the player has enough money. I need to make an appeal to my system of money tws-money. 
I tried to do so:

if localPlayer:getData("tws-money") < tonumber(Money) then

But I get an error. How can I do this here? Please tell me.
I apologize for the bad english.

Link to comment
  • Moderators

Changing the type to share will not solve the issue, because that means that the function should be created on both sides of the resource: tws-main

Thought it will look like it is working because getPlayerMoney already exist as a MTA default function.

 

 

There is a tutorial for this issue:

 

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