So, I’m trying to figure out to use the Native DisplayOnscreenKeyboard properly so that it actually returns a value, and that’s the problem, it doesn’t return a value for me. Here is my code:
function onscreenKeyboard()
local _return = nil
DisplayOnscreenKeyboard(1,"FMMC_KEY_TIP8", "", "", "", "", "", 99)
while true do
DisableAllControlActions(0)
HideHudAndRadarThisFrame()
Citizen.Wait(0)
if UpdateOnscreenKeyboard() == 1 then
_return = GetOnscreenKeyboardResult()
break
elseif UpdateOnscreenKeyboard() == 2 or UpdateOnscreenKeyboard() == 3 then
break
end
end
return _return
end
I tried to test it out but it seems to stop or crash on something… I could use some help on figuring out how to put this into a function of some type.
function KeyboardInput(TextEntry, ExampleText, MaxStringLenght)
-- TextEntry --> The Text above the typing field in the black square
-- ExampleText --> An Example Text, what it should say in the typing field
-- MaxStringLenght --> Maximum String Lenght
AddTextEntry('FMMC_KEY_TIP1', TextEntry) --Sets the Text above the typing field in the black square
DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP1", "", ExampleText, "", "", "", MaxStringLenght) --Actually calls the Keyboard Input
blockinput = true --Blocks new input while typing if **blockinput** is used
while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do --While typing is not aborted and not finished, this loop waits
Citizen.Wait(0)
end
if UpdateOnscreenKeyboard() ~= 2 then
local result = GetOnscreenKeyboardResult() --Gets the result of the typing
Citizen.Wait(500) --Little Time Delay, so the Keyboard won't open again if you press enter to finish the typing
blockinput = false --This unblocks new Input when typing is done
return result --Returns the result
else
Citizen.Wait(500) --Little Time Delay, so the Keyboard won't open again if you press enter to finish the typing
blockinput = false --This unblocks new Input when typing is done
return nil --Returns nil if the typing got aborted
end
end
Example would be this: local Username = KeyboardInput("Name:", "Input Your Username", 20)
How would i print that variable? I tried this but it does not want to work: (In server.lua)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/showid" then
CancelEvent()
chatPrint( 'RPname' )
end
end)
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
You can’t use a client function serversided, also you can trigger chatMessage serversided.
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/showid" then
CancelEvent()
TriggerEvent( 'chatMessage', 'ID: ', { 255, 255, 255 }, 'RPname' )
end
end)
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end