Jump to content

Need help with givePlayerMoney


Recommended Posts

Hi all!

I have one problem, can you please help me to solve it?

Can you please make me an function, for race server like....

Player drives a race and wins map, and server gives player money for victory with  math.random (100-500$)

i tried to make this by myself using this wiki page - https://wiki.multitheftauto.com/wiki/GivePlayerMoney but i failed

Please MTA:SA Community, help me someone :(((

Link to comment
4 hours ago, [MTA]Weed said:

do you have the script where you need the givePlayerMoney, or you need script that will give you money when you hit the marker?

I need it dude. I made userpanel by myself and made rewards only for DD, i cant made same for race by hittin marker. Like 1st place more money, 2nd less, 3rd, less etc... 

 

Please help me dude, i will be very grateful

Link to comment

You can perhaps use a hit counter to calculate some progressive reward amount, goes to infinity in this example.

-- Create a marker
local marker = createMarker(0, 0, 3)

-- Add an event handler for onPlayerMarkerHit on the marker
addEventHandler("onPlayerMarkerHit", marker, function(markerHit, matchingDimension)
	-- If the player element is in the same dimension as the marker
	if (matchingDimension) then
		-- Get the hit count (or default to 0) from the marker
		local markerHitCount = tonumber(getElementData(markerHit, "hitCount") or 0)

		-- Calculate some reward amount down from 500
		local rewardAmount = 500 / (markerHitCount + 1)

		-- Give the calculated reward amount to the player
		givePlayerMoney(source, rewardAmount)

		-- Increment the hit count of the marker
		setElementData(markerHit, "hitCount", markerHitCount + 1)
	end
end)

To reset the hit counter, just do the following:

removeElementData(marker, "hitCount")

 

Edited by myonlake
Link to comment
11 minutes ago, myonlake said:

You can perhaps use a hit counter to calculate some progressive reward amount, goes to infinity in this example.


-- Create a marker
local marker = createMarker(0, 0, 3)

-- Add an event handler for onPlayerMarkerHit on the marker
addEventHandler("onPlayerMarkerHit", marker, function(markerHit, matchingDimension)
	-- If the player element is in the same dimension as the marker
	if (matchingDimension) then
		-- Get the hit count (or default to 0) from the marker
		local markerHitCount = tonumber(getElementData(markerHit, "hitCount") or 0)

		-- Calculate some reward amount down from 500
		local rewardAmount = 500 / (markerHitCount + 1)

		-- Give the calculated reward amount to the player
		givePlayerMoney(source, rewardAmount)

		-- Increment the hit count of the marker
		setElementData(markerHit, "hitCount", markerHitCount + 1)
	end
end)

To reset the hit counter, just do the following:


removeElementData(marker, "hitCount")

 

I tryed like this, but i need to reward player only on finishing marker. Like when he finishes race, 3rd for example. then math.random for reward.... 

Link to comment

Then attach it to the finish marker? And set the rewardAmount to math.random(500) if that's what you want.

If you are using the base race resource, then you can just use the following snippet.

-- Add an event handler for onPlayerFinish
addEventHandler("onPlayerFinish", root, function(rank, time)
	-- Calculate some reward amount down from 500
	local rewardAmount = 500 / rank

	-- Give the calculated reward amount to the player
	givePlayerMoney(source, rewardAmount)
end)

Why don't people search on Google or Wiki first?

https://wiki.multitheftauto.com/wiki/Resource:Race

Edited by myonlake
Link to comment
7 minutes ago, myonlake said:

Then attach it to the finish marker? And set the rewardAmount to math.random(500) if that's what you want.

If you are using the base race resource, then you can just use the following snippet.


-- Add an event handler for onPlayerFinish
addEventHandler("onPlayerFinish", root, function(rank, time)
	-- Calculate some reward amount down from 500
	local rewardAmount = 500 / rank

	-- Give the calculated reward amount to the player
	givePlayerMoney(source, rewardAmount)
end)

Why don't people search on Google or Wiki first?

https://wiki.multitheftauto.com/wiki/Resource:Race

:~ sorry for disturbing again, now bout something other..

I made a code for userpanel, to buy a map for cash, but map is just adding to queue.. Like map doesnt fit..  I see you have big experience with  lua, maybe you can help me with this error.

 

Code 

-- Buy a next map // wolfeens
function buyMap(thePlayer,mapName,command)
    if not PVP[thePlayer] then
        local account = getPlayerAccount(thePlayer)
        if not (isGuestAccount(account)) then
            local playerCash = tonumber(getAccountData(account,"cash"))
            if not (mapName == "") then
                if playerCash >= mapCost then
                    if command then
                        mapName = getMapName(mapName)
                    else
                        mapName = tostring(mapName)
                    end
                    if not mapTimer[mapName] then
                        table.insert(mapQueue,mapName)
                        local freeMaps = tonumber(getAccountData(account,"freeMaps"))
                        if freeMaps ~= 0 then
                            addStat(account,"freeMaps",-1)
                        else
                            setAccountData(account,"cash",playerCash - mapCost)
                        end
                        addStat(account,"buyedMaps",1)
                        scoreboardRefresh(thePlayer)
                        mapTimer[mapName] = true
                        setTimer(resetMapTimer,900000,1,mapName)
                        if #mapQueue == 1 then
                            triggerEvent("onUseranelWantSetMap",getRootElement(),mapQueue[1])
                        end
                        callClientFunction(thePlayer,"setFreeMapPurchase",getAccountData(account,"freeMaps"))
                        unlockAchievement(thePlayer,18)
                        unlockAchievement(thePlayer)
                        showServerMsg(getRootElement(),"Map queue",getPlayerName(thePlayer).." #ffffffbought and add "..mapName.." to map queue")
                        callClientFunction(getRootElement(),"updateMapQueueList",mapQueue)
                    else
                        showServerMsg(thePlayer,"Buy nextmap","#FFFFFFYou can't set this map now, wait some time to set!")
                    end
                else
                    showServerMsg(thePlayer,"Buy nextmap","#FFFFFFYou don't have enough money to set a map!")
                end
            else
                showServerMsg(thePlayer,"Buy nextmap","#FFFFFFPlease select a map from the list first!")
            end
        end
    else
        showServerMsg(thePlayer,"Buy nextmap","#FFFFFFYou can't buy maps because you're playing a PVP match now!")
    end
end

Link to comment
6 minutes ago, fortynigguh said:

:~ sorry for disturbing again, now bout something other..

I made a code for userpanel, to buy a map for cash, but map is just adding to queue.. Like map doesnt fit..  I see you have big experience with  lua, maybe you can help me with this error.

I don't know what you mean exactly, and I don't know how to help since I don't have the full code.

Also, create a new topic for that question. Let's keep this on topic.

Edited by myonlake
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...