really strugling with this LUA script

muythay

Новичок
Автор темы
7
0
hello guys. once again I need simple help from u. im just do dumb.

hw do i make that if gui pops out automatically it chooses correct answear? i just dont get it



my code now :
Код:
local on = require 'lib.samp.events'

function on.onShowDialog(did, style, title, b1, b2, text)
    if id == 16252 then
    end
   
end

Lua:
local ev = require 'lib.samp.events'

function ev.onShowDialog(id, style, title, btn1, btn2, text)
    sampAddChatMessage(id, -1)
    if text:find('Paspausk 1') and id == 16252 then
        sampSendDialogResponse(16252, 1, 4, nil)
        end
    end
end

tried doing this but it still didint work ;/
 

deddosouru

Смотрю аниме, служу Сатане
Друг
2,036
1,323
Lua:
local ev = require 'lib.samp.events'

function ev.onShowDialog(id, style, title, btn1, btn2, text)
    --sampAddChatMessage(id, -1)
    if id == 16252 then
        str = text:match('Paspausk (%d)') --getting needed string
        resp = 3 + tonumber(str) --i think dialog strings starts with 1 so we add 3 to it. because of instructions above
        sampSendDialogResponse(id,1,resp,tostring(resp)) --responding to dialog with string we found
        return false --prevent dialog appear
    end
end
 
  • Нравится
Реакции: muythay и chromiusj

muythay

Новичок
Автор темы
7
0
Lua:
local ev = require 'lib.samp.events'

function ev.onShowDialog(id, style, title, btn1, btn2, text)
    --sampAddChatMessage(id, -1)
    if id == 16252 then
        str = text:match('Paspausk (%d)') --getting needed string
        resp = 3 + tonumber(str) --i think dialog strings starts with 1 so we add 3 to it. because of instructions above
        sampSendDialogResponse(id,1,resp,tostring(resp)) --responding to dialog with string we found
        return false --prevent dialog appear
    end
end
Im really appreciated for your help! I was working into this for hours. I found another method but ur seems way smarter then mine. Maybe u can lead me into way how do I make that it works only then when i press F3? I don't want that to be running all the time.


Lua:
require 'lib.moonloader'
local ev = require 'lib.samp.events'
local key = require 'vkeys'



function ev.onShowDialog(id, style, title, button1, button2, text)
    print(id)
    --AFK
    if and id == 16252 then
        if text:find('%s*{47AB3F}%d%..+') then
            local index = text:match('%s*{47AB3F}(%d)%..+')
            if tonumber(index) == 1 then
                sampSendDialogResponse(id, 1, 3, _)
                elseif tonumber(index) == 2 then
                sampSendDialogResponse(id, 1, 4, _)
                elseif tonumber(index) == 3 then
                sampSendDialogResponse(id, 1, 5, _)
                elseif tonumber(index) == 4 then
                sampSendDialogResponse(id, 1, 6, _)
            end
        end
        return false
    end
end
 

Иглобрюх

Активный
248
74
Im really appreciated for your help! I was working into this for hours. I found another method but ur seems way smarter then mine. Maybe u can lead me into way how do I make that it works only then when i press F3? I don't want that to be running all the time.


Lua:
require 'lib.moonloader'
local ev = require 'lib.samp.events'
local key = require 'vkeys'



function ev.onShowDialog(id, style, title, button1, button2, text)
    print(id)
    --AFK
    if and id == 16252 then
        if text:find('%s*{47AB3F}%d%..+') then
            local index = text:match('%s*{47AB3F}(%d)%..+')
            if tonumber(index) == 1 then
                sampSendDialogResponse(id, 1, 3, _)
                elseif tonumber(index) == 2 then
                sampSendDialogResponse(id, 1, 4, _)
                elseif tonumber(index) == 3 then
                sampSendDialogResponse(id, 1, 5, _)
                elseif tonumber(index) == 4 then
                sampSendDialogResponse(id, 1, 6, _)
            end
        end
        return false
    end
end
code:
require "lib.moonloader"

function main()
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            act = not act
            sampAddChatMessage(act and "enabled" or "disabled", 0xFFFFFF)
        end
    end
end
 
  • Нравится
  • Bug
Реакции: Sam201, muythay и Neon3333

muythay

Новичок
Автор темы
7
0
code:
require "lib.moonloader"

function main()
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            act = not act
            sampAddChatMessage(act and "enabled" or "disabled", 0xFFFFFF)
        end
    end
end
Im really appreciated for your help! Its nice to know that I already found good way to make it.
Lua:
function main()
    while not isSampAvailable() do wait(0) end
    print('KODAS VEIKIA')

    while true do
        wait(0)

        if wasKeyPressed(key.VK_F3) then
            afk = not afk
            if afk then
                sampAddChatMessage('{2b9300}Ijungei AFK bota') else sampAddChatMessage ('{f44336}Isjungei AFK bota')
            end
        end
    end
end



Now the last thing im still working on. The threads... I was trying to implement

Lua:
function timeris()
    timer = math.random(5000, 10000)
    wait(timer)
end

Into already existing code like that.

Lua:
        if text:find('%s*{47AB3F}%d%..+') then
            local index = text:match('%s*{47AB3F}(%d)%..+')
            lua_thread.create(timeris)
            if tonumber(index) == 1 then



All day working on it and I still dont get why doesnt it work as it should? Im still new. But starting to feel LUA language pretty quickly which is nice. Thanks to you people!
 

Иглобрюх

Активный
248
74
Im really appreciated for your help! Its nice to know that I already found good way to make it.
Lua:
function main()
    while not isSampAvailable() do wait(0) end
    print('KODAS VEIKIA')

    while true do
        wait(0)

        if wasKeyPressed(key.VK_F3) then
            afk = not afk
            if afk then
                sampAddChatMessage('{2b9300}Ijungei AFK bota') else sampAddChatMessage ('{f44336}Isjungei AFK bota')
            end
        end
    end
end



Now the last thing im still working on. The threads... I was trying to implement

Lua:
function timeris()
    timer = math.random(5000, 10000)
    wait(timer)
end

Into already existing code like that.

Lua:
        if text:find('%s*{47AB3F}%d%..+') then
            local index = text:match('%s*{47AB3F}(%d)%..+')
            lua_thread.create(timeris)
            if tonumber(index) == 1 then



All day working on it and I still dont get why doesnt it work as it should? Im still new. But starting to feel LUA language pretty quickly which is nice. Thanks to you people!
math.random() is pseudo random. If you want create random delay use this function: https://www.blast.hk/threads/170556/#post-1269739

code:
require "lib.moonloader"

function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage("Loaded", 0x00FF00)
    sampRegisterChatCommand("test", function()
        sampAddChatMessage("math.random(): "..math.random(5000, 10000), 0xFFFFFF)
        sampAddChatMessage("random(): "..random(5000, 10000), 0xFFFFFF)
    end)
    sampRegisterChatCommand("test_delay", function()
        lua_thread.create(function()
            local delay = random(5000, 10000)
            sampAddChatMessage("Generated delay: "..delay, 0xFFFFFF)
            wait(delay)
            sampAddChatMessage("Delay ended", 0xFFFFFF)
        end)
    end)
    sampRegisterChatCommand("reload", function()
        thisScript():reload()
    end)
    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            act = not act
            sampAddChatMessage(act and "enabled" or "disabled", 0xFFFFFF)
        end
    end
end

function random(min, max)
    local kf = math.random(min, max)
    math.randomseed(os.time() * kf)
    local rand = math.random(min, max)
    return tonumber(rand)
end
 
  • Нравится
Реакции: muythay