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 


Confused on how to use lua properly

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
greatveemon
Cheater
Reputation: 0

Joined: 26 Feb 2010
Posts: 43

PostPosted: Thu Sep 21, 2017 4:29 pm    Post subject: Confused on how to use lua properly Reply with quote

Been searching and reading different topic for hours but I can't really find a really helpful lua for CE tutorial around here. I already have some knowledge on lua but I still can't figure out how to apply this with CE. I followed this tutorial, but now what? Is this can only be use on cheat table? or can I still use this on AA?

Anyway, what I just wanted to do is add a function on a cheat table where a pointer address(es) could copy it's own current value and assign itself to the other hotkey. I mean if I press 'Alt+1', the current value of that address will assign/reassign/overwrite on an hotkey 'Ctrl+1'. I hope this is clear.

Thanks in advance.
Cheers
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 12

Joined: 09 Aug 2013
Posts: 344

PostPosted: Thu Sep 21, 2017 9:56 pm    Post subject: Reply with quote

Yeah, there's not really any 1 good place to learn how to use lua in CE, though there is some documentation on various objects/function in the celua.txt file included with CE it doesn't really tell you where you can use lua.

You can use lua in the cheat engine lua table, same place that CE puts the generated code for trainers, as well as in auto assembler scripts by adding {$lua} with the caveat that it runs at the time you enable the script and you can return a string of AA code that it'll be replaced with. You can do more but it requires more explanation/code (see the lua template included with CE). {$asm} ends the lua block btw. I've mostly learned by browsing the forum and a few cheat tables.

Anyways, so you want to be able to press a hotkey and have the value of one memory record copied to another? Not really clear but it sounds kind of like that.

Simple enough:

Code:

{$lua}
[ENABLE]
-- ^ leave out if put in cheat table lua script, eg. trainers

-- global name so make sure it's unique, or if not destroying it feel free to make it local
local getmr = getAddressList().getMemoryRecordByDescription
testing_hotkey = createHotkey(function(sender)
  local mr1 = getmr("memory record name to copy")
  local mr2 = getmr("memory record name to overwrite")
  mr2.Value = mr1.Value
end, {VK_MENU, VK_1})

-- v leave out if put in cheat table lua script, eg. trainers
[DISABLE]
-- destroys / disables the hotkey
testing_hotkey.destroy()


You could get more complicated and have CE loop through all memory records and check if they have a hotkey for ctrl+1 but unless that's changing there's not really any point.
Back to top
View user's profile Send private message
greatveemon
Cheater
Reputation: 0

Joined: 26 Feb 2010
Posts: 43

PostPosted: Fri Sep 22, 2017 2:45 am    Post subject: Reply with quote

so in AA this would be something like this?

Code:
{$lua}
[ENABLE]
-- insert lua code to enable the cheat here

[DISABLE]
-- insert lua code to disable the cheat here

{$asm}
[ENABLE]
-- insert asm code to enable the cheat here

[DISABLE]
-- insert asm code to disable the cheat here


or I should merge asm and lua in the single enable/disable? and can I use the variable globally? like I can put it outside of ENABLE and DISABLE? and does CE lua supports io? like I could read/write onto a xml/text file?
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 12

Joined: 09 Aug 2013
Posts: 344

PostPosted: Fri Sep 22, 2017 6:01 am    Post subject: Reply with quote

Single ENABLE/DISABLE (you can use multiple lua blocks if necessary, just keep in mind that all lua blocks run when the script is enabled), yes they'll be global if you don't declare it as local, and yes CE supports IO Smile

You can see various short examples I've created here (most are lua based): https://github.com/FreeER/CE-Examples

Not to say they're great or anything but other than browsing the forum, celua.txt/main.lua (<- about the same info as the wiki if not slightly more updated), and CE's source, it's one of the few places I know of to find any info.
Back to top
View user's profile Send private message
greatveemon
Cheater
Reputation: 0

Joined: 26 Feb 2010
Posts: 43

PostPosted: Fri Sep 22, 2017 7:35 am    Post subject: Reply with quote

oh.. thanks. will look upon it. Very Happy

Last, just curious. How to do you get the address by registered symbol from other AA codes?

When I'm using getAddress('insertRegisteredSymbolHere'), it doesn't show up the correct address but some gibberish random values. But when I'm adding the symbol manually on the table and putting the it on the pointer textbox, it shows the correct address.

I have no problem on using 'getAddressList().getMemoryRecordByDescription' (which is probably also working with no problem), but I think it would be a little practical if I can get the address(es) directly based on the registered symbol.
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 12

Joined: 09 Aug 2013
Posts: 344

PostPosted: Fri Sep 22, 2017 7:47 am    Post subject: Reply with quote

Keep in mind that getAddress returns a number and if you just print that it's not going to look the same as the addresses that CE shows in hex Smile eg.

Code:
addr = getAddress('Tutorial-i386.exe+4')+0x8
print(addr)
print(('%X'):format(addr))

-- result
4194316
40000C
Back to top
View user's profile Send private message
greatveemon
Cheater
Reputation: 0

Joined: 26 Feb 2010
Posts: 43

PostPosted: Fri Sep 22, 2017 8:03 am    Post subject: Reply with quote

Tried that. and still doesn't work. There is a very big difference. Just going to stick with the 'By description' method. Thanks anyway. Smile

I also saw this isKeyPressed on the documentation. Isn't this is almost as the same as the hotkey? I just need to put this on a conditional statement.
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 12

Joined: 09 Aug 2013
Posts: 344

PostPosted: Fri Sep 22, 2017 8:10 am    Post subject: Reply with quote

Quote:
Just going to stick with the 'By description' method.
Whatever works Smile

Quote:
I also saw this isKeyPressed on the documentation. Isn't this is almost as the same as the hotkey? I just need to put this on a conditional statement.
Kind of, you'd need to put it somewhere that it'd constantly run (like creating a timer or thread) and then you'd use if statements to check each key and do whatever you want when they all pass. Of course if you already have a construct (hotkey) that does all of that for you then why do it manually?
Back to top
View user's profile Send private message
greatveemon
Cheater
Reputation: 0

Joined: 26 Feb 2010
Posts: 43

PostPosted: Fri Sep 22, 2017 11:53 am    Post subject: Reply with quote

Quote:
Of course if you already have a construct (hotkey) that does all of that for you then why do it manually?


because of chances that I could just use array of virtual keys and aligned it with the array on where I will temporary store the values. Just to lessen duplicating of codes.
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