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 do i link a cheat table to a gui?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
C9Angelo
How do I cheat?
Reputation: 0

Joined: 01 Apr 2020
Posts: 8

PostPosted: Mon Apr 06, 2020 4:13 pm    Post subject: how do i link a cheat table to a gui? Reply with quote

asdf.png shows what i'm talking about

basically, i want to be able to link those drop down options from slippery-off ball into a drop down menu on a cetrainer. how would i go about doing that?



asdf.PNG
 Description:
example of what i'm talking about
 Filesize:  26.85 KB
 Viewed:  30031 Time(s)

asdf.PNG


Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Tue Apr 07, 2020 7:31 am    Post subject: Reply with quote

This may not what you want, but maybe you can kidnap the AddressList (the memory record entries collective) into your trainer form?
origin: https://forum.cheatengine.org/viewtopic.php?p=5743590

In cetrainer/exe custom trainer mode originate from a *.ct,
the script in Menu/Table/[Show Cheat Table Lua Script] will be automatic run on start.

Normally, CE Mainform UI, where AddressList located, will be hidden in trainer mode.
By setting Parent property of AddressList as a container ui (wincontrol class) in your custom form, most if not all functionality of memory record will be available in your form.
The container ui can be the form, panel in your form, or tabsheet on a page control etc.
In your *.ct, may put a script line to assign AddressList's parent, may be at last line, or when the correct process is opened etc:
Code:

GetAddressList().Parent = <you container ui>

It may not need in trainer mode, but the AddressList can be restore to its original parent like:
Code:

GetAddressList().Parent = GetMainForm().Panel1 -- <- the original parent


After tested as *.ct,
you can save the *.ct [Menu/Save as] as *.cetrainer or *.exe to see how custom trainer mode work.

think TRAINER, as TABLE ref Smile

_________________
- Retarded.
Back to top
View user's profile Send private message
C9Angelo
How do I cheat?
Reputation: 0

Joined: 01 Apr 2020
Posts: 8

PostPosted: Tue Apr 07, 2020 10:15 am    Post subject: Reply with quote

panraven wrote:
This may not what you want, but maybe you can kidnap the AddressList (the memory record entries collective) into your trainer form?

In cetrainer/exe custom trainer mode originate from a *.ct,
the script in Menu/Table/[Show Cheat Table Lua Script] will be automatic run on start.

Normally, CE Mainform UI, where AddressList located, will be hidden in trainer mode.
By setting Parent property of AddressList as a container ui (wincontrol class) in your custom form, most if not all functionality of memory record will be available in your form.
The container ui can be the form, panel in your form, or tabsheet on a page control etc.
In your *.ct, may put a script line to assign AddressList's parent, may be at last line, or when the correct process is opened etc:
Code:

GetAddressList().Parent = <you container ui>

It may not need in trainer mode, but the AddressList can be restore to its original parent like:
Code:

GetAddressList().Parent = GetMainForm().Panel1 -- <- the original parent


After tested as *.ct,
you can save the *.ct [Menu/Save as] as *.cetrainer or *.exe to see how custom trainer mode work.



i don't know that this is exactly what i need. i probably should elaborate more so i can actually receive help.

if you can see the theory.PNG, the idea is that a change in the items (they would go from Off -> Bronze -> Silver -> Gold -> HOF would correlate to those in my CT. i don't know how to set that up.



theory.PNG
 Description:
 Filesize:  13.15 KB
 Viewed:  29982 Time(s)

theory.PNG


Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Tue Apr 07, 2020 12:38 pm    Post subject: Reply with quote

Sample for change in ui -> change in memory
Code:

local ff = createForm()
ff.Name,ff.OnClose = 'testcombo',function()return caFree end

------- sample combobox setup
local cbs = createComboBox(ff)
cbs.Align = clClient
cbs.Items.Text = [[
--select badge--
0:off
1:Bronze
2:Silver
3:Gold
4:HoF
]]
cbs.ItemIndex = cbs.ItemIndex<0 and 0 or cbs.ItemIndex -- initial selection
cbs.Hint, cbs.ShowHint = 'choose Slippy-off-ball badge', true -- optional, some older ce may not work
cbs.OnChange = function(me) -- do something if selection changed
  local idx = me.ItemIndex
  if idx<0 then return end -- no select yet?
  local item = me.Items[idx]   -- only work if number 0-4 is in items.Text above
  local val = item:match'^%d+' -- ^^ ditto
  local mr = GetAddressList().getMemoryRecordByDescription'-Slippy-off-ball-description'
  if mr then
    mr.Value = val -- set value to corresponding memory record
  else
    print'debug:no memory record, check description'
  end
end
-------
ff.Show()

the reverse, change in memory -> change in ui
Code:


badgeTimer = badgeTimer or createTimer(nil,true)
local t, prevValue = badgeTimer
t.Interval, t.OnTimer = 1000,function(tm)
  local mr = GetAddressList().getMemoryRecordByDescription'-Slippy-off-ball-description'
  if not prevValue or prevValue ~= mr.Value then
    prevValue = mr.Value
    -- find the corresponding index in combobox and set it
    for i=0,cbs.Items.Count-1 do
      if prevValue == cbs.Items[i]:match'^%d+'then
        cbs.ItemIndex = i
        break
      end
    end
  end
end


To do all this in every different badges, you may need to refactor the code a bit, so that the 2 parts related in the same badge but not mixed with other badge.
Or, if you only need an ui for user to change Badge, it may be simpler by choosing 'which badge' with another combo box.

Code:

[combobox->select Badge Description in Memory Record] 
[combobox->select Badge Value]

ie. change '-Slippy-off-ball-description' with content of 1st combo box

_________________
- Retarded.
Back to top
View user's profile Send private message
C9Angelo
How do I cheat?
Reputation: 0

Joined: 01 Apr 2020
Posts: 8

PostPosted: Tue Apr 07, 2020 1:27 pm    Post subject: Reply with quote

panraven wrote:
Sample for change in ui -> change in memory
Code:

local ff = createForm()
ff.Name,ff.OnClose = 'testcombo',function()return caFree end

------- sample combobox setup
local cbs = createComboBox(ff)
cbs.Align = clClient
cbs.Items.Text = [[
--select badge--
0:off
1:Bronze
2:Silver
3:Gold
4:HoF
]]
cbs.ItemIndex = cbs.ItemIndex<0 and 0 or cbs.ItemIndex -- initial selection
cbs.Hint, cbs.ShowHint = 'choose Slippy-off-ball badge', true -- optional, some older ce may not work
cbs.OnChange = function(me) -- do something if selection changed
  local idx = me.ItemIndex
  if idx<0 then return end -- no select yet?
  local item = me.Items[idx]   -- only work if number 0-4 is in items.Text above
  local val = item:match'^%d+' -- ^^ ditto
  local mr = GetAddressList().getMemoryRecordByDescription'-Slippy-off-ball-description'
  if mr then
    mr.Value = val -- set value to corresponding memory record
  else
    print'debug:no memory record, check description'
  end
end
-------
ff.Show()

the reverse, change in memory -> change in ui
Code:


badgeTimer = badgeTimer or createTimer(nil,true)
local t, prevValue = badgeTimer
t.Interval, t.OnTimer = 1000,function(tm)
  local mr = GetAddressList().getMemoryRecordByDescription'-Slippy-off-ball-description'
  if not prevValue or prevValue ~= mr.Value then
    prevValue = mr.Value
    -- find the corresponding index in combobox and set it
    for i=0,cbs.Items.Count-1 do
      if prevValue == cbs.Items[i]:match'^%d+'then
        cbs.ItemIndex = i
        break
      end
    end
  end
end


To do all this in every different badges, you may need to refactor the code a bit, so that the 2 parts related in the same badge but not mixed with other badge.
Or, if you only need an ui for user to change Badge, it may be simpler by choosing 'which badge' with another combo box.

Code:

[combobox->select Badge Description in Memory Record] 
[combobox->select Badge Value]

ie. change '-Slippy-off-ball-description' with content of 1st combo box


This works, the issue is that I wouldn't be able to link that to a CETrainer. So if I already had a CETrainer fully setup, how would I make it so that I can just add a part of the script, change the description, and then have it work?
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Tue Apr 07, 2020 3:02 pm    Post subject: Reply with quote

ok, I combine the 2 part into one function, which is for the scenario of using another 'which badge' combo.

So, if you have an existing [badge value] combo box UDF1.CEComboBox1 , and
[mr description] combo box UDF1.CEComboBox2,

Put this at end of Lua script,
Code:
linkCbs(UDF1.CEComboBox1, UDF1.CEComboBox2)


should assign the interactions between the two combo box and corresponding memory record .

(set list of mr description in UDF1.CEComboBox2)

Try understand the code so that you can expand it if need.

Code:

local cbs = createComboBox(ff)
local cbm = createComboBox(ff)

cbm.Align = clTop
cbs.Left = cbm.Width + 10

cbm.Items.Text = [[
BITVal
BITVal2
]]
--- ^ my list of mr description for test

function linkCbs(cbs, desc_cbs)
-- ui2memory
  cbs.Items.Text = [[
  --select badge--
  0:off
  1:Bronze
  2:Silver
  3:Gold
  4:HoF
  ]]
  cbs.ItemIndex = cbs.ItemIndex<0 and 0 or cbs.ItemIndex -- initial selection
--  cbs.Hint, cbs.ShowHint = 'choose Slippy-off-ball badge', true -- optional, some older ce may not work
  cbs.OnChange = function(me) -- do something if selection changed
    local idx = me.ItemIndex
    if idx<0 then return end -- no select yet?
    local item = me.Items[idx]   -- only work if number 0-4 is in items.Text above
    local val = item:match'^%s*(%d+)' -- ^^ ditto

    local mrIdx = desc_cbs.ItemIndex
    local mrdesc = mrIdx>=0 and desc_cbs.Items[mrIdx]:match'^%s*(.-)%s*$'

    local mr = GetAddressList().getMemoryRecordByDescription(mrdesc)
    if mr then
      mr.Value = val -- set value to corresponding memory record
    elseif not TrainerOrigin then -- not displayed in trainer mode
      print'debug:no memory record, check description'
    end
  end

-- memory to ui

  cbs.badgeTimer = cbs.badgeTimer or createTimer(cbs,true)
  local t, prevValue = cbs.badgeTimer
  t.Interval, t.OnTimer = 200,function(tm)

    local mrIdx = desc_cbs.ItemIndex
    local mrdesc = mrIdx>=0 and desc_cbs.Items[mrIdx]:match'^%s*(.-)%s*$'

    local mr = mrdesc and GetAddressList().getMemoryRecordByDescription(mrdesc)
    if mr and (not prevValue or prevValue ~= mr.Value) then
      prevValue = mr.Value
      -- find the corresponding index in combobox and set it
      for i=0,cbs.Items.Count-1 do
        if prevValue == cbs.Items[i]:match'^%s*(%d+)'then
          cbs.ItemIndex = i
          break
        end
      end
    end
  end

-- end linkCbs
end

linkCbs(cbs, cbm)


_________________
- Retarded.
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