• 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!

[php] Erig.net scripts

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
Since erig is shuting down he release some of his scripts if some one want them you can download them at erig.net right now but im also posting them here can be usefull for someone

All credits to Erig.net

Script 1:
PHP:
<?php

class spCalc {
    const MAX_NUMWORD_LEVEL = '3914867641168863595426'; // results in closest level to 999 vigintillion
    const BACKPACK_SIZE = 20; // 20 slots
    const COST_BLANK_RUNE = 10; // Blank Rune cost
    public static $COST_BACKPACK = 10; // Backpack cost

    static function getXP($from, $to) {
        $to = gmp_sub($to, 1);
        $from--;
        $xp = gmp_div_q(gmp_add(gmp_sub(gmp_mul(50, gmp_pow($to, 3)), gmp_mul(150, gmp_pow($to, 2))), gmp_mul(400, $to)), 3);
        $xp = gmp_sub($xp, gmp_div_q(gmp_add(gmp_sub(gmp_mul(50, gmp_pow($from, 3)), gmp_mul(150, gmp_pow($from, 2))), gmp_mul(400, $from)), 3));
        $ret = gmp_strval($xp);
        if (substr($ret, -1) == "\0x00")
            $ret = substr($ret, 0, -1);

        return $ret;
    }

    static function getMana($voc, $from, $to) {
        switch ($voc) {
            case 'd':
            case 's':
                $pow = 1.1; break;
            case 'p':
                $pow = 1.4; break;
            case 'k':
                $pow = 3.0; break;
            default:
                $pow = 0.0; break;
        }

        $mana_g = '0';

        $scale = bcscale(10);

        for ($cnt = $from + 1; $cnt <= $to; $cnt++) {
            bcscale(10);
            $pow1 = bcpow((string)$pow, (string)($cnt - 1));
            bcscale(0);
            $mul = bcmul('400', $pow1);
            $mana_g = bcadd($mana_g, $mul);
        }

        $mana_g = bcmul($mana_g, 4);

        bcscale($scale);

        return $mana_g;
    }

    static function getManaPercent($voc, $from, $to, $percent) {
        $mana = self::getMana($voc, $from, $to);

        $scale = bcscale(10);

        $mana2 = self::getMana($voc, $from, $from + 1);
        $mana2 = bcmul($mana2, (100 - $percent) / 100);

        bcscale(0);
        $mana = bcsub($mana, $mana2);
        bcscale($scale);

        return $mana;
    }

    static function getManaRegenVocationValue($voc, $promo, $potion, $boots, $ring) {
        $mana = $duration = 0;

        if (($voc == 's' || $voc == 'd') && $promo) {
            $mana = 2; $duration = 2;
        }
        else if (($voc == 's' || $voc == 'd') && !$promo) {
            $mana = 2; $duration = 3;
        }
        else if ($voc == 'p' && $promo) {
            $mana = 2; $duration = 3;
        }
        else if ($voc == 'p' && !$promo) {
            $mana = 2; $duration = 4;
        }
        else if ($voc == 'k') {
            $mana = 2; $duration = 6;
        }

        if ($potion == 'm') {
            $mps = 100 / 2; // Mana Potion gives 100 mana every 2 seconds
            $mana = $mana + ($duration * $mps);
        }

        if ($potion == 's') {
            $mps = 150 / 2; // Strong Mana Potion gives 150 mana every 2 seconds
            $mana = $mana + ($duration * $mps);
        }

        if ($potion == 'g') {
            $mps = 240 / 2; // Great Mana Potion gives 240 mana every 2 seconds
            $mana = $mana + ($duration * $mps);
        }

        if ($boots == 'sb') {
            $mps = 2; // Soft Boots give 2 mana per second
            $mana = $mana + ($duration * $mps);
        }

        if ($ring == 'l') {
            $mps = 8 / 6; // Life Ring gives 8 mana every 6 sconds
            $mana = $mana + ($duration * $mps);
        }

        if ($ring == 'h') {
            $mps = 4; // Ring of Healing gives 4 mana per second
            $mana = $mana + ($duration * $mps);
        }

        return array('mana' => $mana, 'duration' => $duration);
    }

    static function getManaRegenDuration($mana, $voc, $promo, $potion, $boots, $ring) {
        $scale = bcscale(10);

        $vals = self::getManaRegenVocationValue($voc, $promo, $potion, $boots, $ring);
        $div = bcdiv($vals['duration'], $vals['mana']);

        bcscale(0);
        $dur = bcmul($mana, $div);
        bcscale($scale);
        return $dur;
    }

    static function getManaRegenDurationOnePercent($voc, $from, $promo, $potion, $boots, $ring) {
        $mana = self::getMana($voc, $from, $from + 1);
        $dur = self::getManaRegenDuration($mana, $voc, $promo, $potion, $boots, $ring);

        return gmp_strval(gmp_div_q($dur, 100));
    }

    static function getModifierInfo($modifier) {
        $gp = 0;
        $dur = 0;

        // Soft Boots
        if ($modifier == 'sb') {
            // 10000gp every 4 hours (14400 seconds)
            $gp = 10000; $dur = 14400;
        }

        // Life Ring
        if ($modifier == 'l') {
            // 900gp every 20 minutes (1200 seconds)
            $gp = 900; $dur = 1200;
        }

        // Ring of Healing
        if ($modifier == 'h') {
            // 2000gp every 7.5 minutes (450 seconds)
            $gp = 2000; $dur = 450;
        }

        // Mana Potion
        if ($modifier == 'm') {
            // 50gp every 2 seconds
            $gp = 50; $dur = 2;
        }

        // Strong Mana Potion
        if ($modifier == 's') {
            // 80gp every 2 seconds
            $gp = 80; $dur = 2;
        }

        // Great Mana Potion
        if ($modifier == 'g') {
            // 120gp every 2 seconds
            $gp = 120; $dur = 2;
        }

        $scale = bcscale(10);
        $gps = bcdiv($gp, $dur);
        bcscale($scale);

        return array('gps' => $gps, 'gp' => $gp, 'dur' => $dur);
    }

    static function getModifierCost($dur, $modifier) {
        $info = self::getModifierInfo($modifier);
        $scale = bcscale(0);
        $cost = bcmul($dur, $info['gps']);
        bcscale($scale);
        return $cost;
    }

    static function getModifierCostPerMinute($dur, $cost) {
        $scale = bcscale(10);
        $gps = bcdiv($cost, $dur);
        bcscale(1);
        $cost = bcmul($gps, 60);
        bcscale($scale);
        return $cost;
    }

    static function getTotalModifierCost($mods) {
        $scale = bcscale(0);
        $cost = '0';

        foreach ($mods as $mod) {
            $cost = bcadd($cost, $mod['cost']);
        }

        bcscale($scale);
        return $cost;
    }

    static function getTotalModifierCostPerMinute($dur, $totalcost) {
        $scale = bcscale(10);
        $gps = bcdiv($totalcost, $dur);
        bcscale(1);
        $cost = bcmul($gps, 60);
        bcscale($scale);
        return $cost;
    }

    static function getModifierUsed($dur, $modifier) {
        $info = self::getModifierInfo($modifier);
        $scale = bcscale(2);
        $used = bcdiv($dur, $info['dur']);
        bcscale($scale);
        return $used;
    }

    static function getRuneBackpackAmount($mana, $runemana) {
        $scale = bcscale(2);
        $bps = bcdiv($mana, bcmul($runemana, self::BACKPACK_SIZE));
        bcscale($scale);
        return $bps;
    }

    static function getRuneBackpackProfit($mana, $runemana, $bpsell) {
        $scale = bcscale(10);
        $bps = bcdiv($mana, bcmul($runemana, self::BACKPACK_SIZE));
        $bpsell = $bpsell - (self::COST_BLANK_RUNE * 20) - (self::$COST_BACKPACK);
        bcscale(0);
        $profit = bcmul($bps, $bpsell);
        bcscale($scale);
        return $profit;
    }

    static function numWord($n) {
        $a = split(':', 'a:one:two:three:four:five:six:seven:eight:nine');
        $b = split(':', 'a:ten:eleven:twelve:thir:four:fif:six:seven:eigh:nine');
        $c = split(':', 'a:twen:thir:for:fif:six:seven:eigh:nine');
        $d = split(':', 'a:thousand:m:b:tr:quadr:quint:sext:sept:oct:non:dec:undec:duodec:tredec:quattuordec:quindec:sexdec:septendec:octodec:novemdec:vigint');
        if ((string)$n[0] == '-') { $n = substr($n, 1); $v = 1; }
        $n = preg_replace('/[^\d]/', '', $n);

        if ((int)$n == 0) return 'zero';
        if (strlen($n) > 66) return 'invalid';

        while ($n) {
            $w = sprintf('%03d', strlen($n) > 3 ? substr($n, -3) : $n); $n = strlen($n) > 3 ? substr($n, 0, -3) : '';
            $o =   ($w[0] ? $a[$w[0]] . ' hundred ' . ($w[1] || $w[2] ? 'and ' : ''): '')
                 . ($w[1] ? ($w[1] == 1 ? $b[$w[2]+1] . ($w[2] > 2 ? 'teen ' : ' ') : $c[$w[1]-1] . 'ty') : '')
                 . ($w[2] && $w[1] != 1 ? ($w[1] ? '-' : '') . $a[$w[2]] . ' ': '')
                 . ($i && $w != 0 ? ($d[$i] . ($i > 1 ? 'illion' : '') . (!$l[0] && ($l[1] || $l[2]) ? ', and ' : ', ')) : '')
                 . $o;
            $l = $w;
            $i++;
        }

        if (substr($o, -2) == ', ') $o = substr($o, 0, -2);
        return ($v ? 'negative ' : '') . trim($o);
    }

    static function formatNumber($n, $nospaces = false) {
        $d = 0;
        $r = '';
        $parts = explode('.', $n);
        $n = $parts[0];
        $remainder = @$parts[1];

        for ($c = strlen($n) - 1; $c >= 0; $c--, $d++) {
            $r .= $n{$c};
            if ($d % 3 == 2) { $r .= ' ,'; }
        }

        $r = strrev($r);
        if ($r{0} == ',') $r = substr($r, 1);

        if ($nospaces)
            $r = str_replace(' ', '', $r);

        if ($remainder)
            $r .= '.' . $remainder;

        return $r;
    }
}

Script 2:
PHP:
<?php

// usage: $table = spTibExperience::getExperienceTable(array('Antica', 'Pacera'));
// if any element in $table has less than 300 entries then there was a pretty serious failure (since it automatically retries)

class spTibExperience {
    const PAGES = 11;
    const PERPAGE = 25;
    const MAXTIME = 18000; // keep trying for 5 hours, enough time for maintenance/update/etc. to run, in theory..
    const TIMEOUT = 30; // seconds
    const MAXBACKOFF = 600; // maximum "backoff" in case of failure

    static function getExperienceTable($worlds = array()) {
        $start_t = time();

        $table = array();
        $failcnt = 0;
        $output = array();

        do {
            $failures = array();

            if (!function_exists('curl_multi_init')) {
                error_log('spTibExperience requires the cURL PHP extension');
                return false;
            }

            foreach ($worlds as $world) {
                $mh = curl_multi_init();
                $chs = array();
                if (!isset($output[$world])) $output[$world] = array();

                for ($page = 0; $page <= self::PAGES; $page++) {
                    if (isset($output[$world][$page]))
                        continue;

                    $chs[$page] = curl_init();
                    curl_setopt($chs[$page], CURLOPT_URL, $url = sprintf('http://www.tibia.com/community/?subtopic=highscores&world=%s&list=%s&page=%d', $world, 'experience', $page));
                    curl_setopt($chs[$page], CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($chs[$page], CURLOPT_FRESH_CONNECT, true);
                    curl_setopt($chs[$page], CURLOPT_TIMEOUT, self::TIMEOUT);
                    curl_multi_add_handle($mh, $chs[$page]);

                    if (@$GLOBALS['debug']) { error_log("preparing to fetch $url"); }
                }

                do {
                    $mrc = curl_multi_exec($mh, $active);
                } while ($active);

                for ($page = 0; $page <= self::PAGES; $page++) {
                    if (isset($output[$world][$page]))
                        continue;

                    $out = curl_multi_getcontent($chs[$page]);

                    curl_close($chs[$page]);

                    $failure = false;

                    if (preg_match_all('#<TD WIDTH=10%>(.*?)</TD>.*?subtopic=characters&name=.*?">(.*?)</A></TD><TD WIDTH=15%>(.*?)</TD><TD WIDTH=20%>(.*?)</TD></TR>#s', $out, $m)) {
                        if (count($m[2]) != self::PERPAGE) {
                            if (@$GLOBALS['debug']) { error_log("on $world page $page, found " . count($m[2]) . ", not " . self::PERPAGE); }
                            $failure = true;
                        }
/*
                        else if (rand(1, 2) == 1) {
                            if (@$GLOBALS['debug']) { error_log("failing because i can"); }
                            $failure = true;
                        }
*/
                        else {
                            foreach ($m[2] as $k => $name) {
                                $rank = $m[1][$k];
                                $level = $m[3][$k];
                                $xp = $m[4][$k];

                                if (!isset($table[$world])) $table[$world] = array();
                                $table[$world][$rank] = array('name' => $name, 'level' => $level, 'xp' => $xp);
                            }

                            $output[$world][$page] = true;
                        }
                    }
                    else {
                        $failure = true;
                    }

                    if ($failure) {
                        $now_t = time();

                        if (@$GLOBALS['debug']) { error_log("failure for $world page $page"); }

                        if ($now_t - $start_t >= self::MAXTIME)
                            $output[$world][$page] = true;
                    }
                }

                curl_multi_close($mh);

                if (count($output[$world]) <= self::PAGES)
                    $failures[$world] = true;
                else {
                    ksort($output[$world]);
                    unset($failures[$world]);
                }
            }

            if (count($failures)) {
                $failcnt++;

                $backoff = min(self::MAXBACKOFF, pow(2, $failcnt));

                // don't want pow(2, ...) to get too big!
                if (pow(2, $failcnt) > self::MAXBACKOFF)
                    $failcnt--;

                if (@$GLOBALS['debug']) { error_log("backing off for $backoff seconds. will keep trying for " . (self::MAXTIME - ($now_t - $start_t)) . " seconds"); }
                sleep($backoff);
            }
            else {
                foreach ($table as $world => $ranks)
                    ksort($table[$world]);

                ksort($table);
                break;
            }
        } while (1);

        return $table;
    }
}

?>

Script 3:
PHP:
<?php

class spTibCharacter {
    const ATTEMPTS = 5;
    const TIMEOUT = 30; // seconds

    static function getCharacter($names) {
        $table = array();

        do {
            if (!function_exists('curl_multi_init')) {
                error_log('spTibCharacter requires the cURL PHP extension');
                return false;
            }

            $mh = curl_multi_init();
            $chs = array();

            foreach ($names as $name) {
                $chs[$name] = curl_init();
                curl_setopt($chs[$name], CURLOPT_URL, $url = sprintf('http://www.tibia.com/community/?subtopic=characters&name=%s', urlencode($name)));
                curl_setopt($chs[$name], CURLOPT_RETURNTRANSFER, true);
                curl_setopt($chs[$name], CURLOPT_FRESH_CONNECT, true);
                curl_setopt($chs[$name], CURLOPT_TIMEOUT, self::TIMEOUT);
                curl_multi_add_handle($mh, $chs[$name]);

                if (@$GLOBALS['debug']) { error_log("preparing to fetch $url"); }
            }

            do {
                $mrc = curl_multi_exec($mh, $active);
            } while ($active);

            foreach ($names as $name) {
                $out = curl_multi_getcontent($chs[$name]);

                curl_close($chs[$name]);

                $failure = false;

                if (preg_match('@<TR><TD BGCOLOR="#505050" CLASS=white><B>Could not find character</B></TD></TR>@s', $out)) {
                    $table[$name] = array('error' => 'Could not find character');
                }
                else if (preg_match('@<TD WIDTH=20%>Name:</TD><TD>(.+?)</TD></TR>@s', $out, $m)) {
                    $table[$name] = array('name' => $m[1], 'raw' => $out, 'error' => null);

                    if (preg_match('@<TD.*?CLASS=red>Banished:</TD><TD CLASS=red>until .*? because of using unofficial software to play</TD>@s', $out)) {
                        $table[$name]['banished'] = 'unofficial_software';
                    }

                    $table[$name]['origname'] = $name;
                }
                else {
                    $table[$name] = array('error' => 'Unknown error');
                }

            }

            curl_multi_close($mh);
        } while (0);

        return $table;
    }
}

?>

Script 4:
PHP:
<?php

class spUtil {
    static function duration($t) {
        $s = $t % 60;
        $m = ($t / 60) % 60;
        $h = ($t / 60 / 60) % 24;
        $d = ($t / 60 / 60 / 24) % 365;
        $y = (int)($t / 60 / 60 / 24 / 365);

        $r = ($y?"{$y}y ":'') . ($d?"{$d}d ":'') . ($h?"{$h}h ":'') . ($m?"{$m}m ":'') . ($s?"{$s}s ":'');

        if ($r == '')
            return '0s';
        else
           return substr($r, 0, -1);
    }

    static function durationBC($t) {
        $neg = $t < 0;
        if ($neg)
            $t = substr($t, 1);

        $scale = bcscale(10);
        $s = bcmod($t,                60);
        $m = bcmod(bcdiv($t, 60),     60);
        $h = bcmod(bcdiv($t, 3600),   24);
        $d = bcmod(bcdiv($t, 86400), 365);

        bcscale(0);
        $y = bcdiv($t, 31536000);
        bcscale($scale);

        $r = ($y?"{$y}y ":'') . ($d?"{$d}d ":'') . ($h?"{$h}h ":'') . ($m?"{$m}m ":'') . ($s?"{$s}s ":'');

        if ($r == '')
            return '0s';
        else if (!$neg)
           return substr($r, 0, -1);
        else
           return '-' . substr($r, 0, -1);
    }
}

?>
 

Victor

New Member
Joined
Feb 1, 2008
Messages
222
Reaction score
1
http://erig.net/code/spCalc.php

This class is some part of calculator, in example:
PHP:
// mana of druid from level 20 to level 21
$mana = spCalc::getMana('d', 20, 21);

http://erig.net/code/spTibCharacter.php

This class is getting info like name, banished, in example:
PHP:
$results = spTibCharacter::getCharacter(array('Mateusz Dragon Wielki', 'Tomurka'));

foreach ($results as $result) {
     var_dump $result.'<br />';
}

http://erig.net/code/spTibExperience.php

This class is getting level, exp and name of players, who are on TOP 11 page (defined in consts), in example:
PHP:
$results = spTibExperience::getExperienceTable(('pandoria'));

foreach ($results as $result) {
     var_dump($result);
}

http://erig.net/code/spUtil.php

I don't know what it do, maybe some converting time to seconds, months, days, minutes and hours or something like this.

For newbie: It doesn't all classes.
 
Last edited by a moderator:

Minimii

New Member
Joined
Dec 3, 2008
Messages
749
Reaction score
3
Location
Sweden, Piteå
How can I put those scripts on my homepage to work? I just get a blank page with the text on when I input the script in a html file.
 
OP
OP
Mummrik

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
How can I put those scripts on my homepage to work? I just get a blank page with the text on when I input the script in a html file.

i dont have any ide this the script erig is releasing and im not that good at homepages
 
Top