Skip to content

Instantly share code, notes, and snippets.

@FrazzIe
Created July 3, 2019 14:26
Show Gist options
  • Select an option

  • Save FrazzIe/f59813c137496cd94657e6de909775aa to your computer and use it in GitHub Desktop.

Select an option

Save FrazzIe/f59813c137496cd94657e6de909775aa to your computer and use it in GitHub Desktop.
Adapative Card Password Example - FiveM
--[[
Adapative Card Password Example
Schema -> https://adaptivecards.io/explorer/
Designer -> https://adaptivecards.io/designer/
]]--
local attempts = {}
local password = "meep"
local passwordCard = {
["type"] = "AdaptiveCard",
["minHeight"] = "100px",
["body"] = {
{
["type"] = "Container",
["items"] = {
{
["type"] = "TextBlock",
["horizontalAlignment"] = "Left",
["text"] = "Password",
},
{
["type"] = "Input.Text",
["id"] = "password",
["placeholder"] = "Enter Password"
},
{
["type"] = "Container",
["isVisible"] = false,
["items"] = {
{
["type"] = "TextBlock",
["weight"] = "Bolder",
["color"] = "Attention",
["text"] = "Error: Invalid password entered!"
}
}
}
}
}
},
["actions"] = {
{
["type"] = "Action.Submit",
["title"] = "Enter"
}
},
["$schema"] = "http://adaptivecards.io/schemas/adaptive-card.json",
["version"] = "1.2"
}
function showPasswordCard(deferrals, callback, showError, numAttempts)
local card = passwordCard
card.body[1].items[3].isVisible = showError and true or false
if showError and numAttempts then
card.body[1].items[3].items[1].text = "Error: Invalid password entered! (" .. (3 - numAttempts) .. " attempts remaining!)"
end
deferrals.presentCard(card, callback)
print("\x1b[92mCard Sent!\x1b[0m")
end
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
local src = source
deferrals.defer()
Citizen.Wait(50)
print("Deferred \x1b[92m" ..name.."\x1b[0m")
local function passwordCardCallback(data, rawData)
print("\x1b[92mEnter button pressed\x1b[0m")
print("Data: \x1b[97m" .. rawData .. "\x1b[0m")
local match = false
if data then
if data.password then
if data.password == password then
match = true
end
end
end
if not match then
print("\x1b[31mPassword doesn't match, sending another card\x1b[0m")
if not attempts[src] then
attempts[src] = 0
else
attempts[src] = attempts[src] + 1
end
if attempts[src] < 3 then
showPasswordCard(deferrals, passwordCardCallback, true, attempts[src])
else
deferrals.done("You failed all 3 attempts, please try again!")
end
else
deferrals.done();
end
end
showPasswordCard(deferrals, passwordCardCallback)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment