View previous topic :: View next topic |
Author |
Message |
beagle Cheater Reputation: 0
Joined: 27 Aug 2014 Posts: 36
|
Posted: Tue Sep 02, 2014 8:31 pm Post subject: Automatically Save/Remember Settings? |
|
|
Hello,
There are variables in my trainer that i wish users to be able to set themselves, and i don't want them to have to set these every time they start the trainer.
Is there a simple way for me to add saving/loading of settings? All i really need is for the trainer to save their variables when it closes, and then to recall them when they open it again.
Sorry if this is painfully basic.
|
|
Back to top |
|
|
Redouane Master Cheater Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Wed Sep 03, 2014 5:32 am Post subject: Re: Automatically Save/Remember Settings? |
|
|
beagle wrote: | Hello,
There are variables in my trainer that i wish users to be able to set themselves, and i don't want them to have to set these every time they start the trainer.
Is there a simple way for me to add saving/loading of settings? All i really need is for the trainer to save their variables when it closes, and then to recall them when they open it again.
Sorry if this is painfully basic. |
It's easy,you can use the IO library of Lua to create a text file containing the settings (store it in trainerOrigin,the same directory as the trainer),and read from that file when the trainer gets opened.
(Use LuaFileSystem to check if the file exists,or just try to open it and encapsulate your code with pcall/xpcall).
OR
You could use this library:
http://lua-users.org/wiki/WindowsRegistry
To use the windows registry to store your values.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Wed Sep 03, 2014 7:09 am Post subject: |
|
|
Use the settings class to store such data
I'm not on my pc and my mobile royally sucks at copy/paste but look for this in main.lua
Code: |
Settings class This class can be used to read out and set settings of cheat engine and of plugins, and store your own data global functions getSettings(path Optional): Settings - Returns a settings object. If path is nil it will points to the Cheat Engine main settings (Registry) . If name is provides the settings currently accessed will be the one at the subkey provided Note: Keep in mind that it returns a new object each call, even if he same name is used multiple times properties Path: string - Gets/Sets the current subkey (nil if main) Value[]: A table access into the settings. e.g: Value["Count"]=12
|
_________________
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 |
|
|
beagle Cheater Reputation: 0
Joined: 27 Aug 2014 Posts: 36
|
Posted: Wed Sep 03, 2014 8:35 am Post subject: |
|
|
Thanks for the reply guys. I think i have a better understanding of how IO works after reading the lua wiki and lua.main descriptions, but i only know enough lua to make basic modifications to existing functional code.
I searched the forums earlier and only found /viewtopic.php?t=545361, but it was a bit hard to follow and i don't know if that code is working. Are there any basic templates floating around that i can copy&paste in to mess around with?
Thanks again for the help.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Wed Sep 03, 2014 6:40 pm Post subject: |
|
|
To set a value in the registry:
Code: |
settings=getSettings('mytrainerstuff')
settings.Value['DefaultHealth']=100
|
and the next time you run you can do this to get it:
Code: |
settings=getSettings('mytrainerstuff')
DefaultHealth=settings.Value['DefaultHealth']
|
If you get a value that hasn't been defined you'll get an empty string
These settings will retain even when the user deletes the trainer
_________________
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 |
|
|
beagle Cheater Reputation: 0
Joined: 27 Aug 2014 Posts: 36
|
Posted: Wed Sep 03, 2014 8:10 pm Post subject: |
|
|
I must not be doing it right, because the settings don't seem to save.
I have it on buttons so:
On:
settings=getSettings('trainersettings')
settings.Value['button1']=1
<activate script>
change text color green
Off:
settings=getSettings('trainersettings')
settings.Value['button1']=0
<deactivate script>
change text color red
then on the start:
button1=settings.Value['button'1]
if button1==1 then
<activate same script>
end
but when i reload it, the script isn't checked in the cheat table, and the text is still red. I've tried both as .CT and .exe
I also have multiple buttons, and they all use settings=getsettings('trainersettings') like this:
button1=settings.Value['button1']
button2=settings.Value['button2']
button3=settings.Value['button3']
is this ok to do, or do i need to do settings1, settings2, settings3?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Wed Sep 03, 2014 8:20 pm Post subject: |
|
|
settings store values as strings
do if tonumber(button1)==1 then
or if button1=='1' then
or button1=tonumber(settings.Value['button1'])
trainersettings is the group of settings. As long as that is unique to your trainer you can name the values whatever you like.
_________________
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 |
|
|
beagle Cheater Reputation: 0
Joined: 27 Aug 2014 Posts: 36
|
Posted: Wed Sep 03, 2014 8:36 pm Post subject: |
|
|
Ah i always forget to check stuff like that. It works perfectly now, thanks again :)
Oh one last thing, this is entirely unrelated, but when i click the minimize button on my trainer, it minimizes it to a little window in the bottom left hand corner of my screen just above the taskbar, instead of to the taskbar itself.
I have:
form_onClose(MainGUI[1], CloseTrainer)
function CloseTrainer()
form_close(MainGUI[1])
closeCE()
return caFree
end
for the close button, but i don't have anything for the minimize button.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Wed Sep 03, 2014 8:44 pm Post subject: |
|
|
set showInTaskbar to stAlways
(or just remove the minimize button)
_________________
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 |
|
|
beagle Cheater Reputation: 0
Joined: 27 Aug 2014 Posts: 36
|
Posted: Wed Sep 03, 2014 8:49 pm Post subject: |
|
|
is there a lua command for that? my trainer isnt built through the trainer generator, i heavily modified a free lua trainer template i found online.
Last edited by beagle on Wed Sep 03, 2014 8:58 pm; edited 2 times in total |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Wed Sep 03, 2014 8:55 pm Post subject: |
|
|
MainGUI[1].showInTaskbar="stAlways"
_________________
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 |
|
|
beagle Cheater Reputation: 0
Joined: 27 Aug 2014 Posts: 36
|
Posted: Wed Sep 03, 2014 8:59 pm Post subject: |
|
|
thanks :)
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu Sep 04, 2014 9:24 am Post subject: |
|
|
beagle wrote: | I searched the forums earlier and only found /viewtopic.php?t=545361, but it was a bit hard to follow and i don't know if that code is working. |
It is obsolete.
For now, I'm writing something new: "Options" class. It extends "Settings" class. It is still under development, it doesn't support string values (text). My class automatically creates labels, edits and buttons in "settings window".
Usage is something like this:
Code: |
-- place those lines at the bottom of Lua script
musicEnabled=
{ Value=1,
VarName='Enable/Disable trainer music',
GreaterThanOr=0, LessThanOr=1,
Int=true}
-- Value - default value
-- VarName - full variable name
-- GreaterThanOr=0 means: "must be greater than 0 or must be equal to 0"
-- LessThanOr=1 means: "must be less than 1 or must be equal to 1"
-- Int=true means: "must be an integer type"
-- summary: so it must be integer between 0 and 1. The only accepted values are {0,1}
playerSpeed=
{ Value=2000,
VarName='PlayerSpeed',
GreaterThanOr=1,
LessThanOr=10}
-- any real number between 1 and 10 (or equal to 1, or equal to 10)
myOptions=Options(CETrainer.SETTINGSBUTTON, 'settings window caption', 'yourtrainername)
myOptions:addVariables(musicEnabled, playerSpeed)
-- CETrainer.SETTINGSBUTTON this is button object (e.g. add new button to your form
-- and change name to SETTINGSBUTTON or whatever you want)
myOptions:loadSettings()
-- load user defined values (if any)
-- place this line in OnClose event function (or FormClose function) of your trainer main form (CETrainer form)
myOptions:saveSettings()
|
You can test my trainer http://forum.cheatengine.org/viewtopic.php?p=5525146#5525146 , (you don't need game, just watch how my "Options" class works, click "Settings" button)
_________________
|
|
Back to top |
|
|
Cestra Newbie cheater Reputation: 0
Joined: 03 Jun 2016 Posts: 14
|
Posted: Fri Jun 03, 2016 10:09 pm Post subject: |
|
|
Dark Byte wrote: | MainGUI[1].showInTaskbar="stAlways" |
I want to use with image. How can I?
same like close function;
function CEImage3Click(sender)
closeCE()
return caFree
end
|
|
Back to top |
|
|
|