View previous topic :: View next topic |
Author |
Message |
Turok2 How do I cheat? Reputation: 0
Joined: 16 Feb 2024 Posts: 8
|
Posted: Fri Feb 16, 2024 2:54 pm Post subject: Simple trigger script |
|
|
Hi guys, I'm a simple noob, but I'm very curious . In these two images below, the value of the first string (20002D43A7B) changes on columns 7C and 80, going from 0 (which is normal) to 90 (which is the action I'm interested in). How do I write a script that presses the P key on the keyboard every time the value changes from 0 to 90? Thank you very much, I can't figure it out.
Description: |
|
Filesize: |
10.38 KB |
Viewed: |
1374 Time(s) |
|
Description: |
|
Filesize: |
55.72 KB |
Viewed: |
1374 Time(s) |
|
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Fri Feb 16, 2024 4:21 pm Post subject: |
|
|
No guarantee given, but this will press the P key if the values at both addresses = 90 (hex)
Code: |
[ENABLE]
{$LUA}
if syntaxcheck then return end
if kpTimer then kpTimer.destroy() end
kpTimer = createTimer()
kpTimer.Interval = 200
kpTimer.OnTimer = function()
if readByte(0x20002D43A7C) == 0x90 and readByte(0x20002D43A80) == 0x90 then
doKeyPress(VK_P)
end
end
{$ASM}
[DISABLE]
{$LUA}
if syntaxcheck then return end
kpTimer.destroy()
|
|
|
Back to top |
|
|
Turok2 How do I cheat? Reputation: 0
Joined: 16 Feb 2024 Posts: 8
|
Posted: Fri Feb 16, 2024 4:37 pm Post subject: |
|
|
ok i try it and lua say this message:
[ENABLE]
{$LUA}
if syntaxcheck then return end
if kpTimer then kpTimer.destroy() end
kpTimer = createTimer()
kpTimer.Interval = 200
kpTimer.OnTimer = function()
if readByte(0x20002D43A7C) == 0x90 and readByte(0x20002D43A80) == 0x90 then
doKeyPress(VK_P)
end
end
{$ASM}
[DISABLE]
{$LUA}
if syntaxcheck then return end
kpTimer.destroy()
Script Error:[string "[ENABLE]
..."]:1: unexpected symbol near '['
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Fri Feb 16, 2024 5:41 pm Post subject: |
|
|
In my case the code works fine.
Description: |
|
Filesize: |
62.41 KB |
Viewed: |
1345 Time(s) |
|
_________________
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4307
|
|
Back to top |
|
|
Turok2 How do I cheat? Reputation: 0
Joined: 16 Feb 2024 Posts: 8
|
Posted: Fri Feb 16, 2024 5:53 pm Post subject: |
|
|
i love you all guys, it works! THANK YOU!
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Fri Feb 16, 2024 8:21 pm Post subject: |
|
|
ParkourPenguin wrote: | You're calling destroy twice. I don't know if CE catches it, but it's a bad thing to do. Set the global variable to nil after it's destroyed.
|
Noted, thanks. I seldom use globals and wasn't sure if it was necessary to handle it separately; however, correct me if I'm wrong, the enable/disable sections are independent of one another, aren't they?
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Fri Feb 16, 2024 9:43 pm Post subject: |
|
|
I tried 3 variants and found it works.
v1:
Code: | [ENABLE]
{$LUA}
if syntaxcheck then return end
if kpTimer then kpTimer.destroy() end
kpTimer = createTimer()
kpTimer.Interval = 2000
kpTimer.OnTimer = function()
doKeyPress(VK_P)
print(1000)
end
{$ASM}
[DISABLE]
{$LUA}
-- kpTimer.Enabled = false -- It will return an undefined local error!
if syntaxcheck then return end
if kpTimer then kpTimer.destroy() end -- For the "Disable" switch, it will act as stopping the timer!
|
v2:
Code: | [ENABLE]
{$LUA}
if syntaxcheck then return end
--if kpTimer then kpTimer.destroy() end
kpTimer = createTimer()
kpTimer.Interval = 200
kpTimer.OnTimer = function()
doKeyPress(VK_P)
print(1000)
end
{$ASM}
[DISABLE]
{$LUA}
-- kpTimer.Enabled = false -- It will return an undefined local error!
if syntaxcheck then return end
if kpTimer then kpTimer.destroy() end -- For the "Disable" switch, it will act as stopping the timer!
|
It's especially surprising that scenario 3 stops the timer in case of "active=false".
It's nice that @ParkourPenguin caught this detail.
v3:
Code: | {$LUA}
if syntaxcheck then return end
if kpTimer then kpTimer.destroy() end
[ENABLE]
kpTimer = createTimer()
kpTimer.Interval = 2000
kpTimer.OnTimer = function()
doKeyPress(VK_P)
print(1000)
end
[DISABLE] |
Result:
The following detail is revealed;
script.Active = true
(In the script code; the line of code between the first line and "Disable" is activated (Execute).)
script.Active = false
(All lines are activated except the lines between "Enable" - "Disable")
_________________
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4307
|
Posted: Fri Feb 16, 2024 10:28 pm Post subject: |
|
|
LeFiXER wrote: | the enable/disable sections are independent of one another, aren't they? | They're independent in the sense that only one of them is run at a time.
Basically, the lines after [ENABLE] / [DISABLE] are only kept if the script is being enabled or disabled respectively. Above [ENABLE], it's always kept.
e.g. this script:
Code: | {$lua}
if syntaxcheck then return end
[ENABLE]
print'enabled'
[DISABLE]
print'disabled' |
When this is enabled, CE executes this AA script:
Code: | {$lua}
if syntaxcheck then return end
print'enabled' |
And when it's disabled, it executes this AA script:
Code: | {$lua}
if syntaxcheck then return end
print'disabled' |
Local variables aren't kept between invocations.
Code: | {$lua}
if syntaxcheck then return end
[ENABLE]
local v = 5
print(v) -- prints 5
[DISABLE]
print(tostring(v)) -- prints nil |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Sat Feb 17, 2024 12:18 am Post subject: |
|
|
Thanks for the clarification. Your wisdom is always welcome.
|
|
Back to top |
|
|
Turok2 How do I cheat? Reputation: 0
Joined: 16 Feb 2024 Posts: 8
|
Posted: Sat Feb 17, 2024 1:19 am Post subject: |
|
|
Ok daddy I've created the Lua script by extending it with additional values at other addresses. But I don't want to enter Cheat Engine every time and press Ctrl+Alt+L and click Execute Script. Can I bring it to the initial table, where I marked the red lines, and then activate it by checking the box? Thanks a lot! What a great community!
Description: |
|
Filesize: |
85.03 KB |
Viewed: |
1297 Time(s) |
|
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Sat Feb 17, 2024 3:37 am Post subject: |
|
|
Open the Memory View window > Click Tools on the menu > Select Auto Assemble from this menu > Paste your code in this new window, it will be blank to begin with. You can either use a template by clicking Template on the menu followed by Cheat Table Framework (basic framework for a script), and make sure that the [ENABLE] and [DISABLE] sections have the relevant code. Or you can type in [ENABLE]/[DISABLE] yourself.
It will look similar to what I posted initially at the beginning of this thread.
|
|
Back to top |
|
|
|