How to cancel a script after it has started Lua - lua

If I start my script then realise I pressed the wrong button, or don't want it to run all the way to the end, can I add something to the code that if I press the button again, or another button if it can't be the same, it will immediately stop the script?
This is my current script
if (event == "G_PRESSED" and arg == 4 and GetMKeyState("kb") == 3) then
MoveMouseTo( 36165, 57821)
Sleep(math.random(10, 25))
PressMouseButton(3)
ReleaseMouseButton(3)
Sleep(math.random(40, 135))
MoveMouseTo( 36131, 59461)
Sleep(math.random(30, 65))
PressKey ("lalt")
Sleep(math.random(30, 65))
PressKey ("X")
Sleep(math.random(30, 65))
ReleaseKey ("lalt")
ReleaseKey ("X")
PressMouseButton(1)
ReleaseMouseButton(1)
Sleep(math.random(2220, 2270))
MoveMouseTo( 38932, 56060)
Sleep(math.random(10, 25))
PressMouseButton(1)
ReleaseMouseButton(1)
Sleep(math.random(40, 135))
MoveMouseTo( 2595, 3037)
Sleep(math.random(40, 135))
PressMouseButton(1)
ReleaseMouseButton(1)
MoveMouseTo( 4166, 1518)
Sleep(math.random(250, 350))
PressMouseButton(1)
ReleaseMouseButton(1)
MoveMouseTo( 38932, 56060)
Sleep(math.random(40, 135))
PressMouseButton(3)
ReleaseMouseButton(3)
Sleep(math.random(40, 135))
MoveMouseTo( 38590, 57882)
Sleep(math.random(40, 135))
PressKey ("lalt")
Sleep(math.random(40, 135))
PressKey ("X")
Sleep(math.random(40, 135))
ReleaseKey ("lalt")
ReleaseKey ("X")
Sleep(math.random(40, 135))
PressKey ("O")
Sleep(math.random(40, 135))
ReleaseKey ("O")
Sleep(200)
MoveMouseTo( 54436, 55453)
Sleep(math.random(40, 135))
PressMouseButton(1)
ReleaseMouseButton(1)
Sleep(400)
MoveMouseTo( 54299, 48650)
Sleep(150)
PressMouseButton(1)
ReleaseMouseButton(1)
end

Related

Logitech Lua script

im trying to run this script on my logitech mouse. I want the mouse cursor to move down, it does but after a while of the cursor moving down the cursor reverses in direction.
Does anyone know why?
function X4()
local mult= 11
if IsMouseButtonPressed(1)then
repeat
MoveMouseRelative(0*mult, 11*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 11*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 11*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 11*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 10*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 11*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 11*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 12*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 13*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 14*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 14*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 14*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 14*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 14*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 14*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 15*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(0*mult, 16*mult)Sleep(10) if not IsMouseButtonPressed(1) then break end
until not IsMouseButtonPressed(1)
end
end
Your mouse move simulation should be in a reasonable limits.
It's very unrealistic that a human can move mouse cursor faster than 100 pixels in 10 ms.
MoveMouseRelative accepts only integers in the range -127..127
In your case 16*mult = 16*11 = 176 > 127
Values above 127 might be interpreted as negative values.

Can Someone Combine these 2 scripts

Can't get this to work. The first part is a toggle function (mouse button 8) which functions with the use of mouse button 1 being pressed and released. The second part (mouse button 7) is just a "click to use" functionality.
I can flip flop these parts, and only the second part works, which makes me confused.
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 == 8) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 23)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 24)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 21)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 23)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 27)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 26)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 25)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
until not IsMouseButtonPressed(1)
end
end
end
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then
MoveMouseTo(39805, 60267)
Sleep(30)
PressMouseButton(1)
Sleep(50)
ReleaseMouseButton(1)
Sleep(50)
MoveMouseTo(32805, 50267)
Sleep(25)
PressMouseButton(1)
Sleep(30)
ReleaseMouseButton(1)
end
end
Thank you in advance.
Figured it out
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 == 8) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 23)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 24)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 21)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 23)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 27)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 26)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-1, 25)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(16, 4)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
MoveMouseRelative(-16, 0)
Sleep(100) if not IsMouseButtonPressed(1) then break end
until not IsMouseButtonPressed(1)
end
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then
MoveMouseTo(16000, 61000)
Sleep(30)
PressMouseButton(1)
Sleep(50)
ReleaseMouseButton(1)
Sleep(50)
MoveMouseTo(32805, 50267)
Sleep(25)
PressMouseButton(1)
Sleep(30)
ReleaseMouseButton(1)
end
end

Redis crash when turning into replica

I am using redis through docker in my project with the latest version 5.0.7.
I keep the default config of redis, except the appendonly that i put to yes to have persistence of my data.
When i see the save config, it is empty and it does help me because i don't need rdb backup but the problem is i still have logs "DB saved on disk" even if this option is deactivate.
but the real problem is that sometime, the instance redis which is turning in "standalone" was trying to turn into replica. I think the reason is because it is doing backups according to my research. This problem is stopping redis to listen to the user requests and my API went down.
Here is my config :
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) ""
5) "masterauth"
6) ""
7) "cluster-announce-ip"
8) ""
9) "unixsocket"
10) ""
11) "logfile"
12) ""
13) "pidfile"
14) ""
15) "slave-announce-ip"
16) ""
17) "replica-announce-ip"
18) ""
19) "maxmemory"
20) "0"
21) "proto-max-bulk-len"
22) "536870912"
23) "client-query-buffer-limit"
24) "1073741824"
25) "maxmemory-samples"
26) "5"
27) "lfu-log-factor"
28) "10"
29) "lfu-decay-time"
30) "1"
31) "timeout"
32) "0"
33) "active-defrag-threshold-lower"
34) "10"
35) "active-defrag-threshold-upper"
36) "100"
37) "active-defrag-ignore-bytes"
38) "104857600"
39) "active-defrag-cycle-min"
40) "5"
41) "active-defrag-cycle-max"
42) "75"
43) "active-defrag-max-scan-fields"
44) "1000"
45) "auto-aof-rewrite-percentage"
46) "100"
47) "auto-aof-rewrite-min-size"
48) "67108864"
49) "hash-max-ziplist-entries"
50) "512"
51) "hash-max-ziplist-value"
52) "64"
53) "stream-node-max-bytes"
54) "4096"
55) "stream-node-max-entries"
56) "100"
57) "list-max-ziplist-size"
58) "-2"
59) "list-compress-depth"
60) "0"
61) "set-max-intset-entries"
62) "512"
63) "zset-max-ziplist-entries"
64) "128"
65) "zset-max-ziplist-value"
66) "64"
67) "hll-sparse-max-bytes"
68) "3000"
69) "lua-time-limit"
70) "5000"
71) "slowlog-log-slower-than"
72) "10000"
73) "latency-monitor-threshold"
74) "0"
75) "slowlog-max-len"
76) "128"
77) "port"
78) "6379"
79) "cluster-announce-port"
80) "0"
81) "cluster-announce-bus-port"
82) "0"
83) "tcp-backlog"
84) "511"
85) "databases"
86) "16"
87) "repl-ping-slave-period"
88) "10"
89) "repl-ping-replica-period"
90) "10"
91) "repl-timeout"
92) "60"
93) "repl-backlog-size"
94) "1048576"
95) "repl-backlog-ttl"
96) "3600"
97) "maxclients"
98) "10000"
99) "watchdog-period"
100) "0"
101) "slave-priority"
102) "100"
103) "replica-priority"
104) "100"
105) "slave-announce-port"
106) "0"
107) "replica-announce-port"
108) "0"
109) "min-slaves-to-write"
110) "0"
111) "min-replicas-to-write"
112) "0"
113) "min-slaves-max-lag"
114) "10"
115) "min-replicas-max-lag"
116) "10"
117) "hz"
118) "10"
119) "cluster-node-timeout"
120) "15000"
121) "cluster-migration-barrier"
122) "1"
123) "cluster-slave-validity-factor"
124) "10"
125) "cluster-replica-validity-factor"
126) "10"
127) "repl-diskless-sync-delay"
128) "5"
129) "tcp-keepalive"
130) "300"
131) "cluster-require-full-coverage"
132) "yes"
133) "cluster-slave-no-failover"
134) "no"
135) "cluster-replica-no-failover"
136) "no"
137) "no-appendfsync-on-rewrite"
138) "no"
139) "slave-serve-stale-data"
140) "yes"
141) "replica-serve-stale-data"
142) "yes"
143) "slave-read-only"
144) "yes"
145) "replica-read-only"
146) "yes"
147) "slave-ignore-maxmemory"
148) "yes"
149) "replica-ignore-maxmemory"
150) "yes"
151) "stop-writes-on-bgsave-error"
152) "yes"
157) "rdbchecksum"
158) "yes"
159) "activerehashing"
160) "yes"
161) "activedefrag"
162) "no"
163) "protected-mode"
164) "no"
165) "repl-disable-tcp-nodelay"
166) "no"
167) "repl-diskless-sync"
168) "no"
169) "aof-rewrite-incremental-fsync"
170) "yes"
171) "rdb-save-incremental-fsync"
172) "yes"
173) "aof-load-truncated"
174) "yes"
175) "aof-use-rdb-preamble"
176) "yes"
177) "lazyfree-lazy-eviction"
178) "no"
179) "lazyfree-lazy-expire"
180) "no"
181) "lazyfree-lazy-server-del"
182) "no"
183) "slave-lazy-flush"
184) "no"
185) "replica-lazy-flush"
186) "no"
187) "dynamic-hz"
188) "yes"
189) "maxmemory-policy"
190) "noeviction"
191) "loglevel"
192) "notice"
193) "supervised"
194) "no"
195) "appendfsync"
196) "everysec"
197) "syslog-facility"
198) "local0"
199) "appendonly"
200) "yes"
201) "dir"
202) "/data"
203) "save"
204) ""
205) "client-output-buffer-limit"
206) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
207) "unixsocketperm"
208) "0"
209) "slaveof"
210) ""
211) "notify-keyspace-events"
212) ""
213) "bind"
214) ""
And here is the logs before redis stopped listening to the requests redis logs
Thanks for your help.
Finally i found that this commands where exectued by another client to provoke the DB saved disk and also the command SlaveOf to turn the master node into slave.
The configuration of redis is good.

How to stop the function when single shot, but enable while spray/auto shooting

I made a small anti-recoil script for LUA logitech gaming mouse and it seems that it does the function but when I single shot it does the whole thing and doesn't stop when mousebutton is not pressed:
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)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
kaki = not kaki
kus = not kus
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and kaki) then
if kaki then
repeat
Sleep(50)
MoveMouseRelative(0, 1)
Sleep(100)
MoveMouseRelative(0, 16)
Sleep(100)
MoveMouseRelative(0, 26)
Sleep(100)
MoveMouseRelative(-2, 25)
Sleep(100)
MoveMouseRelative(10, 28)
Sleep(100)
MoveMouseRelative(8, 25)
Sleep(100)
MoveMouseRelative(10, 15)
Sleep(100)
MoveMouseRelative(-14, 15)
Sleep(100)
MoveMouseRelative(-34, -1)
Sleep(100)
MoveMouseRelative(-18, 0)
Sleep(100)
MoveMouseRelative(10, 10)
Sleep(100)
MoveMouseRelative(-13, 5)
Sleep(100)
MoveMouseRelative(-20, -5)
Sleep(100)
MoveMouseRelative(-5, 0)
Sleep(100)
MoveMouseRelative(33, 3)
Sleep(100)
MoveMouseRelative(15, 6)
Sleep(100)
MoveMouseRelative(15, 5)
Sleep(100)
MoveMouseRelative(20, 0)
Sleep(100)
MoveMouseRelative(28, -10)
Sleep(100)
MoveMouseRelative(-15, 4)
Sleep(100)
MoveMouseRelative(5, 0)
Sleep(100)
MoveMouseRelative(-8, 8)
Sleep(100)
MoveMouseRelative(-6, 4)
Sleep(100)
MoveMouseRelative(3, -2)
MoveMouseRelative(13, 0)
Sleep(100)
MoveMouseRelative(5, 0)
Sleep(100)
MoveMouseRelative(-15, 0)
Sleep(100)
MoveMouseRelative(-30, 0)
Sleep(100)
MoveMouseRelative(-35, -13)
Sleep(100)
MoveMouseRelative(-13, -4)
Sleep(100)
until not IsMouseButtonPressed(1)
end
end
end
Any suggestions on how to cancel the function mid-way or when mouse button is not pressed and the loop will not complete and end where the last shot was fired.
(In the game when I shoot single shot - the mouse move the whole recoil procedure)
Try using coroutine.
if kaki then
local cor = coroutine.create(function()
MoveMouseRelative(0, 1)
coroutine.yield()
MoveMouseRelative(0, 16)
coroutine.yield()
MoveMouseRelative(0, 26)
coroutine.yield()
MoveMouseRelative(-2, 25)
coroutine.yield()
MoveMouseRelative(10, 28)
coroutine.yield()
MoveMouseRelative(8, 25)
coroutine.yield()
MoveMouseRelative(10, 15)
coroutine.yield()
MoveMouseRelative(-14, 15)
coroutine.yield()
MoveMouseRelative(-34, -1)
coroutine.yield()
MoveMouseRelative(-18, 0)
coroutine.yield()
MoveMouseRelative(10, 10)
coroutine.yield()
MoveMouseRelative(-13, 5)
coroutine.yield()
MoveMouseRelative(-20, -5)
coroutine.yield()
MoveMouseRelative(-5, 0)
coroutine.yield()
MoveMouseRelative(33, 3)
coroutine.yield()
MoveMouseRelative(15, 6)
coroutine.yield()
MoveMouseRelative(15, 5)
coroutine.yield()
MoveMouseRelative(20, 0)
coroutine.yield()
MoveMouseRelative(28, -10)
coroutine.yield()
MoveMouseRelative(-15, 4)
coroutine.yield()
MoveMouseRelative(5, 0)
coroutine.yield()
MoveMouseRelative(-8, 8)
coroutine.yield()
MoveMouseRelative(-6, 4)
coroutine.yield()
MoveMouseRelative(3, -2)
MoveMouseRelative(13, 0)
coroutine.yield()
MoveMouseRelative(5, 0)
coroutine.yield()
MoveMouseRelative(-15, 0)
coroutine.yield()
MoveMouseRelative(-30, 0)
coroutine.yield()
MoveMouseRelative(-35, -13)
coroutine.yield()
MoveMouseRelative(-13, -4)
end)
coroutine.resume(cor)
repeat
Sleep(100)
coroutine.resume(cor)
until not IsMouseButtonPressed(1)
end

Image won't move in Lua LÖVE game

I am writting a game in Lua LÖVE framework, for the LudumDare26. I can't seem to figure out why my "player" won't move when I press WASD.
function love.draw()
playerX = 10
playerY = 10
if love.keyboard.isDown ("w") then
playerY = playerY - 1
elseif love.keyboard.isDown ("s") then
playerY = playerY + 1
elseif love.keyboard.isDown ("a") then
playerX = playerX - 1
elseif love.keyboard.isDown ("d") then
playerX = playerX + 1
end
local x = love.mouse.getX()
local y = love.mouse.getY()
love.graphics.setColor(0, 200, 255, 100)
love.graphics.rectangle("fill", 0, 0, 800, 300)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.rectangle("fill", xCloud, 128, 128, 50)
love.graphics.setColor(50, 160, 80, 255)
love.graphics.rectangle("fill", 0, 300, 800, 300)
love.graphics.setColor(255, 0, 0, 255)
love.graphics.draw(corsair, x - 16, y - 16, 0, 1, 1, 0, 0)
love.graphics.draw(player, playerX, playerY)
love.graphics.line(playerX, playerY, x, y)
end
Take these lines out of love.draw() method:
playerX = 10
playerY = 10

Resources