Great function!
However, I took the liberty to expand it a bit.
First, the last screenshot number will be stored in a text file called "Scnr.txt" (you have to create this file yourself in your screens directory and just write a "0" (zero) at the beginning). This way the screenshots can't be overwritten. The ResetScreenShotIndex() function will just write a zero into the Scnr.txt file so the numbering will start at "0000" again.
Second, I added some leading zeros to the screenshot number. Just to keep the screenshots in a proper order.
void SaveScreenShot2()
{
//get the last screenshot number
int SSIndex = FileOpen("screens/scnr.txt",1);
int ScreenShot_Number = val(FileReadString(SSIndex));
FileClose(SSIndex);
string SSString_Number = str(ScreenShot_Number);
//add some leading zeros if needed
if (ScreenShot_Number < 10)
SSString_Number = "000"+SSString_Number;
if (ScreenShot_Number > 9 && ScreenShot_Number < 100)
SSString_Number = "00"+SSString_Number;
if (ScreenShot_Number > 99 && ScreenShot_Number < 999)
SSString_Number = "0"+SSString_Number;
int ScreenHandler = screen;
int SSX = ImageWidth(ScreenHandler);
int SSY = ImageHeight(ScreenHandler);
string ScreenShot_Filename="screens\ScreenShot_"+SSString_Number+".bmp";
int file;
int row, col;
int something;
Log("Save Screenshot : "+ScreenShot_Filename);
file=FileOpen(ScreenShot_Filename,FILE_WRITE);
FileWrite(file,"BM");
FileWriteQuad(file,0); // file size (ignore)
FileWriteQuad(file,0); // two reserved words
FileWriteQuad(file,54); // offset to image data
FileWriteQuad(file,40); // size of the bitmap info structure
FileWriteQuad(file,SSX); // image width
FileWriteQuad(file,SSY); // image height
FileWriteWord(file,1); // Number of planes? *shrug*
FileWriteWord(file,24); // bits per pixel
FileWriteQuad(file,0); // no compression
FileWriteQuad(file,0); // size of bitmap data (ignore)
FileWriteQuad(file,0); // whatever, man
FileWriteQuad(file,0); // whatever, man...
FileWriteQuad(file,0); // number of colors (ignore)
FileWriteQuad(file,0); // important colors (ignore)
for(row=SSY-1;row>=0;row--)
{
for(col=0;col<SSX;col++)
{
something=GetPixel(col,row,ScreenHandler);
FileWriteByte(file,GetB(something));
FileWriteByte(file,GetG(something));
FileWriteByte(file,GetR(something));
}
}
FileClose(file);
ScreenShot_Number++;
SSIndex = FileOpen("screens/scnr.txt",2);
FileWriteString(SSIndex, str(ScreenShot_Number));
FileClose(SSIndex);
MessageBox("Screenshot saved");
}
void ResetScreenShotIndex()
{
int SSIndex = FileOpen("screens/scnr.txt",2);
FileWriteString(SSIndex, "0");
FileClose(SSIndex);
}