Jump to content

take money from marker edit problem


☠ RaZeR ☠

Recommended Posts

hello guys

 

i want to set money in edit box then if i went to the marker i get the money in edit box

i do it but doesnt work

client !

             sett = guiCreateButton(507, 278, 64, 37, "Set The Money", true)
        money = guiCreateEdit(448, 225, 166, 45, "", true)

addEventHandler ( "onClientGUIClick", resourceRoot,
    function ( )
          if ( source == sett ) then
                local amount = guiGetText ( money )
                    triggerServerEvent( "SendMoney", localPlayer, amount )
           end               
      end
) 


 

server !

 

 addEvent ( "SendMoney", true )
addEventHandler ( "SendMoney", root, Money )
addEventHandler ( "onMarkerHit", resourceRoot, function ( element, amount )
 if ( source == myMarker1 ) then
   if ( getElementType ( element ) == "player" ) then
        destroyElement ( gold )
        setMarkerSize( myMarker1, 0 )
        givePlayerMoney(source, tonumber(amount))
        sendClientMessage ( '- ' .. getPlayerName(element) .. ' money', root, 255, 23, 23, top, 15 )
              outputChatBox(" ", root, 183, 92, 38)

    end
    end
  end))   

 

Edited by FOX_script
Link to comment
addEvent( "onClientSendMoney", true )

local amounts = {}

function handleMoney( money )
  if ( source and getElementType( source ) == "player" and money ) then
    amounts[ source ] = money
  end
end
addEventHandler( "onClientSendMoney", root, handleMoney )

local marker = createMarker() -- Insert your own data
local tick = 0

function handleHit( thePlayer, matchingDimension )
   if ( thePlayer and getElementType( thePlayer ) == "player" and matchingDimension ) then
    local money = amounts[ thePlayer ]
    if ( money ) then
      if ( getTickCount() - tick > 50000 ) then -- Give money each 50sec
        givePlayerMoney( thePlayer, money )
        tick = getTickCount()
        local players = getElementsByType( "player" )
        for i = 1, #players do
         local player = players[ i ]
         outputChatBox( "[MONEY] " .. getPlayerName( thePlayer ) .. " took the money he wanted!", player, 0, 255, 0 )
        end
      end
    end
   end
end
addEventHandler( "onPlayerMarkerHit", root, handleHit )

Client:

sett = guiCreateButton(507, 278, 64, 37, "Set The Money", true)
money = guiCreateEdit(448, 225, 166, 45, "", true)

addEventHandler ( "onClientGUIClick", resourceRoot,
    function ( b, s)
    	if ( b == "left" and s == "down" ) then
          if ( source == sett ) then
                local amount = guiGetText ( money )
                triggerServerEvent( "onClientSendMoney", localPlayer, ( amount ) and tonumber( amount ) or 0 )
           end  
      	end
      end
) 

This should work, just insert the data quoted.

Link to comment
On ١٠‏/١‏/٢٠١٧ at 10:03 AM, Simple01 said:

addEvent( "onClientSendMoney", true )

local amounts = {}

function handleMoney( money )
  if ( source and getElementType( source ) == "player" and money ) then
    amounts[ source ] = money
  end
end
addEventHandler( "onClientSendMoney", root, handleMoney )

local marker = createMarker() -- Insert your own data
local tick = 0

function handleHit( thePlayer, matchingDimension )
   if ( thePlayer and getElementType( thePlayer ) == "player" and matchingDimension ) then
    local money = amounts[ thePlayer ]
    if ( money ) then
      if ( getTickCount() - tick > 50000 ) then -- Give money each 50sec
        givePlayerMoney( thePlayer, money )
        tick = getTickCount()
        local players = getElementsByType( "player" )
        for i = 1, #players do
         local player = players[ i ]
         outputChatBox( "[MONEY] " .. getPlayerName( thePlayer ) .. " took the money he wanted!", player, 0, 255, 0 )
        end
      end
    end
   end
end
addEventHandler( "onPlayerMarkerHit", root, handleHit )

Client:


sett = guiCreateButton(507, 278, 64, 37, "Set The Money", true)money = guiCreateEdit(448, 225, 166, 45, "", true)addEventHandler ( "onClientGUIClick", resourceRoot,    function ( b, s)    	if ( b == "left" and s == "down" ) then          if ( source == sett ) then                local amount = guiGetText ( money )                triggerServerEvent( "onClientSendMoney", localPlayer, ( amount ) and tonumber( amount ) or 0 )           end        	end      end) 

This should work, just insert the data quoted.

He wants to work Marker ..

The marker when touching a person gives money

This money's worth be Edit Box

Link to comment

I don't know what your Money-function does, so I had to guess that you didn't complete that part.

Anyway, what this does, is it sends the amount from client to the server, stores that number in a table and then once they hit the specified marker, they will get that amount and so on. I also added an onPlayerQuit event handler in case you want to avoid confusion.

I also used setElementVisibleTo to show/hide the marker to the player, because setMarkerSize isn't reliable enough (and it's hacky code despite the fact that it might do the job).

Client-side

-- You had their "relative" parameter set to "true", that's why
-- they didn't show... now they're set to "false"
sett = guiCreateButton( 507, 278, 64, 37, "Set The Money", false )
money = guiCreateEdit( 448, 225, 166, 45, "", false )

-- When the button is clicked
addEventHandler( "onClientGUIClick", sett,
	function( )
		-- Get the contents of the edit box
		local amount = money and guiGetText( money )

		-- Let's convert that amount to a number if we can
		amount = tonumber( amount ) and tonumber( math.floor( amount ) )

		-- If the amount is a (realistic) number, we let them continue
		if ( amount ) then
			-- If the amount is greater than 0
			if ( amount > 0 ) then
				-- We send the amount to the server
				triggerServerEvent( "SendMoney", localPlayer, amount )
			else
				-- Otherwise let's output an error message
				outputChatBox( "Bad amount!" )
			end

			-- Let's put our fixed number into the edit box too
			guiSetText( money, amount )
		end
	end, false
)

Server-side

-- Let's initialize a new table to store pending amounts in
local waitlist = { }

-- Once we receive a SendMoney event from the client
addEventHandler( "SendMoney", root,
	function( amount )
		-- Let's convert the sent argument to a number again
		amount = tonumber( amount ) and math.floor( tonumber( amount ) )

		-- If they are who they say they are, and the amount is a (realistic) number
		if ( source == client ) and ( amount ) and ( amount > 0 ) then
			-- Let's add the user and their amount to a table for storage
			waitlist[ client ] = amount

			-- Use this to show myMarker1 for the user
			setElementVisibleTo( myMarker1, client, true )

			-- Output some confirmation
			outputChatBox( amount .. "$ set!", client )
		else
			-- If myMarker1 is showing, hide it
			if ( isElementVisibleTo( myMarker1, client ) ) then
				setElementVisibleTo( myMarker1, client, false )
			end
		end
	end
)

-- Once someone hits myMarker1
addEventHandler( "onMarkerHit", myMarker1,
	function( hitElement, matchingDimension )
		-- If our dimension matches
		if ( matchingDimension ) then
			-- Let's get the amount from the table
			local amount = waitlist[ hitElement ]

			-- If we have an amount stored in the table
			if ( amount ) then
				destroyElement( gold )
				givePlayerMoney( hitElement, amount )
				sendClientMessage( "- " .. getPlayerName( hitElement ) .. " money", root, 255, 23, 23, top, 15 )
				outputChatBox( " ", root, 183, 92, 38 )

				-- Let's hide the marker from the user
				setElementVisibleTo( source, hitElement, false )

				-- Let's reset that pending amount from the table
				waitlist[ hitElement ] = nil
			end
		end
	end
)

-- If someone quits the game, let's be sure to clear their pending amount
addEventHandler( "onPlayerQuit", root,
	function( )
		waitlist[ source ] = nil
	end
)

Tested and working.

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