Im brand new at scripting and have no idea what im doing. Found the below code online and want it to make adjustments. So basically, in fallout 4 lets say a gun's recoil goes to up and to the left originally, but then halfway into shooting it goes to the right. I want the script to initially be able to pull the mouse down and to the right, and then (when the guns recoil starts to go in the other direction) go to the left. Is this possible?
EnablePrimaryMouseButtonEvents (true);
function OnEvent(event,arg)
if IsKeyLockOn("numlock")then
if IsMouseButtonPressed(3)then
repeat
if IsMouseButtonPressed(1) then
repeat
MoveMouseRelative(-1,13)
Sleep(75)
until not IsMouseButtonPressed(1)
end
until not IsMouseButtonPressed(3)
end
end
end
Above is a script I use to move my mouse down when pressing the shooting buttons in Fallout 4 because I have problems which prevent me from countering recoil.
I want the script to not only move down and slightly to the left (MoveMouseRelative(-1,13)) but I want to be able to specify that after a certain amount of time, I then want the script to move in a different direction that again, I can specify.
How would I do this? I believe this is a LUA script or something, and im using a logitech mouse
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn("numlock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- you can add more groups
end
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn("scrolllock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- you can add more groups
end
end
UPDATE:
Step 0.
You are about to modify the behavior of Left Mouse Button.
This is a potentially dangerous operation: you can do almost nothing on your computer without LMB.
So you must create a "spare LMB".
For example, if you don't use Mouse Button 8, you can make it acting like a clone on LMB.
Go to the big mouse picture in LGS and assign command "Left Click" to your physical MB#8.
Now, if something goes wrong and your LMB stops working, you can press MB#8 instead of LMB.
Step 1.
Do you use Mouse Button 4 ("Back") in the game?
Step 2.
You have to remap game action from MB#4 to some other key.
Do the following:
F12
key is not currently used) F12
to your physical MB#4 F12
instead of MB#4 As a result, when you press physical MB#4, the game receives F12
and activates the game action.
Now skip "Step 3" and proceed to "Step 4".
Step 3.
Go to the big mouse picture in LGS.
Unassign standard command "Back" from physical MB#4 (select "Unassign" from the drop-down menu).
Step 4.
Set the script (see below).
Step 5.
Go to the big mouse picture in LGS.
Assign command "Back" to your physical LMB.
You will see a warning about a potentially dangerous operation.
Allow this operation because you have the "spare LMB" if something goes wrong.
-- rapid fire (CAPSLOCK) is independent from anti-recoil (NUMLOCK and SCROLLLOCK)
local rapid_fire_interval = 30 -- milliseconds between LMB press/release simulation
local LMB_down, rapid_fire, prev_time, next_LMB_time
local function PressOrReleaseLMB(only_release)
if LMB_down then
ReleaseMouseButton(1)
LMB_down = false
elseif not only_release then
PressMouseButton(1)
LMB_down = true
end
end
local function Sleep_with_rapid_fire(ms)
-- returns true if LMB was released by user
prev_time = prev_time + ms
while GetRunningTime() < prev_time do
Sleep(10)
if not IsMouseButtonPressed(4) then
return true
end
while rapid_fire and GetRunningTime() >= next_LMB_time then
next_LMB_time = next_LMB_time + rapid_fire_interval
PressOrReleaseLMB() -- press LMB (if it's up) or release LMB (if it's down)
end
end
end
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" or event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
PressOrReleaseLMB(true) -- release LMB
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
PressOrReleaseLMB() -- press LMB
prev_time = GetRunningTime()
next_LMB_time = prev_time + rapid_fire_interval
rapid_fire = IsKeyLockOn("capslock")
if IsMouseButtonPressed(3) then -- RMB pressed
if IsKeyLockOn("numlock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
if Sleep_with_rapid_fire(75) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
if Sleep_with_rapid_fire(75) then return end
end
-- you can add more groups
elseif IsKeyLockOn("scrolllock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
if Sleep_with_rapid_fire(75) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
if Sleep_with_rapid_fire(75) then return end
end
-- you can add more groups
end
end
Sleep_with_rapid_fire(math.huge) -- until user released LMB
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.