Hi everyone !
I would like to set a mechanism pretty simple in appearence :
Press ‘E’ to do something.
While something is doing
Press ‘E’ to stop doing this thing
I can’t get it working.
It’s working well if it’s not the same key to do and stop doing but I really want to use the same key.
Here is my code so far. It pops the ‘Press E to do something’, it’s doing the thing and It also pops the ‘Press E to stop doing the thing’ but it doesn’t stop it.
-- Listen for Player to be near something
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
if(IsNearSomething() == 're') then
doRecolt()
elseif(IsNearSomething() == 'tr') then
DisplayHelpText("Appuyez sur ~INPUT_PICKUP~ pour traiter.")
doTreatment()
elseif(IsNearSomething() == 'se') then
DisplayHelpText("Appuyez sur ~INPUT_PICKUP~ pour vendre.")
doSell()
else
isRecolting, isTreating, isSelling = false
end
end
end)
-- Actions de récolte
function doRecolt()
if (isRecolting == false) then
DisplayHelpText("Appuyez sur ~INPUT_PICKUP~ pour récolter.")
else
DisplayHelpText("Appuyez sur ~INPUT_PICKUP~ pour ~r~arrêter~w~ de récolter.")
drawTxt("~b~Récolte~w~ en cours...",10,0,0.4,0.95,0.4,255,255,255,255)
Citizen.Wait(timeForRecolt - 800)
TriggerEvent("player:receiveItem", tonumber(JOBS[jobId].recolt_item_id), 1)
drawTxt("~g~+1~w~".. tostring(JOBS[jobId].recolt_item_libelle),10,0,0.4,0.95,0.4,255,255,255,255)
end
if IsControlJustPressed(1, 38) then -- If INPUT_PICKUP Is pressed (touche E)
isRecolting = not isRecolting
end
end
Do you have any ideas how to perform this trick ? Am I close ?
Edit : The messages from the drawText function doesn’t stay at screen. That’s another problem, if you have a solution I would like too.
Thank’s in advance fellow developers