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 


Basic Button help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
moon1
How do I cheat?
Reputation: 0

Joined: 11 Apr 2022
Posts: 5

PostPosted: Mon Apr 11, 2022 4:07 am    Post subject: Basic Button help Reply with quote

hello,


I'm fairly new to cheat engine. I generated my own trainer and need help with the ff:

I got the scan already which has 2 hotkey functions:

1st: MB5 Set Value to: 1750
2nd: MB4 Set Value to: 43a

Now, I added a button that says "On" and "Off" (basic button). Basucally, I want the function of the "On" button when clicked to be the "MB5" and the "Off" button to be the "MB4".

Thank you in advance.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Mon Apr 11, 2022 4:36 am    Post subject: Reply with quote

Declare a function that executes the logic based on the keypress for example:
Code:

--VK_XBUTTON1   0x05   X1 mouse button
--VK_XBUTTON2   0x06   X2 mouse button

-- X1 Mouse Button
if isKeyPressed(0x05) then
  local mr = AddressList.getMemoryRecordByDescription('script_description')
  mr.value = 1750
end
Back to top
View user's profile Send private message
moon1
How do I cheat?
Reputation: 0

Joined: 11 Apr 2022
Posts: 5

PostPosted: Mon Apr 11, 2022 9:40 am    Post subject: Reply with quote

Hello, thank you for your response.

I tried your code however, it didn't do anything. Here's the code that I have inside the buttons.


Code:
function CETrainer_CHEATPANELClick(sender)

end

function CETrainer_CEButton1Click(sender)
if isKeyPressed(0x06) then
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = 2000
end
end


function CETrainer_CEButton2Click(sender)
if isKeyPressed(0x05) then
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = '43a'
end
end


attached below is the previous of my simple trainer
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: Mon Apr 11, 2022 11:06 am    Post subject: Reply with quote

well somebody will not have any side buttons in mouse, and the code below that LeFiXER written need to be created in timer and interval which you choose
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Mon Apr 11, 2022 11:43 am    Post subject: Reply with quote

Make sure the key is correct.
Here is a code you can use.

Code:
function MB5()
sleep(100)
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = 2000
end

function MB4()
sleep(100)
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = '43a'
end

CETrainer.CEButton1.OnClick=function()
MB5()
end

CETrainer.CEButton2.OnClick=function()
MB4()
end

if mb5 then mb5.Destroy() mb5=nil end
mb5=createHotkey(MB5, VK_XBUTTON1) --0x05 ?

if mb4 then mb4.Destroy() mb4=nil end
mb4=createHotkey(MB4, VK_XBUTTON2)


For single button, 2 keys, double action:

Code:
local index=2
CETrainer.CEButton1.Caption="ON"

function MB5()
local mr = AddressList.getMemoryRecordByDescription('AOE')
sleep(100)
 if index==1 then
  mr.value = '43a'
  CETrainer.CEButton1.Caption="ON"
  index=2
  else
  mr.value = 2000
  index=1
  CETrainer.CEButton1.Caption="OFF"
 end
end

CETrainer.CEButton1.OnClick=function()
MB5()
end

if mb5 then mb5.Destroy() mb5=nil end
mb5=createHotkey(MB5, VK_XBUTTON1) --0x05 ?

if mb4 then mb4.Destroy() mb4=nil end
mb4=createHotkey(MB5, VK_XBUTTON2)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
moon1
How do I cheat?
Reputation: 0

Joined: 11 Apr 2022
Posts: 5

PostPosted: Mon Apr 11, 2022 12:15 pm    Post subject: Reply with quote

Hello, thank you for the codes @AylinCE. It really works and I appreciate the help.

However, if I want it to be simple for example clicking the button "On" makes the 'AOE' value change from 43a to 3000 and when I click on the "Off" button, it makes the 'AOE' value change back to 43a.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Mon Apr 11, 2022 1:36 pm    Post subject: Reply with quote

I think the first code is suitable for this situation.

Code:
function MB5()
sleep(100)
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = '43a'
end

function MB4()
sleep(100)
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = 3000
end

CETrainer.CEButton1.OnClick=function() --ON
MB5()
end

CETrainer.CEButton2.OnClick=function() --OFF
MB4()
end

if mb5 then mb5.Destroy() mb5=nil end
mb5=createHotkey(MB5, VK_XBUTTON1) --ON key..

if mb4 then mb4.Destroy() mb4=nil end
mb4=createHotkey(MB4, VK_XBUTTON2) --OFF key

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
moon1
How do I cheat?
Reputation: 0

Joined: 11 Apr 2022
Posts: 5

PostPosted: Mon Apr 11, 2022 1:50 pm    Post subject: Reply with quote

AylinCE wrote:
I think the first code is suitable for this situation.

Code:
function MB5()
sleep(100)
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = '43a'
end

function MB4()
sleep(100)
  local mr = AddressList.getMemoryRecordByDescription('AOE')
  mr.value = 3000
end

CETrainer.CEButton1.OnClick=function() --ON
MB5()
end

CETrainer.CEButton2.OnClick=function() --OFF
MB4()
end

if mb5 then mb5.Destroy() mb5=nil end
mb5=createHotkey(MB5, VK_XBUTTON1) --ON key..

if mb4 then mb4.Destroy() mb4=nil end
mb4=createHotkey(MB4, VK_XBUTTON2) --OFF key



Thank you for clarifying this one and providing with a functional code.


How do I create another 2 buttons without the hotkey functions and the scan is labelled as “AS”, what function/s should I use? Or do you have a sample code that I can play with? As in a plain button that does 1 function.

Overview:
(NO HOTKEYS)
scan description: ‘AS’
button 1 is labeled as level 1 and button 2 is labelled as level 2
Level 1 function : if clicked, set AS to 15 and print “Level 1 activated”
Level 2 function:if clicked, set AS to 30 and print “Level 2 activated”

Thank you again in advance!
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Mon Apr 11, 2022 2:45 pm    Post subject: Reply with quote

Code:
CETrainer.CEButton1.OnClick=function() --Button 3 ..
  local mr1 = AddressList.getMemoryRecordByDescription('AS')
  mr1.value = 15
  print("Level 1 Active!")
end

CETrainer.CEButton2.OnClick=function() --Button 4 etc.
  local mr1 = AddressList.getMemoryRecordByDescription('AS')
  mr1.value = 30
  print("Level 2 Active!")
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Mon Apr 11, 2022 3:43 pm    Post subject: This post has 1 review(s) Reply with quote

Not a tutorial, moved to Lua section.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
moon1
How do I cheat?
Reputation: 0

Joined: 11 Apr 2022
Posts: 5

PostPosted: Mon Apr 11, 2022 11:41 pm    Post subject: Reply with quote

Very thankful for this one! Great help!

Last question, is there a way that a Memo can be linked to the button? For example, when I click the button 3 the Memo will display as "Level 1 Activated". If button 4, the Memo will display as "Level 2"

Thank you!
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Tue Apr 12, 2022 2:29 am    Post subject: Reply with quote

A memo box might take up too much space for that.
My advice is to put a label at the bottom of the Trainer form.
Here is your code for both label, note and edit.
(I assume the trainer name is the same)
Edit and use the samples as you wish.

Code:
CETrainer.CEButton1.OnClick=function() --Button 3 ..
  local mr1 = AddressList.getMemoryRecordByDescription('AS')
  mr1.value = 15
  CETrainer.CELabel1.caption="Level 1 Active!"
  --CETrainer.CEMemo1.Add("Level 1 Active!") --Appends to the continuation of the current line.
  --CETrainer.CEMemo1.Lines.Text=("Level 1 Active!") --Clears previous records.
  --CETrainer.CEEdit1.Text="Level 1 Active!"
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
moon1
How do I cheat?
Reputation: 0

Joined: 11 Apr 2022
Posts: 5

PostPosted: Tue Apr 12, 2022 3:47 am    Post subject: Reply with quote

This is very useful! Thank you very much AylinCE!!!
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