Test please. Now you don't need to have lag reset on each savestate. You just save and load and have lag displayed as usual in fceux, and its count is saved and loaded properly as well.
Download KirbyAdventure-LagHUD.luaLanguage: lua
-- 2013
-- lag couter by feos
-- HUD by MUGG
lagged = false
function Stuff()
gui.opacity(0.2)
gui.drawbox(149,8,258,32, "black")
gui.opacity(0.95)
xspeed = memory.readbyte(0x05B9)+memory.readbytesigned(0x05Ba)*256
yspeed = memory.readbyte(0x05Bd)+memory.readbytesigned(0x05Be)*256
xpos = memory.readbyte(0x0083)+memory.readbytesigned(0x0095)*256+memory.readbyte(0x0071)/256
ypos = memory.readbyte(0x00b9)+memory.readbytesigned(0x00cb)*256+memory.readbyte(0x00a7)/256
gui.text(150,9," \n \n ")
gui.text(150,9," pos speed\n(X):\n(Y):", "green")
gui.text(172,17, math.floor(xpos*1000)/1000)
gui.text(224,17, xspeed)
gui.text(172,25, math.floor(ypos*1000)/1000)
gui.text(224,25, yspeed)
end
function DetectLag()
LagFlag = memory.readbyte(0x01a5)
if LagFlag == 1 then lagged = true
else lagged = false
end
end
function SetLag()
if lagged then emu.setlagflag(true)
else emu.setlagflag(false)
end
end
memory.registerexecute(0xC373, DetectLag)
memory.registerexecute(0xC323, SetLag)
emu.registerafter(Stuff)