|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
AvgAlice How do I cheat? Reputation: 0
Joined: 23 Apr 2021 Posts: 3
|
Posted: Fri Apr 23, 2021 12:48 pm Post subject: Adding conditions to hotkey (help) |
|
|
Hello, I've got my first trainer created, used the generic trainer generator to do it, and I need some help setting conditions on a hotkey..
I have a value that represents a timer in a 4 byte value (60=1 second)
I was able to create hotkeys for said value to increase, decrease, set as, etc.
However, if the timer is decreased past 0, it will skip over the scripts that are called at the end of the timer
In my case, i have a hotkey that will decrease [value] by 600 (10 seconds)
what I'm trying to accomplish is:
OnHotkey()
If [value]<= 600, set [value] = 60
if [value]>=600, decrease [value] by 600.
I'm not very familiar with Lua or assembly, hoping this doesn't end up being a convoluted solution
I've seen solutions that involve readInteger("game+addr") and using that value in a variable, but that wasn't working how I had hoped.
Let me know if there's any other info I can provide to help.
Thanks in advance!
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sat Apr 24, 2021 6:12 am Post subject: |
|
|
Code: |
if (hotkeyIncrease or hotkeyDecrease) then
hotkeyIncrease.destroy();
hotkeyDecrease.destroy();
end
your_address = "write here your address"
hotkeyIncrease = createHotkey(increaseValue, VK_CONTROL) -- modify to your hotkeys..
hotkeyDecrease = createHotkey(decreaseValue, VK_SHIFT) -- modify to your hotkeys..
function increaseValue()
hotkeyFunction(600)
end
function decreaseValue()
hotkeyFunction(-600)
end
function hotkeyFunction(amount)
local value = readInteger(your_address);
if (value >= 600) then
writeInteger(your_address,value+amount);
else
writeInteger(your_address,60);
end
end
|
Edit:
whoops you wanted it inside of a hotkey not a timer, fixed.
_________________
|
|
Back to top |
|
|
AvgAlice How do I cheat? Reputation: 0
Joined: 23 Apr 2021 Posts: 3
|
Posted: Sat Apr 24, 2021 2:46 pm Post subject: |
|
|
Thank you for your response! after some messing around with it, i was able to get at least the value to show up properly in the console, so at that point the logic started to work.
However, I have other cheats built into my trainer that work great as they are and i would like to try to shoehorn this into the generic script that's generated.
What i'm trying to modify (this is the hotkey function for decreasing the value by 600):
Code: |
function onHotkey1(Hotkey)
--Executed before the hotkey is handled
CETrainer.CHEAT1.setActive(true, 1500)
if gPlaySoundOnAction then
playSound(gActivateSound)
end
end
memrec1_hotkey2.onHotkey=onHotkey1
|
What i currently have:
Code: |
function onHotkey1(Hotkey)
--Executed before the hotkey is handled
total_addr = "GAME.exe+12A41A4"
local value = readInteger(total_addr);
if (value <= 600) then
writeInteger(total_addr, 60)
print("value is less than 600: ", value)
end
if (value >= 9999999) then
writeInteger(total_addr, 60)
print("value is past 0: ", value)
end
CETrainer.CHEAT1.setActive(true, 1500)
if gPlaySoundOnAction then
playSound(gActivateSound)
end
end
memrec1_hotkey2.onHotkey=onHotkey1
|
Currently, this will roll the timer past zero, resulting in a value greater than 9999999 (it's really over 4000000000, but realistically, the value will never go over 59940 due to max timer display being 999)
If my value is at say 500 and i trigger the hotkey that decreases by 600, the value will be over 9999999, but will freeze at that value until i use the hotkey to increase by 600, where it will then be set to 60 as i want it to be.
I'm not sure why it seems to be running the logic after it increases the value via the "cheat"
Do i need to put this logic elsewhere in the script?
Another thought I had was just watch the value to see if it increases to over 9999999 in a loop and automatically change the value to 60 just as a catch all, but i'm not sure how that would be implemented either.
Any help/advice is super appreciated!
Thanks!!
Last edited by AvgAlice on Sun Apr 25, 2021 2:19 pm; edited 1 time in total |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sun Apr 25, 2021 7:42 am Post subject: |
|
|
Try using a min/max, the reason while
Code: |
local value = readInteger(your_address);
if (value >= 600 and value <= 59940) then -- should prevent over/underflow
writeInteger(your_address,math.max(value+amount,59940)); -- does not let you to increase past 59940
else
writeInteger(your_address,math.min(value+amount,60)); -- cannot be set set to anything below 60.
end
|
Or in a single line.
Code: |
function increaseValue()
hotkeyFunction(600)
end
function decreaseValue()
hotkeyFunction(-600)
end
function hotkeyFunction(amount)
local value = readInteger(your_address);
-- amount can be +-600
writeInteger(your_address,math.max(60,math.min(value+amount,59940)) -- 60 <= value <= 59940
end
|
_________________
|
|
Back to top |
|
|
AvgAlice How do I cheat? Reputation: 0
Joined: 23 Apr 2021 Posts: 3
|
Posted: Sun Apr 25, 2021 2:18 pm Post subject: |
|
|
Well, that didn't quite do what I wanted, but I did find a different solution that works for my use case:
Code: |
function onHotkey1(Hotkey)
--Executed before the hotkey is handled
total_addr = "GAME.exe+12A41A4"
local value = readInteger(total_addr);
if (value <= 600 or value >= 59940) then
writeInteger(total_addr,60)
writeInteger(total_addr, value+600)
end
if gPlaySoundOnAction then
playSound(gActivateSound)
end
CETrainer.CHEAT1.setActive(true, 1500)
end
memrec1_hotkey2.onHotkey=onHotkey1
|
To the user, this will make it so it will not decrease the time the time at all if it is below 10 seconds, avoiding rolling past 0.
Thanks again for your help and in pointing me in the right direction!
|
|
Back to top |
|
|
|
|
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
|
|