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 


changing how fast the float value increases by

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

Joined: 25 Jul 2018
Posts: 4

PostPosted: Fri Sep 07, 2018 1:43 pm    Post subject: changing how fast the float value increases by Reply with quote

DoneState = true
local addr = 0x10BC9C400 - insert address add a 0x because of float
local val = -1
local function timer_tick(timer)
local v = readFloat(addr) -- read value
if v < 0 then -- check value
writeFloat(addr, val + v) -- write value
else
DoneState = true -- this stops the timer, if value if > 100
end
if DoneState == true then
timer.destroy()
end
end


Hi I wanted to know if there is a way to to increase and decrease values several times over a different period of time during the same script.

For example The value of all the addresses in the picture I have linked is currently at 0, I would like the script to change all the values to 150 after 3 seconds, then the values change again to 60 after 1 second.

Also I would like the change in values to be gradual rather than instant, for example if the values are 0 and they are changing to 150 I would like it to go 0,1,2,3,4,5,6,7,8 all the way to 150 within the given time frame.

Thank you.



fiverpng.png
 Description:
 Filesize:  209.12 KB
 Viewed:  2175 Time(s)

fiverpng.png


Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Sep 07, 2018 5:33 pm    Post subject: Reply with quote

hm, maybe something like this... it feels like there should be a better approach though.
Code:
function change(addresses, delta, time, readFunc, writeFunc)
  if delta > time then error('change was written to change values by 1 at a time, but delta is greater than milliseconds given to work change in', 2) end
  readFunc = readFunc or readFloat
  writeFunc = writeFunc or writeFloat
  local t = createTimer()
  local add = delta > 0
  delta = abs(delta)
  t.Interval = floor(time / delta)
  t.OnTimer = function(t)
    for addr in addresses do
      local val = readFunc(addr)
      if add then val = val + 1 else val = val -1 end
      writeFunc(addr, val)
    end
    delta = delta - 1
    if delta <= 0 then t.destroy() end
  end
  return t
end

function delay(time, f)
  local t = createTimer()
  t.Interval = time
  t.OnTimer = function(t)
    if not f(t) then t.destroy() end
  end
  return t
end

local address = {}
for i=0,AddressList.Count-1 do
  addresses[#addresses+1] = AddressList[i].CurrentAddress
end

change(addresses, 150, 3000)
delay(3000, function() change(addresses, 60-150, 1000) end)

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
ND_JOHN
How do I cheat?
Reputation: 0

Joined: 25 Jul 2018
Posts: 4

PostPosted: Sun Sep 09, 2018 6:31 am    Post subject: Reply with quote

FreeER wrote:
hm, maybe something like this... it feels like there should be a better approach though.
Code:
function change(addresses, delta, time, readFunc, writeFunc)
  if delta > time then error('change was written to change values by 1 at a time, but delta is greater than milliseconds given to work change in', 2) end
  readFunc = readFunc or readFloat
  writeFunc = writeFunc or writeFloat
  local t = createTimer()
  local add = delta > 0
  delta = abs(delta)
  t.Interval = floor(time / delta)
  t.OnTimer = function(t)
    for addr in addresses do
      local val = readFunc(addr)
      if add then val = val + 1 else val = val -1 end
      writeFunc(addr, val)
    end
    delta = delta - 1
    if delta <= 0 then t.destroy() end
  end
  return t
end

function delay(time, f)
  local t = createTimer()
  t.Interval = time
  t.OnTimer = function(t)
    if not f(t) then t.destroy() end
  end
  return t
end

local address = {}
for i=0,AddressList.Count-1 do
  addresses[#addresses+1] = AddressList[i].CurrentAddress
end

change(addresses, 150, 3000)
delay(3000, function() change(addresses, 60-150, 1000) end)


I tried the code and i got a error



testing code.png
 Description:
 Filesize:  259.36 KB
 Viewed:  2115 Time(s)

testing code.png


Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Sep 09, 2018 10:38 am    Post subject: Reply with quote

hm, apparently I typoed creating the table as "address" instead of "addresses"
_________________
https://github.com/FreeER/ has a few CE related repos
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