 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
mben Newbie cheater
Reputation: 0
Joined: 20 Jan 2018 Posts: 14
|
Posted: Thu Jan 25, 2018 1:53 pm Post subject: hotkey to frezze record and change status of checkbox |
|
|
hio, i need a function to first check the status of te checkbox in my form and activate and frezze the record of my script so far i have this but it doesnt work
Code: | function toggleRegister1()
addressList = getAddressList()
normal_health = addressList.getMemoryRecordByDescription("Infinite Health Main Campaign Easy - Hard Mode")
UDF1.CECheckbox1.State =1
if (checkbox_getState(UDF1.CECheckbox1) == 1 ) then
memoryrecord_freeze(normal_health)
else
memoryrecord_unfreeze(normal_health)
UDF1.CECheckbox1.State =0
end
end
createHotkey(toggleRegister1,VK_F7) |
the cheat need be avaliable by click in my checkbox and by hotkey
i have to create 5 more hotkeys in this way, any idea or hint what i am doing wrong? thanks in advance!
|
|
Back to top |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Thu Jan 25, 2018 2:23 pm Post subject: |
|
|
well you're setting the state to 1 and then saying if the state is 1 to freeze the memory record so that should always enable it.
Also, CE has an object oriented setup now as well so you can use eg. UDF.CECheckbox1.Checked = true and normal_health.Active = false
For CE 6.7 you can use something like this:
Code: | function setupScriptHandlers(description, checkboxName, hotkeys)
local mr = AddressList.getMemoryRecordByDescription(description)
if not mr then return nil end
local cb = UDF1[checkboxName]
if not cb then return nil end
local handleScript = function(sender)
local newState
if sender == cb then -- if checkbox then match state
newState = sender.Checked
else -- otherwise hotkey so toggle
newState = not mr.Active
end
-- update states
mr.Active = newState
cb.Checked = newState
end
cb.OnChange = handleScript
return createHotkey(handleScript, hotkeys)
end
setupScriptHandlers('Infinite Health Main Campaign Easy - Hard Mode', 'CECheckbox1', VK_F7) |
Though I'd probably change it to take the actual memory record and checkbox rather than just names/descriptions, that way the memory records could be gotten from descriptions or ids or the selected memrec etc.
Code: | function setupScriptHandlers(mr, cb, hotkeys)
if not mr or mr.ClassName ~= 'TMemoryRecord' or mr.Type ~= vtAutoAssembler then return nil, 'invalid memory record' end
--if not cb or cb.ClassName ~= 'TCECheckbox' then return nil, 'invalid checkbox' end
local handleScript = function(sender)
local newState
if sender == cb then -- if checkbox then match state
newState = sender.Checked
else -- otherwise hotkey so toggle
newState = not mr.Active
end
-- update states
mr.Active = newState
cb.Checked = newState
end
if cb then cb.OnChange = handleScript end -- if we have a checkbox set the event
if hotkeys then
return createHotkey(handleScript, hotkeys) -- can get function from hotkey
end
return handleScript -- in case they _just_ want the function (no cb or hotkeys given)
end
setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Easy - Hard Mode'), UDF1.CECheckbox1, VK_F7) |
|
|
Back to top |
|
 |
mben Newbie cheater
Reputation: 0
Joined: 20 Jan 2018 Posts: 14
|
Posted: Thu Jan 25, 2018 2:38 pm Post subject: |
|
|
FreeER wrote: | well you're setting the state to 1 and then saying if the state is 1 to freeze the memory record so that should always enable it.
Also, CE has an object oriented setup now as well so you can use eg. UDF.CECheckbox1.Checked = true and normal_health.Active = false
For CE 6.7 you can use something like this:
Code: | function setupScriptHandlers(description, checkboxName, hotkeys)
local mr = AddressList.getMemoryRecordByDescription(description)
if not mr then return nil end
local cb = UDF1[checkboxName]
if not cb then return nil end
local handleScript = function(sender)
local newState
if sender == cb then -- if checkbox then match state
newState = sender.Checked
else -- otherwise hotkey so toggle
newState = not mr.Active
end
-- update states
mr.Active = newState
cb.Checked = newState
end
cb.OnChange = handleScript
return createHotkey(handleScript, hotkeys)
end
setupScriptHandlers('Infinite Health Main Campaign Easy - Hard Mode', 'CECheckbox1', VK_F7) |
Though I'd probably change it to take the actual memory record and checkbox rather than just names/descriptions, that way the memory records could be gotten from descriptions or ids or the selected memrec etc.
Code: | function setupScriptHandlers(mr, cb, hotkeys)
if not mr or mr.ClassName ~= 'TMemoryRecord' or mr.Type ~= vtAutoAssembler then return nil, 'invalid memory record' end
--if not cb or cb.ClassName ~= 'TCECheckbox' then return nil, 'invalid checkbox' end
local handleScript = function(sender)
local newState
if sender == cb then -- if checkbox then match state
newState = sender.Checked
else -- otherwise hotkey so toggle
newState = not mr.Active
end
-- update states
mr.Active = newState
cb.Checked = newState
end
if cb then cb.OnChange = handleScript end -- if we have a checkbox set the event
if hotkeys then
return createHotkey(handleScript, hotkeys) -- can get function from hotkey
end
return handleScript -- in case they _just_ want the function (no cb or hotkeys given)
end
setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Easy - Hard Mode'), UDF1.CECheckbox1, VK_F7) |
|
thanks by pointing me to the solution, i will try your example, looks very good, it seems save a lot of code, i will try just get back to my home and update here my status, thank you so much!
UPDATE:
works like a charm if i only make one call to the function
but if i make another just right after, only works the last
i mean if i make this:
Code: | setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Easy - Hard Mode'), UDF1.CECheckbox1, VK_F7)
setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Extreme Mode'), UDF1.CECheckbox2, VK_F8) |
only works the last
|
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Thu Jan 25, 2018 6:54 pm Post subject: |
|
|
I'm not really sure way that is not working for the second. But I don't tend to work with hotkeys.
Hopeful this post will get @FreeER's attention.
_________________
|
|
Back to top |
|
 |
mben Newbie cheater
Reputation: 0
Joined: 20 Jan 2018 Posts: 14
|
Posted: Thu Jan 25, 2018 7:09 pm Post subject: |
|
|
TheyCallMeTim13 wrote: | I'm not really sure way that is not working for the second. But I don't tend to work with hotkeys.
Hopeful this post will get @FreeER's attention. |
thanks but for some weird reason i generate the trainer and works fine, maybe some weird conflict with the window game (Max Payne 3) and the cheat engine window program, i dont know, but the stand alone .exe trainer works fine.
thanks again
|
|
Back to top |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Thu Jan 25, 2018 7:13 pm Post subject: |
|
|
Thanks for the post/notification @TheyCallMeTim13
edit: well glad it works in the trainer lol
There is a small issue with checking the checkbox classname, but that's commented out anyways so I wouldn't expect that to be the issue (it should be TCECheckBox not TCECheckbox).
Hm, double check that you've got everything spelled correctly, one way would be to look at the message returned by the function
Code: | -- corrected function
function setupScriptHandlers(mr, cb, hotkeys)
if not mr or mr.ClassName ~= 'TMemoryRecord' or mr.Type ~= vtAutoAssembler then return nil, 'invalid memory record' end
if not cb or cb.ClassName ~= 'TCECheckBox' then return nil, 'invalid checkbox' end
local handleScript = function(sender)
local newState
if sender == cb then -- if checkbox then match state
newState = sender.Checked
else -- otherwise hotkey so toggle
newState = not mr.Active
end
-- update states
mr.Active = newState
cb.Checked = newState
end
if cb then cb.OnChange = handleScript end -- if we have a checkbox set the event
if hotkeys then
return createHotkey(handleScript, hotkeys) -- can get function from hotkey
end
return handleScript -- in case they _just_ want the function (no cb or hotkeys given)
end
-- misspelled name
hk1, msg1 = setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign EZ - Hard Mode'), UDF1.CECheckBox1, VK_F7)
-- correct
hk1Correct, msg1Correct = setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Easy - Hard Mode'), UDF1.CECheckBox1, VK_F7)
-- misspelled checkbox (apparently CECheckbox2 is ok here lol)
hk2, msg2 = setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Extreme Mode'), UDF1.CECheckox2, VK_F8)
-- can't use string for hotkey, must pass number eg. ('W'):byte(1) or string.byte('W',1)
hk2AlsoBad, msg2AlsoBad = setupScriptHandlers(AddressList.getMemoryRecordByDescription('Infinite Health Main Campaign Extreme Mode'), UDF1.CECheckBox2, 'W')
print(('%s %s'):format(hk1, msg1))
print(('%s %s'):format(hk1Correct, msg1Correct))
print(('%s %s'):format(hk2, msg2))
print(('%s %s'):format(hk2AlsoBad, msg2AlsoBad)) | that example (assuming both memory records exist as named) should give the result Code: | nil invalid memory record
userdata: 000000000AA4FE08 nil
nil invalid checkbox
userdata: 000000000AA59C08 nil
| Note that the last one looks successful because the hotkey was created, however the keys are not set, calling hk2AlsoBad.getKeys() will return nil rather than a table of keys. Could do an additional check in the function and return a message string there if .getKeys() is not set
|
|
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
|
|