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 


How to make a script to write contantly a value.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Meiyoh
Master Cheater
Reputation: 1

Joined: 14 Mar 2015
Posts: 290

PostPosted: Thu Mar 23, 2017 12:59 pm    Post subject: How to make a script to write contantly a value. Reply with quote

I need a script to constanstly do this when It's ENABLED in Table Options.

writeInteger("JohnnyMoves", 0x170 + (readInteger"JohnnyMoves+20" or 0))

Can somebody write me the proper code thank you. So it keeps updating the value constantly.

_________________
I am the forgotten one the dead one.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 42

Joined: 09 Aug 2013
Posts: 1089

PostPosted: Thu Mar 23, 2017 2:15 pm    Post subject: This post has 1 review(s) Reply with quote

Well if it's a static value you can simply add a memory record for it and then freeze it (set the memory record's Active property to true in lua), the same can be said if the value you set it to is only rarely updated (just update the value of the memory record when the value you care about changes).

Since you want it to be done constantly here's a lua script that creates a timer that does the work, destroying itself (and thus stopping) if the script is disabled

Code:
{$lua}
[ENABLE]
-- if just a syntax check on save/load don't run the following code
if syntaxcheck then return end

local timer = createTimer()
timer.onTimer = function(timer)
  -- check if the script is disabled
  -- note there's probably a way to set a function to be called when the script is disabled but I don't know it off the top of my head lol
  al = getAddressList()
  mr = al.getMemoryRecordByDescription("Lua Auto Write")
  if not mr.Active then timer.destroy() end

  -- otherwise do the work
  --writeInteger("[Tutorial-i386.exe+1FC5D0]+480", 333) -- tutorial test line
  writeInteger("JohnnyMoves", 0x170 + (readInteger"JohnnyMoves+20" or 0))
end
timer.interval = 100 -- 100 milliseconds is 1/10 of a second

[DISABLE]


edit: "better" (?) lua using OnDeactivate event:
Code:
{$lua}
[ENABLE]
if syntaxcheck then return end

local timer = createTimer()
timer.onTimer = function(timer)
  --writeInteger("[Tutorial-i386.exe+1FC5D0]+480", 333) -- tutorial test line
  writeInteger("JohnnyMoves", 0x170 + (readInteger"JohnnyMoves+20" or 0))
end

local al = getAddressList()
local mr = al.getMemoryRecordByID(136)
mr.OnDeactivate = function(mr,before,cs)
  -- if about to change state, return true to let it contine and deactivate
  if before then return true end
  -- otherwise state has changed so stop the timer
  timer.destroy()
end

timer.interval = 100 -- 1/10 of a second

[DISABLE]


If you wanted an asm script then you could use createThread instead and write asm code to load the desired value and write it then sleep for a little while and repeat

Code:
globalalloc(code,1000)
[ENABLE]
label(codeDisable)
label(loop)

code:
  // load desired value
  mov eax, [JohnnyMoves+20] // assumes JohnnyMoves is a registered symbol already
  add eax, 170
  // store desired value
  mov [JohnnyMoves], eax

  cmp byte ptr [codeDisable], 0
  je loop  // loop if script still enabled
  ret // otherwise let the thread die/return

loop:
  // wait 100 milliseconds
  push #100 // note: mov into ecx for x64
  call kernel32.sleep // returns only after time requested has elapsed
  jmp code // loop

// byte to set when disabling script to let thread know it should die
codeDisable:
  db 0

// register codeDisable as a symbol so it can be used in DISABLE section
// (note code needs to be registered for createThread to work but globalalloc does it for us)
registerSymbol(codeDisable)

createThread(code)

[DISABLE]
codeDisable:
  db 1
unregisterSymbol(codeDisable)


Last edited by FreeER on Thu Mar 23, 2017 3:54 pm; edited 2 times in total
Back to top
View user's profile Send private message
Meiyoh
Master Cheater
Reputation: 1

Joined: 14 Mar 2015
Posts: 290

PostPosted: Thu Mar 23, 2017 3:41 pm    Post subject: Reply with quote

thank you!
_________________
I am the forgotten one the dead one.
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 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