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 


How can I create an empty file in a directory via Lua?

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

Joined: 27 Apr 2013
Posts: 306

PostPosted: Thu Feb 05, 2015 10:59 pm    Post subject: How can I create an empty file in a directory via Lua? Reply with quote

Hey, everyone! I'm just now getting around to creating my own trainers, so I'm a Lua noob for the time being. =) I've tried a couple of things so far with what I'm looking to do, but to no avail. Here's the basic gist of what I'm trying to do:

I have a game that simply looks for a file in the same directory that the game's .exe is in. If it sees the file, it unlocks certain functionality. So, game.exe looks for unlock_file.patch in the same directory. Luckily, unlock_file.patch is just an empty file; only the file name is searched for.

What I want to add into my trainer is the ability for a user to click a button and it will create unlock_file.patch in the game's Steam directory. Again, I'm a complete noob so far, so this is what I've tried based on Google searching:

Code:
function CEButton1Click(sender)
file=io.open("C:\Program Files (x86)\Steam\SteamApps\common\Game\unlock_file.patch", "w")
file:close()
end


This game is also able to be purchased elsewhere, so people may even have it in a completely different directory. With that in mind, perhaps I should have the user browse for the directory game.exe is in, which I imagine I can do via SelectDirectoryDialogue. Anyway, I know that creating this empty file is probably very simple, but I just can't quite get it nailed down. Any help would be very greatly appreciated. Thanks!
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25294
Location: The netherlands

PostPosted: Fri Feb 06, 2015 3:49 am    Post subject: Reply with quote

use \\ instead of \ or use a [[ ... ]] string
and a selectdirectorydialog would probably be best


also,
check out the lfs plugin used here: http://cheatengine.org/download/savesession.rar

and check out how to use it: http://keplerproject.github.io/luafilesystem/manual.html (if used in a trainer donvt forget to manually add it)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Feb 08, 2015 12:14 pm    Post subject: Reply with quote

Code:

function CEButton1Click(sender)

  dialog=createSaveDialog()
  dialog.Filename='unlock_file'
  dialog.DefaultExt=".patch"
  dialog.Filter="Unlock File (*.patch)|*.patch"
  dialog.FilterIndex=1
  dialog.Options = '[ofEnableSizing]'

  if dialog.execute() then
    file=io.open(dialog.Filename, "w")
    file:close()
  end

end

_________________
Back to top
View user's profile Send private message MSN Messenger
h3x1c
Master Cheater
Reputation: 17

Joined: 27 Apr 2013
Posts: 306

PostPosted: Mon Feb 23, 2015 9:14 pm    Post subject: Reply with quote

Thank you, Dark Byte and mgr.inz.Player! I'll give those suggestions a try here soon with my next trainer. I appreciate your help! Very Happy
Back to top
View user's profile Send private message Visit poster's website
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