Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Help LUA REGENERATION CODE

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
danishdanish
Newbie cheater
Reputation: 0

Joined: 15 Mar 2016
Posts: 23

PostPosted: Mon Nov 08, 2021 4:52 am    Post subject: Help LUA REGENERATION CODE Reply with quote

Hello everyone.
First of all I don't know a bit about programming and I needed a code that would generate suns every second in Plants vs zombie game only when the value is under 100, so i asked somebody and he wrote me this code below.

DoneState = false
local addr = 0x10940148
local val = 1
local function timer_tick(timer)
local v = readInteger(addr) -- read value
if v < 100 then -- check value
writeInteger(addr, val + v) -- write value
else
DoneState = true -- this stops the timer, if value if > 100
end
if DoneState == true then
timer.destroy()
end
end

if syntaxcheck then return end
local someTimer = createTimer(MainForm)
someTimer.Interval = 1000
someTimer.OnTimer = timer_tick



The code was working long time ago. It was more than 2 years ago. and Ive emailed this code to myself.
Today I wanted to play the game with this same script but this isn't seem to be working now.

Any help would be greatly appreciated.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Mon Nov 08, 2021 5:03 am    Post subject: Reply with quote

Firstly, use code tags when submitting code [ code ] ... [ /code ] (without spaces). Secondly, the address here; local addr = 0x10940148 will have changed and that's the reason why it's no longer working. Also you will want to assign nil to the timer.

Code:

if DoneState then -- "== true isn't required here"
  timer.destroy()
  timer = nil
end
Back to top
View user's profile Send private message
danishdanish
Newbie cheater
Reputation: 0

Joined: 15 Mar 2016
Posts: 23

PostPosted: Fri Nov 12, 2021 7:33 am    Post subject: Reply with quote

My address is correct. The code is not working.

Anyone else can help me out ? Please .
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Fri Nov 12, 2021 10:06 am    Post subject: Re: Help LUA REGENERATION CODE Reply with quote

danishdanish wrote:

The code was working long time ago. It was more than 2 years ago. and Ive emailed this code to myself.
Today I wanted to play the game with this same script but this isn't seem to be working now.

Any help would be greatly appreciated.


The game will no doubtedly have received updates and therefore the address that holds the value you want to manipulate will have changed also. Having taken a look, this code works absolutely fine without issue. (I can't say for the address but the code works fine).

Code:

{$LUA}
if syntaxcheck then return end
{$ASM}
[ENABLE]
{LUA}
local DoneState = false
local addr = 0x10940148
local val = 1

local t = createTimer(getMainForm())
t.Interval = 1000
t.OnTimer = function()
            local v = readInteger(addr) -- read value

            if v < 100 then -- check value
               writeInteger(addr, val + v) -- write value
            else
               print('Timer finished')
               DoneState = true -- this stops the timer, if value if > 100
            end
            if DoneState then
               print('Timer destroyed')
               t.destroy()
               t = nil
            end
end
{$ASM}
[DISABLE]
{$LUA}
if t then
 t.destroy()
 t = nil
end
Back to top
View user's profile Send private message
danishdanish
Newbie cheater
Reputation: 0

Joined: 15 Mar 2016
Posts: 23

PostPosted: Sun Nov 14, 2021 1:22 am    Post subject: Reply with quote

Figured out. The problem was with this line

"print('Timer finished')
DoneState = true -- this stops the timer, if value if > 100"

I comment it out and the code is now working fine.

Anyways Thanks For your time. I greatly appreciate.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Sun Nov 14, 2021 11:42 am    Post subject: Reply with quote

danishdanish wrote:
Figured out. The problem was with this line

"print('Timer finished')
DoneState = true -- this stops the timer, if value if > 100"

I comment it out and the code is now working fine.

Anyways Thanks For your time. I greatly appreciate.


The code was working fine even with that line uncommented. I know because I tested it.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sun Nov 14, 2021 12:27 pm    Post subject: This post has 1 review(s) Reply with quote

You need "if syntaxcheck then return end" in every {$lua} block.
This doesn't work:
Code:
{$lua}
if syntaxcheck then return end
{$asm}
[ENABLE]
{$lua}
print'Script Enabled'
{$asm}

[DISABLE]
{$lua}
print'Script Disabled'
{$asm}
"Script Enabled" / "Script Disabled" will be printed when the script is saved.
This works:
Code:
[ENABLE]
{$lua}
if syntaxcheck then return end
print'Script Enabled'
{$asm}

[DISABLE]
{$lua}
if syntaxcheck then return end
print'Script Disabled'
{$asm}
This only prints when the script is actually enabled / disabled.

Also, you forgot the $ in "{$LUA}" after [ENABLE] in this post:
https://forum.cheatengine.org/viewtopic.php?p=5775086#5775086

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Wed Nov 17, 2021 1:35 am    Post subject: Reply with quote

Code:
{$lua}
[ENABLE]
--DoneState = false --First of all we don't need that
local addr = 0x10940148
local val = 1
local t = createTimer(nil)
t.Interval = 1000
t.OnTimer = function()
local v = readInteger(addr)
if v >= 100 then
return --Forcing to return if v is bigger or equals 100 e.g. do not write value
end
writeInteger(addr,v + val)
end
[DISABLE]
t.destroy()
t = nil
{$asm}

I haven't checked the code yet, but maybe it might be working

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites