[TFS 1.2+] Give item on level advance

Someone asked me on Discord about script that gives configurable rewards on level advance.
It’s onAdvance event. Rewards are easy configurable and can be limited by vocations and level.

local rookVocations = { 0 }
local sorcererVocations = { 1, 5 }
local druidVocations = { 2, 6 }
local paladinVocations = { 3, 7 }
local knightVocations = { 4, 8 }
local mainVocations = { 1, 2, 3, 4, 5, 6, 7, 8 }
local allVocations = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }

local rewardsConfig = {
    -- 2cc and Magic Sword for every 20 level on main
    {
        level = 20,
        vocations = mainVocations,
        storage = 25100,
        items = {
            { 2160, 2 },
            { 2400, 1 },
        }
    },
    -- wand of inferno for 33 sorc
    {
        level = 33,
        vocations = sorcererVocations,
        storage = 25101,
        items = {
            { 2187, 1 },
        }
    }
}

function onAdvance(player, skill, oldLevel, newLevel)
    if skill ~= SKILL_LEVEL then
        return true
    end

    for i1, rewardConfig in pairs(rewardsConfig) do
        if newLevel == rewardConfig.level then
            if table.contains(rewardConfig.vocations, player:getVocation():getId()) then
                if player:getStorageValue(rewardConfig.storage) < 1 then
                    player:setStorageValue(rewardConfig.storage, os.time())
                    for i2, item in pairs(rewardConfig.items) do
                        player:addItem(item[1], item[2])
                    end
                    player:getPosition():sendMagicEffect(CONST_ME_CRAPS)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You received reward for getting " .. rewardConfig.level .. " level.")
                end
            end
        end
    end

    return true
end

Gesior2012 – block using monster names as new player name

In acc. maker in file system/load.compat.php find function check_name_new_char and above return true add:

    if (stripos(",The Queen of Banshee,Rook,Orc,",
            ',' . $name . ',') !== false) {
        return false;
    }

Line where you need to paste it: https://github.com/gesior/Gesior2012/blob/268f477369c5c4a8ba88084224142941cba15654/system/load.compat.php#L142

List of monsters of your OTS you can generate using http://halp.skalski.pro/2020/05/21/ots-generating-list-of-monster-names/

OTS – generating list of monster names

In OTS folder data/monsters create new file list.php

<?php
$monsters = simplexml_load_file('monsters.xml');

$list = [];
foreach($monsters->monster as $monsterData) {
    $monster = simplexml_load_file((string) $monsterData['file']);
    $list[] = (string) $monster['name'];
}

echo ',' . implode(',', $list) . ',' . PHP_EOL;

Now run that code in console. On machines with PHP installed just type:

php list.php

and it will generate list like:

,Sinister Bunny,Kindra,Necron,Terros,Christmass Destroyer,Christmass Destroyer,C hristmass Destroyer,Christmass Destroyer,Christmass Destroyer,Christmass Destroy er,Christmass Destroyer,Christmass Destroyer,Christmass Destroyer,Christmass Des troyer,Christmass Destroyer,Christmass Destroyer,Corrupted Santa,Tasselis,Laevis ,Dianthis,Saul,Hunlath,Khor,Apocalypse,Pumin,Tafariel,Ashfalor,Infernatil,Vermin or,Bazir,Bazir,Apocalypse Envoy,Training Dummy,Midnight Asura,Dawnfire Asura,Mus hroom Sniffer,Angry Destroyer,Fu…