ESX Identity Timer help

scripting
esx
coding
timer

#1

So i am looking for some help in making a code that when someone types /charselect 1,2,3 they must wait 5mins before the command is executed.


#2
local timer = false
    

in the command

if charNumber == 1 and timer == false then
  timer = true
  SetTimeout(300000, function()
    timer = false
  end)
  ....

I think this helps


#3

Thanks for the fast reply. However is there a way to put this into a separate resource as the command for the current command is confusing. Or if you can help me put that code into the code below much will be appreciated

TriggerEvent('es:addGroupCommand', 'charselect', "user", function(source, args, user)

  local charNumber = tonumber(args[1])
  
  getCharacters(source, function(data)
  
    if charNumber == 1 then
	
      local data = {
        identifier   = data.identifier,
        firstname  = data.firstname1,
        lastname  = data.lastname1,
        dateofbirth  = data.dateofbirth1,
        sex      = data.sex1,
        height    = data.height1
      }

      if data.firstname ~= '' then
	  
        updateIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)
		
          if callback == true then
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Updated your active character to " .. data.firstname .. " " .. data.lastname .. "!")
          
		  else
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
			
          end
		  
        end)
		
      else
	  
        TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "You don\'t have a character in slot 1!")
		
      end
	  
    elseif charNumber == 2 then
	
      local data = {
        identifier   = data.identifier,
        firstname  = data.firstname2,
        lastname  = data.lastname2,
        dateofbirth  = data.dateofbirth2,
        sex      = data.sex2,
        height    = data.height2
      }

      if data.firstname ~= '' then
	  
        updateIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)

          if callback == true then
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Updated your active character to " .. data.firstname .. " " .. data.lastname .. "!")
          
		  else
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
			
          end
		  
        end)
		
      else
	  
        TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "You don\'t have a character in slot 2!")
		
      end
	  
    elseif charNumber == 3 then
	
      local data = {
        identifier   = data.identifier,
        firstname  = data.firstname3,
        lastname  = data.lastname3,
        dateofbirth  = data.dateofbirth3,
        sex      = data.sex3,
        height    = data.height3
      }

      if data.firstname ~= '' then
	  
        updateIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)
		
          if callback == true then
            
			TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Updated your active character to " .. data.firstname .. " " .. data.lastname .. "!")
          
		  else
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
			
          end
		  
        end)
		
      else
	  
        TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "You don\'t have a character in slot 3!")
		
      end
	  
    else
	
      TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
	  
    end
	
  end)
  
end, function(source, args, user)
  TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end, {help = "/charselect 1,2,3"})

#4
local timer = false
TriggerEvent('es:addGroupCommand', 'charselect', "user", function(source, args, user)

  local charNumber = tonumber(args[1])
  
  getCharacters(source, function(data)
  
    if charNumber == 1 then
	
      local data = {
        identifier   = data.identifier,
        firstname  = data.firstname1,
        lastname  = data.lastname1,
        dateofbirth  = data.dateofbirth1,
        sex      = data.sex1,
        height    = data.height1
      }

      if data.firstname ~= '' then
	  
        updateIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)
		
          if callback == true then
		    if timer == false then 
              TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Updated your active character to " .. data.firstname .. " " .. data.lastname .. "!")
              timer = true
              SetTimeout(300000, function()
                timer = false
              end)
			end		
		  else
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
			
          end
		  
        end)
		
      else
	  
        TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "You don\'t have a character in slot 1!")
		
      end
	  
    elseif charNumber == 2 then
	
      local data = {
        identifier   = data.identifier,
        firstname  = data.firstname2,
        lastname  = data.lastname2,
        dateofbirth  = data.dateofbirth2,
        sex      = data.sex2,
        height    = data.height2
      }

      if data.firstname ~= '' then
	  
        updateIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)

          if callback == true then
		    if timer == false then 
              TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Updated your active character to " .. data.firstname .. " " .. data.lastname .. "!")
              timer = true
              SetTimeout(300000, function()
                timer = false
              end)
			end	
			
		  else
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
			
          end
		  
        end)
		
      else
	  
        TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "You don\'t have a character in slot 2!")
		
      end
	  
    elseif charNumber == 3 then
	
      local data = {
        identifier   = data.identifier,
        firstname  = data.firstname3,
        lastname  = data.lastname3,
        dateofbirth  = data.dateofbirth3,
        sex      = data.sex3,
        height    = data.height3
      }

      if data.firstname ~= '' then
	  
        updateIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)
		
          if callback == true then
		    if timer == false then 
              TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Updated your active character to " .. data.firstname .. " " .. data.lastname .. "!")
              timer = true
              SetTimeout(300000, function()
                timer = false
              end)
			end	
		  else
		  
            TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
			
          end
		  
        end)
		
      else
	  
        TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "You don\'t have a character in slot 3!")
		
      end
	  
    else
	
      TriggerClientEvent('chatMessage', source, "[IDENTITY]", {255, 0, 0}, "Failed To Update Identity!")
	  
    end
	
  end)
  
end, function(source, args, user)
  TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end, {help = "/charselect 1,2,3"})

Dindt test, but i think this is working at 100%


#5

Yeah i tested this out & sadly it doesn’t work. Still sets the players character like normal instead of having to wait. Do you know what else to try?