onCreate3DText HELP Отобразить измененный текст немедленно

saradaken

Участник
Автор темы
46
6
Версия MoonLoader
Другое
Hello, I have a question. I am trying to do real-time translation. But my problem is that the translated text is not updated in onCreate3DText in real time. I have to walk far away or go into the house and come back out for the translated text to show. How can I solve this problem?
Здравствуйте, у меня есть вопрос. Я пытаюсь сделать перевод в реальном времени. Но моя проблема в том, что переведенный текст не обновляется в onCreate3DText в реальном времени. Мне приходится уходить далеко или заходить в дом и выходить обратно, чтобы переведенный текст появился. Как мне решить эту проблему?


Lua:
local coroutine_running = false 
local last_translation_time = 0 

function translate(text, back, callback)
    if translatedCache[text] then
        if callback then
            callback(translatedCache[text])
        else
            msg("Error: callback function is nil")
        end
        return 
    end

    if coroutine_running then
        return 
    end

    coroutine_running = true
    msg("Translation in progress, please wait...")

    last_translation_time = os.time()

    lua_thread.create(function()
        local sendtext = toSendGet(text) 
        local ilang1, ilang2 = getlang(back) 

        asyncHttpRequest("GET", "https://script.google.com/macros/s/AKfycbxslVceRG2DSUHR3Jlpt69_0TXkzCU3weD2ZRK7JQXyhQYYA0bcekZ5hIqXOtwCOfoz/exec?q="..sendtext.."&source="..lang1.."&target="..lang2,
                         {},
                         function(response) 
                             if response.status_code == 302 then
                                
                                 local redirectUrl = response.text:match('HREF="([^"]+)"')
                                 if redirectUrl then
                                     redirectUrl = redirectUrl:gsub('amp;', '')
                                    
                                     asyncHttpRequest("GET", redirectUrl, {},
                                         function(finalResponse)
                                          
                                             if finalResponse and finalResponse.text then
                                                 msg("Final response text: " .. finalResponse.text)
                                                
                                                 local translatedText = u8:decode(finalResponse.text) 
                                                 translatedCache[text] = translatedText 
                                                 saveCache() 

                                                
                                                 if callback then
                                                     callback(translatedText)
                                                 end
                                                
                                                 msg("Translation complete!")
                                             else
                                                 msg("Final response text is empty or invalid.") 
                                             end
                                             coroutine_running = false 
                                         end,
                                         function(err)
                                             msg("Redirect request failed: "..tostring(err))
                                             coroutine_running = false 
                                         end)
                                 else
                                     msg("Redirect URL not found in response!")
                                     coroutine_running = false
                                 end
                             else
                                 msg("Request failed with status: "..tostring(response.status_code))
                                 coroutine_running = false 
                             end
                         end,
                         function(err) 
                             msg("Request failed: "..tostring(err))
                             coroutine_running = false 
                         end)
    end)
end

function sampev.onCreate3DText(id, color, position, dist, testLOS, attachedPlayerId, attachedVehicleId, text)
    if text.v then
        if translatedCache[text] then
            text = translatedCache[text]
        else
 
            local originalText = text 

            
            local cachedTranslation = loadCache(originalText)
            if cachedTranslation then
                translatedCache[originalText] = cachedTranslation
                text = cachedTranslation
            else
                
                translate(originalText, false, function(text)
                    if text then
                      
                        translatedCache[originalText] = text
                        saveCache() 
                        -- อัพเดตข้อความ 3D text ทันทีหลังแปลเสร็จ
                        text = otext
                    end
                end)
            end
        end
    end

    return {id, color, position, dist, testLOS, attachedPlayerId, attachedVehicleId, text}
end

up
 
Последнее редактирование:

saradaken

Участник
Автор темы
46
6
Server can update new text, then check event for 3dtext - search in lib/samp/events.lua: string, update or edit for 3dtext. It is first.

Second. If updated and saved, if not need change code, please use return all arguments in body code `if`
I can't find anything like that except onRemove3DTextLabel.