Jump to content
Enyby

Examples of Lua scripts

Recommended Posts


Frozen values from the search

Search for the number 10.
The first 7 results are frozen with a value of 8.

 

gg.searchNumber('10', gg.TYPE_DWORD)
local t = gg.getResults(7)
for i, v in ipairs(t) do
	t[i].value = '8'
	t[i].freeze = true
end
gg.addListItems(t)

 

Share this post


Link to post
Share on other sites

Saving input between script restarts

local configFile = gg.getFile()..'.cfg'
local data = loadfile(configFile)
if data ~= nil then data = data() end
local input = gg.prompt({'Please input something'}, data)
if input == nil then os.exit() end
gg.saveVariable(input, configFile)

 

Share this post


Link to post
Share on other sites

Performing an action by clicking on the GG icon

function doAction()
	local ret = gg.alert('Here some action', 'OK', 'Cancel', 'Exit')
	if ret == 3 then os.exit() end -- exit from the script
end

gg.setVisible(false)
while true do
	if gg.isVisible() then
		gg.setVisible(false)
		doAction()
	end
	gg.sleep(100)
end

 

Share this post


Link to post
Share on other sites

Performing multiple actions

with multiChoice

local t = gg.multiChoice({'A', 'B', 'C', 'D'})
if t == nil then
    gg.alert('Canceled')
else
    if t[1] then
        gg.alert('do A')
    end
    if t[2] then
        gg.alert('do B')
    end
    if t[3] then
        gg.alert('do C')
    end
    if t[4] then
        gg.alert('do D')
    end
end

with prompt

local t = gg.prompt({'A', 'B', 'C', 'D'}, nil, {'checkbox', 'checkbox', 'checkbox', 'checkbox'})
if t == nil then
    gg.alert('Canceled')
else
    if t[1] then
        gg.alert('do A')
    end
    if t[2] then
        gg.alert('do B')
    end
    if t[3] then
        gg.alert('do C')
    end
    if t[4] then
        gg.alert('do D')
    end
end

 

Share this post


Link to post
Share on other sites

Search and replace text

Up to 32 bytes.

Replace must be same length.

gg.clearResults()

function searchText(text)
	local bytes = gg.bytes(text, 'UTF-8')
	local ret = ''
	for i, b in ipairs(bytes) do
		ret = ret .. ';' .. b
	end
	ret = ret:sub(2)..'::'..#bytes
	return gg.searchNumber(ret, gg.TYPE_BYTE)
end

searchText('rfde')

function replaceText(text)
	local bytes = gg.bytes(text, 'UTF-8')
	local all = gg.getResults(100000)
	local len = #bytes
	for i, t in ipairs(all) do
		t.value = bytes[((i - 1) % len) + 1]
	end
	return gg.setValues(all)
end

replaceText('gold')

If you want UTF-16, replace 'UTF-8' in code to 'UTF-16LE'.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×