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] seting timer for disablig scripts

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

Joined: 03 Sep 2014
Posts: 112

PostPosted: Wed Jul 14, 2021 6:54 pm    Post subject: [help] seting timer for disablig scripts Reply with quote

hi all

i wrote a Lua script nut there's something wrong with it. when I disable it and re-enable it CE freezes.

Code:
[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$lua}

function autodisable(sender)

hud_ac = getAddressList().getMemoryRecordByID(17448)
hud_ac.Active=false

hud_deac = getAddressList().getMemoryRecordByID(17449)
hud_deac.Active=false

end

if t == nil then
 t=createTimer(nil)
---if (getAddressList().getMemoryRecordByID(17448).Active==true) or (getAddressList().getMemoryRecordByID(17449).Active==true) then
t.OnTimer=autodisable
t.Interval=1000
t.Enabled=true

---end

end

{$asm}

[DISABLE]
//code from here till the end of the code will be used to disable the cheat

{$lua}
t.Destroy()





also, how can I log or print all active timers?
Back to top
View user's profile Send private message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Thu Jul 15, 2021 1:51 am    Post subject: Reply with quote

You can just write this lua in cheat engine lua table and then call function in AA
Code:
luacall(example())

This will call function example
Code:
if t == nil then
 t=createTimer(nil)
---if (getAddressList().getMemoryRecordByID(17448).Active==true) or (getAddressList().getMemoryRecordByID(17449).Active==true) then
t.OnTimer=autodisable
t.Interval=1000
t.Enabled=true

---end

You disabled if and end
Code:
---This is comment block

You can't use ---, this is just comment block start in single line
Back to top
View user's profile Send private message
reverser69
Expert Cheater
Reputation: 0

Joined: 03 Sep 2014
Posts: 112

PostPosted: Thu Jul 15, 2021 7:22 am    Post subject: Reply with quote

what i want to do is this:
I call two functions of the game via create thread. i kill the thread. but the script remains active. i want to deactivate them after the tread is terminate (ret instruction).

any idea how can I do it better than the above script?
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Thu Jul 15, 2021 10:07 am    Post subject: Reply with quote

Code:

[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$lua}

function autodisable(sender)

hud_ac = getAddressList().getMemoryRecordByID(17448)
hud_ac.Active=false

hud_deac = getAddressList().getMemoryRecordByID(17449)
hud_deac.Active=false

end

if t == nil then
 t=createTimer(nil)
---if (getAddressList().getMemoryRecordByID(17448).Active==true) or (getAddressList().getMemoryRecordByID(17449).Active==true) then
t.OnTimer=autodisable
t.Interval=1000
t.Enabled=true

---end

end

{$asm}

[DISABLE]
//code from here till the end of the code will be used to disable the cheat

{$lua}
t.Destroy()


A single-line Lua comment is initialised with '--'

Here is how I achieved the same thing (disabling the script after a set time defined by the user once the script has been activated)

Code:

local scriptName = 'script_name' -- Enter the name of the script here
local t = createTimer(getMainForm())
      t.Interval = 5000 -- In milliseconds, set to 5 seconds to enable time for the script to execute
      t.OnTimer = function(disableScript)
                  local al = getAddressList()
                  local mr = al.getMemoryRecordByDescription(scriptName)
                    if mr == nil then                                   -- if the script doesn't exist in the table
                       t.destroy()                                      -- destroy the timer
                    else if mr ~= nil and mr.Active == true then        -- if script exists and is activated
                       Sleep(3000)                                      -- wait 3 seconds so it doesn't auto-deactivate
                       mr.Active = false                                -- deactivate script
                       t.Destroy()                                      -- destroy the timer
                       end
                    end
                  end


Just put that below the AA code in your script and once the script is activated it will deactivate after 8 seconds, defined by the timer interval + the length of time to sleep. You can adjust these values as per your requirement.
Back to top
View user's profile Send private message
reverser69
Expert Cheater
Reputation: 0

Joined: 03 Sep 2014
Posts: 112

PostPosted: Thu Jul 15, 2021 3:28 pm    Post subject: Reply with quote

@LeFiXER

i use a "ret" instruction in my cheat. so i think this lua won't be executed?!
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Fri Jul 16, 2021 7:28 am    Post subject: Reply with quote

reverser69 wrote:
@LeFiXER

i use a "ret" instruction in my cheat. so i think this lua won't be executed?!


It shouldn't matter. CE will execute Auto Assembler first and then the Lua script providing it falls under the [ENABLE] section of the script.
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