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 


Auto Change Value using AAscript with lua. Need help.

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

Joined: 14 Dec 2020
Posts: 23

PostPosted: Thu Sep 22, 2022 8:20 am    Post subject: Auto Change Value using AAscript with lua. Need help. Reply with quote

I have 1 cheat table, needs automation like auto change value every 10 seconds.
Default value is 0
after 10 seconds, should change to 1
after 10 seconds, should change to 2
after 10 seconds, back to 0 value.
Then always auto repeat the cycle. If i uncheck the script, it should stop the timer.
I don't want to use 'sleep' because it freezes the CE while onsleep.
also uses getMemoryRecordByDescription.
Thank you guys <3 Idea
Back to top
View user's profile Send private message AIM Address
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Thu Sep 22, 2022 8:39 am    Post subject: Reply with quote

This will do the job:
Code:

if t then t.destroy(); t = nil end

counter = 0
state = false

function getScript(description)
  local mr = AddressList.getMemoryRecordByDescription(description)
  if mr ~= nil then
     return mr
  end
end

myscript = getScript('my_script_description')

t = createTimer(getMainForm())
t.Interval = 1000
t.OnTimer = function ()
            t.Enabled = state
            if state == false then return end
            counter = counter + 1

            if counter == 10 then myscript.value = '1' end
            if counter == 20 then myscript.value = '2' end
            if counter == 30 then
              myscript.value = '0'
              counter = 0
            end
            end
Back to top
View user's profile Send private message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Fri Sep 23, 2022 12:15 pm    Post subject: Reply with quote

Thanks <3 But it's not working for me Sad

I found this code somewhere here from aylinCE, that code isn't mine but that code i think is the one i need.
That code does auto change the value 0 and 4 unlimited cycle.
I want the code do auto change the value 0, 4, 5, 7 unlimited cycle every 500ms. Dunno how it done Sad .
Also it uses AA script because i want it on (active timer) and off (disabled timer).
There's no code in [Disable]
Help me to complete the code. Thank you <3



af.JPG
 Description:
 Filesize:  38.68 KB
 Viewed:  1973 Time(s)

af.JPG


Back to top
View user's profile Send private message AIM Address
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Fri Sep 23, 2022 7:35 pm    Post subject: Reply with quote

May try this.

You can enable Async of the running memory record to avoid freeze.

The first part of the following aa script will force Async of the script mr automatically.

The second part is a sample script to DISABLE the infinite loop by uncheck the Async,ie.
<RIGHT-CLICK the mr and uncheck the Async tick mark>.

Try adapt you code inside the while loop,eg.
-- get target_mr -> m
-- for i,v in ipairs{0,1,2} do m.Value = v ; if memrec.Async then sleep(10000)end end

copy paste to the memory record panel to test
Code:

<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"test async loop"</Description>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>{$lua}
local cnt, mr, wantAsync = 0, memrec, true -- false if force not async
if not syntaxcheck and wantAsync~=mr.Async then
  synchronize(createTimer,1,function()mr.Async = wantAsync; mr.Active = not mr.Active end)
  error'reset'
end
-- test code, stop while loop by Disabling Async
  local mr, cnt = memrec, 0
  while not syntaxcheck and mr.Async do
    cnt, mr.Description = cnt+1, 'running '..(not mr.Active and 'ENABLing ' or 'DISABLing ')..cnt
    sleep(500)
  end
{$asm}
///  aa codes



[ENABLE]
[DISABLE]

</AssemblerScript>
    </CheatEntry>
  </CheatEntries>
</CheatTable>

raw version
Code:

{$lua}
local cnt, mr, wantAsync = 0, memrec, true -- false if force not async
if not syntaxcheck and wantAsync~=mr.Async then
  synchronize(createTimer,1,function()mr.Async = wantAsync; mr.Active = not mr.Active end)
  error'reset'
end
-- test code, stop while loop by Disabling Async
  local mr, cnt = memrec, 0
  while not syntaxcheck and mr.Async do
    cnt, mr.Description = cnt+1, 'running '..(not mr.Active and 'ENABLing ' or 'DISABLing ')..cnt
    sleep(500)
  end
{$asm}

_________________
- Retarded.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Sat Sep 24, 2022 3:53 am    Post subject: This post has 1 review(s) Reply with quote

Code:

[ENABLE]
{$lua}
-- if syntaxcheck then return end

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

myscript = AddressList.getMemoryRecordByDescription("SLCTR")
counter = 0

timerFlash = createTimer()
timerFlash.Interval = 500
timerFlash.OnTimer = function ()
            counter = tonumber(counter) + 1

            if counter == 1 then myscript.value = 0 end
            if counter == 2 then myscript.value = 4 end
            if counter == 3 then myscript.value = 5 end
            if counter == 4 then myscript.value = 7
              counter = 0
            end
            end

{$asm}

[DISABLE]

{$lua}
if timerFlash then timerFlash.Destroy() timerFlash = nil 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
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