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 


Add Delay or sleep to my script (help request )

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Twistedfate
Expert Cheater
Reputation: 1

Joined: 11 Mar 2016
Posts: 231

PostPosted: Mon Aug 08, 2016 2:10 pm    Post subject: Add Delay or sleep to my script (help request ) Reply with quote

I want my script sleep for 10 mil seconds can u add the sleep to the script please ( sleep - delay - disable then enable it self )





Code:


[Enable]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

newmem:
push ecx
mov ecx,#3435647439

cmp [esi+160], ecx
je originalcode




cmp [esi+24],#111
je originalcode
cmp [esi+24],#110
je originalcode

cmp [esi+24],#121
je originalcode

cmp [esi+24],#120
je originalcode

cmp [esi+24],#130
jne originalcode

fimul [esi+20]
mov [esi+20],#0
fdiv qword ptr [roleview.dll+1F3A0]












jmp exit
originalcode:
fimul [esi+20]
fdiv qword ptr [roleview.dll+1F3A0]

exit:
pop ecx
jmp returnhere

"roleview.dll"+21B0:
jmp newmem
nop
nop
nop
nop
returnhere:
[Disable]
dealloc(newmem)
"roleview.dll"+21B0:
fimul [esi+20]
fdiv qword ptr [roleview.dll+1F3A0]
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Mon Aug 08, 2016 3:37 pm    Post subject: Reply with quote

A very literal interpretation of what you said:
Code:
...
newmem:
push #10
call kernel32.Sleep
...

Another interpretation that's probably a bit closer to what you want:
Code:
local rec = getAddressList().getMemoryRecordByDescription("whatever")
sleep(10)
rec.Active = false
rec.Active = true

I wouldn't recommend directly integrating this Lua code into the AA script (make another thread do it if needed).

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Twistedfate
Expert Cheater
Reputation: 1

Joined: 11 Mar 2016
Posts: 231

PostPosted: Mon Aug 08, 2016 3:52 pm    Post subject: Reply with quote

Quote:
very literal interpretation of what you said


Sry for my bad English
What I want :
the script run for 10 mil sec then the game normal code run the the script run again . which one could i use ?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Mon Aug 08, 2016 4:02 pm    Post subject: Reply with quote

Your English isn't the problem; it's that you didn't give much information.

Do you want the script to infinitely disable and enable itself?

How long do you want the game to run the original code for?

The second example I posted is closer to what you want, but again, you shouldn't put that in the script directly (I don't know what CE would do). Creating another thread to do that would be safer.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Twistedfate
Expert Cheater
Reputation: 1

Joined: 11 Mar 2016
Posts: 231

PostPosted: Mon Aug 08, 2016 4:19 pm    Post subject: Reply with quote

Quote:
Do you want the script to infinitely disable and enable itself?


Yes

Quote:
How long do you want the game to run the original code for?


always except the 10mil sec when my script run .


Quote:
The second example


How can I but it in my code or give me example of thread and thank you ^^
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Mon Aug 08, 2016 4:34 pm    Post subject: This post has 1 review(s) Reply with quote

Quote:
always except the 10mil sec when my script run .

Think about this logically.
  1. You enable your script.
  2. Wait 10 ms.
  3. The script disables itself.
  4. Wait X ms.
  5. The script enables itself.
What is X, because if X is 0, you might as well leave the script enabled.

Quote:
How can I but it in my code

Just wrap that code in a call to createNativeThread, and use {$lua} and {$asm} tags to separate it from the rest of the script:
Code:
{$lua}
createNativeThread(function(t)
    local rec = getAddressList().getMemoryRecordByDescription("whatever")
    sleep(10)
    if rec.Active then   -- don't toggle it if you disable it
      rec.Active = false
      sleep(X)
      rec.Active = true
    end
  end)
{$asm}

One obvious problem is that if you disable/enable it yourself too quickly it will create two threads, but that shouldn't be a problem given a low sleep time. Of course, disabling it yourself might be challenging then.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Twistedfate
Expert Cheater
Reputation: 1

Joined: 11 Mar 2016
Posts: 231

PostPosted: Mon Aug 08, 2016 5:29 pm    Post subject: Reply with quote

Thank you I did it its cooooooooooooooool man


I pasted it in the script upper part and renamed( what ever )with script name
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Aug 08, 2016 6:08 pm    Post subject: Reply with quote

There a reason you didn't just go with a Lua timer?
Code:
{$lua}
[ENABLE]
myrecord = getAddressList().getMemoryRecordByDescription("whatever")
if mytimer == nil then
  mytimer = createTimer(nil, false)
end
mytimer.Interval = 10
mytimer.OnTimer = function(timer)
  myrecord.Active = not myrecord.Active
end
mytimer.Enabled = true
[DISABLE]
mytimer.Enabled = false
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Mon Aug 08, 2016 6:20 pm    Post subject: Reply with quote

Because he originally wanted it in that AA script, and using a timer directly in the [ENABLE] section would entail stuff I didn't want to have to explain.

Also, the GUI becomes unresponsive if you call sleep from the main thread. It's nearly unnoticeable if you set the timer's interval to 1000 and sleep for 10 (OP edited previous post; delay between reactivating is 1000), but it's still not a good habit. Disregarding that, however, I absolutely would use a timer in the Lua script window or in another script.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Aug 08, 2016 6:28 pm    Post subject: This post has 1 review(s) Reply with quote

No, you definitely wouldn't call sleep at all.
You'd use the timer itself to handle both enable/disable of the secondary script.
If you want different intervals, you can change them within the function too.
Code:
  if myrecord.Active then
    myrecord.Active = false
    mytimer.Interval = 1000
  else
    myrecord.Active = true
    mytimer.Interval = 10
  end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Mon Aug 08, 2016 6:33 pm    Post subject: Reply with quote

True. I never thought of changing the interval from within the OnTimer function.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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