TFS 1.X Bounty Hunter System

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by imkingran, Apr 14, 2014.

  1. Cotizado

    Cotizado Member

    Joined:
    May 12, 2008
    Messages:
    321
    yes much players don't check the bounty page so the broadcast should work as a reminder
     
  2. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    data/globalevents/bounty.lua
    Code:
    function onThink(interval)
    
        local player = db.storeQuery("SELECT `sp_id`, `prize` FROM `bounty_hunters` WHERE `killed` = '0' ORDER BY `prize` DESC LIMIT 3;")
        local output = "MOST WANTED:\n"
        if(player ~= false) then
            local number = 1
                    while (true) do
                        local name = result.getDataString(player, "sp_id")
                        local prize = result.getDataInt(player, "prize")
                        local playerName = db.storeQuery("SELECT `name` FROM `players` WHERE `players`.`id` = "..name..";")
                        local playerName1 = result.getDataString(playerName, "name")
                        output = output.. "\n"..number..". "..playerName1.." - "..prize.."k"
                        number = number + 1
                        if not(result.next(player)) then
                            break
                        end
                    end
                    result.free(player)
        end
        Game.broadcastMessage(output)
    
    return true
    end  
    globalevents.xml
    Code:
    <globalevent name="bounty" interval="3600000" script="bounty.lua"/>
     
    Cotizado likes this.
  3. giddy92

    giddy92 Member

    Joined:
    Aug 8, 2014
    Messages:
    69
    When i kill the "hunt" player, i dont any gold. And on website he are still "still alive"
     
  4. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    Code:
    function onKill(cid, target)
    local player2 = Creature(target)
    if not player2:isPlayer() then
    return true
    end
    ---- BOUNTY HUNTERS START -----
    pid = cid
    pid2 = player2:getGuid()
        local result_plr = db.storeQuery("SELECT * FROM `bounty_hunters` WHERE `sp_id` = "..pid2.." AND `killed` = 0;")
        if(result_plr ~= false) then
        prize = tonumber(result.getDataInt(result_plr, "prize"))
        bid = tonumber(result.getDataInt(result_plr, "id"))
        result.free(result_plr)
        else
        prize = 0
        bid = 0
        end
    
    if (bid ~= 0 and prize ~= 0 and not(getTileInfo(getCreaturePosition(cid)).pvp)) then
        local player = Player(cid)
        db.query("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..getPlayerGUID(cid)..", `kill_time` = " .. os.time() .. " WHERE `id`  = "..bid..";")
        player:setBankBalance(player:getBankBalance() + prize)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTERS] You killed hunted player, so you gained the reward!')
        Game.broadcastMessage("Bounty Hunter Update:\n " .. player:getName() .. " has killed " .. player2:getName() .. " and earned the prize of " .. prize .. " gps!", MESSAGE_EVENT_ADVANCE)
    end
    ---- BOUNTY HUNTERS END -----
    return true
    end
    Let me know if you get any errors. The gold is added to the players bank account, not his backpack.
     
    Last edited: Nov 15, 2014
  5. giddy92

    giddy92 Member

    Joined:
    Aug 8, 2014
    Messages:
    69
    Now all work! Thanks! :)
     
  6. Cotizado

    Cotizado Member

    Joined:
    May 12, 2008
    Messages:
    321
    i haven't tested it but should be great if only broadcast the hunted players that are online
     
  7. giddy92

    giddy92 Member

    Joined:
    Aug 8, 2014
    Messages:
    69
    I think I could use one change.
    For example, if someone actually marks someone to kill another person has not already can do.
    You can do this:
    if 5 players mark to kill the player "Test Player"
    And a player kill "Test Player" will get a reward from the "oldest marks"
    And so, until the fall as many times as is provided prizes for him.
     
  8. strutZ

    strutZ Australian OT Member {AKA Beastn} Premium User

    Joined:
    Nov 16, 2014
    Messages:
    1,177
    How do i make it not use the decimal point? for example my minimum bounty is 1000. i want it to be 1k, 10k, 100k etc

    nevermind i did it. Anyone else want to change it like mine change

    Code:
    $b = round($bounty[prize] / 1000000,2);
    to
    Code:
    $b = round($bounty[prize] / 1000,2);
     
  9. Tickit

    Tickit Member

    Joined:
    Feb 20, 2009
    Messages:
    364
    I got this one onDeath [​IMG]
     
  10. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,518
    what tfs r u using?
     
  11. Tickit

    Tickit Member

    Joined:
    Feb 20, 2009
    Messages:
    364
  12. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,518
    change
    Code:
    if (bid ~= 0 and prize ~= 0 and not(getTileInfo(getCreaturePosition(cid)).pvp)) then
    db.query("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..getPlayerGUID(cid)..", `kill_time` = " .. os.time() .. " WHERE `id` = "..bid..";")
    
    to
    Code:
    if (bid ~= 0 and prize ~= 0 and (not creature:getTile():hasFlag(TILESTATE_PVPZONE))) then
    db.query("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..creature:getGuid()..", `kill_time` = " .. os.time() .. " WHERE `id` = "..bid..";")
    
     
  13. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    Are you sure your using the script from the first post? I don't see a getCreaturePosition on line 19 in the bh-kill script. o_O
     
  14. Tickit

    Tickit Member

    Joined:
    Feb 20, 2009
    Messages:
    364
    Nope I'm using the one you posted on this page ^ up there. Because I had the same problem as giddy92.

    EDIT: Used the correct code and now it worked. Wierd, I tested with that one b4.
     
    Last edited: Mar 17, 2015
  15. danalex07

    danalex07 New Member

    Joined:
    Aug 29, 2010
    Messages:
    14
    nice men, it works perfect
     
    imkingran likes this.
  16. Sir Knighter

    Sir Knighter ArchLight Developer Premium User

    Joined:
    Jun 29, 2009
    Messages:
    3,394
    Anyone end up making a Znote Version of the Php for this?
     
  17. Eldin

    Eldin Eldin Projects Premium User

    Joined:
    Jun 12, 2008
    Messages:
    1,259
    A simple talkaction in-game to see the hunted players and their price would be great as well. :)

    Kind Regards,
    Eldin
     
  18. Codex NG

    Codex NG Coding Junkie

    Joined:
    Jul 24, 2015
    Messages:
    2,874
    This is why there needs to be a standardized aac which utilizes an api similar to Joomla..
    https://api.joomla.org/cms-3/index.html

    Then there will be less questions like "is it compatible with x"
     
  19. Sir Knighter

    Sir Knighter ArchLight Developer Premium User

    Joined:
    Jun 29, 2009
    Messages:
    3,394
    Agreed.
     
  20. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    [​IMG]

    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 
     
    Eldin likes this.

Share This Page