I recently started working on a job system. I was using keyboardInput which @Flatracer gave me. It works perfectly, however I recently was working on a different script, which also uses keyboardInput. Here is the client.lua:
local Job
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
RegisterCommand("job", function()
Job = KeyboardInput("Job:", "", 20)
end, false)
However when I type /job in game it opens up the keyboardInput from my previous script. “Roleplay name:” instead of “Job:”
local Job
Citizen.CreateThread(function ()
while true do
Citizen.Wait(10000)
TriggerServerEvent('salary')
end
end)
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
RegisterCommand("jobs", function()
TriggerServerEvent("jobs")
end, false)
RegisterCommand("job", function()
Job = KeyboardInput("Job:", "", 20)
end, false)
Server.lua:
RegisterNetEvent("jobs")
AddEventHandler("jobs", function(jobs)
TriggerClientEvent("chatMessage", -1, "JOBS", {255,255,255}, "Current Job: "..Job)
TriggerClientEvent("chatMessage", -1, " Other Jobs: Tow | Taxi | Construction")
end)
RegisterServerEvent('salary')
AddEventHandler('salary', function()
local salary = 100
if Job == 'Tow' then
user.addBank(300)
notification('Salary Recieved ' .. playerName )
elseif Job == 'Taxi' then
user.addBank(200)
notification('Salary Recieved ' .. playerName )
elseif Job == 'Construction' then
user.addBank(100)
notification('Salary Recieved ' .. playerName )
else
notification('The job you entered has not been found.' .. playerName )
end
end)
function notification(msg)
SetNotificationTextEntry("STRING")
AddTextComponentString(msg)
DrawNotification(false, false)
end
So, when you enter your job the message, for example, notification('Salary Recieved ' .. playerName ), doesn’t appear?
Edit: Does it add the money to the Bank Account?
If so, that is because you cant use natives serversided, they only work clientsided. So you would have to add a Client Event to draw that message.
I’ve got a couple problems, first off when I type /job it shows me this: http://prntscr.com/h4175b (From my other script)
And I cannot do /jobs as when I do it nothing happens.
Also I am not even sure if its giving me the money because I have no money HUD for some reason lol. That’s not related but I am not sure how to check my money. (Using essentialmode).
Edit: Check if you get any error messages in the RCON Log or the debug log (F8) Edit 2: An Error like this: attempt to concatenate a nil value (global 'Job')