Jump to content

Destroy Marker


Recommended Posts

Hi guys!
I need help
I made this script so that when a player takes a marker he earns 30,000, the problem is that I add the destroyElement function to eliminate the marker when taking it, but I want to only delete the player that takes it and not all.
 
local money2 = createMarker(-282.60000610352, 405.79998779297, 69.300003051758, 'corona', 7, 255, 0, 0, 255)
setElementDimension (money2, 336) 
function playrules(thePlayer)
givePlayerMoney (thePlayer, 35000)
destroyElement(money2)
end 
addEventHandler ( "onMarkerHit", money2, playrules )

Try creating it in client and also it was destroyed for all, besides that gave me error the givePlayerMoney:

local money2 = createMarker(-282.60000610352, 405.79998779297, 69.300003051758, 'corona', 7, 255, 0, 0, 255)
setElementDimension (money, 336) 
function MarkerHit ( thePlayer, amount )
givePlayerMoney (thePlayer, 35000)
destroyElement(money2)
end
addEventHandler ( "onClientMarkerHit", money2, MarkerHit )

Who can help me to destroy the marker only to the player who takes it?

 

 

 

 


 

 


 

 

Link to comment

The reason givePlayerMoney isn't working client side is because you're passing it an extra argument, which is thePlayer. givePlayerMoney in client side has only one argument, which is the amount of money to give.

 

Also, I believe there is no way for an element that is showing to everyone to be destroyed for one player only, hence you should use setElementVisibleTo and a table with stored players that already entered the marker so they don't get the money again.

  • Like 1
Link to comment

Always use givePlayerMoney server-side, because the player's money will not be synchronized with the server and the money will not 'change' when you call getPlayerMoney server-side.

Try this:

addEventHandler( "onClientResourceStart", resourceRoot,
	function()
		local money2 = createMarker(-282.60000610352, 405.79998779297, 69.300003051758, 'corona', 7, 255, 0, 0, 255)
		setElementDimension (money2, 336)
		
		addEventHandler ( "onClientMarkerHit", money2, MarkerHit )
	end
)

function MarkerHit( p, md )
	if p == localPlayer and md then
		triggerServerEvent( "doGiveMoneyOnMarkerHit", p, 35000 )
		destroyElement( source )
	end
end

Server

addEvent( "doGiveMoneyOnMarkerHit", true )
addEventHandler( "doGiveMoneyOnMarkerHit", root,
	function( v )
		if v then
			givePlayerMoney( client, tonumber(v) )
		end
	end
)

 

Edited by DNL291
  • Like 1
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...