BGMI and Python Magic
So, yeah i am a kind of addict to PUBG mobile and since it has been relaunched again in India after the ban, while playing on day i got an idea of screaming diff sounds when i kill someone (ofcourse in "virtual" game), and here we are after a month of that idea, yeah it took me month as i myself forgot the idea next day:).
Initially i thought of running python script on my smartphone, as that would be much more sophisticated , but running full pc like python on android is still not the thing (mostly lack of direct lib support),if i were more into android app development i might have done that but nevertheless i am still happy with as my expected result.
Now lets take a look how you can also have your own pubg screamer, have fun.
Supplies
For the supplies you only need a PC, a smartphone with pubg installed and a usb cables(no need if wireless method of casting used)
First lets download all the complementry pieces of software required to run out program,
download python3 from here at the official python site
next we need a way to cast the smartphone screen to pc for that purpose i am using scrcpy, you can to use other ways for casting, use google to see diff ways and how to do that.
Now lets install required python libs, open your cmd (on window) or terminal (linux) and type the following commands in terminal on by one (you have to install pip if you get "command not found" in return, most probably it should be pre installed), and for linux users replace pip part with pip3 (it should work,as i haven't tested it, google it if you get stuck anywhere as there steps are much better documented there), commands are-
pip install pillow
pip install playsound
pip install pyscreenshot
i have used six libs in my program, other three libs are python built-in libs , if you get any problem till here leave a comment, i would love to short the issue
Now go to my github page and download the zip file(direct download here) and extract then folder, you will get five files and one folder in the extracted folder from which copy three .py extension file(coordinate_finder, data_creator and the_screamer) to the folder you want to put the program(i created folder BGMI in my D drive).
Now open your cmd prompt/ terminal and open your newly created folder in terminal (for window user you can see in my attached pic how i navigated) or you can right click inside your folder and click open terminal here (for linux).
Now use for prefered program to cast your smartphone screen to pc and put the windows full screenmode on landscape mode for refrence purposes, so that each time kill feed land at the same spot and then run pubg mobile on smarthone(make sure nothing is covering the kill box at any point of time)
First of all we would find the coordinate to get the screenshot of only the kill numbers from our screen, open cmd prompt and type [pyhton coordinate_finder.py] without brackets, this program will show you the croped screenshot of the screen, open the same coordinate_finder.py in text editor (like notepad) and vary values of x1,x2, y1,y2 variable till you get only the number of kill as shown in above images.
Very imp-- Once you find the final coordinates update these coordinate values across both the two remaining scripts.
In this step we will create the data of image for each kill from which our final progarm will compare to calculate realtime kills. For this step enter a new match of pubg mobile (i am in warehouse mode for whole of my program testing as it comaratively easy to kill as to classic match) and open cmd prompt/terminal and navigate to your folder and now run data_creator.py [python data_creator.py], this program will ask for an input from user, either 1 or 2.
For making ref of each kill in ref input 1 in cmd prompt/ terminal for each kill, first entering 1 will save 0 kill ref, again entering 1 will make first kill ref and so on, do this for each kill and when you have sufficient kill enter 2 to end program.
again important-- open the_screamer.py in text editor and change the value of variable maxkills with the higest kill you saved through data_creator.py, like for my case i have data for max of 12 kills.
Now in your program folder you could see a new folder named data, open the folder and you would have two more folder in it "img" and "files".
take your audio files (only in mp3 format) and paste them into 'files' folder, you can take my audio files from extracted folder in "audio".
again its important to rename mp3 files with the corresponding kill number which you want to play on that kill.
like mp3 file named 5.mp3 will play on fifth kill. don't put mp3 file less than kills in "files" folder.
Boom you at done at here, only thing left is to run the final script.
Before running make sure to change coordinate and maxkills variable in the_screamer.py program.
Now cast your smartphone to pc, enter into match on pubg mobile and then open terminal, navigate to your folder and then run the_screamer.py [python the_screamer.py], it should work now file in video.
The program terminates itself when max recorded kills are reached or you can interrupt the program in terminal using ctrl+c.
If still any problem persist comment below, it would surely be solved (hopefully :) )
Explaination
This part is only the explaination how the program works you can skip it without any guilt
....
The basic idea is to take the screenshot of only the kills from whole screen then the modify() function (see the_screamer.py for refrence) makes that screenshot invrted in colour (so that we get kills in black) and a little contrasty and then convert it into one bit black & white image, since only two colour image is much more easy to compare (hight contrast just improves the better line detection ), the images we get after this correction are same as you can see in "data/img" folder. Then the diff() function claculate the rms diff b/w the captured image and all stored images and the stores the diff in rmsdiff[] list. The lest diff image is our kill. If the new kill is diff from last kill them the kill named mp3 file is played if not differen then do nothing.
Yeah it's that simple, hopefully you like it. Thanks for reading, have fun with it.
And bear my speeling mistakes as i can't read again what i have written -_-