View previous topic :: View next topic |
Author |
Message |
mikey1993 Newbie cheater Reputation: 0
Joined: 20 Jul 2017 Posts: 22
|
Posted: Thu Jul 20, 2017 5:13 am Post subject: Assigning Lua script to key |
|
|
Hi guys, I'm new to Cheat Engine and extremely new to Lua scripting. I want to thank anyone that might be able to help me in advance.
I've written a Lua script and it's all working exactly how I want. When I execute the script everything is perfect. What I am having a heap of trouble with is figuring out how to assign the script to Numpad4 key.
I want to be able to play the game and press 4 and the script executes.
Please if anyone can help I would really appreciate it.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Thu Jul 20, 2017 5:38 am Post subject: |
|
|
createHotkey(scriptfunction, VK_4)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
mikey1993 Newbie cheater Reputation: 0
Joined: 20 Jul 2017 Posts: 22
|
Posted: Thu Jul 20, 2017 5:53 am Post subject: |
|
|
Thank you so much Dark. I did what you said and there must be one more thing I'm missing. I'll paste the script below. When I press 4 I get a pop up box with the message ":Error attempt to call a nill value"
createHotkey(scriptfunction, VK_NUMPAD4)
DeadlyShock = 65575
DemonStrike = 65576
WhirlingDervish = 65577
BastardSwing = 65578
local PercentageSkill = readInteger("0x221101e")
local PercentageSkill2 = readInteger("0x2211032")
if (PercentageSkill == DeadlyShock) then
writeInteger("0x221101e",DemonStrike)
elseif (PercentageSkill == DemonStrike) then
writeInteger("0x221101e",DeadlyShock)
end
if (PercentageSkill2 == WhirlingDervish) then
writeInteger("0x2211032",BastardSwing)
elseif (PercentageSkill2 == BastardSwing) then
writeInteger("0x2211032",WhirlingDervish)
end
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Thu Jul 20, 2017 6:18 am Post subject: |
|
|
mikey1993 wrote: | When I press 4 I get a pop up box with the message ":Error attempt to call a nill value" |
That's because scriptfunction wasn't defined to be a function (so it was nil which causes lua to try and call a nil value, nil is lua's version of javascript's undefined aka not set), try
Code: | scriptfunction = function()
DeadlyShock = 65575
DemonStrike = 65576
WhirlingDervish = 65577
BastardSwing = 65578
local PercentageSkill = readInteger("0x221101e")
local PercentageSkill2 = readInteger("0x2211032")
if (PercentageSkill == DeadlyShock) then
writeInteger("0x221101e",DemonStrike)
elseif (PercentageSkill == DemonStrike) then
writeInteger("0x221101e",DeadlyShock)
end
if (PercentageSkill2 == WhirlingDervish) then
writeInteger("0x2211032",BastardSwing)
elseif (PercentageSkill2 == BastardSwing) then
writeInteger("0x2211032",WhirlingDervish)
end
end
createHotkey(scriptfunction, VK_NUMPAD4) |
or
Code: | createHotkey(function()
... -- your code here
end, VK_NUMPAD4) |
|
|
Back to top |
|
|
mikey1993 Newbie cheater Reputation: 0
Joined: 20 Jul 2017 Posts: 22
|
Posted: Thu Jul 20, 2017 7:02 am Post subject: |
|
|
Ok, I've tried both of them and neither work. For the 2nd example you showed me I get the error msg
"[string "createHotkey(function()
..."]:17: syntax error near ')'
It's referring to line 17 which I'll copy paste down below.
end VK_NUMPAD4)
sorry for being so nub. The solution is probably simple and I'm not seeing it .
Thank you again for the help your giving me guys.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Thu Jul 20, 2017 7:18 am Post subject: |
|
|
there should be a comma between end and VK_NUMPAD4 to separate the two arguments (the function to run when the hotkey is run and the key that triggers the hotkey)
|
|
Back to top |
|
|
mikey1993 Newbie cheater Reputation: 0
Joined: 20 Jul 2017 Posts: 22
|
Posted: Thu Jul 20, 2017 11:53 pm Post subject: |
|
|
Thank you so much FreeER. It's working now. It's not consistent though. 1 in 3 times that I press 4 nothing happens. The point of the script I have written is to free up 2 slots in my skill bar. I have 4 skills and 2 off them require a specific kind of weapon to use them so I was trying to set things up so that when I switch weapons the skills also switch out. Now when I switch weapons the weapon switches fine but the skills sometimes aren't switching. Is there a solution to this that you might know of ?
edit: I think I've found the issue. I checked my process list and there were 4-5 cheat engine processes running. Once I closed them all down and restarted the consistency appears to be 100%.
thank you for all the help you all have provided me. I very much appreciate it.
|
|
Back to top |
|
|
mikey1993 Newbie cheater Reputation: 0
Joined: 20 Jul 2017 Posts: 22
|
Posted: Tue Aug 01, 2017 8:12 pm Post subject: |
|
|
Is it possible to do something like this with hotkeys and if I haven't done it right could someone correct it for me.
createHotKey(function()
DoStuff
end, VK_NUMPAD1 + VK_LMENU)
In doing so give myself more options key options aka ALT + 1 through to 0 and so on. thanks for any replies.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Tue Aug 01, 2017 9:39 pm Post subject: |
|
|
Absolutely, you should just need a comma between the key codes so that they are separate parameters (up to 4 or 5 keys are supported if I recall correctly, though not sure if that's a software limit or simply the fact that most keyboards aren't designed to detect an unlimited number of keys being pressed)
|
|
Back to top |
|
|
mikey1993 Newbie cheater Reputation: 0
Joined: 20 Jul 2017 Posts: 22
|
Posted: Sat Aug 05, 2017 12:09 am Post subject: |
|
|
Thank you again FreeER. You were very right about that xd
|
|
Back to top |
|
|
|