|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
SadrienHatesU Newbie cheater Reputation: 0
Joined: 08 May 2017 Posts: 14 Location: I don't exist... Unfortunately
|
Posted: Sun Feb 11, 2018 4:01 am Post subject: Hotkey Function in Lua, making it apply only once per click. |
|
|
Quote: | -- create the hotkey
ClickToTeleportHK = createHotkey(function()
-- get the value of Mouse in world
local valueY = tonumber (MouseY.Value)
local valueX = tonumber (MouseX.Value)
local valueZ = tonumber (MouseZ.Value)
-- divide by 32 and add 0.3
valueY = (valueY /-32) + 0.3
valueX = (valueX /32)
valueZ = (valueZ /32)
-- store the value in Transient Position
TransientY.Value = tostring(valueY)
TransientX.Value = tostring(valueX)
TransientZ.Value = tostring(valueZ)
ModelY.Value = tostring(valueY)
ModelX.Value = tostring(valueX)
ModelZ.Value = tostring(valueZ)
end,
{VK_F6}) |
Is the current code for the function. I would just like to know if there is a very efficient method of making this proc only once each time it is clicked, instead of repeating while held to keep the code neat.
_________________
Um... Hello... Thanks for taking the time to read my pointless signature
Last edited by SadrienHatesU on Sun Feb 11, 2018 4:37 am; edited 1 time in total |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Feb 11, 2018 4:25 am Post subject: |
|
|
Code: | setGlobalKeyPollInterval(100)
function createNonRepHotkey(func, ...)
local getTickCount=getTickCount
local lastTickCount=0
local function changedBehaviour(sender)
local TC = getTickCount()
--call orig func when elap is bigger than 300ms
if (TC - lastTickCount) > 300 then func(sender) end
lastTickCount = TC
end
local hk = createHotkey(changedBehaviour, ...)
hk.DelayBetweenActivate = 10
return hk
end
-- create the hotkey
ClickToTeleportHK = createNonRepHotkey(function()
-- get the value of Mouse in world
local valueY = tonumber (MouseY.Value)
local valueX = tonumber (MouseX.Value)
local valueZ = tonumber (MouseZ.Value)
-- divide by 32 and add 0.3
valueY = (valueY /-32) + 0.3
valueX = (valueX /32)
valueZ = (valueZ /32)
-- store the value in Transient Position
TransientY.Value = tostring(valueY)
TransientX.Value = tostring(valueX)
TransientZ.Value = tostring(valueZ)
ModelY.Value = tostring(valueY)
ModelX.Value = tostring(valueX)
ModelZ.Value = tostring(valueZ)
end, {VK_F6}) |
_________________
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Sun Feb 11, 2018 6:34 am Post subject: |
|
|
This alternative use an internal timer to monitor the combo keys holding state, ready for another function activation if any combo keys is released.
Code: |
local function nonRepHK(fn, ...)
local keys = ...
if type(keys)~= 'table' then keys = table.pack(...)end
local timer, pressed = createTimer(nil,false)
timer.Interval = 25
local HK = createHotkey(function(hk)
if not pressed then
pressed, timer.Enabled = true, true
return fn(hk)
end
end, ...)
local hkmt = getmetatable(HK)
local onDie = hkmt and hkmt.Destroy
if onDie then
hkmt.Destroy = function(hk)
timer = nil, timer.Destroy()
return onDie(hk)
end
end
timer.OnTimer = function (tm)
if pressed then
for i=1,#keys do
if not isKeyPressed(keys[i])then
pressed, tm.Enabled = false, false
return
end
end
end
end
return HK
end
-- test
nonRepHK(function()print'press'end, VK_F6)
|
_________________
- Retarded. |
|
Back to top |
|
|
|
|
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
|
|