Was wondering how to add the sleep timer to my LUA script so it doesn't continually loop as fast as possible and press 0x29, I'd like to make it so when buttons 1 and 3 are pressed on my mouse it hits key 0x29 once every 3-4 seconds instead of as fast as possible.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" then
if (arg == 1 or arg == 2) then
mb1 = IsMouseButtonPressed(1);
mb2 = IsMouseButtonPressed(3);
--OutputLogMessage(tostring(mb1) .. " - " .. tostring(mb2));
if (mb1 == true and mb2 == true) then
PressAndReleaseKey(0x29);
end
end
end
end
You can get the current time in milliseconds by GetRunningTime()
local last_time = -math.huge
local is_pressed = {}
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_RELEASED" and (arg == 1 or arg == 2) then
is_pressed[arg] = false
elseif event == "MOUSE_BUTTON_PRESSED" and (arg == 1 or arg == 2) then
is_pressed[arg] = true
local mb1 = is_pressed[1]
local mb2 = is_pressed[2]
--OutputLogMessage(tostring(mb1) .. " - " .. tostring(mb2))
if mb1 and mb2 and GetRunningTime() - last_time > 5000 then
PressAndReleaseKey(0x29)
last_time = GetRunningTime()
end
end
end
I'm working on a recoil script, and I want to be able to activate or toggle it using two mouse buttons at the same time. This is what I have so far. I want to use g4 and g5 to make it work, not just g4
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end
end
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
if btn_5_is_pressed then
recoil = not recoil
spot = not spot
else
btn_4_is_pressed = true
end
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
if btn_4_is_pressed then
recoil = not recoil
spot = not spot
else
btn_5_is_pressed = true
end
elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 4) then
btn_4_is_pressed = false
elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 5) then
btn_5_is_pressed = false
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end
end
EDIT
Toggle by double-click of mouse button #6:
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
local now = GetRunningTime()
if now - (prev_time or -1000000) < 200 then
prev_time = nil
recoil = not recoil
else
prev_time = now
end
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end
my logitech LUA script used to work flawlessly, but for some reason now i can only adjust "sleeptime" by increments of 15 instead of 1. i used to be able to adjust sleeptime up and down by 1, but now the speed doesn't change unless i adjust 15 times. what am i missing?
sleeptime=15
function OnEvent(event, arg)
EnablePrimaryMouseButtonEvents(true)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7 and IsModifierPressed("lshift")) then
sleeptime = sleeptime - 1
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7 and IsModifierPressed("ctrl")) then
sleeptime = sleeptime + 1
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7 and IsModifierPressed("alt")) then
sleeptime = 15
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3)) then
repeat
Sleep(sleeptime)
MoveMouseRelative(3, 3)
Sleep(5)
MoveMouseRelative(-3, 3)
until not IsMouseButtonPressed(1)
end
end
local vertical_speed = 3.0
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 7 then
if IsModifierPressed("lshift") then
vertical_speed = vertical_speed * 1.05 -- increase speed
elseif IsModifierPressed("ctrl") then
vertical_speed = vertical_speed / 1.05 -- decrease speed
else IsModifierPressed("alt")
vertical_speed = 3.0
end
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) then
local frac, x, y = 0, 1
repeat
Sleep(15)
x, y, frac = -x, math.modf(frac + vertical_speed)
MoveMouseRelative(x * 3, y)
until x > 0 and not IsMouseButtonPressed(1)
end
end
so i have a problem with a LUA Script that im currently building. I have variable for a Gun Spray Pattern, but i want to add a 9ms delay between the Coordinates, unfortunately i cant find a vay to add delays to between the coordinates. Its should look like this
{x=2,y=2}DELAY{x=1,y=1}DELAY......
I know that its impossible to put delays in Variables but i would hope to find a way to put the delays in a loop maybe??.
Heres the code:
local Macro_Activation_Key = 4
local Selection_Key = 3
local Spray_Randomize1 = math.random(24,24)
local Spray_Randomize2 = math.random(20,20.5)
local Spray_Randomize3 = math.random(24,24)
local Recoil_Activator
R_Weapon_Selector = false,0
EnablePrimaryMouseButtonEvents(true);
local AK47_Pattern = {{x=0,y=2},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=4},{x=0,y=4},{x=0,y=5},{x=0,y=8},{x=0,y=8},{x=0,y=8}}
local M4A1_Pattern = {{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=-1,y=4},{x=-1,y=4},{x=0,y=5},{x=-1,y=5},{x=-1,y=5},{x=0,y=5},{x=0,y=5},{x=0,y=5}}
local function RetrieveWeaponName(weapon,act) if weapon == 1 then
return"AK47" elseif weapon == 3 then
return"M4A1" end if act then
return"ON_Macro" else return"OFF_Macro" end end
local function OutputLogs(weapon, act)
OutputLogMessage(RetrieveWeaponName(weapon,act).."\n");
OutputDebugMessage(RetrieveWeaponName(weapon,act).."\n");
ClearLCD();
OutputLCDMessage(RetrieveWeaponName(weapon,act));
end function
OnEvent(event, arg) if (event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key) then
Recoil_Activator = not Recoil_Activator OutputLogs(nil,Recoil_Activator) end
if Recoil_Activator then
if (event == "MOUSE_BUTTON_PRESSED" and arg == Selection_Key) then
if R_Weapon_Selector >= 3 then R_Weapon_Selector = 0 end R_Weapon_Selector = R_Weapon_Selector + 1 OutputLogs(R_Weapon_Selector,nil) end if (R_Weapon_Selector == 1) and IsMouseButtonPressed(1) then
for i = 1, #AK47_Pattern do if IsMouseButtonPressed(1) then Sleep(Spray_Randomize1) MoveMouseRelative( AK47_Pattern[i].x, AK47_Pattern[i].y ) end end end
if (R_Weapon_Selector == 3) and IsMouseButtonPressed(1) then for i = 1, #M4A1_Pattern do if IsMouseButtonPressed(1) then Sleep(Spray_Randomize3) MoveMouseRelative( M4A1_Pattern[i].x, M4A1_Pattern[i].y )
I want to add Delay to the local AK47_Pattern and M4a1_Pattern Variables.
Appreciate all kinds of help
end end end end end
local Macro_Activation_Key = 4
local Selection_Key = 3
local Recoil_Activator, R_Weapon_Selector = false,0
EnablePrimaryMouseButtonEvents(true)
-- d = delay to wait before moving the mouse (d=9 by default)
local AK47_Pattern = {{x=0,y=2},{d=11,x=0,y=2},{d=12,x=0,y=2},{x=0,y=3},{x=0,y=4},{x=0,y=4},{x=0,y=5},{x=0,y=8},{x=0,y=8},{x=0,y=8}}
local M4A1_Pattern = {{x=0,y=1},{d=5,x=0,y=1},{d=7,x=0,y=2},{x=0,y=2},{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=-1,y=4},{x=-1,y=4},{x=0,y=5},{x=-1,y=5},{x=-1,y=5},{x=0,y=5},{x=0,y=5},{x=0,y=5}}
local function RetrieveWeaponName(weapon,act)
if weapon == 1 then
return"AK47"
elseif weapon == 3 then
return"M4A1"
end
if act then
return"ON_Macro"
else
return"OFF_Macro"
end
end
local function OutputLogs(weapon, act)
OutputLogMessage(RetrieveWeaponName(weapon,act).."\n")
OutputDebugMessage(RetrieveWeaponName(weapon,act).."\n")
ClearLCD()
OutputLCDMessage(RetrieveWeaponName(weapon,act))
end
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key) then
Recoil_Activator = not Recoil_Activator
OutputLogs(nil,Recoil_Activator)
end
if Recoil_Activator then
if (event == "MOUSE_BUTTON_PRESSED" and arg == Selection_Key) then
if R_Weapon_Selector >= 3 then
R_Weapon_Selector = 0
end
R_Weapon_Selector = R_Weapon_Selector + 1
OutputLogs(R_Weapon_Selector,nil)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
if R_Weapon_Selector == 1 then
for i = 1, #AK47_Pattern do
Sleep(AK47_Pattern[i].d or 9)
MoveMouseRelative( AK47_Pattern[i].x, AK47_Pattern[i].y )
if not IsMouseButtonPressed(1) then
break
end
end
end
if R_Weapon_Selector == 3 then
for i = 1, #M4A1_Pattern do
Sleep(M4A1_Pattern[i].d or 9)
MoveMouseRelative( M4A1_Pattern[i].x, M4A1_Pattern[i].y )
if not IsMouseButtonPressed(1) then
break
end
end
end
end
end
end
As the title says I'm trying to figure out how to get this piece of stolen code to work :p
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(5) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 3) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and recoil) then
if recoil then
repeat
Sleep(1)
MoveMouseRelative(-400, 0)
Sleep(1)
until not IsMouseButtonPressed(5)
end
end
end
No matter what sleep timer I add I can't get it to work the way I want : I want a single press pixel perfect 180/360 degree turn in call of duty and not have to hold down the mb5 button in order to turn.
MoveAmount = -400
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(4) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
for x=1,10,1
do
MoveMouseRelative(MoveAmount, 0)
Sleep(5)
end
end
end
While you're holding down mb5, then every 2 seconds, this line of code is happening:
MoveMouseRelative(-400, 0)
I guess the problem is that moving the mouse -400 pixels isn't exactly a 180 degree turn, and the correct number will probably be different for everyone depending on their mouse sensitivity settings.
You could try some different numbers instead of -400 to see if it works more like what you want.
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 3) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and recoil) then
local distance = 400 -- adjust this value
while distance > 0 do
local delta = math.min(100, distance)
distance = distance - delta
MoveMouseRelative(-delta, 0)
Sleep(15)
end
end
end