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 


Repeated Commands
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Mon Mar 26, 2018 2:26 pm    Post subject: Repeated Commands Reply with quote

Hello,

Just created a default trainer script today that changes a value when a certain memory address pops up.

My problem is that this has to be applied using a "hotkey" i was wondering if someone could tell me how to make this automatically applied every 3 or 4 seconds.

Its probably an option available when making a trainer but i never noticed it. (Only just started using this today)

The function of this cheat is to simply apply my nickname to a titlebar instead of the default "guest" name Razz


[/img]



20180326_214426.png
 Description:
My name appears like when i hit the hotkey in the trainer.
 Filesize:  348.97 KB
 Viewed:  10172 Time(s)

20180326_214426.png




Last edited by Genjuro on Mon Mar 26, 2018 2:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Mar 26, 2018 2:46 pm    Post subject: Reply with quote

Code:
local t = createTimer()
t.OnTimer = some lua function to run after the interval (will be passed the timer object)
t.Interval = milliseconds to delay until next run eg 3000 for 3 seconds

_________________
https://github.com/FreeER/ has a few CE related repos


Last edited by FreeER on Tue Mar 27, 2018 6:28 am; edited 1 time in total
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Mon Mar 26, 2018 2:54 pm    Post subject: Reply with quote

Excellant dude, i will try to add this in later 😁

At work now.
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Tue Mar 27, 2018 8:47 am    Post subject: Reply with quote

Ok i dont know what im doing here, i have the trainer script straight from the auto generator here :

Code:
 <?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="26">
  <Forms>
    <CETrainer Class="TTrainerForm" Encoding="Ascii85">.....form data.....</CETrainer>
  </Forms>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"No description"</Description>
      <LastState RealAddress="7FF7950CC230"/>
      <VariableType>String</VariableType>
      <Length>22</Length>
      <Unicode>0</Unicode>
      <CodePage>0</CodePage>
      <ZeroTerminate>1</ZeroTerminate>
      <Address>wmn5r.exe+194C230</Address>
      <Hotkeys>
        <Hotkey>
          <Action>Set Value</Action>
          <Keys>
            <Key>83</Key>
          </Keys>
          <Value>GENJURO</Value>
          <Description>name</Description>
          <ID>0</ID>
        </Hotkey>
      </Hotkeys>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
  <LuaScript>--TRAINERGENERATORSTART--
--This is autogenerated code. Changing code in this block will
--get erased and rewritten if you regenerate the trainer code

--Uncomment the following line if this is a Cheat Table format trainer and you don't want CE to show (Tip, save as .CETRAINER alternatively)
--hideAllCEWindows()

RequiredCEVersion=6.7
if (getCEVersion==nil) or (getCEVersion()&lt;RequiredCEVersion) then
  messageDialog('Please install Cheat Engine '..RequiredCEVersion, mtError, mbOK)
  closeCE()
end
addresslist=getAddressList()
memrec0=addresslist.getMemoryRecordByID(0)

memrec0_hotkey0=memrec0.getHotkeyByID(0)

function onHotkey0(Hotkey)
  --Executed before the hotkey is handled
  CETrainer.CHEAT0.setActive(true, 1500)
  if gPlaySoundOnAction then
    playSound(gActivateSound)
  end
end

memrec0_hotkey0.onHotkey=onHotkey0
CETrainer.SEPERATOR.Visible=false

getAutoAttachList().add("wmn5r.exe")
gPlaySoundOnAction=false
CETrainer.show()
function AboutClick()
  showMessage(gAboutText)
end
gAboutText=[[This trainer was made by Cheat Engine
cheatengine]]

function CloseClick()
  --called by the close button onClick event, and when closing the form
  closeCE()
  return caFree --onClick doesn't care, but onClose would like a result
end

--TRAINERGENERATORSTOP--
</LuaScript>
</CheatTable>



and want to change this so the <Value>GENJURO</Value> is written to the address above every 3 or 4 seconds (so i dont need a hotkey), with the timer that was posted above

Code:

local t = createTimer()
t.OnTimer = some lua function to run after the interval (will be passed the timer object)
t.Interval = milliseconds to delay until next run eg 3000 for 3 seconds


Also i understand this is a script that needs cheat engine to be installed in order to run. Im guessing this should be easy to change to a portable .exe when im done tweaking it?


Last edited by Genjuro on Wed Mar 28, 2018 5:22 am; edited 1 time in total
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Mar 27, 2018 12:26 pm    Post subject: Reply with quote

I'd probably go with something like this (note that I removed the form encoding to make it display a little nicer on the forum, replace it with the original)
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="26">
  <Forms>
    <CETrainer Class="TTrainerForm" Encoding="Ascii85">...ASCII encoded trainer...</CETrainer>
  </Forms>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"GENJURO"</Description>
      <LastState RealAddress="7FF7950CC230"/>
      <VariableType>String</VariableType>
      <Length>22</Length>
      <Unicode>0</Unicode>
      <CodePage>0</CodePage>
      <ZeroTerminate>1</ZeroTerminate>
      <Address>wmn5r.exe+194C230</Address>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
  <LuaScript>--TRAINERGENERATORSTART--
hideAllCEWindows()
addresslist=AddressList or getAddressList()

GENJURO_mr=addresslist.getMemoryRecordByID(0)

GENJURO_timer = createTimer()
GENJURO_timer.Enabled = false
GENJURO_timer.Interval = 3000 -- every 3 seconds
GENJURO_timer.OnTimer = function(t)
  GENJURO_mr.Value = "GENJURO"
end

GENJURO_hotkey = createHotkey(function (Hotkey)
  -- determine toggle state
  local state = not GENJURO_timer.Enabled
  -- update state
  CETrainer.CHEAT0.setActive(state, 1500)
  if gPlaySoundOnAction then
    playSound(state and gActivateSound or gDeactivateSound)
  end
  GENJURO_timer.Enabled = state
end, {('S'):byte(1)})

CETrainer.SEPERATOR.Visible=false

getAutoAttachList().add("wmn5r.exe")
gPlaySoundOnAction=false
CETrainer.show()
function AboutClick()
  showMessage(gAboutText)
end
gAboutText=[[This trainer was made by Cheat Engine
cheatengine]]

function CloseClick()
  --called by the close button onClick event, and when closing the form
  closeCE()
  return caFree --onClick doesn't care, but onClose would like a result
end

--TRAINERGENERATORSTOP--
</LuaScript>
</CheatTable>


That does leave the hotkey in but it's a toggle rather than having to press it every time it changes and you can just remove the hotkey part and enable the timer when it's created if you like.

And yeah, getting an exe should be about as simple as file->save and choosing the exe option.

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Tue Mar 27, 2018 1:07 pm    Post subject: Reply with quote

Lost count how many times ive edited this reply.

Its working nice and smooth Very Happy

FreeER is a god
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Thu Mar 29, 2018 4:38 am    Post subject: Reply with quote

Ok now i want to add an editbox and enter button to the form to change the "name" value that is being repeated.

ive put this together but when i click enter nothing happens :
Code:

function EnterClick(sender)
  writeInteger("GENJURO_mr.Value", getProperty(CETrainer.TCEEdit,"Text"))
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Mar 29, 2018 5:39 am    Post subject: Reply with quote

writeInteger takes an address to write to and an Integer, you're giving it two strings, the current name and the new name. While GENJURO_mr.Address, without quotes, would be the address you'd still want writeString, however in this case what you'd really want to do is change a global variable and have the timer use that when updating the value otherwise it only gets written once (and presumably without the timer it changes back). Also I kind of doubt that you named the edit box TCEEdit (which happens to be the "className" of all edit boxes) eg.


Code:
thename = "GENJURO"
GENJURO_timer.OnTimer = function(t)
  GENJURO_mr.Value = thename
end
function EnterClick(sender)
  thename = CETrainer.CEEdit1.Text
  -- ^ equivalent to getProperty(CETrainer.CEEdit1,"Text"))
  -- getProperty existed pre 6.5 while .Text did not, both work
  -- generated trainers have an if statement that only allow
  -- versions older than what they were created with so it's
  -- not considered bad practice or anything to use .Text :)
end

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Thu Mar 29, 2018 6:05 am    Post subject: Reply with quote

sorry man all the examples I could find were written like that.

Well ive changed the script with the above and its printing whats contained in thename but the enter button isnt taking whats in the edit box.

Dont be suprised if this has been assembled wrong. Just pity me Very Happy

(cant upload images)

ok the edit box in the object inspector is named as

Name: TCEEdit

so ive put the script together like this :
Code:

addresslist=AddressList or getAddressList()

GENJURO_mr=addresslist.getMemoryRecordByID(0)

GENJURO_timer = createTimer()
GENJURO_timer.Enabled = true
GENJURO_timer.Interval = 1000
thename = "GENJURO"
GENJURO_timer.OnTimer = function(t)
  GENJURO_mr.Value = thename
end

CETrainer.SEPERATOR.Visible=false

getAutoAttachList().add("wmn5r.exe")
gPlaySoundOnAction=false
CETrainer.show()
function AboutClick()
  showMessage(gAboutText)
end
gAboutText=[[This trainer was made by Cheat Engine
cheatengine]]

function CloseClick()
  --called by the close button onClick event, and when closing the form
  closeCE()
  return caFree --onClick doesn't care, but onClose would like a result
end

--TRAINERGENERATORSTOP--
function EnterClick(sender)
  thename = CETrainer.Name.Text
end
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Mar 29, 2018 6:22 am    Post subject: Reply with quote

Did you do anything in the form editor to associate the EnterClick function with the CEEdit box? If not then it won't be called. Also, I don't remember CE having an event when the enter button is press, you have to check for it yourself in the Changed/KeyPress event (whatever it's called, I don't remember off the top of my head), didn't mention it before since I figured the function was part some other code you found but since I don't see any... Smile

something like
Code:
function CEEdit1KeyPress(sender, key)
  if key=='\r' or key == '\n' then EnterClick(sender) end
  return key
end

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Thu Mar 29, 2018 6:24 am    Post subject: Reply with quote

Ok i changed the name of the edit box to make more sense and it seems to be working now.

Again thanks a lot.

Would it be ok to give u credit for this?

Its gonna make a few people quite happy
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Mar 29, 2018 6:29 am    Post subject: Reply with quote

No problem, and if you want to mention that I helped you with the lua code then feel free Smile
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Thu Mar 29, 2018 6:31 am    Post subject: Reply with quote

Dude your getting full credit for the whole thing...

All i did was fumble about

Your amazing man Very Happy
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Mar 29, 2018 6:38 am    Post subject: Reply with quote

Take some credit, you found the the right address to change and got someone to help you at the least, clearly more than anyone else had taken the time to do Smile
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Genjuro
Newbie cheater
Reputation: 0

Joined: 26 Mar 2018
Posts: 15

PostPosted: Sun Apr 15, 2018 1:04 pm    Post subject: Reply with quote

Is there a way to add another address to be changed in this script?

I noticed another part of the game where your name should be displayed.

Would it be somthing like
Code:
<LastState RealAddress="7FF7950CC230, 7FF7950DC240"/>
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
Goto page 1, 2  Next
Page 1 of 2

 
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