Adaptive card not working? Question
What happened?
Adaptive card in playerConnecting: Action.Submit never reaches the presentCard callback
What we're doing: players who connect with a generated name (e.g. QuickLizard4924) get an adaptive card with an Input.Text during deferrals. On submit we call SET_PLAYER_NAME and then deferrals.done().
Setup: FXServer build 38435 (Linux), Lua 5.4 resource. Other resources also defer in playerConnecting (es_extended, ox_inventory, a name check), all finished before the card is shown.
Code (simplified):
AddEventHandler('playerConnecting', function(name, _, deferrals)
local src = source
deferrals.defer()
Wait(0)
deferrals.update('Checking...')
Wait(3000) -- let other resources finish their deferrals
local answer, answered = nil, false
pcall(deferrals.presentCard, json.encode({
['$schema'] = 'http://adaptivecards.io/schemas/adaptive-card.json',
type = 'AdaptiveCard', version = '1.5',
body = {
{ type = 'TextBlock', text = 'Choose your nickname' },
{ type = 'Input.Text', id = 'nickname', maxLength = 24 },
},
actions = { { type = 'Action.Submit', title = 'Continue' } },
}), function(data, rawData)
print('card answer', rawData) -- never printed
answer, answered = data.nickname, true
end)
while not answered do Wait(500) end -- polls the callback result
SetPlayerName(src, answer)
deferrals.done()
end)
How our real code differs from the usual examples:
• presentCard is called through pcall(deferrals.presentCard, card, cb), not deferrals.presentCard(card, cb).
• The callback only stores the answer; the handler's own coroutine polls for it every 500 ms and then calls SetPlayerName and deferrals.done().
• deferrals.presentCard is a callable table in Lua (type() is table, not function), which we first got wrong and skipped the card entirely.
What happens:
• The card renders correctly, the text field works.
• Clicking Continue does nothing: the callback is never called, nothing in the server console, the card stays open.
• Before we added the 3 s wait, the card was visible for a moment and then got replaced by the joined progress text (resource: message) as soon as another resource called update()/done().
Questions:
- Is there anything that prevents the
submitCardresponse from reaching the callback when several resources use deferrals for the same client, or whenpresentCardis called throughpcall? - Is card version
1.5/ a top-levelAction.Submitsupported by the current client UI, or should we use1.0and anActionSet? - Is there a supported way to keep a card with a text input on screen while other resources still call
update()? Re-sending the card resets the input.
Expected result
When i click continue, its should accept the name and let me connect to the server
Reproduction steps
ITs above
Importancy
Unknown
Area(s)
FiveM
Specific version(s)
38435 linux
Additional information
No response
@kFxDaKing I'm not sure, but try adaptive card version 1.0 or 1.2 / 1.3
Could reproduce this on 38435. Your card code is fine (pcall and version 1.5 work), the problem is another resource calling deferrals.update() while the card is open: the client swaps the card for the progress text and it never comes back. Opened a fix: https://github.com/citizenfx/fivem/pull/4399
Until that's in, the only workaround is to present the card after every other resource is done calling update().