Jump to content

help


Hugos

Recommended Posts

Posted

I have a "guiCreateEdit," I need to prohibit the user from entering any characters except numbers. And I need to bring them out using "dxDrawText," but replacing them with "*" (asterisk). How do I do that?

addEvent("edit", true)
function editbox()
	PIN = guiCreateEdit(0, 0, 0, 0, "", false) 
end
addEventHandler("edit", resourceRoot, edit)

function pin()
	dxDrawText(guiGetText(PIN), 0, 0, 100, 100, tocolor(0, 0, 0), 1, Font, "center", "center", true, true, true)
end

(It is string.gsub necessary to use? )

Posted
1 hour ago, Hugos said:

I have a "guiCreateEdit," I need to prohibit the user from entering any characters except numbers. And I need to bring them out using "dxDrawText," but replacing them with "*" (asterisk). How do I do that?


addEvent("edit", true)
function editbox()
	PIN = guiCreateEdit(0, 0, 0, 0, "", false) 
end
addEventHandler("edit", resourceRoot, edit)

function pin()
	dxDrawText(guiGetText(PIN), 0, 0, 100, 100, tocolor(0, 0, 0), 1, Font, "center", "center", true, true, true)
end

(It is string.gsub necessary to use? )

1.

local character
local forbidden_characters = {
	["w"] = "w",
	["a"] = "a",
	["s"] = "s",
	["d"] = "d",
}

function onClientCharacter(char)
	if forbidden_characters[char] then
		character = char
	end
end
addEventHandler("onClientCharacter", getRootElement(), onClientCharacter)

function onClientGUIChanged(element)
	if element then -- add check for your element
		local gui_text = guiGetText(element)
		if gui_text then
			local forbidden_character = character
			local check = forbidden_characters[forbidden_character]
			if check then
				local replace = string.gsub(gui_text, check, "")
				guiSetText(element, replace)
			end
		end
	end
end
addEventHandler("onClientGUIChanged", getRootElement(), onClientGUIChanged)

Tested a bit, and looks like works for typing, you would need to replace string with characters to "" when player paste something. Also you need to fill table with forbidden characters.

https://wiki.multitheftauto.com/wiki/OnClientPaste

  • Like 1
Posted (edited)

All right, I already figured it out. Everything is much easier...

pin = ("" ..string.gsub(guiGetText(PIN), "%D", "").. "")
guiSetText(PIN, pin)

string.gsub - we replace in line "%D" on "" , and all.

  • guiGetText(PIN) - My line with we enter the text;
  • "%D" - Any letter or symbol other than digit;
  • "" - emptiness;
Edited by Hugos
  • Like 1

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