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

TFS 1.X Bounty Hunter System

ZISr5Nk.png

Code:
<talkaction words="!hunted" separator=" " script="test/bounthunter_check.lua" />

Code:
local config = {
    dialogBoxImageId = 24560, -- change this ID to the image you want to see on the Dialog Box
    delay = true, -- Would you like to add a delay on this talkaction?
    delayTime = 30, -- time in seconds you would like to add a delay on the talkaction
    delayStorage = 60799 -- empty storage value
}


function onSay(cid, words, param)
    local player = Player(cid)
    if config.delay and player:getStorageValue(config.delayStorage) > os.time() then
        player:sendCancelMessage('Please wait another ' .. (player:getStorageValue(config.delayStorage) - os.time()) .. ' seconds before you try the command again.')
        return false
    end
 
    local huntedPlayers = db.storeQuery("SELECT `sp_id`, `prize` FROM `bounty_hunters` WHERE `killed` = '0' ORDER BY `prize` DESC;")
    local output = "MOST WANTED:\n"
    if(huntedPlayers ~= false) then
        local number = 1
                while (true) do
                    local id = result.getDataInt(huntedPlayers, "sp_id")
                    local prize = result.getDataInt(huntedPlayers, "prize")
                    local playerName = db.storeQuery("SELECT `name`,`level` FROM `players` WHERE `id` = "..id..";")
                    if playerName then
                        local playerName1 = result.getDataString(playerName, "name")
                        local level = result.getDataInt(playerName, "level")
                        output = output .. "\n" .. number .. ". " .. playerName1 .. " [" .. level .. "] --- " .. prize .. "gps"
                        number = number + 1
                    end
                    if not(result.next(huntedPlayers)) then
                        break
                    end
                end
                result.free(huntedPlayers)
    end
 
    player:showTextDialog(config.dialogBoxImageId, output)
    if config.delay then
        player:setStorageValue(config.delayStorage, os.time() + config.delayTime)
    end     
    return false
end

The window that shows the people who are being hunt shows up but is empty, no errors are shown in the console.
any idea's?
 
The window that shows the people who are being hunt shows up but is empty, no errors are shown in the console.
any idea's?

Code:
local config = {
    dialogBoxImageId = 24560, -- change this ID to the image you want to see on the Dialog Box
    delay = true, -- Would you like to add a delay on this talkaction?
    delayTime = 30, -- time in seconds you would like to add a delay on the talkaction
    delayStorage = 60799 -- empty storage value
}

function onSay(cid, words, param)
    local player = Player(cid)
    if config.delay and player:getStorageValue(config.delayStorage) > os.time() then
        player:sendCancelMessage('Please wait another ' .. (player:getStorageValue(config.delayStorage) - os.time()) .. ' seconds before you try the command again.')
        return false
    end
    local huntedPlayers = db.storeQuery("SELECT `target_id`, `prize`, `currencyType` FROM `bounty_hunter_system` WHERE `killed` = '0' ORDER BY `id` DESC;")
    local output = "MOST WANTED:\n"
    if(huntedPlayers ~= false) then
        local number = 1
                while (true) do
                    local id = result.getDataInt(huntedPlayers, "target_id")
                    local prize = result.getDataInt(huntedPlayers, "prize")
                    local currencyType = result.getDataString(huntedPlayers, "currencyType")
                    local playerName = db.storeQuery("SELECT `name`,`level` FROM `players` WHERE `id` = "..id..";")
                    if playerName then
                        local playerName1 = result.getDataString(playerName, "name")
                        local level = result.getDataInt(playerName, "level")
                        output = output .. "\n" .. number .. ". " .. playerName1 .. " [" .. level .. "] --- " .. prize .. " " .. currencyType
                        number = number + 1
                    end
                    if not(result.next(huntedPlayers)) then
                        break
                    end
                end
                result.free(huntedPlayers)
    end
    player:showTextDialog(config.dialogBoxImageId, output)
    if config.delay then
        player:setStorageValue(config.delayStorage, os.time() + config.delayTime)
    end   
    return false
end
 
@imkingran how i put first code man ???


Code:
--[[ db table
    CREATE TABLE IF NOT EXISTS `bounty_hunter_system` (
     `id` int(11) NOT NULL auto_increment,
     `hunter_id` int(11) NOT NULL,
     `target_id` int(11) NOT NULL,
     `killer_id` int(11) NOT NULL,
     `prize` bigint(20) NOT NULL,
     `currencyType` varchar(32) NOT NULL,
     `dateAdded` int(15) NOT NULL,
     `killed` int(11) NOT NULL,
     `dateKilled` int(15) NOT NULL,
     PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
]]
--------------------------------------
---------- START OF CONFIG -----------
--------------------------------------
local customCurrency = '' -- by default bank balance and premium points are included but you can add other stackable currencies like gold nuggets etc here eg, 'gold nugget' or you can use the itemID or the item name
local config = {
    ipCheck = true, -- players from same IP can not place bounty on each other
    minLevelToAddBounty = 20, -- min lvl req to place a bounty
    minLevelToBeTargeted = 20, -- min lvl req to be targeted by a bounty
    broadcastKills = true, -- Should it broadcast a message to the whole game-world when someone was killed?
    broadcastHunt = false, -- Should it broadcast a message to the whole game-world when someone is added to the bounty list?
    mailbox_position = Position(32351,32223,6), -- If you are using a custom currency then we will send it to the players Mailbox, in order to do it you just need to put the location of one mailbox from your map here, doesn't matter which
    currencies = {
        ['gold'] = {       
            minAmount = 1000000, -- Min amount of Gold allowed
            maxAmount = 1000000000, -- Max amount of gold allowed
            func =
                function(player, prize, currency)
                    return player:setBankBalance(player:getBankBalance() + prize)
                end,
            check =
                function(player, amount, currency)
                    if player:getBankBalance() >= amount then
                        return player:setBankBalance(player:getBankBalance() - amount)
                    end
                    return false
                end,
        },
        ['points'] = {
            minAmount = 10, -- Min amount of premium points allowed
            maxAmount = 500, -- Max amount of premium points allowed
            func =
                function(player, prize, currency)
                    return player:addPremiumPoints(prize)
                end,
            check =
                function(player, prize, currency)
                    if player:getPremiumPoints() > prize then
                        return player:removePremiumPoints(prize)
                    end
                    return false
                end
        },
        [customCurrency] = {
            minAmount = 10, -- Min amount of custom item allowed
            maxAmount = 3000, -- Max amount of custom item allowed
            func =
                function(player, prize, currency)
                    return player:sendParcel(prize)
                end,
            check =
                function(player, amount, currency)
                    local itemID = ItemType(customCurrency):getId()
                    if itemID > 0 and player:getItemCount(itemID) >= amount then
                        player:removeItem(itemID, amount)
                        return true
                    end
                    return false
                end,
        }
    }
}
--------------------------------------
----------- END OF CONFIG ------------
--------------------------------------
-- Only edit below if you know what you are doing --
local function trimString(str)
  return (str:gsub("^%s*(.-)%s*$", "%1"))
end
local function addItemsToBag(bpID, itemID, count)
    local masterBag = Game.createItem(bpID,1)
    local stackable = ItemType(itemID):isStackable()
    if stackable then
        if count > 2000 then
            local bp = Game.createItem(bpID,1)
            masterBag:addItemEx(bp)
            for i = 1, count do
                if bp:getEmptySlots() < 1 then
                    bp = Game.createItem(bpID,1)
                    masterBag:addItemEx(bp)
                end
                bp:addItem(itemID)
            end
        end
        return masterBag
    end
    if count > 20 then
        local bp = Game.createItem(bpID,1)
        masterBag:addItemEx(bp)
        for i = 1, count do
            if bp:getEmptySlots() < 1 then
                bp = Game.createItem(bpID,1)
                masterBag:addItemEx(bp)
            end
            bp:addItem(itemID)
        end
    return masterBag
    end
    for i = 1, count do   
        masterBag:addItem(itemID)
    end
    return masterBag
end
function Player:sendParcel(amount)
    local itemID = ItemType(customCurrency):getId()
    if itemID == 0 then
        print('Error in sending parcel. Custom currency was not set properly double check the spelling.')
        return
    end
    local container = Game.createItem(2595, 1)
    container:setAttribute(ITEM_ATTRIBUTE_NAME, 'Bounty Hunters Mail')
    local label = container:addItem(2599, 1)
    label:setAttribute(ITEM_ATTRIBUTE_TEXT, self:getName())
    label:setAttribute(ITEM_ATTRIBUTE_WRITER, "Bounty Hunters Mail")
    local parcel = addItemsToBag(1988, itemID, amount)
    container:addItemEx(parcel)
    container:moveTo(config.mailbox_position)
end
function Player:getPremiumPoints(points)
    local points = db.storeQuery("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. self:getAccountId() .. ";")
    if points then
        local pointTotal = result.getDataInt(points, "premium_points")
        result.free(points)
    return pointTotal
    end
    return 0
end
function Player:addPremiumPoints(points)
    return db.query("UPDATE accounts SET premium_points = premium_points + "..points.." where id = "..self:getAccountId()..";")
end
function Player:removePremiumPoints(points)
    return db.query("UPDATE accounts SET premium_points = premium_points - "..points.." where id = "..self:getAccountId()..";")
end
function Player:getBountyInfo()
    local result_plr = db.storeQuery("SELECT prize, id, currencyType FROM `bounty_hunter_system` WHERE `target_id` = "..self:getGuid().." AND `killed` = 0;")
    if (result_plr == false) then
        return {false, 0, 0, 0, 0}
    end
    local prize = tonumber(result.getDataInt(result_plr, "prize"))
    local id = tonumber(result.getDataInt(result_plr, "id"))
    local bounty_type = tostring(result.getDataString(result_plr, "currencyType"))
    result.free(result_plr)
    return {true, prize, id, bounty_type, currency}
end
local function addBountyKill(killer, target, prize, id, bounty_type, currency)
    if not config.currencies[bounty_type] then
        print('error in adding bounty prize')
        return true
    end
    config.currencies[bounty_type].func(killer, prize, currency)
    db.query("UPDATE `bounty_hunter_system` SET `killed` = 1, `killer_id`="..killer:getGuid()..", `dateKilled` = " .. os.time() .. " WHERE `id`  = "..id..";")
    killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTER SYSTEM] You killed ' .. target:getName() .. ' and earned a reward of ' .. prize .. ' ' .. bounty_type .. 's!')
    if config.broadcastKills then
        Game.broadcastMessage("Bounty Hunter Update:\n " .. killer:getName() .. " has killed " .. target:getName() .. " and earned a reward of " .. prize .. " " .. bounty_type .. "!", MESSAGE_EVENT_ADVANCE)
    end
    return true
end
local function addBountyHunt(player, target, amount, currencyType)
    db.query("INSERT INTO `bounty_hunter_system` VALUES (NULL," .. player:getGuid() .. "," .. target:getGuid() .. ",0," .. amount .. ", '" .. currencyType .. "', " .. os.time() .. ", 0, 0);")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTER SYSTEM] You have placed bounty on " .. target:getName() .. " for a reward of " .. amount .. " " .. currencyType .. "!")
    if config.broadcastHunt then
        Game.broadcastMessage("[BOUNTY_HUNTER_SYSTEM]\n " .. player:getName() .. " has put a bounty on " .. target:getName() .. " for " .. amount .. " " .. t[2] .. ".", MESSAGE_EVENT_ADVANCE)
    end
return false
end
function onBountyHunterSay(player, words, param)
    if player:getLevel() < config.minLevelToAddBounty then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You need level ' .. config.minLevelToAddBounty .. ' to use this command.')
        return false
    end
    local t = param:split(",")
    local name = t[1]
    local currencyType = t[2] and trimString(t[2]) or nil
    local amount = t[3] and tonumber(t[3]) or nil
    if not (name and currencyType and amount) then
        local item = ItemType(customCurrency)
        local text = '[BOUNTY HUNTER SYSTEM GUIDE]\n\nCommand Usage:\n!hunt playerName, type(gold/' .. customCurrency .. '/points), amount' .. '\n\n' .. 'Hunting for Gold:\n' .. '--> !hunt Joe,gold,150000\n' .. '--> Placed a bounty on Joe for the amount of 150,000 gps.' .. '\n\n' .. 'Hunting for Premium Points:\n' .. '--> !hunt Joe,points,100\n' .. '--> Placed a bounty on Joe for the amount of 100 premium points.'
        text = text .. (item:getId() > 0 and ('\n\n' .. 'Hunting for ' .. item:getPluralName() .. ':\n' .. '--> !hunt Joe,' .. customCurrency .. ',50\n' .. '--> Placed a bounty on Joe for the amount of 50 ' .. item:getPluralName()) or '')
        player:popupFYI(text)
        return false
    end
    local target = Player(name)
    if not target then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] A player with the name of ' .. name .. ' is not online.')
    return false
    end
    if target:getGuid() == player:getGuid() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may not place a bounty on yourself!')
    return false
    end
    if config.ipCheck and target:getIp() == player:getIp() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may not place a bounty on a player from the same IP Address!')
    return false
    end
    if target:getLevel() < config.minLevelToBeTargeted then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may only target players level ' .. config.minLevelToBeTargeted .. ' and above!')
    return false
    end
    local info = target:getBountyInfo()
    if info[1] then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTER SYSTEM] This player has already been hunted.")
        return false
    end
    local typ = config.currencies[currencyType]
    if not typ then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] The currency type "' .. currencyType .. '" is not a valid bounty currency. [Currencies: gold/points' .. (customCurrency ~= '' and '/'..customCurrency..'' or '') .. ']')
    return false
    end
    local minA, maxA = typ.minAmount, typ.maxAmount
    if amount < minA or amount > maxA then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] The currency type of "' .. currencyType .. '" allows the amount to be in the range of ' .. minA .. ' --> ' .. maxA .. '.')
    return false
    end   
    if not typ.check(player, amount, currencyType) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You do not have ' .. amount .. ' ' .. currencyType .. '. [Error: Insufficient Funds]')
    return false
    end   
    
    return addBountyHunt(player, target, amount, currencyType)
end
function onBountyHunterKill(creature, target)
    if not target:isPlayer() then
        return true
    end
    if creature:getTile():hasFlag(TILESTATE_PVPZONE) then
        return true
    end
    local info = target:getBountyInfo()
    if not info[1] then
        return true
    end
    return addBountyKill(creature, target, info[2], info[3], info[4], info[5])
end
 
This part insert into your database:
PHP:
CREATE TABLE IF NOT EXISTS `bounty_hunter_system` (
     `id` int(11) NOT NULL auto_increment,
     `hunter_id` int(11) NOT NULL,
     `target_id` int(11) NOT NULL,
     `killer_id` int(11) NOT NULL,
     `prize` bigint(20) NOT NULL,
     `currencyType` varchar(32) NOT NULL,
     `dateAdded` int(15) NOT NULL,
     `killed` int(11) NOT NULL,
     `dateKilled` int(15) NOT NULL,
     PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The rest put with your other libraries. Mine is in: data/lib/bounty_hunter.lua

Then in data/global.lua you can add at the top
dofile('data/lib/bounty_hunter.lua')
 
OK! So maybe I am stupid and all that yessss, so take my hand and please tell me where do I add this code, cuz I am confused and upset with myself since I can't see such a clear thing when everyone is enjoying this system with no questions about it:

library [database query on top]: (AND YES! I get it is a Library and allready created the table, just dont know where to put this)
Code:
--[[ db table
    CREATE TABLE IF NOT EXISTS `bounty_hunter_system` (
     `id` int(11) NOT NULL auto_increment,
     `hunter_id` int(11) NOT NULL,
     `target_id` int(11) NOT NULL,
     `killer_id` int(11) NOT NULL,
     `prize` bigint(20) NOT NULL,
     `currencyType` varchar(32) NOT NULL,
     `dateAdded` int(15) NOT NULL,
     `killed` int(11) NOT NULL,
     `dateKilled` int(15) NOT NULL,
     PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
]]


--------------------------------------
---------- START OF CONFIG -----------
--------------------------------------
local customCurrency = '' -- by default bank balance and premium points are included but you can add other stackable currencies like gold nuggets etc here eg, 'gold nugget' or you can use the itemID or the item name
local config = {
    ipCheck = true, -- players from same IP can not place bounty on each other
    minLevelToAddBounty = 20, -- min lvl req to place a bounty
    minLevelToBeTargeted = 20, -- min lvl req to be targeted by a bounty
    broadcastKills = true, -- Should it broadcast a message to the whole game-world when someone was killed?
    broadcastHunt = false, -- Should it broadcast a message to the whole game-world when someone is added to the bounty list?
    mailbox_position = Position(32351,32223,6), -- If you are using a custom currency then we will send it to the players Mailbox, in order to do it you just need to put the location of one mailbox from your map here, doesn't matter which
    currencies = {
        ['gold'] = {         
            minAmount = 1000000, -- Min amount of Gold allowed
            maxAmount = 1000000000, -- Max amount of gold allowed
            func =
                function(player, prize, currency)
                    return player:setBankBalance(player:getBankBalance() + prize)
                end,
            check =
                function(player, amount, currency)
                    if player:getBankBalance() >= amount then
                        return player:setBankBalance(player:getBankBalance() - amount)
                    end
                    return false
                end,
        },
        ['points'] = {
            minAmount = 10, -- Min amount of premium points allowed
            maxAmount = 500, -- Max amount of premium points allowed
            func =
                function(player, prize, currency)
                    return player:addPremiumPoints(prize)
                end,
            check =
                function(player, prize, currency)
                    if player:getPremiumPoints() > prize then
                        return player:removePremiumPoints(prize)
                    end
                    return false
                end
        },
        [customCurrency] = {
            minAmount = 10, -- Min amount of custom item allowed
            maxAmount = 3000, -- Max amount of custom item allowed
            func =
                function(player, prize, currency)
                    return player:sendParcel(prize)
                end,
            check =
                function(player, amount, currency)
                    local itemID = ItemType(customCurrency):getId()
                    if itemID > 0 and player:getItemCount(itemID) >= amount then
                        player:removeItem(itemID, amount)
                        return true
                    end
                    return false
                end,
        }
    }
}
--------------------------------------
----------- END OF CONFIG ------------
--------------------------------------
-- Only edit below if you know what you are doing --

local function trimString(str)
  return (str:gsub("^%s*(.-)%s*$", "%1"))
end

local function addItemsToBag(bpID, itemID, count)
    local masterBag = Game.createItem(bpID,1)
    local stackable = ItemType(itemID):isStackable()
 
    if stackable then
        if count > 2000 then
            local bp = Game.createItem(bpID,1)
            masterBag:addItemEx(bp)
            for i = 1, count do
                if bp:getEmptySlots() < 1 then
                    bp = Game.createItem(bpID,1)
                    masterBag:addItemEx(bp)
                end
                bp:addItem(itemID)
            end
        end
        return masterBag
    end
 
    if count > 20 then
        local bp = Game.createItem(bpID,1)
        masterBag:addItemEx(bp)
        for i = 1, count do
            if bp:getEmptySlots() < 1 then
                bp = Game.createItem(bpID,1)
                masterBag:addItemEx(bp)
            end
            bp:addItem(itemID)
        end
    return masterBag
    end
 
    for i = 1, count do     
        masterBag:addItem(itemID)
    end
    return masterBag
end

function Player:sendParcel(amount)
    local itemID = ItemType(customCurrency):getId()
    if itemID == 0 then
        print('Error in sending parcel. Custom currency was not set properly double check the spelling.')
        return
    end
    local container = Game.createItem(2595, 1)
    container:setAttribute(ITEM_ATTRIBUTE_NAME, 'Bounty Hunters Mail')
    local label = container:addItem(2599, 1)
    label:setAttribute(ITEM_ATTRIBUTE_TEXT, self:getName())
    label:setAttribute(ITEM_ATTRIBUTE_WRITER, "Bounty Hunters Mail")
    local parcel = addItemsToBag(1988, itemID, amount)
    container:addItemEx(parcel)
    container:moveTo(config.mailbox_position)
end

function Player:getPremiumPoints(points)
    local points = db.storeQuery("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. self:getAccountId() .. ";")
    if points then
        local pointTotal = result.getDataInt(points, "premium_points")
        result.free(points)
    return pointTotal
    end
    return 0
end

function Player:addPremiumPoints(points)
    return db.query("UPDATE accounts SET premium_points = premium_points + "..points.." where id = "..self:getAccountId()..";")
end

function Player:removePremiumPoints(points)
    return db.query("UPDATE accounts SET premium_points = premium_points - "..points.." where id = "..self:getAccountId()..";")
end

function Player:getBountyInfo()
    local result_plr = db.storeQuery("SELECT prize, id, currencyType FROM `bounty_hunter_system` WHERE `target_id` = "..self:getGuid().." AND `killed` = 0;")
    if (result_plr == false) then
        return {false, 0, 0, 0, 0}
    end
    local prize = tonumber(result.getDataInt(result_plr, "prize"))
    local id = tonumber(result.getDataInt(result_plr, "id"))
    local bounty_type = tostring(result.getDataString(result_plr, "currencyType"))
    result.free(result_plr)
    return {true, prize, id, bounty_type, currency}
end

local function addBountyKill(killer, target, prize, id, bounty_type, currency)
    if not config.currencies[bounty_type] then
        print('error in adding bounty prize')
        return true
    end
    config.currencies[bounty_type].func(killer, prize, currency)
    db.query("UPDATE `bounty_hunter_system` SET `killed` = 1, `killer_id`="..killer:getGuid()..", `dateKilled` = " .. os.time() .. " WHERE `id`  = "..id..";")
    killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTER SYSTEM] You killed ' .. target:getName() .. ' and earned a reward of ' .. prize .. ' ' .. bounty_type .. 's!')
    if config.broadcastKills then
        Game.broadcastMessage("Bounty Hunter Update:\n " .. killer:getName() .. " has killed " .. target:getName() .. " and earned a reward of " .. prize .. " " .. bounty_type .. "!", MESSAGE_EVENT_ADVANCE)
    end
    return true
end

local function addBountyHunt(player, target, amount, currencyType)
    db.query("INSERT INTO `bounty_hunter_system` VALUES (NULL," .. player:getGuid() .. "," .. target:getGuid() .. ",0," .. amount .. ", '" .. currencyType .. "', " .. os.time() .. ", 0, 0);")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTER SYSTEM] You have placed bounty on " .. target:getName() .. " for a reward of " .. amount .. " " .. currencyType .. "!")
    if config.broadcastHunt then
        Game.broadcastMessage("[BOUNTY_HUNTER_SYSTEM]\n " .. player:getName() .. " has put a bounty on " .. target:getName() .. " for " .. amount .. " " .. t[2] .. ".", MESSAGE_EVENT_ADVANCE)
    end
return false
end

function onBountyHunterSay(player, words, param)
    if player:getLevel() < config.minLevelToAddBounty then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You need level ' .. config.minLevelToAddBounty .. ' to use this command.')
        return false
    end
    local t = param:split(",")
    local name = t[1]
    local currencyType = t[2] and trimString(t[2]) or nil
    local amount = t[3] and tonumber(t[3]) or nil
 
    if not (name and currencyType and amount) then
        local item = ItemType(customCurrency)
        local text = '[BOUNTY HUNTER SYSTEM GUIDE]\n\nCommand Usage:\n!hunt playerName, type(gold/' .. customCurrency .. '/points), amount' .. '\n\n' .. 'Hunting for Gold:\n' .. '--> !hunt Joe,gold,150000\n' .. '--> Placed a bounty on Joe for the amount of 150,000 gps.' .. '\n\n' .. 'Hunting for Premium Points:\n' .. '--> !hunt Joe,points,100\n' .. '--> Placed a bounty on Joe for the amount of 100 premium points.'
        text = text .. (item:getId() > 0 and ('\n\n' .. 'Hunting for ' .. item:getPluralName() .. ':\n' .. '--> !hunt Joe,' .. customCurrency .. ',50\n' .. '--> Placed a bounty on Joe for the amount of 50 ' .. item:getPluralName()) or '')
        player:popupFYI(text)
        return false
    end
 
    local target = Player(name)
    if not target then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] A player with the name of ' .. name .. ' is not online.')
    return false
    end

    if target:getGuid() == player:getGuid() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may not place a bounty on yourself!')
    return false
    end
 
    if config.ipCheck and target:getIp() == player:getIp() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may not place a bounty on a player from the same IP Address!')
    return false
    end
 
    if target:getLevel() < config.minLevelToBeTargeted then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may only target players level ' .. config.minLevelToBeTargeted .. ' and above!')
    return false
    end
 
    local info = target:getBountyInfo()
    if info[1] then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTER SYSTEM] This player has already been hunted.")
        return false
    end
 
    local typ = config.currencies[currencyType]
    if not typ then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] The currency type "' .. currencyType .. '" is not a valid bounty currency. [Currencies: gold/points' .. (customCurrency ~= '' and '/'..customCurrency..'' or '') .. ']')
    return false
    end
 
    local minA, maxA = typ.minAmount, typ.maxAmount
    if amount < minA or amount > maxA then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] The currency type of "' .. currencyType .. '" allows the amount to be in the range of ' .. minA .. ' --> ' .. maxA .. '.')
    return false
    end     
 
    if not typ.check(player, amount, currencyType) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You do not have ' .. amount .. ' ' .. currencyType .. '. [Error: Insufficient Funds]')
    return false
    end     
    
    return addBountyHunt(player, target, amount, currencyType)
end



function onBountyHunterKill(creature, target)
    if not target:isPlayer() then
        return true
    end

    if creature:getTile():hasFlag(TILESTATE_PVPZONE) then
        return true
    end

    local info = target:getBountyInfo()
    if not info[1] then
        return true
    end

    return addBountyKill(creature, target, info[2], info[3], info[4], info[5])
end
 
@Nixdo Hey mate, I edited the first page, now it will update your database automatically if the table does not currently exist.

Just recopy the library file from the first page (or just copy the first 2 lines involving the database) and then reload the libs on your server.
 
OK! So maybe I am stupid and all that yessss, so take my hand and please tell me where do I add this code, cuz I am confused and upset with myself since I can't see such a clear thing when everyone is enjoying this system with no questions about it:

library [database query on top]: (AND YES! I get it is a Library and allready created the table, just dont know where to put this)
Code:
--[[ db table
    CREATE TABLE IF NOT EXISTS `bounty_hunter_system` (
     `id` int(11) NOT NULL auto_increment,
     `hunter_id` int(11) NOT NULL,
     `target_id` int(11) NOT NULL,
     `killer_id` int(11) NOT NULL,
     `prize` bigint(20) NOT NULL,
     `currencyType` varchar(32) NOT NULL,
     `dateAdded` int(15) NOT NULL,
     `killed` int(11) NOT NULL,
     `dateKilled` int(15) NOT NULL,
     PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
]]


--------------------------------------
---------- START OF CONFIG -----------
--------------------------------------
local customCurrency = '' -- by default bank balance and premium points are included but you can add other stackable currencies like gold nuggets etc here eg, 'gold nugget' or you can use the itemID or the item name
local config = {
    ipCheck = true, -- players from same IP can not place bounty on each other
    minLevelToAddBounty = 20, -- min lvl req to place a bounty
    minLevelToBeTargeted = 20, -- min lvl req to be targeted by a bounty
    broadcastKills = true, -- Should it broadcast a message to the whole game-world when someone was killed?
    broadcastHunt = false, -- Should it broadcast a message to the whole game-world when someone is added to the bounty list?
    mailbox_position = Position(32351,32223,6), -- If you are using a custom currency then we will send it to the players Mailbox, in order to do it you just need to put the location of one mailbox from your map here, doesn't matter which
    currencies = {
        ['gold'] = {        
            minAmount = 1000000, -- Min amount of Gold allowed
            maxAmount = 1000000000, -- Max amount of gold allowed
            func =
                function(player, prize, currency)
                    return player:setBankBalance(player:getBankBalance() + prize)
                end,
            check =
                function(player, amount, currency)
                    if player:getBankBalance() >= amount then
                        return player:setBankBalance(player:getBankBalance() - amount)
                    end
                    return false
                end,
        },
        ['points'] = {
            minAmount = 10, -- Min amount of premium points allowed
            maxAmount = 500, -- Max amount of premium points allowed
            func =
                function(player, prize, currency)
                    return player:addPremiumPoints(prize)
                end,
            check =
                function(player, prize, currency)
                    if player:getPremiumPoints() > prize then
                        return player:removePremiumPoints(prize)
                    end
                    return false
                end
        },
        [customCurrency] = {
            minAmount = 10, -- Min amount of custom item allowed
            maxAmount = 3000, -- Max amount of custom item allowed
            func =
                function(player, prize, currency)
                    return player:sendParcel(prize)
                end,
            check =
                function(player, amount, currency)
                    local itemID = ItemType(customCurrency):getId()
                    if itemID > 0 and player:getItemCount(itemID) >= amount then
                        player:removeItem(itemID, amount)
                        return true
                    end
                    return false
                end,
        }
    }
}
--------------------------------------
----------- END OF CONFIG ------------
--------------------------------------
-- Only edit below if you know what you are doing --

local function trimString(str)
  return (str:gsub("^%s*(.-)%s*$", "%1"))
end

local function addItemsToBag(bpID, itemID, count)
    local masterBag = Game.createItem(bpID,1)
    local stackable = ItemType(itemID):isStackable()

    if stackable then
        if count > 2000 then
            local bp = Game.createItem(bpID,1)
            masterBag:addItemEx(bp)
            for i = 1, count do
                if bp:getEmptySlots() < 1 then
                    bp = Game.createItem(bpID,1)
                    masterBag:addItemEx(bp)
                end
                bp:addItem(itemID)
            end
        end
        return masterBag
    end

    if count > 20 then
        local bp = Game.createItem(bpID,1)
        masterBag:addItemEx(bp)
        for i = 1, count do
            if bp:getEmptySlots() < 1 then
                bp = Game.createItem(bpID,1)
                masterBag:addItemEx(bp)
            end
            bp:addItem(itemID)
        end
    return masterBag
    end

    for i = 1, count do    
        masterBag:addItem(itemID)
    end
    return masterBag
end

function Player:sendParcel(amount)
    local itemID = ItemType(customCurrency):getId()
    if itemID == 0 then
        print('Error in sending parcel. Custom currency was not set properly double check the spelling.')
        return
    end
    local container = Game.createItem(2595, 1)
    container:setAttribute(ITEM_ATTRIBUTE_NAME, 'Bounty Hunters Mail')
    local label = container:addItem(2599, 1)
    label:setAttribute(ITEM_ATTRIBUTE_TEXT, self:getName())
    label:setAttribute(ITEM_ATTRIBUTE_WRITER, "Bounty Hunters Mail")
    local parcel = addItemsToBag(1988, itemID, amount)
    container:addItemEx(parcel)
    container:moveTo(config.mailbox_position)
end

function Player:getPremiumPoints(points)
    local points = db.storeQuery("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. self:getAccountId() .. ";")
    if points then
        local pointTotal = result.getDataInt(points, "premium_points")
        result.free(points)
    return pointTotal
    end
    return 0
end

function Player:addPremiumPoints(points)
    return db.query("UPDATE accounts SET premium_points = premium_points + "..points.." where id = "..self:getAccountId()..";")
end

function Player:removePremiumPoints(points)
    return db.query("UPDATE accounts SET premium_points = premium_points - "..points.." where id = "..self:getAccountId()..";")
end

function Player:getBountyInfo()
    local result_plr = db.storeQuery("SELECT prize, id, currencyType FROM `bounty_hunter_system` WHERE `target_id` = "..self:getGuid().." AND `killed` = 0;")
    if (result_plr == false) then
        return {false, 0, 0, 0, 0}
    end
    local prize = tonumber(result.getDataInt(result_plr, "prize"))
    local id = tonumber(result.getDataInt(result_plr, "id"))
    local bounty_type = tostring(result.getDataString(result_plr, "currencyType"))
    result.free(result_plr)
    return {true, prize, id, bounty_type, currency}
end

local function addBountyKill(killer, target, prize, id, bounty_type, currency)
    if not config.currencies[bounty_type] then
        print('error in adding bounty prize')
        return true
    end
    config.currencies[bounty_type].func(killer, prize, currency)
    db.query("UPDATE `bounty_hunter_system` SET `killed` = 1, `killer_id`="..killer:getGuid()..", `dateKilled` = " .. os.time() .. " WHERE `id`  = "..id..";")
    killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTER SYSTEM] You killed ' .. target:getName() .. ' and earned a reward of ' .. prize .. ' ' .. bounty_type .. 's!')
    if config.broadcastKills then
        Game.broadcastMessage("Bounty Hunter Update:\n " .. killer:getName() .. " has killed " .. target:getName() .. " and earned a reward of " .. prize .. " " .. bounty_type .. "!", MESSAGE_EVENT_ADVANCE)
    end
    return true
end

local function addBountyHunt(player, target, amount, currencyType)
    db.query("INSERT INTO `bounty_hunter_system` VALUES (NULL," .. player:getGuid() .. "," .. target:getGuid() .. ",0," .. amount .. ", '" .. currencyType .. "', " .. os.time() .. ", 0, 0);")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTER SYSTEM] You have placed bounty on " .. target:getName() .. " for a reward of " .. amount .. " " .. currencyType .. "!")
    if config.broadcastHunt then
        Game.broadcastMessage("[BOUNTY_HUNTER_SYSTEM]\n " .. player:getName() .. " has put a bounty on " .. target:getName() .. " for " .. amount .. " " .. t[2] .. ".", MESSAGE_EVENT_ADVANCE)
    end
return false
end

function onBountyHunterSay(player, words, param)
    if player:getLevel() < config.minLevelToAddBounty then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You need level ' .. config.minLevelToAddBounty .. ' to use this command.')
        return false
    end
    local t = param:split(",")
    local name = t[1]
    local currencyType = t[2] and trimString(t[2]) or nil
    local amount = t[3] and tonumber(t[3]) or nil

    if not (name and currencyType and amount) then
        local item = ItemType(customCurrency)
        local text = '[BOUNTY HUNTER SYSTEM GUIDE]\n\nCommand Usage:\n!hunt playerName, type(gold/' .. customCurrency .. '/points), amount' .. '\n\n' .. 'Hunting for Gold:\n' .. '--> !hunt Joe,gold,150000\n' .. '--> Placed a bounty on Joe for the amount of 150,000 gps.' .. '\n\n' .. 'Hunting for Premium Points:\n' .. '--> !hunt Joe,points,100\n' .. '--> Placed a bounty on Joe for the amount of 100 premium points.'
        text = text .. (item:getId() > 0 and ('\n\n' .. 'Hunting for ' .. item:getPluralName() .. ':\n' .. '--> !hunt Joe,' .. customCurrency .. ',50\n' .. '--> Placed a bounty on Joe for the amount of 50 ' .. item:getPluralName()) or '')
        player:popupFYI(text)
        return false
    end

    local target = Player(name)
    if not target then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] A player with the name of ' .. name .. ' is not online.')
    return false
    end

    if target:getGuid() == player:getGuid() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may not place a bounty on yourself!')
    return false
    end

    if config.ipCheck and target:getIp() == player:getIp() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may not place a bounty on a player from the same IP Address!')
    return false
    end

    if target:getLevel() < config.minLevelToBeTargeted then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You may only target players level ' .. config.minLevelToBeTargeted .. ' and above!')
    return false
    end

    local info = target:getBountyInfo()
    if info[1] then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTER SYSTEM] This player has already been hunted.")
        return false
    end

    local typ = config.currencies[currencyType]
    if not typ then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] The currency type "' .. currencyType .. '" is not a valid bounty currency. [Currencies: gold/points' .. (customCurrency ~= '' and '/'..customCurrency..'' or '') .. ']')
    return false
    end

    local minA, maxA = typ.minAmount, typ.maxAmount
    if amount < minA or amount > maxA then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] The currency type of "' .. currencyType .. '" allows the amount to be in the range of ' .. minA .. ' --> ' .. maxA .. '.')
    return false
    end    

    if not typ.check(player, amount, currencyType) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[BOUNTY_HUNTER_SYSTEM] You do not have ' .. amount .. ' ' .. currencyType .. '. [Error: Insufficient Funds]')
    return false
    end    
   
    return addBountyHunt(player, target, amount, currencyType)
end



function onBountyHunterKill(creature, target)
    if not target:isPlayer() then
        return true
    end

    if creature:getTile():hasFlag(TILESTATE_PVPZONE) then
        return true
    end

    local info = target:getBountyInfo()
    if not info[1] then
        return true
    end

    return addBountyKill(creature, target, info[2], info[3], info[4], info[5])
end

I SAID NOTHING!!! I MUST HAVE SCROLLED DOWN TOO FAST OR SOMETHING!!...:eek:o_O Now I found theplace to put the libraries...

Well, but now I see that the command is not taking money from me and I am getting no messages nor errors in the server log...any idea why that is happening?😅
 
Well, but now I see that the command is not taking money from me and I am getting no messages nor errors in the server log...any idea why that is happening?😅

Looking at the code it should take/remove/add from your bank balance. So did you check to see if it altered your bank balance?
 
@Nixdo Hey mate, I edited the first page, now it will update your database automatically if the table does not currently exist.

Just recopy the library file from the first page (or just copy the first 2 lines involving the database) and then reload the libs on your server.
HAHAHAHAHA!!! Wow you are quick mate!!

I am now gonna try it out just that way, and thanks for the help!!
Post automatically merged:

Looking at the code it should take/remove/add from your bank balance. So did you check to see if it altered your bank balance?
Yeah! Nothing is happening...

Is it maybe cuz I am trying to hunt my same account second character?
 
HAHAHAHAHA!!! Wow you are quick mate!!

I am now gonna try it out just that way, and thanks for the help!!
Post automatically merged:


Yeah! Nothing is happening...

Is it maybe cuz I am trying to hunt my same account second character?


Not it should not matter, actually I just tested in that same situation x'D.
How are you typing the command?
For normal coins it is, for example:
!hunt Druid Sample, gold, 1000000

(oops gold not coins :p)
 
Not it should not matter, actually I just tested in that same situation x'D.
How are you typing the command?
For normal coins it is, for example:
!hunt Druid Sample, gold, 1000000

(oops gold not coins :p)
Like this: "!hunt Nixy, gold, 60000"
But since I can not put the webpage thingy, can't check if I did the command correctly.

04:31 Naji: You certainly have made a pretty penny. Your account balance is 605597 gold.
04:32 Kenpachy [125]: !hunt Nixy, gold, 60000
04:32 Kenpachy [125]: hi
04:33 Kenpachy [125]: balance
04:33 Naji: You certainly have made a pretty penny. Your account balance is 605597 gold.

Edit: Naji is allways fun to read! Such a rich bastard xD
 
@Nixdo

You should be getting messages in your local chat updating you like this:
Code:
22:39 [BOUNTY HUNTER SYSTEM] You have placed bounty on Paladin Sample for a reward of 1000000 gold!

Code:
22:38 Naji: You have made ten millions and it still grows! Your account balance is 76029008 gold.
22:39 Godric [534]: balance
22:39 Naji: You have made ten millions and it still grows! Your account balance is 75029008 gold.
 
@Nixdo

You should be getting messages in your local chat updating you like this:
Code:
22:39 [BOUNTY HUNTER SYSTEM] You have placed bounty on Paladin Sample for a reward of 1000000 gold!

Code:
22:38 Naji: You have made ten millions and it still grows! Your account balance is 76029008 gold.
22:39 Godric [534]: balance
22:39 Naji: You have made ten millions and it still grows! Your account balance is 75029008 gold.
Nope...It is still not getting my command at all...I mean it does get it but does not hunt any character neither gives me a feedback, it is like the program don't pay attention to me even if it sees what I am telling him xD
 
Nope...It is still not getting my command at all...I mean it does get it but does not hunt any character neither gives me a feedback, it is like the program don't pay attention to me even if it sees what I am telling him xD

Then I believe it wasn't installed properly. Go check and make sure you got all the parts added, including the registration of the creatureevent in login.lua, and after you double checked you have all the files then:

/reload global
/reload talkactions
/reload creaturescripts
 
Then I believe it wasn't installed properly. Go check and make sure you got all the parts added, including the registration of the creatureevent in login.lua, and after you double checked you have all the files then:

/reload global
/reload talkactions
/reload creaturescripts
That! That might be the problem, the login.lua, forgot about it. Well I added it before the "return true" at the end of the login.lua, do not know if thats the right place for this one, it was for other systematics... 😅 😂

So...should I add it in a specific place?
 
That! That might be the problem, the login.lua, forgot about it. Well I added it before the "return true" at the end of the login.lua, do not know if thats the right place for this one, it was for other systematics... 😅 😂

So...should I add it in a specific place?

Paste your login.lua here
 
Paste your login.lua here
Lua:
function Player.sendTibiaTime(self, hours, minutes)
    local msg = NetworkMessage()
    msg:addByte(0xEF)
    msg:addByte(hours)
    msg:addByte(minutes)
    msg:sendToPlayer(self)
    msg:delete()
    return true
end

local function onMovementRemoveProtection(cid, oldPos, time)
    local player = Player(cid)
    if not player then
        return true
    end

    local playerPos = player:getPosition()
    if (playerPos.x ~= oldPos.x or playerPos.y ~= oldPos.y or playerPos.z ~= oldPos.z) or player:getTarget() then
        player:setStorageValue(Storage.combatProtectionStorage, 0)
        return true
    end

    addEvent(onMovementRemoveProtection, 1000, cid, oldPos, time - 1)
end

function onLogin(player)
    local items = {
        {2120, 1},
        {2148, 3}
    }   
    if player:getLastLoginSaved() == 0 then
        local backpack = player:addItem(1988)
        if backpack then
            for i = 1, #items do
                backpack:addItem(items[i][1], items[i][2])
            end
        end
        player:addItem(2050, 1, true, 1, CONST_SLOT_AMMO)
    else
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, string.format("Your last visit in ".. SERVER_NAME ..": %s.", os.date("%d. %b %Y %X", player:getLastLoginSaved())))
    end
    
    local playerId = player:getId()
    DailyReward.init(playerId)

    player:loadSpecialStorage()

    if player:getGroup():getId() >= 4 then
        player:setGhostMode(true)
    end

    -- Stamina
    nextUseStaminaTime[playerId] = 1

    -- EXP Stamina
    nextUseXpStamina[playerId] = 1

    -- Prey Small Window
    if player:getClient().version > 1110 then
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            player:sendPreyData(slot)
        end
    end

    -- New prey
    nextPreyTime[playerId] = {
        [CONST_PREY_SLOT_FIRST] = 1,
        [CONST_PREY_SLOT_SECOND] = 1,
        [CONST_PREY_SLOT_THIRD] = 1
    }

    if (player:getAccountType() == ACCOUNT_TYPE_TUTOR) then
    local msg = [[:: Tutor Rules
        1 *> 3 Warnings you lose the job.
        2 *> Without parallel conversations with players in Help, if the player starts offending, you simply mute it.
        3 *> Be educated with the players in Help and especially in the Private, try to help as much as possible.
        4 *> Always be on time, if you do not have a justification you will be removed from the staff.
        5 *> Help is only allowed to ask questions related to tibia.
        6 *> It is not allowed to divulge time up or to help in quest.
        7 *> You are not allowed to sell items in the Help.
        8 *> If the player encounters a bug, ask to go to the website to send a ticket and explain in detail.
        9 *> Always keep the Tutors Chat open. (required).
        10 *> You have finished your schedule, you have no tutor online, you communicate with some CM in-game
        or ts and stay in the help until someone logs in, if you can.
        11 *> Always keep a good Portuguese in the Help, we want tutors who support, not that they speak a satanic ritual.
        12 *> If you see a tutor doing something that violates the rules, take a print and send it to your superiors. "
        - Commands -
        Mute Player: /mute nick, 90 (90 seconds)
        Unmute Player: /unmute nick.
        - Commands -]]
        player:popupFYI(msg)
    end

    -- Open channels
    if table.contains({TOWNS_LIST.DAWNPORT, TOWNS_LIST.DAWNPORT_TUTORIAL}, player:getTown():getId())then
        player:openChannel(3) -- World chat
    else
        player:openChannel(3) -- World chat
        player:openChannel(5) -- Advertsing main
    end

    -- Rewards
    local rewards = #player:getRewardList()
    if(rewards > 0) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have %d %s in your reward chest.",
        rewards, rewards > 1 and "rewards" or "reward"))
    end

    -- Update player id
    local stats = player:inBossFight()
    if stats then
        stats.playerId = player:getId()
    end

    if player:getStorageValue(Storage.combatProtectionStorage) < 1 then
        player:setStorageValue(Storage.combatProtectionStorage, 1)
        onMovementRemoveProtection(playerId, player:getPosition(), 10)
    end
    -- Set Client XP Gain Rate
    local baseExp = 100
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        baseExp = getRateFromTable(experienceStages, player:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
    end

    local staminaMinutes = player:getStamina()
    local doubleExp = false --Can change to true if you have double exp on the server
    local staminaBonus = (staminaMinutes > 2400) and 150 or ((staminaMinutes < 840) and 50 or 100)
    if doubleExp then
        baseExp = baseExp * 2
    end
    player:setStaminaXpBoost(staminaBonus)
    player:setBaseXpGain(baseExp)

    if player:getClient().version > 1110 then
        local worldTime = getWorldTime()
        local hours = math.floor(worldTime / 60)
        local minutes = worldTime % 60
        player:sendTibiaTime(hours, minutes)
    end

    if player:getStorageValue(Storage.isTraining) == 1 then --Reset exercise weapon storage
        player:setStorageValue(Storage.isTraining,0)
    end
    
    player:registerEvent('BountyHunterKill')
    
    return true
end
 
Back
Top