If you're running a gold farm the last thing you want are your bots competing against each other for resources. By setting up a database to reserve worlds you'll never have this problem again.
The first thing you'll need to do is set up the database. There are guides to do this on villavu forums.
I use phpMyAdmin to view my dataabase.
Create a table called "Worlds" with primary key "World" (int) and "InUse" (int). Once done, insert each world (1-150) & 0 for the InUse field (see below)
Your database is now ready to receive world information
We now need to write some php scripts to receive & pass information from our simba script to the database.
Save the following code as worldmanager.php on your server.
PHP Code:
<?php
$user_name = "Justin69"; //Username for the account you created
$pass_word = "69969"; //Password for the account you created
$database = "world_manager"; //The name of the database you created
$server = "localhost";
$theaction=$_GET['action']; //Now we're creating the variables we're passing through the URL
$world=$_GET['world'];
if ($theaction=='getworld'){
$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
//This query will return 1 if the world is free, 0 if taken
$SQL = "SELECT CASE WHEN InUse =0 THEN TRUE ELSE FALSE END AS InUse FROM Worlds WHERE world = $world";
$result = mysql_query($SQL);
if($result){
while ($db_field = mysql_fetch_assoc($result)){
$InUse = $db_field['InUse'];
print $InUse; //prints "1" for our simba script to read
}
}else
print "Table not found";
}else
print "Database not found";
}elseif ($theaction=='takeworld'){
$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "UPDATE Worlds SET InUse = 1 WHERE world = $world";
$result = mysql_query($SQL);
if($result){
print "1";
}else
print "0";
}else
print "Database not found";
}elseif ($theaction=='clearworld'){
$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "UPDATE Worlds SET InUse = 0 WHERE world = $world";
$result = mysql_query($SQL);
if($result){
print "1";
}else
print "0";
}else
print "Database not found";
}else
print "Failed";
?>
Now in your simba script you will use the following functions to access the database
Simba Code:
var
currentWorld : Integer;
//checkWorld checks if the passed world is taken, return true if available, false if in use by another bot.
function checkWorld(world : Integer) : Boolean;
begin
if (GetPage('http://www.domain.it/worldmanager.php?action=getworld&checkworld=' + IntToStr(world)) = '1') then
exit(true)
else
exit(false);
end;
//Returns the first available world in the database and sets it as occupied.
//Declare constant WORLD_LIST at the start of your list to have create a desired world order for your bots. ex
//WORLD_LIST = [2,77,64,100,10,84,56,4,23,45,31,105,5,119,14,54,123,103,9,16,67,39,22,60,98,99,22,1,69,134,139,6,32,71,24,46,70,21,88,40,44,26,36,28];
function getFreeWorld() : Integer;
var
i : Integer;
begin
for i := 0 to length(WORLD_LIST) - 1 do
begin
if checkWorld(WORLD_LIST[i]) then
begin
if not (GetPage('http://www.domain.it/worldmanager.php?action=takeworld&world=' + IntToStr(WORLD_LIST[i])) = '1') then
writeln('ERROR WRITING WORLD TO DATABASE!')
else
writeln('World ', WORLD_LIST[i], ' successfully reserved!');
currentWorld := WORLD_LIST[i];
exit(currentWorld);
end;
end;
exit(-1);
end;
//Call this function to release the world from database on terminate
procedure setWorldClear();
begin
if not (GetPage('http://www.domain.it/worldmanager.php?action=clearworld&world=' + IntToStr(currentWorld)) = '1') then
writeln('ERROR CLEARING WORLD FROM DATABASE!')
else
writeln('World ', currentWorld, ' successfully freed.');
end;
And that's it. From here you can add more variables and further automate your gold farm.
What you can do with a database is pretty much limitless - if you're running a gold farm you need to be storing as much data as possible
Here are some ideas of what to do with data stored by your scripts
-See which account is in which world
-Run 1 script to log in all your bots queueing username/passwords
-See how world populations effect spawn rates (& profit/hour) & better refine your world list
-Know exactly how much money is on an account
-Calculate average ban rates based on script versions
-Know exactly when to resupply an account/trade profits off
-Store bond activation date & avoid accounts going f2p
-Track which worlds your bots get banned on most frequently
-Let friends run your scripts, track & charge a % of their profits
Note: You can store this data locally in text files but if you run bots from various computers/servers they'll end up interfering with each other & your statistics will be inaccurate.
Good luck!