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 


Stop increment if value reache to 100

 
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: Fri Aug 03, 2018 3:18 pm    Post subject: Stop increment if value reache to 100 Reply with quote

I asked posted that "I want add a specif value (suppose 1) to the base address after every 3 seconds. And I don't have any idea about Lua Scripting and how to do that (sorry). If someone could help me out would be really appreciated. Thank you Smile
Base address is 10940148"

then a someone replied me with the code



DoneState = false
local addr = 0x10940148
local val = 1
local function timer_tick(timer)
writeInteger(addr, val + readInteger(addr))
-- writeFloat(addr, val + readFloat(addr))
if DoneState == true then
timer.destroy()
end
end
local someTimer = createTimer(MainForm)
someTimer.Interval = 3000
someTimer.OnTimer = timer_tick




This script is working fine but there is no way to stop it. I asked him to modify it so I can stop it then he replied,

"Timers don't stop for the game, you'd need to find some way to know in the script if the game is paused.

To stop the timer:

Code:
DoneState = true

Just put that in the disable section, and the other in the enable section."




Ok I got it but the only thing I wanna ask is how to stop the increment when my value reaches to 100. If someone modifies it to that, I would not need to stop it every time.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Fri Aug 03, 2018 3:44 pm    Post subject: Re: Stop increment if value reache to 100 Reply with quote

Code:
{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
DoneState = false
local addr = 0x10940148
local val = 1
local function timer_tick(timer)
local v = readInterer(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 = 3000
someTimer.OnTimer = timer_tick
------------------------------ DISABLE ------------------------------
[DISABLE]
if syntaxcheck then return end
DoneState = true -- this stops the timer, when the script is disabled

_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Aug 03, 2018 3:55 pm    Post subject: Reply with quote

original thread: https://forum.cheatengine.org/viewtopic.php?p=5741371#5741371

Not sure why you're creating a new thread.

If all you want is to max at 100, basic logic says to compare the value to 100 before writing
Code:
local maxval = 100
local value = readInteger(addr) + val
if value > maxval then value = maxval end
writeInteger(addr, value)


If you actually want the timer to stop (so it refills health, or whatever, then stops until you reactivate) whenever the new value is 100 (or add an else to the above if statement) set the donestate to true or directly call timer.destroy() or use memrec.Active = false to disable the script and let the disable section run etc.

If you didn't want it to increase when the game is paused you'd have to find someway to check if it's paused (alt-tabbed is pretty simple with getForegroundProcess() ~= getOpenedProcessID())

_________________
https://github.com/FreeER/ has a few CE related repos


Last edited by FreeER on Sat Aug 04, 2018 6:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
danishdanish
Newbie cheater
Reputation: 0

Joined: 15 Mar 2016
Posts: 23

PostPosted: Fri Aug 03, 2018 4:38 pm    Post subject: Re: Stop increment if value reache to 100 Reply with quote

TheyCallMeTim13 wrote:
Code:
{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
DoneState = false
local addr = 0x10940148
local val = 1
local function timer_tick(timer)
local v = readInterer(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 = 3000
someTimer.OnTimer = timer_tick
------------------------------ DISABLE ------------------------------
[DISABLE]
if syntaxcheck then return end
DoneState = true -- this stops the timer, when the script is disabled





I am getting this error
Error:[string "DoneState = false..."]:5: attempt to call a nil value (global 'readInterer')
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Fri Aug 03, 2018 4:43 pm    Post subject: Reply with quote

Opps, typo.
"readInterer" should be "readInteger".

Code:
{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
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 = 3000
someTimer.OnTimer = timer_tick
------------------------------ DISABLE ------------------------------
[DISABLE]
if syntaxcheck then return end
DoneState = true -- this stops the timer, when the script is disabled

_________________
Back to top
View user's profile Send private message Visit poster's website
danishdanish
Newbie cheater
Reputation: 0

Joined: 15 Mar 2016
Posts: 23

PostPosted: Sat Aug 04, 2018 4:52 pm    Post subject: Reply with quote

TheyCallMeTim13 wrote:
Opps, typo.
"readInterer" should be "readInteger".

Code:
{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
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 = 3000
someTimer.OnTimer = timer_tick
------------------------------ DISABLE ------------------------------
[DISABLE]
if syntaxcheck then return end
DoneState = true -- this stops the timer, when the script is disabled



Thank you, its working but for one cycle only, after then (reaching to max health and got damaged again) I have to restart it. Is there any possibility that I would not need to start it again and again, so I can play with satisfaction Very Happy Thanks in adv.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Aug 04, 2018 5:18 pm    Post subject: This post has 1 review(s) Reply with quote

Dude, for real?
Read the comments, the part that says "this stops the timer, if value is > 100"; maybe try and comment out or remove that part so the timer doesn't stop then but only when the script is disabled.

Just in case you don't know what a comment is.
https://en.wikibooks.org/wiki/Lua_Programming/comment

_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sat Aug 04, 2018 6:25 pm    Post subject: Reply with quote

Quote:
maybe try and comment out or remove that part so the timer doesn't stop then
or, you know, use the code I gave earlier, but you have to use a tiny bit of brain power to know where to put it in your (original) code (hint, it's changing what value the writeInteger call writes).

CE is all about figuring out how someone else's stuff works and making it do what you want from the value scanning to the asm hooking, no real reason you shouldn't have to think a bit with lua too unless you specifically ask someone else to do all the work for you (in which case, that's just a table/trainer request!) Smile

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
danishdanish
Newbie cheater
Reputation: 0

Joined: 15 Mar 2016
Posts: 23

PostPosted: Sat Aug 04, 2018 8:37 pm    Post subject: Reply with quote

yay It worked Very Happy Smile Thank you very much. Thank you both of you and FreeER I don't know anything about programming Razz but thanks for your reply. And once again special thanks for TheyCallMeTim13 You are a boss Cool Cool Cool Cool God Bless You.
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