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 


Switch 2 Game In a Trainer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Feb 07, 2017 10:27 pm    Post subject: Switch 2 Game In a Trainer Reply with quote

Hi there,

Code:
fo = createForm()
fo.Height = 90
fo.Width = 352
fo.Position = poScreenCenter
fo.Caption = "Switch Game"

Pn = createPanel(fo)
Pn.Height = 90
Pn.Width = 352

lb = createLabel(Pn)
lb.Top = 55
lb.Left = 150
lb.Caption = "Waiting for open game"

B1 = createButton(Pn)
B1.Height = 25
B1.Width = 75
B1.Left = 20
B1.Top = 20
B1.Caption = "Explorer"
--B1.onClick = exploreFile

B2 = createButton(Pn)
B2.Height = 25
B2.Width = 75
B2.Left = 100
B2.Top = 20
B2.Caption = "Game 1"
--B2.onClick = game_check1()

B3 = createButton(Pn)
B3.Height = 25
B3.Width = 75
B3.Left = 180
B3.Top = 20
B3.Caption = "Game 2"
--B3.onClick = game_check2()

B4 = createButton(Pn)
B4.Height = 25
B4.Width = 75
B4.Left = 260
B4.Top = 20
B4.Caption = "Exit"
--B4.onClick = exitTrainer

-------------------------------

function exploreFile()
 local dialog = createOpenDialog(nil)
 dialog.options = "[ofAllowMultiSelect]"
 local result = dialog.execute()
 if result then
 local files = dialog.files
 for i = 0, files.count - 1 do
 shellExecute("cmd", [[/c start "" "]]..files[i]..[["]])
 end
 end
 dialog.destroy()
end

function getProcess_NameFromID(processId)
 local processName = nil
 local list = createStringlist()
 getProcesslist(list)
 for i = 0, list.Count-1 do
 local id, name = list.String[i]:match("(.*)-(.*)")
 if processId == tonumber(id, 16) then
 processName = name
 break
 end
 end
 return processName
end

function game_check1()
 if readInteger("PlantsvsZombies.exe") ~= nil then
 shellExecute("taskkill", "/IM PlantsvsZombies.exe /F")
 end
 game = "Kingdom Rush - "
 if readInteger("Kingdom.exe") == nil then
 lb.Caption = string.format(game.."not detected")
 lb.Font.Color = 0x009900
 beep()
 else
 openProcess("Kingdom.exe")
 local id = getOpenedProcessID()
 local name = getProcess_NameFromID(processId)
 lb.Caption = string.format("Detected " ..id.." - "..name)
 lb.Font.Color = 0x009900
 end
end

function game_check2()
 if readInteger("Kingdom.exe") ~= nil then
 shellExecute("taskkill", "/IM Kingdom.exe /F")
 end
 game = "Plants vs Zombies - "
 if readInteger("PlantsvsZombies.exe") == nil then
 lb.Caption = string.format(game.."not detected")
 lb.Font.Color = 0x009900
 beep()
 else
 openProcess("PlantsvsZombies.exe")
 local id = getOpenedProcessID()
 local name = getProcess_NameFromID(processId)
 lb.Caption = string.format("Detected " ..id.." - "..name)
 lb.Font.Color = 0x009900
 end
end

function exitTrainer()
 closeCE()
 return caFree
end


B1.onClick = exploreFile
B2.onClick = game_check1()
B3.onClick = game_check2()
B4.onClick = exitTrainer
form_onClose(fo, exitTrainer)
fo.Show()



B1 button = use to explorer games in a folder (similar to windows explorer)
B2 button = use to open game 1, while kill game 2 if game 2 running in memory
B3 button = use to open game 2, while kill game 1 if game 1 running in memory
lb label = to show what name game opened + PID (also use to show message if needed)

Problem :
1. Label lb Caption directly show "Plants vs Zombies - Not Detected" when opening trainer without waiting for a button clicked
2. No game process attached when click button B2 or B3 even game already open using button B1 (explorer game)

What's wrong need to fix ?

Thank you
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