Post subject: Minimap lua script
Editor, Expert player (2480)
Joined: 4/8/2005
Posts: 1573
Location: Gone for a year, just for varietyyyyyyyyy!!
This is a minimap lua script for a GBA game called Rebelstar - Tactical Command. The script is useful for observing hidden enemy units. I'm not a coder, so this can be improved a lot. (For easier testing, start Skirmish Game instead of New Campaign.)
while true do
vba.registerbefore( function ()

-- Relevant unit stats are collected here:

x1 = memory.readbyte(0x0200f441)
y1 = memory.readbyte(0x0200f445)
h1 = memory.readbyte(0x0200f454)
t1 = memory.readbyte(0x0200f450)

x2 = memory.readbyte(0x0200f489)
y2 = memory.readbyte(0x0200f48d)
h2 = memory.readbyte(0x0200f49c)
t2 = memory.readbyte(0x0200f498)

x3 = memory.readbyte(0x0200f4d1)
y3 = memory.readbyte(0x0200f4d5)
h3 = memory.readbyte(0x0200f4e4)
t3 = memory.readbyte(0x0200f4e0)

x4 = memory.readbyte(0x0200f519)
y4 = memory.readbyte(0x0200f51d)
h4 = memory.readbyte(0x0200f52c)
t4 = memory.readbyte(0x0200f528)

x5 = memory.readbyte(0x0200f561)
y5 = memory.readbyte(0x0200f565)
h5 = memory.readbyte(0x0200f574)
t5 = memory.readbyte(0x0200f570)

x6 = memory.readbyte(0x0200f5a9)
y6 = memory.readbyte(0x0200f5ad)
h6 = memory.readbyte(0x0200f5bc)
t6 = memory.readbyte(0x0200f5b8)

x7 = memory.readbyte(0x0200f5f1)
y7 = memory.readbyte(0x0200f5f5)
h7 = memory.readbyte(0x0200f604)
t7 = memory.readbyte(0x0200f600)

x8 = memory.readbyte(0x0200f639)
y8 = memory.readbyte(0x0200f63d)
h8 = memory.readbyte(0x0200f64c)
t8 = memory.readbyte(0x0200f648)

x9 = memory.readbyte(0x0200f681)
y9 = memory.readbyte(0x0200f685)
h9 = memory.readbyte(0x0200f694)
t9 = memory.readbyte(0x0200f690)

x10 = memory.readbyte(0x0200f6c9)
y10 = memory.readbyte(0x0200f6cd)
h10 = memory.readbyte(0x0200f6dc)
t10 = memory.readbyte(0x0200f6d8)

x11 = memory.readbyte(0x0200f711)
y11 = memory.readbyte(0x0200f715)
h11 = memory.readbyte(0x0200f724)
t11 = memory.readbyte(0x0200f720)

x12 = memory.readbyte(0x0200f759)
y12 = memory.readbyte(0x0200f75d)
h12 = memory.readbyte(0x0200f76c)
t12 = memory.readbyte(0x0200f768)

x13 = memory.readbyte(0x0200f7a1)
y13 = memory.readbyte(0x0200f7a5)
h13 = memory.readbyte(0x0200f7b4)
t13 = memory.readbyte(0x0200f7b0)

x14 = memory.readbyte(0x0200f7e9)
y14 = memory.readbyte(0x0200f7ed)
h14 = memory.readbyte(0x0200f7fc)
t14 = memory.readbyte(0x0200f7f8)

x15 = memory.readbyte(0x0200f831)
y15 = memory.readbyte(0x0200f835)
h15 = memory.readbyte(0x0200f844)
t15 = memory.readbyte(0x0200f840)

x16 = memory.readbyte(0x0200f879)
y16 = memory.readbyte(0x0200f87d)
h16 = memory.readbyte(0x0200f88c)
t16 = memory.readbyte(0x0200f888)

x17 = memory.readbyte(0x0200f8c1)
y17 = memory.readbyte(0x0200f8c5)
h17 = memory.readbyte(0x0200f8d4)
t17 = memory.readbyte(0x0200f8d0)

x18 = memory.readbyte(0x0200f909)
y18 = memory.readbyte(0x0200f90d)
h18 = memory.readbyte(0x0200f91c)
t18 = memory.readbyte(0x0200f918)

x19 = memory.readbyte(0x0200f951)
y19 = memory.readbyte(0x0200f955)
h19 = memory.readbyte(0x0200f964)
t19 = memory.readbyte(0x0200f960)

x20 = memory.readbyte(0x0200f999)
y20 = memory.readbyte(0x0200f99d)
h20 = memory.readbyte(0x0200f9ac)
t20 = memory.readbyte(0x0200f9a8)

x21 = memory.readbyte(0x0200f9e1)
y21 = memory.readbyte(0x0200f9e5)
h21 = memory.readbyte(0x0200f9f4)
t21 = memory.readbyte(0x0200f9f0)

x22 = memory.readbyte(0x0200fa29)
y22 = memory.readbyte(0x0200fa2d)
h22 = memory.readbyte(0x0200fa3c)
t22 = memory.readbyte(0x0200fa38)

x23 = memory.readbyte(0x0200fa71)
y23 = memory.readbyte(0x0200fa75)
h23 = memory.readbyte(0x0200fa84)
t23 = memory.readbyte(0x0200fa80)

-- Play area size is used as minimap box size:
bx = memory.readbyte(0x0200ff84)
by = memory.readbyte(0x0200ff86)
gui.fillbox(0, 0, bx, by, "grey")

-- Minimap borders:
gui.line(bx, by, 0, by, "black")
gui.line(bx, by, bx, 0, "black")

-- Enemy units are red:
if (t1 ~= 0) then gui.pixel(x1, y1, "red") end
if (t2 ~= 0) then gui.pixel(x2, y2, "red") end
if (t3 ~= 0) then gui.pixel(x3, y3, "red") end
if (t4 ~= 0) then gui.pixel(x4, y4, "red") end
if (t5 ~= 0) then gui.pixel(x5, y5, "red") end
if (t6 ~= 0) then gui.pixel(x6, y6, "red") end
if (t7 ~= 0) then gui.pixel(x7, y7, "red") end
if (t8 ~= 0) then gui.pixel(x8, y8, "red") end
if (t9 ~= 0) then gui.pixel(x9, y9, "red") end
if (t10 ~= 0) then gui.pixel(x10, y10, "red") end
if (t11 ~= 0) then gui.pixel(x11, y11, "red") end
if (t12 ~= 0) then gui.pixel(x12, y12, "red") end
if (t13 ~= 0) then gui.pixel(x13, y13, "red") end
if (t14 ~= 0) then gui.pixel(x14, y14, "red") end
if (t15 ~= 0) then gui.pixel(x15, y15, "red") end
if (t16 ~= 0) then gui.pixel(x16, y16, "red") end
if (t17 ~= 0) then gui.pixel(x17, y17, "red") end
if (t18 ~= 0) then gui.pixel(x18, y18, "red") end
if (t19 ~= 0) then gui.pixel(x19, y19, "red") end
if (t20 ~= 0) then gui.pixel(x20, y20, "red") end
if (t21 ~= 0) then gui.pixel(x21, y21, "red") end
if (t22 ~= 0) then gui.pixel(x22, y22, "red") end
if (t23 ~= 0) then gui.pixel(x23, y23, "red") end

-- Dead units are grey:
if (h1 == 0) then gui.pixel(x1, y1, "grey") end
if (h2 == 0) then gui.pixel(x2, y2, "grey") end
if (h3 == 0) then gui.pixel(x3, y3, "grey") end
if (h4 == 0) then gui.pixel(x4, y4, "grey") end
if (h5 == 0) then gui.pixel(x5, y5, "grey") end
if (h6 == 0) then gui.pixel(x6, y6, "grey") end
if (h7 == 0) then gui.pixel(x7, y7, "grey") end
if (h8 == 0) then gui.pixel(x8, y8, "grey") end
if (h9 == 0) then gui.pixel(x9, y9, "grey") end
if (h10 == 0) then gui.pixel(x10, y10, "grey") end
if (h11 == 0) then gui.pixel(x11, y11, "grey") end
if (h12 == 0) then gui.pixel(x12, y12, "grey") end
if (h13 == 0) then gui.pixel(x13, y13, "grey") end
if (h14 == 0) then gui.pixel(x14, y14, "grey") end
if (h15 == 0) then gui.pixel(x15, y15, "grey") end
if (h16 == 0) then gui.pixel(x16, y16, "grey") end
if (h17 == 0) then gui.pixel(x17, y17, "grey") end
if (h18 == 0) then gui.pixel(x18, y18, "grey") end
if (h19 == 0) then gui.pixel(x19, y19, "grey") end
if (h20 == 0) then gui.pixel(x20, y20, "grey") end
if (h21 == 0) then gui.pixel(x21, y21, "grey") end
if (h22 == 0) then gui.pixel(x22, y22, "grey") end
if (h23 == 0) then gui.pixel(x23, y23, "grey") end

-- Player units are green:
if (t1 == 0) then gui.pixel(x1, y1, "green") end
if (t2 == 0) then gui.pixel(x2, y2, "green") end
if (t3 == 0) then gui.pixel(x3, y3, "green") end
if (t4 == 0) then gui.pixel(x4, y4, "green") end
if (t5 == 0) then gui.pixel(x5, y5, "green") end
if (t6 == 0) then gui.pixel(x6, y6, "green") end
if (t7 == 0) then gui.pixel(x7, y7, "green") end
if (t8 == 0) then gui.pixel(x8, y8, "green") end
if (t9 == 0) then gui.pixel(x9, y9, "green") end
if (t10 == 0) then gui.pixel(x10, y10, "green") end
if (t11 == 0) then gui.pixel(x11, y11, "green") end
if (t12 == 0) then gui.pixel(x12, y12, "green") end
if (t13 == 0) then gui.pixel(x13, y13, "green") end
if (t14 == 0) then gui.pixel(x14, y14, "green") end
if (t15 == 0) then gui.pixel(x15, y15, "green") end
if (t16 == 0) then gui.pixel(x16, y16, "green") end
if (t17 == 0) then gui.pixel(x17, y17, "green") end
if (t18 == 0) then gui.pixel(x18, y18, "green") end
if (t19 == 0) then gui.pixel(x19, y19, "green") end
if (t20 == 0) then gui.pixel(x20, y20, "green") end
if (t21 == 0) then gui.pixel(x21, y21, "green") end
if (t22 == 0) then gui.pixel(x22, y22, "green") end
if (t23 == 0) then gui.pixel(x23, y23, "green") end

end)
  vba.frameadvance()
end
Skilled player (1828)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Nice idea! You can compress this script quite a lot by using a for loop. It would look something like this:
while true do
vba.registerbefore( function () 

startx = 0x0200f441

for k=0,22,1 do

x=memory.readbyte(72*k+startx)
h=memory.readbyte(72*k+startx+4)
t=memory.readbyte(72*k+startx+15)
h=memory.readbyte(72*k+startx+19)

if (t ~= 0) then gui.pixel(x, y, "red") end
if (t == 0) then gui.pixel(x, y, "green") end
if (h == 0) then gui.pixel(x, y, "grey") end

end

end)
  vba.frameadvance()
end 
Editor, Expert player (2480)
Joined: 4/8/2005
Posts: 1573
Location: Gone for a year, just for varietyyyyyyyyy!!
Tack ska du ha, Randil! The script is easier to manage now. :) What I would also like to have is making the enemies always visible (not only in the minimap). It can be done by changing the visibility value of all units:
memory.writebyte(72*k+startx+11, 1)
The problem is that when the enemies are visible, the game behaves differently (causing desyncs). I suppose one possibility would be to run this part of the script in a "parallel game", use gui.gdscreenshot and then paste it on top of the original game screen with 50% opacity. But it's a bit too complicated for me at the moment.