Happy Snail

A collection of Ikariam Tutorials from a hard-core player and Java Script programmer

Greasemonkey Madness

The purpose of this tutorial is to introduce you, dear reader to joys of programming and automation. This is part of the initiative to teach programming to all and is supported by

Programming for the Masses project.

So, you always wanted to learn programming but found it boring and nobody told you were to start.  Why not start with basics and move to the games you love?

A simplest program could be as simple as this:

<html>

<script>

 document.write(  56797777 + 678784456  );

</script>  

</html> 

Usually programming lessons start with outputting "hello world" to the screen.  This is pretty boring and of itself useless.  The above code - is a little more useful.  It would output a sum of 56797777 + 678784456.  Try to work it out in your head!  Any fool can type "hello world", you don't need a computer program for that, but very few people can work out the maths above without a calculator or at least a pen and paper.  Copy the code above to notepad and save it with a .html or .htm extension.  Voila! you have created your first application. Change the numbers in the code, and the output will change too.


The little beauty below removes dangerous accelerate loading buttons. These buttons pop up every time you start loading something in your port.  Due to proximity of the accelerate and recall buttons is all to easy to click a wrong button.  Imagine you accidentally order sending coal to Newcastle, notice your mistake and instead of hitting the recall button you hit the silly accelerate button and waste your Ambrosia? Mistakes like this do wonders for player's blood pressure, therefore it is in the interest of the Public Health to run this script that will remove the dangerous little accelerate buttons.

             // ==UserScript==
// @name           remove stupid accelerators
// @namespace      removes dangerous accelerate loading buttons
// @author         TestUser
// @license        GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
// @homepage       http://userscripts.org/scripts/show/50784
// @description    Removes Plus features as a test - I am not against paying to play
// @include        http://s*.ikariam.*/index.php*
// @include        http://s*.*.ikariam.*/index.php*
// @version        0.02
// @exclude        http://board.ikariam.*/*
// @exclude        http://support*.ikariam.*/*
//
// ==/UserScript==


// this is the code that gets a random number for delay - between 500 and 1500 miliseconds.
var delay = getRandomInt (500, 1500);
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

var accelerate;  // accelerate loading of ships (military view)
function removeAccelerate(){
accelerate= document.evaluate("//a[contains(@id,'AccLoading')]", document.body, null, 9, null).singleNodeValue; 
 if (accelerate) { //alert('accelerate');
 accelerate.parentNode.removeChild(accelerate);
 window.clearInterval(ac);
 } 
}

delay = getRandomInt (500, 1500);
var ac = setInterval( removeAccelerate, delay );

var accelerateInPort;  // accelerate loading of ships (port view)
function removeAccelerateInPort(){
accelerateInPort= document.evaluate("//a[contains(@id,'js_accloading')]", document.body, null, 9, null).singleNodeValue; 
 if (accelerateInPort) { //alert('accelerate');
 accelerateInPort.parentNode.removeChild(accelerateInPort);
 window.clearInterval(accloading);
 } 
}
delay = getRandomInt (500, 1500);
var accloading = setInterval( removeAccelerateInPort, delay );

How does it work? First we get the element we want to remove - we use Xpath expression, but document.getElementById("id_of_element");  would also work, but you need to use a full id,  and that id can change. Xpath is so much more advanced. For example we obtain the element whose id contains "AccLoading", we only need a partial match.  It would even match jscript_dfdfAccLoading88f".

accelerate= document.evaluate("//a[contains(@id,'AccLoading')]", document.body, null, 9, null).singleNodeValue;  

 

 

This little script clicks the get daily bonus button, so you don't have to! Of course both of these scripts can be combined into one.

// ==UserScript==
// @name           click
// @namespace      clicks the button to get daily bonus after a random delay
// @author         TestUser
// @license        GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
// @homepage       http://userscripts.org/scripts/show/50784
// @description    Removes Plus features as a test - I am not against paying to play
// @include        http://s*.ikariam.*/index.php*
// @include        http://s*.*.ikariam.*/index.php*
// @version        0.02
// @exclude        http://board.ikariam.*/*
// @exclude        http://support*.ikariam.*/*
//
// ==/UserScript==


// this is the code that gets a random number for delay - between 500 and 1500 miliseconds.
var delay = getRandomInt (500, 1500);
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

var btn = document.getElementsByClassName("button okButton")[0]; // gets all buttons by this class name - there should be only one
// this is the code that activates clicking of a button  after a random delay
if ( btn )  {  //  only runs on the first page load - when there is the button we want to click
setTimeout( click_it, delay );
}

// this is the code that actually clicks the button
function click_it() {   
document.evaluate("//input[@value='Confirm' and @type='submit' and contains(@class, 'button okButton')]", document, null, 9, null).singleNodeValue.click();
}

 

More scrips are coming soon. I intend to write a detailed Greasemonkey tutorial using Ikariam as an example.  Whatch this space.

And this little piece of delightful code will keep clicking "Capture" button in the Pirate Fortress - it will keep doing so 24/7 - earning you a lot of capture points, while saving you from repetitive strain syndrome and shortage of sleep. This code is like a Terminator - it will absolutely not stop. I have run a test - and the amount of cupture points collected was insane!  A human would have to spend hours sitting in front of computer clicking a button every 2.5 minutes to get the same result.

function click_townView(){
var townView=document.evaluate("//a[@title='Inspect the selected town']", document.body, null, 9, null).singleNodeValue;   
if ( townView ){ delay = getRandomInt (1000, 2000); townView.click(); }
} //eof

function click_pirateFort(){
var pirateFort=document.evaluate("//a[contains(@title,'Pirate Fortress')]", document.body, null, 9, null).singleNodeValue;   
if ( pirateFort ){ pirateFort.click(); }
else{ delay = getRandomInt (1000, 2000); click_townView(); }
} //eof

/* click_captureSmuglersBtn() is the function that keep clicking "Capture" button
   every 2.5 minutes.
   But if we are thrown out of the pirate fort, we need to get back into Town View,
   and then into the Pirate Fort, so we have click_townView() and click_pirateFort() too
*/

function click_captureSmuglersBtn(){
var captureSmuglersBtn=document.evaluate("//a[contains(@class,'button capture')]", document.body, null, 9, null).singleNodeValue;   
if ( captureSmuglersBtn  ){ captureSmuglersBtn.click();
//setTimeout( clickBtn, 1500 );  // go to next city
window.clearInterval(int1);
setTimeout( myPause, 151000 ); // pause for 2.5 minutes and 1 sec
}
else{ delay = getRandomInt (1000, 2000); click_pirateFort(); }
} //eof

var delay = getRandomInt (1000, 3000);

function myPause(){  int1=setInterval( click_captureSmuglersBtn, delay); }

var int1=setInterval( click_captureSmuglersBtn, delay);

//************  calculate random delays  **************
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

 

Filed under: Ikariam bot, Ikariam auto, Ikariam Pirate, Ikariam pirate fortress, Ikariam pirate script, Ikariam piracy automation

An Adventure Book set in Ikariam world

Setting of this book is the world of Ikariam. Imagine Ikariam mixed with Second Life and you get a Matrix-like world set in Ancient Greece. There are epic adventures, unexpected turns and revelations. Read the full book description and the first two chapters free on Amazon. This book has 5 star reviews and it is only £0.99.
You can also read a FREE online version here.


       

 


House of Cain is a scarily realistic military fiction book about Russia versus NATO war in North-Eastern Europe. The novel's main hero, Arthur Greenberg, is a British expatriate caught in the thick of it. WARNING: this book contains graphic combat scenes.

   

Ikariam News

v 0.7.0 released December 2015 has an important modification: the barbarians now have a lot of loot, but they can strike back. It seems prudent for a cautious player not to let them get higher than level 9. If we don't attack them for 2 or 3 days their level will drop, but if they have reached level 10, they will decline to level 10 only. Nobody knows what would happen when the barbarians reach level 50, but they could be troublesome at higher levels. Read this post on Ikariam boards for more information.

 

 


 

 

Domain name change in effect from 12 September 2013  means that some scripts will need to be upgraded.  Scripts on this site have been upgraded and all work.

Test Server new domain name is:   http://test.en.ikariam.gameforge.com/

Regular servers new domain name is: http://en.ikariam.gameforge.com/

  

 

 

 

 

 

 

 


 

 

 

 

 

 

A new 0.5.3 version introduced an extra dimension of Piracy to Ikariam around Christmas of 2012.  While Piracy is definitely an optional side-game, it has already sparked a few full-sized alliance wars and innumerable lesser conflicts. Passions run high, as a high military score is no defence aganst pirates; and casual Piracy players get robbed of their Pirate Points again and again by much smaller players who take the new side game of piracy too seriously.  The piracy favours a small player who can afford mobile colonies. Naturally the large players retaliate with military attacks.  This in turn led to pirates changing their player names frequently to avoid revenge. Large players with fully developped cities feel at a disadvantage as they cannot demolish their cities for mobile piracy, as without mobile cities it is not possible to excell at this side game.  Scripts naturally exist to automate piracy point generation, but this had been nipped in the bud, by the Game Forge when they introduced anti-bot CAPCHA measures a month into the game, to stop "dishonest pirates". 

A "dishonest" lover of automation as I am, I had written and deplyed such a script on a day one, and run it non-stop on multiple acconts 24/7. While most of my points was stolen by mibile pirates I still managed to get into the top 20 in the first 2 months.  Alas the CAPCHA had put an end to this noble endevour to automate online game playing. 


***

A new 0.5.0.1 version has been released early in May  2012. 

Two extra building spaces introduced, plus completely new graphics.  Now it is much easier to build 11 and 12th cities.

Most if not all of the userscrips (legal and otherwise) stopped working. The new version relies heavily on Ajax technology that makes the classical getElemtnById or document.evaluate Xpath experssion followed by element.click() to fail.  Many object identifiers (element id, attribute names etc) have also been changed; however the game is still ideally suited for userscript developpers. As a scripwright I discovered that adding setTimeout and setInterval to various blocks of code makes it all work again. It appears the game loads background image first, and then other elements, such as buildings are loaded asynchronously via Ajax later. A userscript runs immediately on dom ready, before the onload even occurs: before the buildings etc. have loaded. Making a script start looking for its targets after a few seconds delay allows it to find them again.  For example before the new version it was possible to access and click the button that gives daily bonus with this Xpath line:

document.evaluate("//input[@value='Confirm' and @type='submit' and contains(@class, 'button okButton')]", document, null, 9, null).singleNodeValue.click();

it not longer works now, because when the page loads there is still no input element we want.  But if we put the code above in a function and run the fuction a few seconds after the page loads it will work again.  If just like myself you are too lazy to click the various buttons yourself let the script do it for you.  

I am currently rewriting my favorite function neighborAutoFarm() 

My other projects

Subversive Medicine  is a series of esseys on medicine, dentistry and futurism. Is modern dentistry a fraud? Are robots going to make us all unemployed? Read all about it there.

 

Emotional AI is an AI project developing virtual conversation agent in .hta and javascript. This is a downloadable application that allows building off-line chatbots and virtual agents. There is a fuzzy string matching demo.


Simple Stylometry WebApp Free Proofreading and Editing App for aspiring authors. Use this proofreading and editing tool to analyze your writing for overused and glue words. Hunt down and destroy those pesky adverbs to make your great story even better! It can be used for editing business letters and school essays too.



Share on Facebook