View previous topic :: View next topic |
Author |
Message |
danishdanish Newbie cheater Reputation: 0
Joined: 15 Mar 2016 Posts: 23
|
Posted: Fri Aug 03, 2018 3:18 pm Post subject: Stop increment if value reache to 100 |
|
|
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 |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Fri Aug 03, 2018 3:44 pm Post subject: Re: Stop increment if value reache to 100 |
|
|
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 |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Fri Aug 03, 2018 3:55 pm Post subject: |
|
|
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())
_________________
Last edited by FreeER on Sat Aug 04, 2018 6:20 pm; edited 1 time in total |
|
Back to top |
|
|
danishdanish Newbie cheater Reputation: 0
Joined: 15 Mar 2016 Posts: 23
|
Posted: Fri Aug 03, 2018 4:38 pm Post subject: Re: Stop increment if value reache to 100 |
|
|
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 |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Fri Aug 03, 2018 4:43 pm Post subject: |
|
|
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 |
|
|
danishdanish Newbie cheater Reputation: 0
Joined: 15 Mar 2016 Posts: 23
|
Posted: Sat Aug 04, 2018 4:52 pm Post subject: |
|
|
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 Thanks in adv.
|
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Aug 04, 2018 5:18 pm Post subject: |
|
|
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 |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Sat Aug 04, 2018 6:25 pm Post subject: |
|
|
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!)
_________________
|
|
Back to top |
|
|
danishdanish Newbie cheater Reputation: 0
Joined: 15 Mar 2016 Posts: 23
|
Posted: Sat Aug 04, 2018 8:37 pm Post subject: |
|
|
yay It worked Thank you very much. Thank you both of you and FreeER I don't know anything about programming but thanks for your reply. And once again special thanks for TheyCallMeTim13 You are a boss God Bless You.
|
|
Back to top |
|
|
|