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: please help me, maybe I'm only sleeping :oops:

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
danrevella
Master Cheater
Reputation: 2

Joined: 11 Jun 2008
Posts: 290

PostPosted: Tue Feb 18, 2014 12:06 pm    Post subject: LUA: please help me, maybe I'm only sleeping :oops: Reply with quote

Hi!!
I have "stolen" some code here in the forum...... ehm.....
My purpose is:
INSIDE a game I press an hotkey performing the follows:
-open the process of the game in CE
-immediately pause it
-auto popup in CE.
I have found this LUA code:
Code:

function func(sender)
print("Hello")
return true
end
hkey=createHotkey("func",VK_A)
generichotkey_onHotkey(hkey,func)
 

who executing perform his job.....
So I have think: OK, only a few modifications and I'll be ready:
Code:

function func(sender)
print("Hello")

mygame=getForegroundProcess()
openProcess(mygame)
pause()

return true
end
hkey=createHotkey("func",VK_A)
generichotkey_onHotkey(hkey,func)


But it does NOT works Crying or Very sad Crying or Very sad Crying or Very sad

Maybe someone may be so kind to:
a) completing the code for me so it is immediatelly working
b) let me know why I'm so stupid that after many hours of research I'm still not able in fixing by myself?

Please....... Crying or Very sad

Danrevella

p.s. I have many problems in reading in english, and maybe I still don't understand what LUA exactelly is: a language,a script propcessor,or what.[/code]
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Tue Feb 18, 2014 7:28 pm    Post subject: Re: LUA: please help me, maybe I'm only sleeping :oops: Reply with quote

danrevella wrote:
a) completing the code for me so it is immediatelly working
Closest thing I could get: CE is drawn over my test application, but does NOT have window focus.
Code:
function ShowCE(sender)
  print("Hello");

  local mygame=getForegroundProcess();
  openProcess(mygame);
  pause();
  getMainForm().setFocus();

  return true;
end


if (hkey==nil) then
  hkey.destroy();
end

hkey=createHotkey(ShowCE,VK_F2);
hkey.setOnHotkey(ShowCE);

danrevella wrote:
b) let me know why I'm so stupid that after many hours of research I'm still not able in fixing by myself?
Look at main.lua (text file) if that's not already done.

danrevella wrote:
I still don't understand what LUA exactelly is: a language,a script propcessor,or what.
LUA is a language. The script processor is called...... the lua interpreter/engine/VM (virtual machine). On other words it doesn't really have a name afaik.
_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
danrevella
Master Cheater
Reputation: 2

Joined: 11 Jun 2008
Posts: 290

PostPosted: Wed Feb 19, 2014 5:07 am    Post subject: Reply with quote

Many thanks, now I'll go and study better,
BTW the script still does not work for me:

Code:
Error:[string "function ShowCE(sender)..."]:14: attempt to index global 'hkey' (a nil value)


Where is my mistake?
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Wed Feb 19, 2014 5:15 am    Post subject: Reply with quote

It's just me being a complete retard:
Code:
if (hkey==nil) then
  hkey.destroy();
end

should be:
Code:
if (hkey~=nil) then
  hkey.destroy();
  hkey=nil;
end

...That's what you get for making post-time changes.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
danrevella
Master Cheater
Reputation: 2

Joined: 11 Jun 2008
Posts: 290

PostPosted: Wed Feb 19, 2014 6:16 am    Post subject: Reply with quote

Now the code works with no error, BTW does not get his goal: in fact i run it, go to my game and inside the game i press F2, but what i get is that CE now have open "cheatengine_x86_64exe" .
The code now appears as follows:
Code:
function ShowCE(sender)
  print("Hello");

  local mygame=getForegroundProcess();
  openProcess(mygame);
  pause();
  getMainForm().setFocus();

  return true;
end

if (hkey~=nil) then
  hkey.destroy();
  hkey=nil;
end


hkey=createHotkey(ShowCE,VK_F2);
hkey.setOnHotkey(ShowCE);

Thanks!
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Wed Feb 19, 2014 6:31 am    Post subject: Reply with quote

I couldn't reproduce your problem.
The only possible cause I can think of is that you hold the hotkey for too long, activating it twice. First activation gives focus to CE (doesn't happen on my end), second activation targets CE.

Try to increase CE settings->hotkeys->delay betweens reactivating hotkeys.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
danrevella
Master Cheater
Reputation: 2

Joined: 11 Jun 2008
Posts: 290

PostPosted: Wed Feb 19, 2014 7:36 am    Post subject: Reply with quote

Gniarf wrote:
I couldn't reproduce your problem.
The only possible cause I can think of is that you hold the hotkey for too long, activating it twice. First activation gives focus to CE (doesn't happen on my end), second activation targets CE.

Try to increase CE settings->hotkeys->delay betweens reactivating hotkeys.

You were right...
Many thanks now I have a good base to start my study...
Unfortunelly seems to be the doesn't exist LUA documentation in italian... Crying or Very sad
But still a question: is it possible inside LUA call the standard win32api in any mode?
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Wed Feb 19, 2014 7:53 am    Post subject: This post has 1 review(s) Reply with quote

danrevella wrote:
Unfortunelly seems to be the doesn't exist LUA documentation in italian...
No offense, but generally when you want to do something complex in I.T. you need to understand english. So learn it, it will serve you many times.

danrevella wrote:
But still a question: is it possible inside LUA call the standard win32api in any mode?
Afaik, no.
The closest thing I see is a lua script that executes an autoassembler script that calls a winapi. Remember that the autoAssemble(.., ..) lua function can inject code inside CE or inside the target.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
danrevella
Master Cheater
Reputation: 2

Joined: 11 Jun 2008
Posts: 290

PostPosted: Thu Feb 20, 2014 5:24 am    Post subject: Reply with quote

Thanks for your suggestion, now finally I have got a working script really usefull (for me at least..)
Code:
first_time=true;
function togglePause()
  if first_time then
  local mygame=getForegroundProcess();
  --print(mygame);
  openProcess(mygame);
  pause()
  first_time=nil
  end
  if processPaused then unpause()
                  else   pause()
                  getMainForm().setFocus();
                  end
    processPaused = not processPaused
    end
    if pauseHotkey~=nil then
    pauseHotkey.destroy();
    pauseHotkey=nil
    end
pauseHotkey = createHotkey(togglePause,VK_F12)

It performs the follow:
-)the very first time that hotkey is invocated, it get the pid of the game actually in foreground, then open it in CE and immediatelly pause it.
-)passing control to CE
-)from this moment hotkey is now a toggle pause/unpause the game.

The only way still does not works very well is when I try to bring back CE.
Does exist a better (hard) way to bring back to foremost CE?

Thanks for all the help.
Back to top
View user's profile Send private message
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