Thursday, 15 December 2011

I can haz my own script?

I want to do some coding, can you teach me?
Short Answer? No I can not, but i can help you get set up.

Follow the white rabbit

Get Notepad++ i highly recommend it. Its free and works great!

After you have installed it and you want to have a look at someone elses code, firstly go and get it. You can view anyones source code, its rather easy to get especially from a bookmarklet, Take for example my drone bookmarklet 
you can see the part that starts with http:// and ends with .js.

All scripts will start with http and end with .js some can end with .txt, but for this i am going to use the drone location as an example copy and paste that into your web browser it will display a page similar to this:
Copy and paste that into Notepad++ and save it as a .js extentsion

Why? because it turns a page from this

to this.

What did it just do?

It did syntax highlighting and makes it awhole lot easier to code and fix things.

For Mafiawars you dont really need to open with javascript:(function(){ and close with })() because MW already knows its javascript but i prefer too.

Commenting is always good because you can read the script writers notes which sometimes explain things, other times they comment bits of code out to try fix it when there is a code change. Heres a quick example:

if that is loaded into mafiawars it will give you two popups, first one saying "Hello Worlds" and then after you clicked ok, you'd then get "well done" When testing code or trying to fix it, adding an alert with a simple "return;" after it will firstly alert you when you get to that part of the code and then the "return;" will stop the code from continuing which is good because then you can update that part of code without it running thru everything else and going haywire.

When the browser is reading a scriipt it reads it from top to bottom.

most things get wrapped up into a function, and to read these pics you will need to click on them to make them bigger.

After making changes or writing a script you need to host it somewhere, Userscripts is a good site and allows you to do live editing etc If you sign up to there and upload a script you will notice your script gets a number in the address bar, you can use that number to use the userscript site as a temp host for your bookmarklet ( With uploading scripts to you must include the following at the begining of your script: change the name and description.
With the actual part of making the bookmarklet you yourself have to figure out what the code is, but you can usually piggy back off the ingame code or other peoples code.

When i started out i was mainly modding other peoples code and hard coding in speed options that the script writers hadnt allowed. One of my bigger mods that was maybe known was Brawler Lite where i ended up removing sections of code from Aruns Brawler (Original author) and moving things around and adding my own tweak(s). Inwhich i probably learnt the most of coding from, i was lucky because i had a fully commented script so it explained what everything did. I later did minor updates on OGP (for new districts/cities) and linked those that asked me for it if Lefty hadnt updated his yet.

Its nice to link your modification of a script to its original author and let them know, if they like your idea they might take it on to there original with a credits to you link. Its also good to make it clear that your modification is a modification, so you dont confuse people and they get mad at the original author.

Most script writers are happy to hear your ideas on a script or code input on a current script, some will give you help on your own.

Most things are google-able i have learnt much from going thru other peoples scripts and googling some of there code and seeing examples of how it runs. An example was setTimeout(functionnamehere,5000); where 1000 = 1 second, so that bit of code would launch the function in 5 seconds.

Bit of a slack article but i hope it has shown you how to get a basic setup to improve your coding, im happy to try and help just ask.


  1. Very good info i want to start learning how to do this TYVM for this info it will help to get me started