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

Znote AAC - Patch for listing vocations

Breed

Intermediate OT User
Joined
Jan 7, 2015
Messages
517
Reaction score
122
This will allow you to automatically get all the vocations for your server and exclude any you don't want to list

In the config.php file starting on line 257
You will find this code below
PHP:
// Vocation ids and names.
    $config['vocations'] = array(
        0 => 'No vocation',
        1 => 'Sorcerer',
        2 => 'Druid',
        3 => 'Paladin',
        4 => 'Knight',
        5 => 'Master Sorcerer',
        6 => 'Elder Druid',
        7 => 'Royal Paladin',
        8 => 'Elite Knight',
    );

You are going to replace all of that with this code
PHP:
// change this to your vocations.xml path
$vpath = 'C:\docs\1041 server\data\XML\vocations.xml';
$voc = array();
$doNotListTheseVocations = array(0,5,6,7,8);

if(file_exists($vpath) && $xml = simplexml_load_file($vpath)){
    foreach($xml as $xmlx){
        if(!in_array(intval($xmlx['id']), $doNotListTheseVocations, true)){
            if(isset($xmlx['id']) && isset($xmlx['name']) ){
                $voc[intval($xmlx['id'])] = (string)$xmlx['name'];
            }
        }
    }
}$config['vocations'] = $voc;

What does this do?
It parses the vocations.xml file on your server and gets both name & id for each vocation and stores it in an array so that the AAC can use it when you go to create a new character.

If you make a change in your vocations.xml file it will reflect here, so if you rename your vocations you don't need to touch this ever again it will automatically update.

You can also exclude any vocation
PHP:
$doNotListTheseVocations = array(0,5,6,7,8);

If you were to use print_r on $config['vocations'] you would see this output
PHP:
Array
(
    [1] => Sorcerer
    [2] => Druid
    [3] => Paladin
    [4] => Knight
)
 
Last edited:
You should cache the results to avoid reloading and parsing vocations.xml every time a visitor loads the page.
https://github.com/Znote/ZnoteAAC/blob/master/index.php#L39-46

Load:
PHP:
$cache = new Cache('engine/cache/news');
$news = $cache->load();

Save:
PHP:
$cache = new Cache('engine/cache/news');
$news = array("your vocations array?");
$cache->setContent($news);
$cache->save();

And I would generate the vocations from a dedicated file in the special folder.

You only need to run this code when you have edited vocations.xml (which probably is not very frequent).
The web server only need access to the OT directory when generating the file, always having access to OT directory can be a security issue.
config.php will be a more clean config file. (Although I cringe a bit every time I see my own shitty timezone/time function, don't follow my mistake). :( :p
 
Back
Top