• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Hunting graphics

elf

Sing, sing blue silver
Senator
Joined
Dec 11, 2007
Messages
3,666
Solutions
1
Reaction score
125
Location
Warsaw, Poland
GitHub
tayandenga
Twitch
tayandenga
Well, I don't have anything to say, as it's based on Lua script by Mock, so all (almost! :peace:) credits go to him. I've personally added a simple caching, so the image won't need to be generated each time someone wants to see it.

Original topic: http://otland.net/f81/hunting-graphics-56772/

Code:
<?php
$config = array(
    'cache' => 3 * 60 * 60, # seconds
    'multiplier' => 10, # keep it max 10 (for small servers), 5<->2 for huge ones
    'x' => 1471,
    'y' => 1141,
    'file' => './map.png',
    'store' => './pos.txt'
);

if(!file_exists($config['file']) || fileatime($config['file']) < time() - $config['cache'])
{
    $img = imagecreatetruecolor($config['x'], $config['y']);
    $n = floor(255 / $config['multiplier']);

    $colors = array(
        0 => imagecolorallocate($img, 0, $config['multiplier'], $config['multiplier'])
    );
    for($i = 1; $i <= $n; $i++)
    {
        if($i == $n)
        {
            $colors[imagecolorallocate($img, 0, $config['multiplier'] * $i, $config['multiplier'] * $i)] = imagecolorallocate($img, 255, 0, 0);
            for($j = 0; $j <= $n; $j++)
            {
                if($j == $n)
                {
                    $colors[imagecolorallocate($img, 255, $config['multiplier'] * $j, 0)] = imagecolorallocate($img, 255, 255, 0);
                    for($k = 0; $k <= $n; $k++)
                        $colors[imagecolorallocate($img, 255, 255, $config['multiplier'] * $k)] = imagecolorallocate($img, 255, 255, $config['multiplier'] * $k + $config['multiplier']);
                }
                else
                    $colors[imagecolorallocate($img, 255, $config['multiplier'] * $j, 0)] = imagecolorallocate($img, 255, $config['multiplier'] * $j + $config['multiplier'], 0);
            }
        }
        else
            $colors[imagecolorallocate($img, 0, $config['multiplier'] * $i, $config['multiplier'] * $i)] = imagecolorallocate($img, 0, $config['multiplier'] * $i + $config['multiplier'], $config['multiplier'] * $i + $config['multiplier']);    
    }

    $positions = @file_get_contents($config['store']);
    foreach(explode(';', $positions) as $position)
    {
        $pos = explode(',', $position);
        $c = imagecolorat($img, $pos[0], $pos[1]);
        if($colors[$c] != NULL)
            imagesetpixel($img, $pos[0], $pos[1], $colors[$c]);
    }

    $size = count($colors) - 1;
    for($i = 0; $i <= $size; $i++)
    {
        for($x = ($config['x'] - 5); $x <= $config['x']; $x++)
        {
            for($y = ($config['y'] - ($size - $i)); $y <= $config['y']; $y++)
            {
                $c = imagecolorat($img, $x, $y);
                if($colors[$c] != NULL)
                    imagesetpixel($img, $x, $y, $colors[$c]);
            }
        }
    }

    imagepng($img, $config['file']);
}
else
    $img = imagecreatefrompng($config['file']);

header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>

EDIT:
Oh, and here's how it looks: http://wypas.eu/map.phtml

EDIT #2:
Here's my version (storing positions at database table, per world data), still gathering information: http://wypas.eu/images/active.php
 
Last edited:
Awesome. I was going to create this in php myself. =D

Glad you beat me to it so it's "pro" scripted.
 
Last edited:
You can easily use your own map as base...

Instead
Code:
$img = imagecreatetruecolor($config['x'], $config['y']);
use
Code:
$img = imagecreatefrompng('./path_to_map_negative.png');

and then add to colors:
Code:
imagecolorallocate($img, R, G, B) => imagecolorallocate($img, 0, $config['multiplier'], $config['multiplier'])
where R, G and B is the RGB color of land color.

Here's how it looks at end (the link's at first post):
http://wypas.eu/images/active.php

Land color is 70 70 70.
 
I don't understand what this script is for ;d

Basicaly script put dots on image by positions where player(s) killed monster(s). Repeatings are each time highlighted. With it you can diagnose which hunting spots are most popular on your server / map.

On the active.php you can see where are players of WypasOTS hunting, and which are favorite spots. On the right down corner you have the color scale, descending.
 
Back
Top