View previous topic :: View next topic |
Author |
Message |
el_beta How do I cheat?
Reputation: 0
Joined: 05 Apr 2019 Posts: 9
|
Posted: Fri Apr 05, 2019 10:39 am Post subject: Unable to draw on Bitmap Canvas |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25788 Location: The netherlands
|
Posted: Fri Apr 05, 2019 11:26 am Post subject: |
|
|
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 |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4700
|
Posted: Fri Apr 05, 2019 11:39 am Post subject: |
|
|
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 |
|
 |
el_beta How do I cheat?
Reputation: 0
Joined: 05 Apr 2019 Posts: 9
|
Posted: Fri Apr 05, 2019 1:16 pm Post subject: |
|
|
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 |
|
 |
el_beta How do I cheat?
Reputation: 0
Joined: 05 Apr 2019 Posts: 9
|
Posted: Sat Apr 06, 2019 1:43 am Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25788 Location: The netherlands
|
Posted: Sat Apr 06, 2019 2:41 am Post subject: |
|
|
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 |
|
 |
|