local sub = string.sub local find = string.find g_mapPieceValues = g_mapPieceValues or "FFFFFFFFF" -- nine values local fileRead = false local levelName = nil local sprites = nil local function loadSprites() sprites = { { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_1.png" ) ), x = 20, y = 20, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_2.png" ) ), x = 40, y = 20, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_3.png" ) ), x = 60, y = 20, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_4.png" ) ), x = 20, y = 40, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_5.png" ) ), x = 40, y = 40, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_6.png" ) ), x = 60, y = 40, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_7.png" ) ), x = 20, y = 60, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_8.png" ) ), x = 40, y = 60, xsize = 20, ysize = 20 }, { spr = CreateSprite( LoadImage( "scriptbank\\images\\eye_9.png" ) ), x = 60, y = 60, xsize = 20, ysize = 20 } } for _, v in pairs( sprites ) do SetSpritePosition( v.spr, 200, 200 ) SetSpriteSize( v.spr, v.xsize, v.ysize ) end end local function saveValues() local file = io.open( "scriptbank\\mappieces.dat", "w+" ) io.output( file ) if file ~= nil then io.write( levelName, "\n" ) io.write( g_mapPieceValues, "\n" ) end io.close( file ) end function fe_setPiece( num ) local str = g_mapPieceValues if num == 1 then g_mapPieceValues = 'T' .. sub( str, 2, #str ) elseif num == #str then g_mapPieceValues = sub( str, 1, num - 1 ) .. 'T' elseif num < #str then g_mapPieceValues = sub( str, 1, num - 1 ) .. 'T' .. sub( str, num + 1, #str ) end saveValues() end function fe_gotPiece( num ) return sub( g_mapPieceValues, num, num ) == 'T' end function file_example_init( e ) if sprites == nil then loadSprites() end end local function getLevelName( str ) local spos = 1 local epos = 0 while epos < #str do epos = find( str, '\\', spos + 1 ) or #str if epos < #str then spos = epos + 1 end end return sub( str, spos, epos ) end local mouseClick = false local imageDisplayed = false function file_example_main( e ) if not fileRead then levelName = getLevelName( g_LevelFilename ) if strLevelFilename ~= nil then -- we have just loaded this level from a save game so save the file saveValues() else -- level change or new game local file = io.open( "scriptbank\\" .. "mappieces.dat", "r") if file ~= nil then local level = file:read() g_mapPieceValues = file:read() io.close( file ) end end fileRead = true end local pieces = "" local allFound = true for i = 1, #g_mapPieceValues do if fe_gotPiece( i ) then pieces = pieces .. i .. " " else allFound = false end end if allFound then Prompt( "All Found" ) else PromptLocal( e, pieces ) end if g_MouseClick == 1 then if not mouseClick then mouseClick = true if imageDisplayed then imageDisplayed = false for _, v in pairs( sprites ) do SetSpritePosition( v.spr, 200, 200 ) end else imageDisplayed = true for k, v in pairs( sprites ) do if fe_gotPiece( k ) then SetSpritePosition( v.spr, v.x, v.y ) end end end end else mouseClick = false end end