Hugos Posted August 28, 2019 Posted August 28, 2019 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? ) Говорю на русском. Sorry for bad english.
Moderators IIYAMA Posted August 28, 2019 Moderators Posted August 28, 2019 (edited) 38 minutes ago, Hugos said: (It is string.gsub necessary to use? ) Is quickest method, but not the only way. https://stackoverflow.com/questions/47766700/how-to-extract-numbers-from-a-string-in-Lua Edited August 28, 2019 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
sacr1ficez Posted August 28, 2019 Posted August 28, 2019 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 1 Script security
Hugos Posted August 29, 2019 Author Posted August 29, 2019 (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 August 29, 2019 by Hugos 1 Говорю на русском. Sorry for bad english.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now