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

AAC Player Mount List for myacc

Joined
Aug 15, 2014
Messages
143
Reaction score
24
This code for gesior dont work in myacc

Lua:
$mounts = $mounts->getAllMountsByPlayerId($player_id);
            if ($mounts != false) {
                foreach ($mounts as $value) {
                    $main_content .= "<img src='AnimatedOutfits/animoutfit.php?id={$value['clientid']}'>";
                }
            }


Can anyone help me make it show the mounts that the player has?mount.png

Storage is accumulation and is very confusing to detect...
2.png

how to make this madness detectable? I'm 1 week and I can't create the code...
 
Solution
OK, so I have it working.

Result:
1691260381921.png

1) system/pages/characters.php

Before:
PHP:
$twig->display('characters.html.twig', array(

Add:
PHP:
    require LIBS . 'Mounts.php';
    $mounts = new Mounts();
    $mounts = $mounts->getAllMountsByPlayerId($player->getId());
    $mountsStr = '';
    if ($mounts) {
        foreach ($mounts as $value) {
            $mountsStr .= "<img src='{$config['outfit_images_url']}?id={$value['clientid']}'>";
        }
    }

After:
PHP:
'outfit' => isset($outfit) ? $outfit : null,

Add:
PHP:
'mounts' => $mountsStr,

2) system/templates/characters.html.twig

Before:
Code:
{% if deaths|length > 0 %}

Add:
Code:
        <br/>
        <table border="0" cellspacing="1" cellpadding="4"...
Can you post the function: getAllMountsByPlayerId? It doesn't exist in myaac and in gesior too, so I don't know what it does.
 
PHP:
<?php

/**
 * Created by PhpStorm.
 * User: Ricardo
 * Date: 18/03/2018
 * Time: 02:11
 */

class Mounts
{
    private $mountsbyid;
    private $mountsbycliid;
    private $key;

    /**
     * Mounts constructor.
     */
    public function __construct()
    {
        $this->loadFromFile(Website::getWebsiteConfig()->getValue('Mounts_path'));
    }

    private function loadFromFile($file)
    {

        if (Website::fileExists($file)) {
            $xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA);
            $json = json_encode($xml);
            $mounts = json_decode($json, true)['mount'];
            $news = [];
            $cliid = [];
            $i = 0;
            foreach ($mounts as $mount) {
                $mount = $mount['@attributes'];
                $news[$mount['id']] = $mount;
                $news[$mount['id']]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $news[$mount['id']]['storage'] = (1 << ($mount['id'] - 1) % 31);
                $cliid[$mount['clientid']] = $mount;
                $cliid[$mount['clientid']]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $cliid[$mount['clientid']]['storage'] = (1 << ($mount['id'] - 1) % 31);
                $keys[$news[$mount['id']]['key']][$i] = $mount;
                $keys[$news[$mount['id']]['key']][$i]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $keys[$news[$mount['id']]['key']][$i]['value'] = (1 << ($mount['id'] - 1) % 31);
                $i++;
            }
            $this->key = $keys;
            $this->setMountsById($news);
            $this->setMountsbycliid($cliid);
        } else {
            throw new InvalidArgumentException("#M-1 <b>ERROR: #M-1:</b> Class::Mounts - Mount File not exists in {$file}.");
        }
    }

    /**
     * @param mixed $mounts
     */
    private function setMountsById($mounts)
    {
        $this->mountsbyid = $mounts;
    }

    /**
     * @param mixed $mountsbycliid
     */
    private function setMountsbycliid($mountsbycliid)
    {
        $this->mountsbycliid = $mountsbycliid;
    }

    public function getMountsByClientId($client_id)
    {
        $id = (int) $client_id;
        $mounts = $this->getMountsbycliid();
        return $mounts[$id];
    }

    /**
     * @return mixed
     */
    private function getMountsbycliid()
    {
        return $this->mountsbycliid;
    }

    /**
     * @param $player_id
     * @return array|bool
     */
    public function getAllMountsByPlayerId($player_id)
    {
        $player = new Player();
        $player->loadById($player_id);

        $p = [];
        for ($i = 0; $i < 10; $i++) {
            $var = (10000000 + 2001);
            $var = $var + $i;
            if ($player->getStorage($var) != NULL) {
                $p[$i]['key'] = $var;
                $p[$i]['storage'] = $player->getStorage($var);
            }
        }
        if ($p != NULL) {
            foreach ($p as $storages) {
                $teste = $this->getMountsByKey($storages['key']);
                foreach ($teste as $mount) {
                    if (((1 << (($mount['id'] - 1) % 31)) & $storages['storage'])) {
                        $top = $this->getMountsById($mount['id']);
                        $kappa[] = $top;
                    }
                }
            }
            return $kappa;
        } else {
            return false;
        }
    }

    /**
     * @return mixed
     */
    public function getMountsByKey($key)
    {
        $key = (int) $key;
        $mounts = $this->key;
        return $mounts[$key];
    }

    /**
     * @param $id
     * @return mixed
     */
    public function getMountsById($id)
    {
        $id = (int) $id;
        $mounts = $this->getMounts();
        return $mounts[$id];
    }

    /**
     * @return mixed
     */
    private function getMounts()
    {
        return $this->mountsbyid;
    }
}

This is the mecanism that all otservers use to catch all players mounts.

It uses practically the same storage to store several values progressively.
This function is hard to understand. 4 days to reproduce and nothing..
 
OK, so I have it working.

Result:
1691260381921.png

1) system/pages/characters.php

Before:
PHP:
$twig->display('characters.html.twig', array(

Add:
PHP:
    require LIBS . 'Mounts.php';
    $mounts = new Mounts();
    $mounts = $mounts->getAllMountsByPlayerId($player->getId());
    $mountsStr = '';
    if ($mounts) {
        foreach ($mounts as $value) {
            $mountsStr .= "<img src='{$config['outfit_images_url']}?id={$value['clientid']}'>";
        }
    }

After:
PHP:
'outfit' => isset($outfit) ? $outfit : null,

Add:
PHP:
'mounts' => $mountsStr,

2) system/templates/characters.html.twig

Before:
Code:
{% if deaths|length > 0 %}

Add:
Code:
        <br/>
        <table border="0" cellspacing="1" cellpadding="4" width="100%">
            <tr bgcolor="{{ config.vdarkborder }}">
                <td colspan="2" class="white"><b>Mounts</b></td>
            </tr>
            <tr>
                <td colspan="2">
                    {{ mounts|raw }}
                </td>
            </tr>
        </table>

3) create new file:
system/libs/Mounts.php
PHP:
<?php

/**
 * Created by PhpStorm.
 * User: Ricardo
 * Date: 18/03/2018
 * Time: 02:11
 */

class Mounts
{
    private $mountsbyid;
    private $mountsbycliid;
    private $key;

    /**
     * Mounts constructor.
     */
    public function __construct()
    {
        $this->loadFromFile(config('data_path') . 'XML/mounts.xml');
    }

    private function loadFromFile($file)
    {
        if (file_exists($file)) {
            $xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA);
            $json = json_encode($xml);
            $mounts = json_decode($json, true)['mount'];
            $news = [];
            $cliid = [];
            $i = 0;
            foreach ($mounts as $mount) {
                $mount = $mount['@attributes'];
                $news[$mount['id']] = $mount;
                $news[$mount['id']]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $news[$mount['id']]['storage'] = (1 << ($mount['id'] - 1) % 31);
                $cliid[$mount['clientid']] = $mount;
                $cliid[$mount['clientid']]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $cliid[$mount['clientid']]['storage'] = (1 << ($mount['id'] - 1) % 31);
                $keys[$news[$mount['id']]['key']][$i] = $mount;
                $keys[$news[$mount['id']]['key']][$i]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $keys[$news[$mount['id']]['key']][$i]['value'] = (1 << ($mount['id'] - 1) % 31);
                $i++;
            }
            $this->key = $keys;
            $this->setMountsById($news);
            $this->setMountsbycliid($cliid);
        } else {
            throw new InvalidArgumentException("#M-1 <b>ERROR: #M-1:</b> Class::Mounts - Mount File not exists in {$file}.");
        }
    }

    /**
     * @param mixed $mounts
     */
    private function setMountsById($mounts)
    {
        $this->mountsbyid = $mounts;
    }

    /**
     * @param mixed $mountsbycliid
     */
    private function setMountsbycliid($mountsbycliid)
    {
        $this->mountsbycliid = $mountsbycliid;
    }

    public function getMountsByClientId($client_id)
    {
        $id = (int) $client_id;
        $mounts = $this->getMountsbycliid();
        return $mounts[$id];
    }

    /**
     * @return mixed
     */
    private function getMountsbycliid()
    {
        return $this->mountsbycliid;
    }

    /**
     * @param $player_id
     * @return array|bool
     */
    public function getAllMountsByPlayerId($player_id)
    {
        $player = new OTS_Player();
        $player->load($player_id);

        $p = [];
        for ($i = 0; $i < 10; $i++) {
            $var = (10000000 + 2001);
            $var = $var + $i;
            if ($player->getStorage($var) != NULL) {
                $p[$i]['key'] = $var;
                $p[$i]['storage'] = $player->getStorage($var);
            }
        }
        if ($p != NULL) {
            foreach ($p as $storages) {
                $teste = $this->getMountsByKey($storages['key']);
                foreach ($teste as $mount) {
                    if (((1 << (($mount['id'] - 1) % 31)) & $storages['storage'])) {
                        $top = $this->getMountsById($mount['id']);
                        $kappa[] = $top;
                    }
                }
            }
            return $kappa;
        } else {
            return false;
        }
    }

    /**
     * @return mixed
     */
    public function getMountsByKey($key)
    {
        $key = (int) $key;
        $mounts = $this->key;
        return $mounts[$key];
    }

    /**
     * @param $id
     * @return mixed
     */
    public function getMountsById($id)
    {
        $id = (int) $id;
        $mounts = $this->getMounts();
        return $mounts[$id];
    }

    /**
     * @return mixed
     */
    private function getMounts()
    {
        return $this->mountsbyid;
    }
}
 
Solution
Thanks
You do the things seems so easy bro.
Post automatically merged:

5 days in this and you did in 2 minutes, little diference kkk
 
Last edited:
OK, so I have it working.

Result:
View attachment 77292

1) system/pages/characters.php

Before:
PHP:
$twig->display('characters.html.twig', array(

Add:
PHP:
    require LIBS . 'Mounts.php';
    $mounts = new Mounts();
    $mounts = $mounts->getAllMountsByPlayerId($player->getId());
    $mountsStr = '';
    if ($mounts) {
        foreach ($mounts as $value) {
            $mountsStr .= "<img src='{$config['outfit_images_url']}?id={$value['clientid']}'>";
        }
    }

After:
PHP:
'outfit' => isset($outfit) ? $outfit : null,

Add:
PHP:
'mounts' => $mountsStr,

2) system/templates/characters.html.twig

Before:
Code:
{% if deaths|length > 0 %}

Add:
Code:
        <br/>
        <table border="0" cellspacing="1" cellpadding="4" width="100%">
            <tr bgcolor="{{ config.vdarkborder }}">
                <td colspan="2" class="white"><b>Mounts</b></td>
            </tr>
            <tr>
                <td colspan="2">
                    {{ mounts|raw }}
                </td>
            </tr>
        </table>

3) create new file:
system/libs/Mounts.php
PHP:
<?php

/**
 * Created by PhpStorm.
 * User: Ricardo
 * Date: 18/03/2018
 * Time: 02:11
 */

class Mounts
{
    private $mountsbyid;
    private $mountsbycliid;
    private $key;

    /**
     * Mounts constructor.
     */
    public function __construct()
    {
        $this->loadFromFile(config('data_path') . 'XML/mounts.xml');
    }

    private function loadFromFile($file)
    {
        if (file_exists($file)) {
            $xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA);
            $json = json_encode($xml);
            $mounts = json_decode($json, true)['mount'];
            $news = [];
            $cliid = [];
            $i = 0;
            foreach ($mounts as $mount) {
                $mount = $mount['@attributes'];
                $news[$mount['id']] = $mount;
                $news[$mount['id']]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $news[$mount['id']]['storage'] = (1 << ($mount['id'] - 1) % 31);
                $cliid[$mount['clientid']] = $mount;
                $cliid[$mount['clientid']]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $cliid[$mount['clientid']]['storage'] = (1 << ($mount['id'] - 1) % 31);
                $keys[$news[$mount['id']]['key']][$i] = $mount;
                $keys[$news[$mount['id']]['key']][$i]['key'] = (int) abs(10002001 + ($mount['id'] / 31));
                $keys[$news[$mount['id']]['key']][$i]['value'] = (1 << ($mount['id'] - 1) % 31);
                $i++;
            }
            $this->key = $keys;
            $this->setMountsById($news);
            $this->setMountsbycliid($cliid);
        } else {
            throw new InvalidArgumentException("#M-1 <b>ERROR: #M-1:</b> Class::Mounts - Mount File not exists in {$file}.");
        }
    }

    /**
     * @param mixed $mounts
     */
    private function setMountsById($mounts)
    {
        $this->mountsbyid = $mounts;
    }

    /**
     * @param mixed $mountsbycliid
     */
    private function setMountsbycliid($mountsbycliid)
    {
        $this->mountsbycliid = $mountsbycliid;
    }

    public function getMountsByClientId($client_id)
    {
        $id = (int) $client_id;
        $mounts = $this->getMountsbycliid();
        return $mounts[$id];
    }

    /**
     * @return mixed
     */
    private function getMountsbycliid()
    {
        return $this->mountsbycliid;
    }

    /**
     * @param $player_id
     * @return array|bool
     */
    public function getAllMountsByPlayerId($player_id)
    {
        $player = new OTS_Player();
        $player->load($player_id);

        $p = [];
        for ($i = 0; $i < 10; $i++) {
            $var = (10000000 + 2001);
            $var = $var + $i;
            if ($player->getStorage($var) != NULL) {
                $p[$i]['key'] = $var;
                $p[$i]['storage'] = $player->getStorage($var);
            }
        }
        if ($p != NULL) {
            foreach ($p as $storages) {
                $teste = $this->getMountsByKey($storages['key']);
                foreach ($teste as $mount) {
                    if (((1 << (($mount['id'] - 1) % 31)) & $storages['storage'])) {
                        $top = $this->getMountsById($mount['id']);
                        $kappa[] = $top;
                    }
                }
            }
            return $kappa;
        } else {
            return false;
        }
    }

    /**
     * @return mixed
     */
    public function getMountsByKey($key)
    {
        $key = (int) $key;
        $mounts = $this->key;
        return $mounts[$key];
    }

    /**
     * @param $id
     * @return mixed
     */
    public function getMountsById($id)
    {
        $id = (int) $id;
        $mounts = $this->getMounts();
        return $mounts[$id];
    }

    /**
     * @return mixed
     */
    private function getMounts()
    {
        return $this->mountsbyid;
    }
}
not work for me, im using myaac 0.8.13 with template tibiana.
 
Back
Top