Difference between revisions of "Tutorials:Lua:Setup Auto Attach"

From Cheat Engine
Jump to navigation Jump to search
Line 20: Line 20:
 
local function autoAttachTimer_tick(timer) ---- Timer tick call back
 
local function autoAttachTimer_tick(timer) ---- Timer tick call back
 
if autoAttachTimerTickMax > 0 and autoAttachTimerTicks >= autoAttachTimerTickMax then
 
if autoAttachTimerTickMax > 0 and autoAttachTimerTicks >= autoAttachTimerTickMax then
timer.destroy() ---- Destory timer if max ticks is reached
+
timer.destroy() ---- Destroy timer if max ticks is reached
 
end
 
end
 
if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then ---- Check if process is running
 
if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then ---- Check if process is running
timer.destroy() ---- Destory timer
+
timer.destroy() ---- Destroy timer
 
openProcess(PROCESS_NAME) ---- Open the process
 
openProcess(PROCESS_NAME) ---- Open the process
 
end
 
end
Line 42: Line 42:
 
<span style="color:rgb(249, 38, 114);">local</span> <span style="color:rgb(249, 38, 114);">function</span> <span style="color:rgb(166, 226, 46);">autoAttachTimer_tick</span><span style="color:rgb(248, 248, 242);">(timer)</span> <span style="color:rgb(117, 113, 94);">---- Timer tick call back</span>
 
<span style="color:rgb(249, 38, 114);">local</span> <span style="color:rgb(249, 38, 114);">function</span> <span style="color:rgb(166, 226, 46);">autoAttachTimer_tick</span><span style="color:rgb(248, 248, 242);">(timer)</span> <span style="color:rgb(117, 113, 94);">---- Timer tick call back</span>
 
   <span style="color:rgb(249, 38, 114);">if</span> autoAttachTimerTickMax &gt; <span style="color:rgb(174, 129, 255);">0</span> <span style="color:rgb(249, 38, 114);">and</span> autoAttachTimerTicks &gt;= autoAttachTimerTickMax <span style="color:rgb(249, 38, 114);">then</span>
 
   <span style="color:rgb(249, 38, 114);">if</span> autoAttachTimerTickMax &gt; <span style="color:rgb(174, 129, 255);">0</span> <span style="color:rgb(249, 38, 114);">and</span> autoAttachTimerTicks &gt;= autoAttachTimerTickMax <span style="color:rgb(249, 38, 114);">then</span>
       timer.destroy() <span style="color:rgb(117, 113, 94);">---- Destory timer if max ticks is reached</span>
+
       timer.destroy() <span style="color:rgb(117, 113, 94);">---- Destroy timer if max ticks is reached</span>
 
   <span style="color:rgb(249, 38, 114);">end</span>
 
   <span style="color:rgb(249, 38, 114);">end</span>
 
   <span style="color:rgb(249, 38, 114);">if</span> getProcessIDFromProcessName(PROCESS_NAME) <span style="color:pink;">~=</span> <span style="color:rgb(174, 129, 255);">nil</span> <span style="color:rgb(249, 38, 114);">then</span> <span style="color:rgb(117, 113, 94);">---- Check if process is running</span>
 
   <span style="color:rgb(249, 38, 114);">if</span> getProcessIDFromProcessName(PROCESS_NAME) <span style="color:pink;">~=</span> <span style="color:rgb(174, 129, 255);">nil</span> <span style="color:rgb(249, 38, 114);">then</span> <span style="color:rgb(117, 113, 94);">---- Check if process is running</span>
       timer.destroy() <span style="color:rgb(117, 113, 94);">---- Destory timer</span>
+
       timer.destroy() <span style="color:rgb(117, 113, 94);">---- Destroy timer</span>
 
       openProcess(PROCESS_NAME) <span style="color:rgb(117, 113, 94);">---- Open the process</span>
 
       openProcess(PROCESS_NAME) <span style="color:rgb(117, 113, 94);">---- Open the process</span>
 
   <span style="color:rgb(249, 38, 114);">end</span>
 
   <span style="color:rgb(249, 38, 114);">end</span>

Revision as of 06:53, 16 March 2017

How to setup a Lua auto attach script

On the Cheat Engine main form press Ctrl+Alt+L to open the cheat table Lua script form.

Now Let's add the Lua script for the auto attach to process timer.

PROCESS_NAME = 'Tutorial-i386.exe' -------- -------- Auto Attach -------- local autoAttachTimer = nil local autoAttachTimerInterval = 100 local autoAttachTimerTicks = 0 local autoAttachTimerTickMax = 5000 local function autoAttachTimer_tick(timer) ---- Timer tick call back if autoAttachTimerTickMax > 0 and autoAttachTimerTicks >= autoAttachTimerTickMax then timer.destroy() ---- Destroy timer if max ticks is reached end if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then ---- Check if process is running timer.destroy() ---- Destroy timer openProcess(PROCESS_NAME) ---- Open the process end autoAttachTimerTicks = autoAttachTimerTicks + 1 ---- Increase ticks end autoAttachTimer = createTimer(getMainForm()) ---- Create timer with the main form as it's parent autoAttachTimer.Interval = autoAttachTimerInterval ---- Set timer interval autoAttachTimer.OnTimer = autoAttachTimer_tick ---- Set timer tick call back

Set the process name to the process you are attaching to, use the full process name from the process list.

Launch the process then click execute script in the cheat table Lua script form.

Tutorials.Lua.AutoAttachScript.01.png


You should see the process name at the top of the Cheat Engine form.

Tutorials.Lua.AutoAttachScript.02.png


Now when ever the cheat table is opened Cheat Engine will attempt to run the cheat table Lua script which will start the auto attach timer. By default Cheat Engine will ask to run the cheat table Lua script.

Note: You can change what Cheat Engine does with the cheat table Lua script in the Cheat Engine general settings.


See also

Syntax Highlighter