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 


Help with a simple script

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

Joined: 29 Apr 2024
Posts: 5
Location: France

PostPosted: Mon Apr 29, 2024 4:09 pm    Post subject: Help with a simple script Reply with quote

I'm pretty new in Cheat engine and don't know anything about Lua but I think I have to use it.
I'm practicing with creating a cheat trainer for Terraria and here's what I want to do : I have static pointers which point to the X and Y of the player, and I want to create a noclip with these two. I wanted to do a assembler script which when enabled, if you click on the right arrow key, X value is incremented by 10 for example. But I have no idea how to do that, I think I need Lua script but I don't even know if we can enable and disable like an assembler script.

If somebody could lead me I would be very grateful Surprised

_________________
How tf do I cheat ?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 34

Joined: 16 Feb 2017
Posts: 1418

PostPosted: Mon Apr 29, 2024 4:58 pm    Post subject: Reply with quote

It focuses on a single address in the address list and allows you to increase (key: Right) or decrease (key: Left) the value when you give the correct description name (Change "No description").

-- Lua script:
Code:
function icreaseValue(desc,val,ops)

getMemRecByDesc = getAddressList().getMemoryRecordByDescription
CheatEntry=getMemRecByDesc(desc)
  if ops==2 then
    CheatEntry.Value = CheatEntry.Value + tonumber(val)
  elseif ops==1 then
    CheatEntry.Value = CheatEntry.Value - tonumber(val)
  end
end

function keyFunc1() -- decrease
sleep(100)
icreaseValue("No description","10.0",1)
end

function keyFunc2() -- increase
sleep(100)
icreaseValue("No description","10.0",2)
end

if lkey then lkey.Destroy() lkey=nil end
if rkey then rkey.Destroy() rkey=nil end

lkey=createHotkey(keyFunc1,VK_LEFT)
rkey=createHotkey(keyFunc2,VK_RIGHT)

_________________
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
Laeoying
How do I cheat?
Reputation: 0

Joined: 29 Apr 2024
Posts: 5
Location: France

PostPosted: Mon Apr 29, 2024 5:09 pm    Post subject: Reply with quote

AylinCE wrote:
It focuses on a single address in the address list and allows you to increase (key: Right) or decrease (key: Left) the value when you give the correct description name (Change "No description").

-- Lua script:
Code:
function icreaseValue(desc,val,ops)

getMemRecByDesc = getAddressList().getMemoryRecordByDescription
CheatEntry=getMemRecByDesc(desc)
  if ops==2 then
    CheatEntry.Value = CheatEntry.Value + tonumber(val)
  elseif ops==1 then
    CheatEntry.Value = CheatEntry.Value - tonumber(val)
  end
end

function keyFunc1() -- decrease
sleep(100)
icreaseValue("No description","10.0",1)
end

function keyFunc2() -- increase
sleep(100)
icreaseValue("No description","10.0",2)
end

if lkey then lkey.Destroy() lkey=nil end
if rkey then rkey.Destroy() rkey=nil end

lkey=createHotkey(keyFunc1,VK_LEFT)
rkey=createHotkey(keyFunc2,VK_RIGHT)


It's perfectly working, thanks a lot !! Surprised
But even with changing the sleep time amount, it keeps being slow.. How could I make it smoother ?
And do you know how could I make it like an assembler script ? (like active, non-active)

_________________
How tf do I cheat ?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 34

Joined: 16 Feb 2017
Posts: 1418

PostPosted: Mon Apr 29, 2024 5:25 pm    Post subject: Reply with quote

Code:
function ScrActives()
sleep(100)
getMemRecByDesc = getAddressList().getMemoryRecordByDescription
CheatEntry=getMemRecByDesc("No description") -- edit; Your script desc ..
  if CheatEntry.Active==false then
    CheatEntry.Active=true
  else
    CheatEntry.Active=false
  end
end

if akey then akey.Destroy() akey=nil end

akey=createHotkey(ScrActives,VK_F8)


The sleep time was set only to ensure that it detects key pressure properly.
You can reduce or increase it to a suitable period. (50ms or 200ms)

_________________
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
Laeoying
How do I cheat?
Reputation: 0

Joined: 29 Apr 2024
Posts: 5
Location: France

PostPosted: Mon Apr 29, 2024 5:34 pm    Post subject: Reply with quote

Changing sleep time or even removing it do not really slowing it down, if I increase to like 10000, it's working but it keeps being slow if I put it small or removing it. (when I say slow, it's between 1 second and I'd say 300-400ms, it's kind of random)
_________________
How tf do I cheat ?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 34

Joined: 16 Feb 2017
Posts: 1418

PostPosted: Mon Apr 29, 2024 5:51 pm    Post subject: Reply with quote

Not "sleep()"
For stable clicking.
Code:
setGlobalDelayBetweenHotkeyActivation(1)


Fast and asynchronous (Random) (You will understand from the value change.)
Code:
setGlobalKeyPollInterval(1)


Edit:

Code:
function icreaseValue(desc,val,ops)

getMemRecByDesc = getAddressList().getMemoryRecordByDescription
CheatEntry=getMemRecByDesc(desc)
 if CheatEntry.Active==true then
  if ops==2 then
    CheatEntry.Value = CheatEntry.Value + tonumber(val)
  elseif ops==1 then
    CheatEntry.Value = CheatEntry.Value - tonumber(val)
  end
 end
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
Laeoying
How do I cheat?
Reputation: 0

Joined: 29 Apr 2024
Posts: 5
Location: France

PostPosted: Mon Apr 29, 2024 7:38 pm    Post subject: Reply with quote

I think I have everything I need, thanks a lot for your help <3
_________________
How tf do I cheat ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 465

Joined: 09 May 2003
Posts: 25509
Location: The netherlands

PostPosted: Tue Apr 30, 2024 12:19 am    Post subject: Reply with quote

instead of setGlobalDelayBetweenHotkeyActivation(1) you can also use createHotkey and then set the hotkey's individial DelayBetweenActivate to 1

this way if you have other hotkeys they don't flicker on/off 50 times and end up in a random state when you press the hotkey

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Laeoying
How do I cheat?
Reputation: 0

Joined: 29 Apr 2024
Posts: 5
Location: France

PostPosted: Tue Apr 30, 2024 5:15 am    Post subject: Reply with quote

I added a toggle button and it doesn't flip quickly thanks to sleep but your version looks cleaner tbh I'll try that, thanks !
_________________
How tf do I cheat ?
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