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 


Loop timer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
!BEWARE!
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 26 Jun 2013
Posts: 56
Location: !BEWARE!

PostPosted: Thu Jul 07, 2022 2:15 pm    Post subject: Loop timer Reply with quote

Im looking for simple script to automatic loop timer
Timer working in seconds from 60 to 0
Details:
address: 701527F8
Type: Float
Value (example display form) : 48.84574654 (8 symbols after dot)

How it should work:
When timer down to value 1, set it to 60
operated on hotkeys to turn ON & OFF script

_________________
!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Thu Jul 07, 2022 4:37 pm    Post subject: Reply with quote

Code:
if secTim1 then secTim1.Destroy() secTim1=nil end
secTim1=createTimer() secTim1.Interval=1000 secTim1.Enabled=false

local sec = 60

function createAddr(addr,val)
  print("before: "..readFloat(addr))
  writeFloat(addr,val)
  print("after: "..readFloat(addr))
end

secTim1.OnTimer=function()
sec = tonumber(sec) - 1
print(sec)
 if sec==0 then
     createAddr("701527F8","48.84574654")
      secTim1.Enabled=false
 end
end

function timerHotkey()
sleep(120)
 if secTim1.Enabled==false then
  sec = 60
  secTim1.Enabled=true
  else
  secTim1.Enabled=false
 end
end

if actKey then actKey.Destroy() actKey=nil end
actKey=createHotkey(timerHotkey, VK_F8)

_________________
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
!BEWARE!
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 26 Jun 2013
Posts: 56
Location: !BEWARE!

PostPosted: Fri Jul 08, 2022 2:41 am    Post subject: Reply with quote

Thanks, tested and working but not exactly as should.
Probably I not enough cleary told. Timer is already in my app and i dont need another timer.
I just only need loop timer in my aplication.
Its counting down from 60 to 0
I need script checking value in 701527F8 address and when it become "1", just set "60". I need it working in loop, every time when value down to 1, make it 60. With possibility to turn sript On & OFF by hotkey.
And i would be grateful if you could make it as script in my address, not as LUA script.


_________________
!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!!BEWARE!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Fri Jul 08, 2022 6:16 am    Post subject: Reply with quote

You may try following, but it use no lua timer (I assume the value countdown is in game) and needs 2 hot keys for on/off , ie. not toggle
1. select 2 set of hotkey, as example, ON use ctrl-shift+[ (K1) and off use ctrl+shift+] (K2)
2. right click your memory record, [set/change hotkeys] and create following hotkey IN ORDER:
2.1 (K1), FREEZE
2.2 (K2), UNFREEZE
2.3 (K1), SET_VALUE_TO, value field input
"tonumber(value)and(tonumber(value)<=1 and 60 or value)"(no quotes)

The order matter because "value" will stay only if the memory record is already froze.

In case, you need some timer counter effect, try use this slightly modified value:
"tonumber(value)and(tonumber(value)<=1 and 60 or tonumber(value) - 0.1 )" (no quote)

This make the value count down toward zero, and if <=1 flip to 60.
This is because memory record has its own activate/update timer, it has the equivalent logic as:
Code:
update_timer.OnTimer = function()
  local value = memory_record.Value
  value = tonumber(value)and(tonumber(value)<=1 and 60 or tonumber(value) - 0.1 ) -- the expression in hotkey[set_value_to]field
  memory_record.Value = value
end


ADDED:
directly/manually set value will clear the "value" expression set by hotkey, it need apply the ON-hotkey again to have the effect.

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

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Fri Jul 08, 2022 9:51 am    Post subject: Reply with quote

Copy the code below and paste it into the address list.
(In the original language of the page if possible)

Options:
1) When the group is activated, ON-OFF switch is created. (Default F8 key)
2) Each time you click the F8 key, the timer script will run or be stopped.
3) When the timer script is active; When 60 seconds becomes 1, the loop goes back to 60 and continues.
4) When the timer is 1, the default address value is changed to the given value.

This is just an example and you can edit them.

Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>4</ID>
      <Description>"StartHack (HotKey)"</Description>
      <Options moHideChildren="1"/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
{$Lua}
if syntaxcheck then return end

local set = 1

function TIMER_ON_OFF()
sleep(120)
  al=getAddressList()
  local memrec1=addresslist_getMemoryRecordByDescription(al,"secTmr")
  if memrec1~=nil then
   if set==1 then
    memrec1.Active = true
    set = 2
    else
    memrec1.Active = false
    set = 1
   end
   else
   print("memrec not found")
 end
end

if TimKey then TimKey.Destroy() TimKey=nil end --kill key

TimKey=createHotkey(TIMER_ON_OFF,VK_F8)

{$asm}

[DISABLE]

{$Lua}
if TimKey then TimKey.Destroy() TimKey=nil end --kill key

</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>1</ID>
          <Description>"secTmr"</Description>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$Lua}
if syntaxcheck then return end

if secTim1 then secTim1.Destroy() secTim1=nil end
secTim1=createTimer() secTim1.Interval=1000 secTim1.Enabled=true

local sec = 60

secTim1.OnTimer=function()
sec = tonumber(sec) - 1
--print(sec)
 if sec==1 then
  al=getAddressList()
  local mem=addresslist_getMemoryRecordByDescription(al,"Hack")
   mem.Value = "48.84574654"
   sec = 60
 end
end

{$asm}

[DISABLE]

{$Lua}
secTim1.Destroy()
</AssemblerScript>
        </CheatEntry>
        <CheatEntry>
          <ID>2</ID>
          <Description>"Hack"</Description>
          <ShowAsSigned>0</ShowAsSigned>
          <VariableType>Float</VariableType>
          <Address>701527F8</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>

_________________
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