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 


change CEImage from lua code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
akikazu12
Newbie cheater
Reputation: 0

Joined: 08 Apr 2020
Posts: 14

PostPosted: Wed Apr 08, 2020 7:39 pm    Post subject: change CEImage from lua code Reply with quote

how to change CEImage from lua code?
so I want to translate numbers to Image, I have the images with same name as the value, So when the value changes, I want the image will also change, there are only 16 possibilities at that address, and I have all the 16 pictures,so how do I do it with lua code?

thank you
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Wed Apr 08, 2020 11:20 pm    Post subject: Reply with quote

I don't know where is your values and images store (could be on the table, local disk or on cheat table file), however, this is an example:


Code:
-- Load image from Cheat Table File according to the given value

myvalue = {1, 2, 3}
myimage = {"_1.png","_2.png","_3.png"}

form = createForm()
edt = createEdit(form)

img = createImage(form)
img.setSize(200,200)
img.setPosition(0,40)
img.stretch = true

function picShow()
 e_index = tonumber(edt.Text)
 if e_index == nil then return nil end
 if e_index < 0 or e_index > 16 then
  showMessage('Only accept number 1 to 16')
  edt.Text = ''
  img.visible=false
 end
 index = myvalue[e_index]
 if index == nil then
    return nil
 else
    img.visible=true
    image = myimage[index]
    img.Picture.loadFromStream(findTableFile(image).Stream)
 end
end

edt.OnChange = picShow

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
akikazu12
Newbie cheater
Reputation: 0

Joined: 08 Apr 2020
Posts: 14

PostPosted: Thu Apr 09, 2020 12:26 am    Post subject: Reply with quote

Corroder wrote:
I don't know where is your values and images store (could be on the table, local disk or on cheat table file), however, this is an example:



thank you for the reply, I have all my pictures in my local disk, so what I want is there are 5 images based on value, the image changes as the value change, there are only 16 type of value, but those 5 images are the order of the first 5 things that would appear, so I'll know what would come in the next 5 things, I have already make a 1 image, but I need 5, I code it in stupid way I guess, it would take so much time for 5 images(16 picture/image)

Code:
function CETrainer_CETimer1Timer(sender)
 local Almemrec=addresslist_getMemoryRecordByDescription(getAddressList(), "Top 1")
 local Alvalue=memoryrecord_getValue(Almemrec)
 control_setCaption(CETrainer_CELabel1, Alvalue)
 if Alvalue == "1085890304" then
  CETrainer_i1085890304.Visible = true
 else
  CETrainer_i1085890304.Visible = false
 end
 if Alvalue == "1085892352" then
  CETrainer_i1085892352.Visible = true
 else
  CETrainer_i1085892352.Visible = false
 end
 if Alvalue == "1086071808" then
  CETrainer_i1086071808.Visible = true
 else
  CETrainer_i1086071808.Visible = false
 end
 if Alvalue == "1085920512" then
  CETrainer_i1085920512.Visible = true
 else
  CETrainer_i1085920512.Visible = false
 end
 if Alvalue == "1085892608" then
  CETrainer_i1085892608.Visible = true
 else
  CETrainer_i1085892608.Visible = false
 end
 if Alvalue == "1085892096" then
  CETrainer_i1085892096.Visible = true
 else
  CETrainer_i1085892096.Visible = false
 end
 if Alvalue == "1085892864" then
  CETrainer_i1085892864.Visible = true
 else
  CETrainer_i1085892864.Visible = false
 end
 if Alvalue == "1085890560" then
  CETrainer_i1085890560.Visible = true
 else
  CETrainer_i1085890560.Visible = false
 end
 if Alvalue == "1085918720" then
  CETrainer_i1085918720.Visible = true
 else
  CETrainer_i1085918720.Visible = false
 end
  if Alvalue == "1085922048" then
  CETrainer_i1085922048.Visible = true
 else
  CETrainer_i1085922048.Visible = false
 end
  if Alvalue == "1086074112" then
  CETrainer_i1086074112.Visible = true
 else
  CETrainer_i1086074112.Visible = false
 end
  if Alvalue == "1086079232" then
  CETrainer_i1086079232.Visible = true
 else
  CETrainer_i1086079232.Visible = false
 end
 if Alvalue == "1086084864" then
  CETrainer_i1086084864.Visible = true
 else
  CETrainer_i1086084864.Visible = false
 end
  if Alvalue == "1086084352" then
  CETrainer_i1086084352.Visible = true
 else
  CETrainer_i1086084352.Visible = false
 end
 if Alvalue == "1085895936" then
  CETrainer_i1085895936.Visible = true
 else
  CETrainer_i1085895936.Visible = false
 end
 if Alvalue == "1085912320" then
  CETrainer_i1085912320.Visible = true
 else
  CETrainer_i1085912320.Visible = false
 end
end


what I did there is I add 16 CEImages with pictures from my local disk, and I check the value one by one, if it match it shows the picture, if else it won't visible..

what I need is the Image changes along with the value,
something like
CETrainer_CEImage1.setPicture = value.png
something like that
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Apr 09, 2020 6:20 am    Post subject: Reply with quote

Quote:
I guess, it would take so much time for 5 images(16 picture/image)


Should be a trick to do this, something like:

Code:
UDF1.Show()

alValue = '1085890304'
objname = 'CETrainer_i'..alValue
image = UDF1.findComponentByName(objname) or false

x = image.getName()
print(x)

nm = string.sub(objname, -10)
print(nm)

if string.sub(objname, -10) == alValue then
  -- image.getName().Visible = true
else
  -- image.getName().Visible = false
end


But I don't know how to set the found component visible to true or false. Maybe some else able to helps.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1549

PostPosted: Thu Apr 09, 2020 8:03 am    Post subject: Reply with quote

Use 1 "CELabel" and 1 "CEImage".
Change the picture by value.
First, add your pictures to the table, "CE >> Table >> Add file".
NOTE: check the format added to the table, ".PNG" or ".png"?
The code below takes the picture name from "CELabel" and uploads it to "CEImage".

Example 1:
Code:
local name = CETrainer.CELabel1.caption..".png" --? .PNG or name=Alvalue..".png"

function LoadImage()
CETrainer.CEImage1.Picture.loadFromStream(findTableFile(name).Stream)
end

function CETrainer_CETimer1Timer(sender)
 local Almemrec=addresslist_getMemoryRecordByDescription(getAddressList(), "Top 1")
 local Alvalue=memoryrecord_getValue(Almemrec)
 CETrainer.CELabel1.caption = Alvalue
 if Alvalue then
LoadImage()
end
end


Example 2:
Note: This method returns an "Error: Invalid class object" error.
Perhaps a solution should be sought for naming.

Code:
function ExitImage()
CETrainer.i1085890304.visible=false
CETrainer.i1085892352.visible=false
CETrainer.i1086071808.visible=false
--...... All Image etc.
CETrainer.i1085912320.visible=false
end

function CETrainer_CETimer1Timer(sender)
 local Almemrec=addresslist_getMemoryRecordByDescription(getAddressList(), "Top 1")
 local Alvalue=memoryrecord_getValue(Almemrec)
-- CETrainer.CELabel1.caption = Alvalue
ExitImage()
 if Alvalue then
local name = "CETrainer.i"..Alvalue
print(name)
 control_setVisible(name, true) --Error: Invalid class object
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Apr 09, 2020 8:28 am    Post subject: Reply with quote

Here is the simple solution:

Code:
UDF1.Show()   -- change UDF1 to your form name

alValue = '1085890304'  -- change this part to value from address list

--- you can put this part as a function if you want

for i = 0, UDF1.ComponentCount - 1 do
  nm = UDF1.Component[i].Name
  if string.sub(nm, -10) == tostring(alValue) then
    img = UDF1.findComponentByName(nm)
    img.Visible = true
  else
   -- img.Visible = false  --> you can add this line if you want
  end
end


_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
akikazu12
Newbie cheater
Reputation: 0

Joined: 08 Apr 2020
Posts: 14

PostPosted: Thu Apr 09, 2020 9:09 am    Post subject: Reply with quote

Corroder wrote:
Here is the simple solution:


[/code]

Aylin wrote:
Use 1 "CELabel" and 1 "CEImage".
Change the picture by value.
First, add your pictures to the table, "CE >> Table >> Add file".
NOTE: check the format added to the table, ".PNG" or ".png"?
The code below takes the picture name from "CELabel" and uploads it to "CEImage".

Example 1:

Example 2:
Note: This method returns an "Error: Invalid class object" error.
Perhaps a solution should be sought for naming.


damn, thank you so much guys, you are awesome, it works!! thank you! saves a lot of time!
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Apr 09, 2020 9:25 am    Post subject: Reply with quote

akikazu12 wrote:
damn, thank you so much guys, you are awesome, it works!! thank you! saves a lot of time!


Which one is working?. I think @Aylin example 2 is work.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
akikazu12
Newbie cheater
Reputation: 0

Joined: 08 Apr 2020
Posts: 14

PostPosted: Thu Apr 09, 2020 10:33 am    Post subject: Reply with quote

Corroder wrote:
akikazu12 wrote:
damn, thank you so much guys, you are awesome, it works!! thank you! saves a lot of time!


Which one is working?. I think @Aylin example 2 is work.

I use Aylin's example 1, I have Top 1, Top 2 ~5, so I just add the others and another 4 CEImage, and it works perfectly
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Apr 09, 2020 5:43 pm    Post subject: Reply with quote

Not bad for 16 images. Just considering if sometimes you find a case with says 100 images or more. Also, considering by store images as CE Table file and writing 16 images components one by one, it makes your CETraner growing on byte sizes.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
akikazu12
Newbie cheater
Reputation: 0

Joined: 08 Apr 2020
Posts: 14

PostPosted: Thu Apr 09, 2020 6:33 pm    Post subject: Reply with quote

Corroder wrote:
Not bad for 16 images. Just considering if sometimes you find a case with says 100 images or more. Also, considering by store images as CE Table file and writing 16 images components one by one, it makes your CETraner growing on byte sizes.


Yes, I thought about that before, I've tried to put them into table file, but I didn't know how to load data from table, that's why I ended up writing 16 images one by one from CEImage
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