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 


Unable to draw on Bitmap Canvas

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

Joined: 05 Apr 2019
Posts: 9

PostPosted: Fri Apr 05, 2019 10:39 am    Post subject: Unable to draw on Bitmap Canvas Reply with quote

I'm working on a simple Radar Hack in CE. I've obtained the coordinates of the player and also managed to translate the coordinates to Radar Coordinates. All that is left is drawing markers on those Radar Coordinates to denote players (I tried using a 3x3 filled rectangle for this purpose).

This is my first time working with the CE Lua API and Forms Designing. I've used CE for other basic purposes though. I googled up for some docs and examples. I came across this:
viewtopic.php?t=574084

Looking at the example, I wrote up something. But it isn't drawing the markers for some reason. I've already banged my head enough and I really need assistance now. This is the final missing piece of puzzle. Any help is greatly appreciated.

I came up with this code:
Code:

-- UDF1 : TCEForm                (BorderStyle: bsNone; FormStyle: fsSystemStayOnTop)
--  |---> CEImage1: TCEImage     (Fits exactly on the form. i.e, same dimensions and pos)

-- some declaration here
RadarTimer     =    nil
RadarBox     =    nil

-- initialization
function initialize()
   -- some initializtion here

    -- Initialize Timer
   RadarTimer              =    createTimer(UDF1, false)
    RadarTimer.Interval     =    200
    RadarTimer.OnTimer      =    RadarTimer_tick

    -- Initialize RadarBox (Bitmap)
    RadarBox                =    UDF1.CEImage1.Picture.Bitmap
    RadarBox.Width          =    RadarBox_Size
    RadarBox.Width          =    RadarBox_Size

    -- Let the user know
    print("Initialized")

    -- Enable the Radar
    RadarTimer.Enabled      =    true
end

function RadarTimer_tick(sender)
   -- some calculation here
   -- Clear Canvas
    RadarBox.Canvas.clear()
    -- Draw Local Player Marker (3x3 rectangle centered at (x,y))
    RadarBox.Canvas.Brush.Color = 0xff
    RadarBox.Canvas.FillRect(x-1, y-1, x+1, y+1)

    -- Draw Other Player Markers
    for i = 0, n-1 do
       -- some calculation here

       -- Draw Other Player Marker (3x3 rectangle centered at (MapX,MapY))
       RadarBox.Canvas.Brush.Color = 0xff0000
        RadarBox.Canvas.FillRect(MapX-1, MapY-1, MapX+1, MapY+1)
    end

    RadarBox.TransparentColor     =     clBlack
    UDF1.CEImage1.Transparent     =     true
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Fri Apr 05, 2019 11:26 am    Post subject: Reply with quote

i really recommend using the paintbox and do your rendering in onPaint and then a timer that calls paintbox.repaint() every now and then


anyhow, for your approach:
1: radarbox.height is never set (only width twice)
2: where does radarbox_Size get it's value from? if it's undefined it will be nil/0

_________________
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
View user's profile Send private message MSN Messenger
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Fri Apr 05, 2019 11:39 am    Post subject: Reply with quote

You might also have problems with initializing an object with a variable that hasn't been defined yet (or has an old value from a previous execution). e.g.:
Code:
local t = createTimer()
t.OnTimer = foo

function foo() print'yes' end

assert(t.OnTimer == nil)  -- true

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
el_beta
How do I cheat?
Reputation: 0

Joined: 05 Apr 2019
Posts: 9

PostPosted: Fri Apr 05, 2019 1:16 pm    Post subject: Reply with quote

Dark Byte wrote:
i really recommend using the paintbox and do your rendering in onPaint and then a timer that calls paintbox.repaint() every now and then


Will try.

Dark Byte wrote:

anyhow, for your approach:
1: radarbox.height is never set (only width twice)
2: where does radarbox_Size get it's value from? if it's undefined it will be nil/0


1. I changed it and it worked. Radar started working but improperly.
2. I wrote only the necessary parts of the program. Forgot to mention that it was set to 0 initially. It was done in my code though.

I am getting something on the radar but it isn't right. I was supposed to get a red square (representing me) in the middle with multiple blue squares (representing others) in the map.

But what I see is one red square in the middle and the whole background color is blue.

This is the code I used.

Code:

-- Draw Other Player Markers
RadarBox.Canvas.Brush.Color = 0xff0000
if MapX > 0 and MapX < RadarBox_Size and MapY > 0 and MapY < RadarBox_Size then
       print("MapX MapY = "..MapX.." "..MapY)
       print("")
       RadarBox.Canvas.FillRect(MapX-RMark_Hsize, MapY-RMark_Hsize, MapX+RMark_Hsize, MapY+RMark_Hsize)
end


The map coordinates obtained look good enough. What's going wrong then? Is it the Canvas.clear() thing?

EDIT: I also noticed another thing, I see what expected results for like a split second and the whole thing becomes blue all of a sudden with a red square in the middle.
Back to top
View user's profile Send private message
el_beta
How do I cheat?
Reputation: 0

Joined: 05 Apr 2019
Posts: 9

PostPosted: Sat Apr 06, 2019 1:43 am    Post subject: Reply with quote

Dark Byte wrote:
i really recommend using the paintbox and do your rendering in onPaint and then a timer that calls paintbox.repaint() every now and then


anyhow, for your approach:
1: radarbox.height is never set (only width twice)
2: where does radarbox_Size get it's value from? if it's undefined it will be nil/0


I GOT IT TO WORK!!!!!!

Instead of clearing the screen using Canvas.Clear()
I simply filled the Radar with Black Color.

-> I would like to know if it is possible to draw Player Markers (those red and blue squares) on a transparent form which will lie on the actual map?

-> Is there any effective way to start and exit the script? Like maybe some sort of keybind to scan for nearby players, another keybind to start displaying them on radar, another to stop the script.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Sat Apr 06, 2019 2:41 am    Post subject: Reply with quote

You can do something like this to make a transparent window:
Code:

local f=createForm()
f.Color=0x0000ff
local p=createPanel(f)
p.Color=0x00ff00
p.Font.Color=0xff0000
p.Caption='Drag here'
p.OnMouseDown=function(p) f.dragNow() end


f.OnPaint=function(s)
  f.Canvas.Pen.Color=0xff00ff
  f.Canvas.Pen.Width=4
  f.Canvas.Line(20,60,90,90)

  f.Canvas.Pen.Color=0x0000fe --almost red but not quite
  f.Canvas.Line(60,90,120,130)
end

f.BorderStyle='bsNone'

f.setLayeredAttributes(0x0000ff,0,LWA_COLORKEY) --make red invisible



Note though that mouseclicks will not pass through to the background

And you can use
Code:

createHotkey(function(x)
--do whatever happens in the hotkey press
end, key1,key2, key3)

_________________
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
View user's profile Send private message MSN Messenger
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