Jump to content

Remove all characters


Zcraks

Recommended Posts

local function backspacePress ( button, press )
	if button == 'backspace' and press then
		if value ~= 'none' then
			editBox[value] = utf8.sub(editBox[value], 1,utf8.len(editBox[value])-1)
		end
    end
end
addEventHandler("onClientKey", root, backspacePress )

How do I create a condition where if a player presses the "backspace" button, the characters are deleted until the player releases the button ?

Link to comment
  • Moderators
2 hours ago, Zcraks said:

How do I create a condition where if a player presses the "backspace" button

Doesn't the event onClientKey detects hold? hmmm

 

Well if it doesn't:

local nextCharacterRemoveTime = 0
local characterRemoveInterval = 200
function checkCharacterRemove ()
	if getKeyState ( "backspace" ) then -- https://wiki.multitheftauto.com/wiki/GetKeyState
		local timeNow = getTickCount()
		if timeNow > nextCharacterRemoveTime then
			nextCharacterRemoveTime = timeNow + characterRemoveInterval
			-- strip the string!
		end
	end
end



function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
	if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then
	    local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
		if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
			for i, v in ipairs( aAttachedFunctions ) do
				if v == func then
					return true
				end
			end
		end
	end
	return false
end

local function backspacePress ( button, press )
	if button == 'backspace' then
		if press then
			if not isEventHandlerAdded("onClientRender", root, checkCharacterRemove ) then
				addEventHandler("onClientRender", root, checkCharacterRemove)
			end
    	elseif isEventHandlerAdded("onClientRender", root, checkCharacterRemove ) then
			removeEventHandler("onClientRender", root, checkCharacterRemove)
		end
	end
end
    

 

  • Like 1
Link to comment
9 hours ago, IIYAMA said:

Doesn't the event onClientKey detects hold? hmmm

 

Well if it doesn't:

Actually it does, you can use the second argument to detect if he's still pressing "holding" or not, so if he released the key this means he's not holding it anymore.

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