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 with SCRIPT

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

Joined: 26 Oct 2021
Posts: 31
Location: Earth

PostPosted: Mon Aug 29, 2022 11:03 am    Post subject: Help with SCRIPT Reply with quote

Hi, I need help with a lua script, here is my script

{$lua}
[ENABLE]
-- code to find the hotkeys
al = getAddressList()
mr = al.getMemoryRecordByDescription("Aim")
-- get hotkeys, based on position in list aka index not ID (at least fairly sure it's index)
hk = mr.Hotkey[0]

-- set a function to run the second hotkey after the first has run
-- and the first key has been released
hk.onPostHotKey = function(sender)
timer = createTimer()
timer.Interval = 100 -- check every 100 milliseconds
timer.OnTimer = function(timer)
if not isKeyPressed(hk.keys[1]) then
sender.Owner.Hotkey[1].doHotkey()
timer.destroy()
end
end
end
[DISABLE]
-- lua code

The script gets the hotkey (X) from aim and sets the value to 100 as long as i hold down the hotkey,

Now I want to add to the script to allow another hotkey to be used whilst im holding down the (X) without the current hotkey getting reverted constantly to 100, I want to add a hotkey (MouseButton4) to set the value to 50 as long as I hold down X and hit MouseButton4 but when i let go of the hotkey the value should return to 120 like it currently does
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Mon Aug 29, 2022 11:40 am    Post subject: Reply with quote

Here:
Code:

aim = AddressList.getMemoryRecordByDescription('Aim')
key = --VK code
if hk then hk.destroy(); hk = nil end

hk = createTimer(getMainForm())
hk.interval = 100
hk.OnTimer = function()
              if isKeyPressed(0x6D) then -- Numpad Subtract Key
                 aim.setvalue(100)
              end
             end


You can change 0x6D for one that matches the keys listed here.
Key codes
Back to top
View user's profile Send private message
Aziixz
Cheater
Reputation: 0

Joined: 26 Oct 2021
Posts: 31
Location: Earth

PostPosted: Mon Aug 29, 2022 1:24 pm    Post subject: Reply with quote

The code keeps spitting out attempt to index a nil value (field '?' , perhaps I've done something wrong,

aim = AddressList.getMemoryRecordByDescription('Aim')
key = --VK code
if hk then hk.destroy(); hk = nil end

hk = createTimer(getMainForm())
hk.interval = 100
hk.OnTimer = function()
if isKeyPressed(0x06) then -- Numpad Subtract Key
aim.setvalue(100)
end
end

I changed it to 0x06 as thats mouse button 4, but it keeps spitting out errors,

I've attached the .ct for added information and screen shots. I'm trying to get FOV which has the 2 hotkeys set up with the script which outputs 100 when Right Mouse Button Is Held Down to output a value of 50 when i hit mouse button 4,

sorry don't know alot about lua

thanks for helping



Help Script.jpg
 Description:
 Filesize:  33.19 KB
 Viewed:  1431 Time(s)

Help Script.jpg


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

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

PostPosted: Mon Aug 29, 2022 10:11 pm    Post subject: Reply with quote

In the Cheat Table Lua Script window (Table > Show Cheat Table Lua Script):
Code:

if syntaxcheck then return end
-- Set VK Code here to match the key you wish to use
local key = 0x6D --VK code
-- Retrieve the "Aim" memory record object
local aim = AddressList.getMemoryRecordByDescription('Aim')
-- Create a timer component and set Cheat Engine as the parent, disabled by default
hk = createTimer(getMainForm(), false)
-- Set the interval to 100ms
hk.interval = 100
hk.OnTimer = function()
                                        -- Read the 4-byte value at address symbol 'hotkeyvalue' that we allocated in the Toggle script
              local v = readInteger('hotkeyvalue')
              -- Check if we have set a value
              if v ~= nil then
                       -- If we have set a value then check if we pressed "key"
                 if isKeyPressed(key) then
                          -- Set value to v which was set by 'hotkeyvalue'
                    aim.value = v
                 end
              end
             end


Add this script:
Code:

[ENABLE]
{$LUA}
if syntaxcheck then return end

hk.Enabled = true
print('Timer enabled = ' .. tostring(hk.Enabled))
{$ASM}
alloc(hotkeyvalue,$4)
registersymbol(hotkeyvalue)
[DISABLE]
{$LUA}
if syntaxcheck then return end

hk.Enabled = false
print('Timer enabled = ' .. tostring(hk.Enabled))
{$ASM}
dealloc(hotkeyvalue)
unregistersymbol(hotkeyvalue)


Then add an address manually with the address:
Code:

hotkeyvalue

type: 4-bytes

Enable the script you added to the table, then set the value of hotkeyvalue as you see fit. I have commented a lot of the code to explain what it is doing.
Back to top
View user's profile Send private message
Aziixz
Cheater
Reputation: 0

Joined: 26 Oct 2021
Posts: 31
Location: Earth

PostPosted: Tue Aug 30, 2022 12:57 pm    Post subject: Reply with quote

Thank you so much Very Happy
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