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 add item descriptions in a combo box?

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

Joined: 07 Mar 2022
Posts: 9

PostPosted: Wed Mar 09, 2022 7:30 am    Post subject: How can I add item descriptions in a combo box? Reply with quote

I know for a dropdown list in a table, I can use hexID:Description, so user only see the item names in the memory record list.

When I make a trainer using Form Designer, this rule doesn't seem to be working. How can I do the same in a combo box? I need to add item IDs but I only want users to see the item names

e.g. 40000 = fire
40001 = ice
40002 = water

and users just see fire, ice and water in the list of my trainer

My list is quite long. Any examples would be great.

I am not a native speaker. If you can't understand what I am asking, I will try harder to explain it more clearly. Very Happy
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Wed Mar 09, 2022 7:50 am    Post subject: Reply with quote

Best I can say is use a lua table with the names and values set to the IDs. Some UI setups do allow text and values for comboboxes but I don't think CE does.
Code:
local tbl = {
['some name for a thing'] = 0x100,
--...
}

local ID = tbl[comboBox.selectedItemText]


I'm not real familiar with the CE UI stuff so change the combobox stuff to how you need to access it's selected item text.

_________________
Back to top
View user's profile Send private message Visit poster's website
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1531

PostPosted: Wed Mar 09, 2022 8:31 am    Post subject: Reply with quote

Code:
if form then form.destroy() form = nil end
form = createForm()  -- Your Trainer ex(UDF1)
form.Popupmode = 0;
form.Position = poDesktopCenter
form.Width = 220
form.Height = 140

local Lbl1 = createLabel(form) -- Your label ex(UDF1.CELabel1)
Lbl1.AutoSize=false
Lbl1.Left=40 Lbl1.Height=23 Lbl1.Top=20 Lbl1.Width=140
Lbl1.Color=65280 Lbl1.Font.Size=9 Lbl1.Font.Style='fsBold'
Lbl1.ShowHint=true Lbl1.Alignment="taCenter" Lbl1.caption=". . ."
 Lbl1.OptimalFill=true

local CBox1 = createComboBox(form) -- Your Combobax ex(UDF1.CEComboBox1)
CBox1.Left=40 CBox1.Height=27 CBox1.Top=53 CBox1.Width=140
CBox1.AutoSize=false
CBox1.Font.Height=-13 CBox1.Font.Size=10 CBox1.Font.Style='[]'
CBox1.ReadOnly=true CBox1.ShowHint=false CBox1.Hint=''
CBox1.Style='csDropDownList'

local Lbl2 = createLabel(form) --desc
Lbl2.AutoSize=false
Lbl2.Left=40 Lbl2.Height=23 Lbl2.Top=85 Lbl2.Width=140
Lbl2.Color=65280 Lbl2.Font.Size=9 Lbl2.Font.Style='fsBold'
Lbl2.ShowHint=true Lbl2.Alignment="taCenter"
 Lbl2.OptimalFill=true

local tblMaterials={"Fire", "Ice", "Water", "Earth", "Wood", "Stone", "Timber", "Gold", "Silver", "Bronze"}
local tblMtrlCode={4000,4001,4002,4003,4004,4005,4006,4007,4008,4009}

CBox1.clear()
CBox1.Items.Add("Select Materials")
for i,k in pairs(tblMaterials) do
CBox1.Items.Add(k)
end

CBox1.ItemIndex="0"
Lbl2.caption="Index: " .. CBox1.ItemIndex

CBox1.OnChange=function()
local index = CBox1.ItemIndex
  index=tonumber(index)
 if index~=0 then
  if index then
   Lbl1.caption=tblMaterials[index] .. " = " .. tblMtrlCode[index]
   Lbl2.caption="Index: " .. CBox1.ItemIndex
  end
 end
end


EDIT :
Ops! You said you had a long list.
If you're too lazy to string them in the table, I'll assume they're listed in a txt file and have you string them in the table.

Your sample txt list:
Code:
Fire: 40000
Ice: 40001
Water: 40002
Earth: 40003
Wood: 40004
Stone: 40005
Timber: 40006
Gold: 40007
Silver: 40008
Bronze: 40009


Code:
Code:
local tblMaterials={}
local tblMtrlCode={}
local des1=""
local code1=""

function readFile(path)
f=io.open(path, "r")
record = f:read("*all")
f:close()
sl=createStringList()
sl.Text=record

 for i=0, strings_getCount(sl) -1 do
  des=(sl[i]):match("(%w+): ")
  code=(sl[i]):match("(%d+)")
   if des~=nil or code~=nil then
    des1=des1 .. "'" .. des .. "',"
    code1=code1 .. code .. ","
    tblMaterials[i+1]=des
    tblMtrlCode[i+1]=code
   end
 end
 sl.Destroy()
end

path=[[C:\myMaterial.txt]] --your txt file path
readFile(path)

print(des1)
print(code1)

print(tblMaterials[3] .. ": " .. tblMtrlCode[3])


Enjoy it! Wink

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Centos
How do I cheat?
Reputation: 0

Joined: 07 Mar 2022
Posts: 9

PostPosted: Thu Mar 10, 2022 2:32 am    Post subject: Reply with quote

AylinCE wrote:
Code:
if form then form.destroy() form = nil end
form = createForm()  -- Your Trainer ex(UDF1)
form.Popupmode = 0;
form.Position = poDesktopCenter
form.Width = 220
form.Height = 140

local Lbl1 = createLabel(form) -- Your label ex(UDF1.CELabel1)
Lbl1.AutoSize=false
Lbl1.Left=40 Lbl1.Height=23 Lbl1.Top=20 Lbl1.Width=140
Lbl1.Color=65280 Lbl1.Font.Size=9 Lbl1.Font.Style='fsBold'
Lbl1.ShowHint=true Lbl1.Alignment="taCenter" Lbl1.caption=". . ."
 Lbl1.OptimalFill=true

local CBox1 = createComboBox(form) -- Your Combobax ex(UDF1.CEComboBox1)
CBox1.Left=40 CBox1.Height=27 CBox1.Top=53 CBox1.Width=140
CBox1.AutoSize=false
CBox1.Font.Height=-13 CBox1.Font.Size=10 CBox1.Font.Style='[]'
CBox1.ReadOnly=true CBox1.ShowHint=false CBox1.Hint=''
CBox1.Style='csDropDownList'

local Lbl2 = createLabel(form) --desc
Lbl2.AutoSize=false
Lbl2.Left=40 Lbl2.Height=23 Lbl2.Top=85 Lbl2.Width=140
Lbl2.Color=65280 Lbl2.Font.Size=9 Lbl2.Font.Style='fsBold'
Lbl2.ShowHint=true Lbl2.Alignment="taCenter"
 Lbl2.OptimalFill=true

local tblMaterials={"Fire", "Ice", "Water", "Earth", "Wood", "Stone", "Timber", "Gold", "Silver", "Bronze"}
local tblMtrlCode={4000,4001,4002,4003,4004,4005,4006,4007,4008,4009}

CBox1.clear()
CBox1.Items.Add("Select Materials")
for i,k in pairs(tblMaterials) do
CBox1.Items.Add(k)
end

CBox1.ItemIndex="0"
Lbl2.caption="Index: " .. CBox1.ItemIndex

CBox1.OnChange=function()
local index = CBox1.ItemIndex
  index=tonumber(index)
 if index~=0 then
  if index then
   Lbl1.caption=tblMaterials[index] .. " = " .. tblMtrlCode[index]
   Lbl2.caption="Index: " .. CBox1.ItemIndex
  end
 end
end


EDIT :
Ops! You said you had a long list.
If you're too lazy to string them in the table, I'll assume they're listed in a txt file and have you string them in the table.

Your sample txt list:
Code:
Fire: 40000
Ice: 40001
Water: 40002
Earth: 40003
Wood: 40004
Stone: 40005
Timber: 40006
Gold: 40007
Silver: 40008
Bronze: 40009


Code:
Code:
local tblMaterials={}
local tblMtrlCode={}
local des1=""
local code1=""

function readFile(path)
f=io.open(path, "r")
record = f:read("*all")
f:close()
sl=createStringList()
sl.Text=record

 for i=0, strings_getCount(sl) -1 do
  des=(sl[i]):match("(%w+): ")
  code=(sl[i]):match("(%d+)")
   if des~=nil or code~=nil then
    des1=des1 .. "'" .. des .. "',"
    code1=code1 .. code .. ","
    tblMaterials[i+1]=des
    tblMtrlCode[i+1]=code
   end
 end
 sl.Destroy()
end

path=[[C:\myMaterial.txt]] --your txt file path
readFile(path)

print(des1)
print(code1)

print(tblMaterials[3] .. ": " .. tblMtrlCode[3])


Enjoy it! Wink


Thank you so much! Your code is running perfect for the example you give. But I still got some issues because my list is slighly different. It looks like:

01BA1DC0:seed
001FD72D0:machine gun
00B39AD0:shot gun
01EA29F0:heavy metal gear
00C9AE20:long sword

So the IDs are in hex and descriptions may contain more than one word. I tried and got this error::[string "local tblMaterials={}
..."]:17: attempt to concatenate a nil value (global 'des').

I am not quite familar with this stuff. Help me...Embarassed
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1531

PostPosted: Thu Mar 10, 2022 6:42 am    Post subject: Reply with quote

Adding from list to table:

Code:
list=[[01BA1DC0:seed
001FD72D0:machine gun
00B39AD0:shot gun
01EA29F0:heavy metal gear
00C9AE20:long sword]]

local tblMaterials={}
local tblMtrlCode={}
local des1=""
local code1=""

function readFile(path,frm)
list=""
 if frm==1 then
  f=io.open(path, "r")
  list = f:read("*all")
  f:close()
  else
  list=path
 end
sl=createStringList()
sl.Text=list

 for i=0, strings_getCount(sl) -1 do
  des=(sl[i]):match(":(.*)")
  code=(sl[i]):match("(.-):")
   if des~=nil or code~=nil then
    des1=des1 .. "'" .. des .. "',"
    code1=code1 .. "'" .. code .. "',"
    tblMaterials[i+1]=des
    tblMtrlCode[i+1]=code
   end
 end
 sl.Destroy()
end

--path=[[C:\myMaterial.txt]] --your txt file path
--readFile(path,1)
readFile(list,2)

print(des1)
print(code1)

print(tblMaterials[3] .. ": " .. tblMtrlCode[3] .. ": " .. readInteger(tblMtrlCode[3])) --"read" Make sure the address is working. Otherwise, disable reading.


gui usage:
Code:
if form then form.destroy() form = nil end
form = createForm()  -- Your Trainer ex(UDF1)
form.Popupmode = 0;
form.Position = poDesktopCenter
form.Width = 220
form.Height = 140

local Lbl1 = createLabel(form) -- Your label ex(UDF1.CELabel1)
Lbl1.AutoSize=false
Lbl1.Left=40 Lbl1.Height=23 Lbl1.Top=20 Lbl1.Width=140
Lbl1.Color=65280 Lbl1.Font.Size=9 Lbl1.Font.Style='fsBold'
Lbl1.ShowHint=true Lbl1.Alignment="taCenter" Lbl1.caption=". . ."
 Lbl1.OptimalFill=true

local CBox1 = createComboBox(form) -- Your Combobax ex(UDF1.CEComboBox1)
CBox1.Left=40 CBox1.Height=27 CBox1.Top=53 CBox1.Width=140
CBox1.AutoSize=false
CBox1.Font.Height=-13 CBox1.Font.Size=10 CBox1.Font.Style='[]'
CBox1.ReadOnly=true CBox1.ShowHint=false CBox1.Hint=''
CBox1.Style='csDropDownList'

local Lbl2 = createLabel(form) --desc
Lbl2.AutoSize=false
Lbl2.Left=40 Lbl2.Height=23 Lbl2.Top=85 Lbl2.Width=140
Lbl2.Color=65280 Lbl2.Font.Size=9 Lbl2.Font.Style='fsBold'
Lbl2.ShowHint=true Lbl2.Alignment="taCenter"
 Lbl2.OptimalFill=true

local tblMaterials={'seed','machine','shot','heavy','long'}
--local tblMtrlCode={0x01BA1DC0,0x001FD72D0,0x00B39AD0,0x01EA29F0,0x00C9AE20}
local tblMtrlCode={"06C3BB60","06D51CB0","06D52624","06D529EC","06D52DB4"}

CBox1.clear()
CBox1.Items.Add("Select Materials")
for i,k in pairs(tblMaterials) do
CBox1.Items.Add(k)
end

CBox1.ItemIndex="0"
Lbl2.caption="Index: " .. CBox1.ItemIndex

CBox1.OnChange=function()
local index = CBox1.ItemIndex
  index=tonumber(index)
 if index~=0 then
  code=readInteger(tblMtrlCode[index])
  if code~=nil then -- Make sure the address gives an up-to-date value. If not, the address is old and create it again.
   Lbl1.caption=tblMaterials[index] .. " = " .. code
   Lbl2.caption="Index: " .. CBox1.ItemIndex
  end
  else
   Lbl2.caption="Index: " .. CBox1.ItemIndex
   Lbl1.caption=". . ."
 end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Centos
How do I cheat?
Reputation: 0

Joined: 07 Mar 2022
Posts: 9

PostPosted: Thu Mar 10, 2022 7:49 pm    Post subject: Reply with quote

That's flawless. Thank you sir ! Very Happy
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