wait() в функции

saspepir

Участник
Автор темы
64
2
Как использовать wait среди функции? Есть поток, но оно все равно не работает
Создание thr:
thr = lua_thread.create_suspended(txyz)
Функция:
function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then 
thr:run()
        wait(1000)
        sampAddChatMessage("nnnnn", -1)
    end
end
 
Решение
Lua:
function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then   
       lua_thread.create(function()
               wait(1000)
               sampAddChatMessage("nnnnn", -1)
       end)  
   end
end
так вроде

или так

Lua:
local thr = lua_thread.create_suspended(function()
    --code
end)

function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then
        thr:run()
    end
end

saspepir

Участник
Автор темы
64
2
вэйт надо в thr, ты же его запускаешь
у меня thr на функцию эту. А если просто thr:run оставить то функция потока не работает
ты ведь про то, чтобы сделать так?
Lua:
thr = lua_thread.create_suspended(thread_function)
и в функции
Lua:
function thread_function() --potok
    sampAddChatMessage("aaaaaaaaaaaaaaaaa", -1)
    wait(100)
    sampAddChatMessage("aaaaaaaaaaaaaaaaa", -1)
end
 

ID_Heaven

Известный
810
284
Lua:
function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then   
       lua_thread.create(function()
               wait(1000)
               sampAddChatMessage("nnnnn", -1)
       end)  
   end
end
так вроде

или так

Lua:
local thr = lua_thread.create_suspended(function()
    --code
end)

function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then
        thr:run()
    end
end
 

saspepir

Участник
Автор темы
64
2
Lua:
function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then  
       lua_thread.create(function()
               wait(1000)
               sampAddChatMessage("nnnnn", -1)
       end) 
   end
end
так вроде

или так

Lua:
local thr = lua_thread.create_suspended(function()
    --code
end)

function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then
        thr:run()
    end
end
во втором случае крашит когда беру статус потока, можешь помочь?
получаю статус и крашит:
lua_thread.create(function()
    strr = lua_thread:status()
end)
 

ID_Heaven

Известный
810
284
можешь помочь?
вряд ли, попробуй написать там, отвечают/помогают быстро
 

saspepir

Участник
Автор темы
64
2
Lua:
function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then  
       lua_thread.create(function()
               wait(1000)
               sampAddChatMessage("nnnnn", -1)
       end) 
   end
end
так вроде

или так

Lua:
local thr = lua_thread.create_suspended(function()
    --code
end)

function txyz(targetX,targetY,targetZ)
    setCharCoordinates(PLAYER_PED, targetX, targetY, targetZ)
    X, Y, Z = getCharCoordinates(PLAYER_PED)
    if X>targetX-3 and X<targetX+3 and Y>targetY-3 and Y<targetY+3 then
        thr:run()
    end
end
а можно как то вообще удалить этот поток после end) или он сам удаляется?