Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Lua Script | Creating script that will run automatically

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Mon Dec 14, 2020 3:46 pm    Post subject: Lua Script | Creating script that will run automatically Reply with quote

Hello masters, help me with my script i don't know how to code Lua perfectly
this is my example :
function execute()
for i=1,1 do
doKeyPress(VK_A)
sleep(500)
doKeyPress(VK_B)
end
end
createHotkey(execute, VK_F9)
..............................................
that function is if i press F9, that code will run 1x cycle only asap.
but my plan is to make that code run in the specific time
example: the time now is 5:00AM in the morning. The script will run itself next hour and ten minutes (6:10AM) and auto run again in 7:20AM.
Thanks masters.
Back to top
View user's profile Send private message AIM Address
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Tue Dec 15, 2020 6:31 pm    Post subject: Reply with quote

You can probably get an idea from the main code.

ParkourPenguin wrote:
os.date only formats time points. AFAIK there's nothing in the standard library to format time intervals, so you'll have to do that yourself:
Code:
function format_seconds(sec)
  if sec < 0 then return '00:00:00' end
  return ('%02d:%02d:%02d'):format(sec // (60*60), (sec // 60) % 60, sec % 60)
end

Use os.difftime to get the number of seconds left.
Code:
local start = os.date'*t'
local finish = {}

for k,v in pairs(start) do finish[k] = v end
finish.min = finish.min + 10

local starttime = os.time(start)
local finishtime = os.time(finish)

function status()
  print(os.date('Start time:  %X', starttime))
  print(os.date('Finish time: %X', finishtime))
  print('Remaining:   ' .. format_seconds(os.difftime(finishtime, os.time())))
end


Here is a scenario that is a bit more complicated and close to the code you want.
You can adjust the hours as specified. You can add more time if you want.
Set it to a close hour and minute to try.

Code:
if f then f.destroy() end

f=createForm(true)
f.Position=poDesktopCenter
f.Width=220 f.Height=105

local l1=createLabel(f) l1.AutoSize=false
l1.Height=25 l1.Width=200 l1.Left=10 l1.Top=10
l1.Font.Size=12 l1.Font.Style="fsBold" l1.Alignment="taCenter"

local l2=createLabel(f) l2.AutoSize=false
l2.Height=25 l2.Width=200 l2.Left=10 l2.Top=40
l2.Font.Size=12 l2.Font.Style="fsBold" l2.Alignment="taCenter"

local l3=createLabel(f) l3.AutoSize=false
l3.Height=25 l3.Width=200 l3.Left=10 l3.Top=70
l3.Font.Size=12 l3.Font.Style="fsBold" l3.Alignment="taCenter"

---------------------- function -------------------
function execute()
--for i=1,1 do
doKeyPress(VK_A)
sleep(500)
doKeyPress(VK_B)
--end
end
if exeKey1 then exeKey1.destroy() end
exeKey1=createHotkey(execute, VK_F9)

function format_seconds(sec)
  if sec < 0 then return '00:00:00' end
  return ('%02d:%02d:%02d'):format(sec // (60*60), (sec // 60) % 60, sec % 60)
end

local d1 = os.date'*t'
local xx=1
--local x = ({"h05m00s00", "h06m10s00", "h07m20s00", "h08m30s00"}) -- x = 4
local x = ({"h03m17s00", "h03m19s00", "h03m21s00"}) --x = 3 or 4.. 5.. 6 etc.
local prt3=""
if secTimer then secTimer.destroy() end
secTimer=createTimer() secTimer.Interval=1000 secTimer.Enabled=true

secTimer.OnTimer=function()
if prt3==("Remaining:     00:00:00") then
xx=xx + 1 doKeyPress(VK_F9) end --Execute code
if xx==4 then --If "x" is 3 set here to 4. If you put 6 hours in the "x", make it 7 here.
secTimer.Enabled=false l1.caption="Execute time: Finish!"
else
local xh,xm,xs=string.match(x[xx], "h(.*)m(.*)s(.*)")
--print("\nxx: "..xx)
local xxx1,xxx2,xxx3=3600*xh, 60*xm, xs*1
local xxx4=xxx1+xxx2+xxx3

l1.caption=("Execute time:   "..xh..":"..xm..":"..xs)

local dh,dm,ds=os.date("%H"), os.date("%M"), os.date("%S")

local xxx5,xxx6,xxx7=3600*dh, 60*dm, ds*1
local xxx8=xxx5+xxx6+xxx7
xxx9=xxx4-xxx8--3*3600
xxx8 = os.time(d1)
l2.caption=(os.date("Current time:   %H:%M:%S"))

prt3=('Remaining:     '..format_seconds(xxx9))
l3.caption=(prt3)
end
end
Back to top
View user's profile Send private message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Wed Dec 16, 2020 4:19 pm    Post subject: Lua Script | Creating script that will run automatically Reply with quote

Thank you for this answers man, i really appreciated it.
I understand lua a bit. Still complicated for me to do these codes.
this code worked and i tried, but i don't know how to set the time, when i change the code a bit, it gives me error after pressing execute lua
I'm willing to pay u money via paypal for your code work. I'm bad in english i can't explain it perfectly. If you have time man to connect to my pc via teamviewer or Anydesk. pm me man.
Thanks! Smile
Back to top
View user's profile Send private message AIM Address
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Thu Dec 17, 2020 1:12 pm    Post subject: Reply with quote

Hello.
Thanks for your offer, of course I would like to help.
But in CEF it is more correct to dedicate "Aid, Donation, Coffee, Support, Initiative ..." to the Cheat Engine and DarkByte.
This; It will help keep the Cheat Engine open.
From a cup of coffee to an annual subscription, you can use the link below to support whatever you wish.

Cheat Engine / DarkByte Donate:
https://www.paypal.com/xclick/business=dark_byte%40hotmail.com&no_note=1&tax=0&lc=US

Now back to the problem;

To set the time (set the Run time), edit the following sections in the script;

1)
Code:
local x = ({"h03m17s00", "h03m19s00", "h03m21s00"})


edit :
Code:
local x = ({"h05m00s00", "h06m10s00", "h07m20s00", "h08m30s00"})


2)
Code:
if xx==4 then
secTimer.Enabled=false l1.caption="Execute time: Finish!"


edit :
Code:
if xx==5 then
secTimer.Enabled=false l1.caption="Execute time: Finish!"


Time setting is based on 00-23. Accordingly, 5 in the morning; It is set to 05:00:00.

If you are installing this setup before midnight (before 00:00:00), it probably won't be able to detect 5:00:00 the next morning.
If so, let's edit the code like this;

Code:
if f then f.destroy() end

f=createForm(true)
f.Position=poDesktopCenter
f.Width=220 f.Height=105

local l1=createLabel(f) l1.AutoSize=false
l1.Height=25 l1.Width=200 l1.Left=10 l1.Top=10
l1.Font.Size=12 l1.Font.Style="fsBold" l1.Alignment="taCenter"

local l2=createLabel(f) l2.AutoSize=false
l2.Height=25 l2.Width=200 l2.Left=10 l2.Top=40
l2.Font.Size=12 l2.Font.Style="fsBold" l2.Alignment="taCenter"

local l3=createLabel(f) l3.AutoSize=false
l3.Height=25 l3.Width=200 l3.Left=10 l3.Top=70
l3.Font.Size=12 l3.Font.Style="fsBold" l3.Alignment="taCenter"

---------------------- function -------------------
function execute()
--for i=1,1 do
doKeyPress(VK_A)
sleep(500)
doKeyPress(VK_B)
--end
end
if exeKey1 then exeKey1.destroy() end
exeKey1=createHotkey(execute, VK_F9)

function format_seconds(sec)
  if sec < 0 then return '00:00:00' end
  return ('%02d:%02d:%02d'):format(sec // (60*60), (sec // 60) % 60, sec % 60)
end

local d1 = os.date'*t'
local xx=1
local xv=""
--local x = ({"h05m00s00", "h06m10s00", "h07m20s00", "h08m30s00"}) -- x = 4
local x = ({"h23m21s00", "h05m34s00", "h22m36s00", "h22m38s00"}) --x = 3 or 4.. 5.. 6 etc.
local prt3=("Remaining:   Pending...")
if secTimer then secTimer.destroy() end
secTimer=createTimer() secTimer.Interval=1000 secTimer.Enabled=true

secTimer.OnTimer=function()
l2.caption=(os.date("Current ("..os.date("%p").."):   %H:%M:%S"))
if prt3==("Remaining:       00:00:00") then
xx=xx + 1 doKeyPress(VK_F9) end --Execute code
if xx==5 then
 l1.caption="Execute time: Finish!" prt3=("Remaining:   Pending...") l3.caption=(prt3)
else
local xh,xm,xs=string.match(x[xx], "h(.*)m(.*)s(.*)")
--print("\nxx: "..xx)
local xxx1,xxx2,xxx3=3600*xh, 60*xm, xs*1
local xxx4=xxx1+xxx2+xxx3
local ampm="12:00:00"
local exeT=(xh..":"..xm..":"..xs)
if ampm<exeT then
l1.caption=("Execute PM("..xx.."):    "..exeT)
else
l1.caption=("Execute AM("..xx.."):    "..exeT)
end

local dh,dm,ds=os.date("%H"), os.date("%M"), os.date("%S")

local xxx5,xxx6,xxx7=3600*dh, 60*dm, ds*1
local xxx8=xxx5+xxx6+xxx7

xxx9=xxx4-xxx8
prt3=('Remaining:       '..format_seconds(xxx9))
l3.caption=(prt3)
xv="1"
collectgarbage("count")

if xxx4<xxx8 then
xv="2"
xxx8=86400-xxx8
xxx9=xxx8+xxx4
prt3=('Remaining:     '..format_seconds(xxx9))
l3.caption=(prt3)
collectgarbage("count")
end
end
end


Everything aside; From within you or the CEF, anyone who wants to reach me can come to this group that I manage:
https://www.facebook.com/groups/KINGS.OF.THE.GAME
Back to top
View user's profile Send private message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Sat Dec 26, 2020 1:08 pm    Post subject: Reply with quote

ByTransient wrote:
Hello.
Thanks for your offer, of course I would like to help.
But in CEF it is more correct to dedicate "Aid, Donation, Coffee, Support, Initiative ..." to the Cheat Engine and DarkByte.
This; It will help keep the Cheat Engine open.
From a cup of coffee to an annual subscription, you can use the link below to support whatever you wish.

Cheat Engine / DarkByte Donate:
_note=1&tax=0&lc=US

Now back to the problem;

To set the time (set the Run time), edit the following sections in the script;

1)
Code:
local x = ({"h03m17s00", "h03m19s00", "h03m21s00"})


edit :
Code:
local x = ({"h05m00s00", "h06m10s00", "h07m20s00", "h08m30s00"})


2)
Code:
if xx==4 then
secTimer.Enabled=false l1.caption="Execute time: Finish!"


edit :
Code:
if xx==5 then
secTimer.Enabled=false l1.caption="Execute time: Finish!"


Time setting is based on 00-23. Accordingly, 5 in the morning; It is set to 05:00:00.

If you are installing this setup before midnight (before 00:00:00), it probably won't be able to detect 5:00:00 the next morning.
If so, let's edit the code like this;

Code:
if f then f.destroy() end

f=createForm(true)
f.Position=poDesktopCenter
f.Width=220 f.Height=105

local l1=createLabel(f) l1.AutoSize=false
l1.Height=25 l1.Width=200 l1.Left=10 l1.Top=10
l1.Font.Size=12 l1.Font.Style="fsBold" l1.Alignment="taCenter"

local l2=createLabel(f) l2.AutoSize=false
l2.Height=25 l2.Width=200 l2.Left=10 l2.Top=40
l2.Font.Size=12 l2.Font.Style="fsBold" l2.Alignment="taCenter"

local l3=createLabel(f) l3.AutoSize=false
l3.Height=25 l3.Width=200 l3.Left=10 l3.Top=70
l3.Font.Size=12 l3.Font.Style="fsBold" l3.Alignment="taCenter"

---------------------- function -------------------
function execute()
--for i=1,1 do
doKeyPress(VK_A)
sleep(500)
doKeyPress(VK_B)
--end
end
if exeKey1 then exeKey1.destroy() end
exeKey1=createHotkey(execute, VK_F9)

function format_seconds(sec)
  if sec < 0 then return '00:00:00' end
  return ('%02d:%02d:%02d'):format(sec // (60*60), (sec // 60) % 60, sec % 60)
end

local d1 = os.date'*t'
local xx=1
local xv=""
--local x = ({"h05m00s00", "h06m10s00", "h07m20s00", "h08m30s00"}) -- x = 4
local x = ({"h23m21s00", "h05m34s00", "h22m36s00", "h22m38s00"}) --x = 3 or 4.. 5.. 6 etc.
local prt3=("Remaining:   Pending...")
if secTimer then secTimer.destroy() end
secTimer=createTimer() secTimer.Interval=1000 secTimer.Enabled=true

secTimer.OnTimer=function()
l2.caption=(os.date("Current ("..os.date("%p").."):   %H:%M:%S"))
if prt3==("Remaining:       00:00:00") then
xx=xx + 1 doKeyPress(VK_F9) end --Execute code
if xx==5 then
 l1.caption="Execute time: Finish!" prt3=("Remaining:   Pending...") l3.caption=(prt3)
else
local xh,xm,xs=string.match(x[xx], "h(.*)m(.*)s(.*)")
--print("\nxx: "..xx)
local xxx1,xxx2,xxx3=3600*xh, 60*xm, xs*1
local xxx4=xxx1+xxx2+xxx3
local ampm="12:00:00"
local exeT=(xh..":"..xm..":"..xs)
if ampm<exeT then
l1.caption=("Execute PM("..xx.."):    "..exeT)
else
l1.caption=("Execute AM("..xx.."):    "..exeT)
end

local dh,dm,ds=os.date("%H"), os.date("%M"), os.date("%S")

local xxx5,xxx6,xxx7=3600*dh, 60*dm, ds*1
local xxx8=xxx5+xxx6+xxx7

xxx9=xxx4-xxx8
prt3=('Remaining:       '..format_seconds(xxx9))
l3.caption=(prt3)
xv="1"
collectgarbage("count")

if xxx4<xxx8 then
xv="2"
xxx8=86400-xxx8
xxx9=xxx8+xxx4
prt3=('Remaining:     '..format_seconds(xxx9))
l3.caption=(prt3)
collectgarbage("count")
end
end
end


Everything aside; From within you or the CEF, anyone who wants to reach me can come to this group that I manage:
xxxfacebooxxxom/groups/KINxxxS.OF.THE.GAME


Thank you so much!
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites