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 


Hold down key to change value

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

Joined: 20 Aug 2016
Posts: 44

PostPosted: Sat Jan 14, 2017 10:12 pm    Post subject: Hold down key to change value Reply with quote

I've been trying to make a lua script to change a value when you hold down a key, and return to original value when you stop.
But it doesn't work and I don't see what it's wrong. I'm kinda new to this.
Code:
function checkKeys(timer)
  if (isKeyPressed(VK_Z)) then
     local addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8]+0"
     local function set(value)writeFloat(addr,value)end
     local function test(value)return value==readFloat(addr)end
     if test(-980) then
        set(-100)
  else
        set(-980)
     end
  end
end

  t=createTimer(nil)
  timer_setInterval(t, 100)
  timer_onTimer(t, checkKeys)
  timer_setEnabled(t, true)

Can anyone help me? Thanks.
Any easier way to do what I need it's helpful too.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Jan 14, 2017 10:33 pm    Post subject: Reply with quote

Code:
local addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8]+0"
local function set(value)writeFloat(addr,value)end
local function test(value)return value==readFloat(addr)end

if mytimer == nil then
  mytimer = createTimer(nil, false)
end
mytimer.Interval = 100
mytimer.OnTimer = function(timer)
  if not isKeyPressed(VK_Z) then
    set(-980)
    timer.Enabled = false
  end
end

if myhotkey then
  myhotkey.Destroy()
end
myhotkey = createHotkey(function()
  if not mytimer.Enabled then
    set(-100)
    mytimer.Enabled = true
  end
end, VK_Z)
Back to top
View user's profile Send private message
Greenhouse
Cheater
Reputation: 0

Joined: 20 Aug 2016
Posts: 44

PostPosted: Sun Jan 15, 2017 5:12 am    Post subject: Reply with quote

Zanzer wrote:
Code:
local addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8]+0"
local function set(value)writeFloat(addr,value)end
local function test(value)return value==readFloat(addr)end

if mytimer == nil then
  mytimer = createTimer(nil, false)
end
mytimer.Interval = 100
mytimer.OnTimer = function(timer)
  if not isKeyPressed(VK_Z) then
    set(-980)
    timer.Enabled = false
  end
end

if myhotkey then
  myhotkey.Destroy()
end
myhotkey = createHotkey(function()
  if not mytimer.Enabled then
    set(-100)
    mytimer.Enabled = true
  end
end, VK_Z)

It doesn't work either. The value just doesn't change.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jan 15, 2017 8:04 am    Post subject: Reply with quote

Should the address be
Code:
[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jan 15, 2017 8:22 am    Post subject: Reply with quote

You can use "toggle" version:
Code:
function theCheatTimerOnTimer(t)
  local val = readFloat(addr)
  if val and (val>=-981 and val<=-979) then -- change to -100 only when it is around -980
    writeFloat(addr,-100)
  end
end

function theCheatHotkeyOnHotkey(t)
  if theCheatTimer.Enabled then
    speakEnglish('disabled.')
    theCheatTimer.Enabled = false
    writeFloat(addr,-980)
  else
    speakEnglish('enabled.')
    theCheatTimer.Enabled = true
  end
end

if theCheatTimer==nil then theCheatTimer = createTimer(nil,false) end
theCheatTimer.Interval = 10
theCheatTimer.Enabled = false
theCheatTimer.OnTimer = theCheatTimerOnTimer

if theCheatHotkey~=nil then theCheatHotkey.destroy(); theCheatHotkey=nil end
theCheatHotkey = createHotkey(theCheatHotkeyOnHotkey,VK_Z)

addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8]+0"

_________________
Back to top
View user's profile Send private message MSN Messenger
Greenhouse
Cheater
Reputation: 0

Joined: 20 Aug 2016
Posts: 44

PostPosted: Sun Jan 15, 2017 8:38 am    Post subject: Reply with quote

mgr.inz.Player wrote:
You can use "toggle" version:
Code:
function theCheatTimerOnTimer(t)
  local val = readFloat(addr)
  if val and (val>=-981 and val<=-979) then -- change to -100 only when it is around -980
    writeFloat(addr,-100)
  end
end

function theCheatHotkeyOnHotkey(t)
  if theCheatTimer.Enabled then
    speakEnglish('disabled.')
    theCheatTimer.Enabled = false
    writeFloat(addr,-980)
  else
    speakEnglish('enabled.')
    theCheatTimer.Enabled = true
  end
end

if theCheatTimer==nil then theCheatTimer = createTimer(nil,false) end
theCheatTimer.Interval = 10
theCheatTimer.Enabled = false
theCheatTimer.OnTimer = theCheatTimerOnTimer

if theCheatHotkey~=nil then theCheatHotkey.destroy(); theCheatHotkey=nil end
theCheatHotkey = createHotkey(theCheatHotkeyOnHotkey,VK_Z)

addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8]+0"

It's not working either, the value just doesn't change.
The address is right, but doesn't change anything.
Image: i(dot)imgur(dot)com/UtQdojA.png

Zanzer wrote:
Should the address be
Code:
[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+278]+D8

Still not working.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jan 15, 2017 9:29 am    Post subject: Reply with quote

Address is not right, you have the offsets backwards.
Code:
local addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+0]+D8]+278"
Back to top
View user's profile Send private message
Greenhouse
Cheater
Reputation: 0

Joined: 20 Aug 2016
Posts: 44

PostPosted: Sun Jan 15, 2017 11:06 am    Post subject: Reply with quote

Zanzer wrote:
Address is not right, you have the offsets backwards.
Code:
local addr = "[[[HelloNeighborReborn-Win64-Shipping.exe+027A2310]+0]+D8]+278"

I thought that the offsets had to be in that order.
Well, that's why it wasn't working. Thanks.
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