detect dialog close

sulovy

Новичок
Автор темы
19
0
en: how to detect when dialog is closed? like when i close dialog id 5001 it should print "Dialog ID: 5001 closed" in chat and how can i make it? in lua
ru: как определить, когда диалог закрыт? например, когда я закрываю диалог с идентификатором 5001, он должен вывести в чате сообщение «Dialog ID: 5001 closed» и как это сделать? в lua
 

Vintik

Через тернии к звёздам
Проверенный
1,563
1,033
Hi.

You should understand, that you can close dialog either with button (for example, press any button at the bottom dialog, press enter/escape) or without button (for example, open a new dialog without closing an old one — and in this case server will not receive information about closing).
Usually you close dialog with button, so let's dive deeper into this case:

You can use SAMP.Lua library, there is a special callback-function, which sends to the server every time you close dialog:
Lua:
sampev.onSendDialogResponse(dialogId, button, listboxId, input)
    -- here's code
end
 

meowprd

Тот самый Котовский
Проверенный
1,302
732
In addition to the previous answer, I can add that you can also use the RPC hook, which will get rid of the samp.events dependency
Lua:
function onSendRpc(id, bs, p, r, oc, st)
  if id == 62 then
    local dialogID = raknetBitStreamReadInt16(bs)
    --Also u can use
    --local button = raknetBitStreamReadInt8(bs)
    --local listitem = raknetBitStreamReadInt16(bs)
    --local inputedText = raknetBitStreamReadString(bs, raknetBitStreamReadInt8(bs))
    sampAddChatMessage(string.format("Sended response for dialog %d", dialogID), -1)
  end
end

-- Or use this method

addEventHandler('onSendRpc', function(id, bs, p, r, oc, st)
  if id == 62 then
    local dialogID = raknetBitStreamReadInt16(bs)
    --Also u can use
    --local button = raknetBitStreamReadInt8(bs)
    --local listitem = raknetBitStreamReadInt16(bs)
    --local inputedText = raknetBitStreamReadString(bs, raknetBitStreamReadInt8(bs))
    sampAddChatMessage(string.format("Sended response for dialog %d", tonumber(dialogID)), -1)
  end
end)

RPC Info:
DialogResponse - ID: 62 // Parameters: INT16 wDialogID, UINT8 bResponse, INT16 wListItem, UINT8 bTextLength, char[] Text
 
Последнее редактирование:
  • Нравится
Реакции: Vintik