- 370
- 75
- Версия MoonLoader
- Другое
Почему когда скрипт активен и я ввожу что-то в чат, то в чат пишется сначала то что я нажал, а затем то на что надо было подменить? Вроде блокирую через
consumeWindowMessage
@chapo
consumeWindowMessage
Lua:
local chatReplaceVar = -1
local inputIndex = 1
local replacingString = ""
local lastKeyTime = 0
local keyDelay = 100
function main()
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand('replaceon', function(param)
if param and param ~= "" then
chatReplaceVar = tonumber(param)
printChat(('Подмена ввода включена: '..tostring(chatReplaceVar)))
else
chatReplaceVar = 123456
printChat(('Подмена ввода включена: 123456'))
end
replacingString = tostring(chatReplaceVar)
inputIndex = 1
end)
sampRegisterChatCommand('replaceoff', function()
chatReplaceVar = -1
inputIndex = 1
printChat(('Подмена ввода отключена'))
end)
printChat(('Скрипт загружен. Команды: /replaceon [число] /replaceoff'))
while true do
wait(0)
if not sampIsChatInputActive() then
inputIndex = 1
end
end
end
addEventHandler('onWindowMessage', function(msg, wparam, lparam)
if chatReplaceVar == -1 then return end
if not sampIsChatInputActive() then return end
replacingString = tostring(chatReplaceVar)
if msg == 0x0100 then
local currentTime = os.clock() * 1000
if wparam == 8 then
if inputIndex > 1 then
inputIndex = inputIndex - 1
end
return true
end
if wparam == 13 then
inputIndex = 1
return false
end
if inputIndex <= #replacingString then
local nextDigit = tonumber(string.sub(replacingString, inputIndex, inputIndex))
if currentTime - lastKeyTime > keyDelay then
keyStroke(nextDigit, 100)
inputIndex = inputIndex + 1
lastKeyTime = currentTime
consumeWindowMessage(true, true)
return true
else
consumeWindowMessage(true, false)
return true
end
end
if inputIndex > #replacingString then
consumeWindowMessage(true, true)
return true
end
end
end)
function printChat(text)
sampAddChatMessage(text, -1)
end
function keyStroke(char, delay)
if char == nil then return end
local key = tonumber(char)
if not key or key < 0 or key > 9 then return end
local vkCode = 0x30 + key
lua_thread.create(function()
setVirtualKeyDown(vkCode, true)
wait(delay or 500)
setVirtualKeyDown(vkCode, false)
wait(10)
end)
end
@chapo
Последнее редактирование: