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

TalkAction Bounty Hunters System (Player Hunt System)

masteuszx

OtsList.eu
Joined
Aug 3, 2008
Messages
784
Reaction score
45
The Forgotten Server 0.3+ !

Hello guys! :p

When I realised, that there is no one script like this, I decided to paste it here. This script is 100% by me!

This script work when someone type !hunt [prize],[nick]. Money are taken automatically and who kill victim, he gain the prize :D

Let`s start!

SQL Code:
Code:
CREATE TABLE IF NOT EXISTS `bounty_hunters` (
  `id` int(11) NOT NULL auto_increment,
  `fp_id` int(11) NOT NULL,
  `sp_id` int(11) NOT NULL,
  `k_id` int(11) NOT NULL,
  `added` int(15) NOT NULL,
  `prize` bigint(20) NOT NULL,
  `killed` int(11) NOT NULL,
  `kill_time` int(15) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Create file bh-add.lua in talkactions/scripts and paste into
Code:
function onSay(cid, words, param)
if(param == "") then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Use: \"!hunt [prize],[nick]\" where prize is for example 1(k).")
		return TRUE
	end
	local t = string.explode(param, ",")
	if(not t[2]) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Use: \"!hunt [prize],[nick]\" where prize is for example 1(k).")
		return TRUE
	end
	
	local sp_id = getPlayerGUIDByName(t[2])
	if sp_id == nil then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] This player doesn't exists.")		
		return TRUE
	end
	
    local result_plr = db.getResult("SELECT * FROM `bounty_hunters` WHERE `sp_id` = "..sp_id.." AND `killed` = 0;")
    if(result_plr:getID() ~= -1) then
		is = tonumber(result_plr:getDataInt("sp_id"))
		result_plr:free()
    else
		is = 0
    end
    prize = tonumber(t[1])

	if(prize == nil or prize < 1) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Use: \"!hunt [prize],[nick]\" where prize is for example 1(k).")
		return TRUE
	end
	
	if(prize >= 100000000000000000000) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Sorry, you typed too big number!")
		return TRUE
	end

	if is ~= 0 then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] This player has already hunted.")	
		return TRUE
	end
	
		if doPlayerRemoveMoney(cid, prize*1000) == TRUE then
		    db.executeQuery("INSERT INTO `bounty_hunters` VALUES (NULL,"..getPlayerGUID(cid)..","..sp_id..",0," .. os.time() .. ","..prize..",0,0);")
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Hunt has been added!")			
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] You haven't got enough money!")			
		end
	
	
	return 1
end

Open file creaturescripts.xml in creaturescripts, add inside:
Code:
<event type="kill" name="BountyHunter" script="kill.lua"/>

Open file login.lua in creaturescripts/scripts and after
Code:
	registerCreatureEvent(cid, "PlayerDeath")
paste
Code:
	registerCreatureEvent(cid, "BountyHunter")

Open file kill.lua, or create him in creaturescripts/scripts
and paste inside this:
Code:
function onKill(cid, target)
if isPlayer(target) == TRUE then
---- BOUNTY HUNTERS START -----
pid = cid
pid2 = getPlayerGUID(target)
    local result_plr = db.getResult("SELECT * FROM `bounty_hunters` WHERE `sp_id` = "..pid2.." AND `killed` = 0;")
    if(result_plr:getID() ~= -1) then
    prize = tonumber(result_plr:getDataInt("prize"))
    bid = tonumber(result_plr:getDataInt("id"))
	result_plr:free()
    else
    prize = 0
	bid = 0
    end

if (bid ~= 0 and prize ~= 0 and not(getTileInfo(getCreaturePosition(cid)).pvp)) then
    db.executeQuery("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..getPlayerGUID(cid)..", `kill_time` = " .. os.time() .. " WHERE `id`  = "..bid..";")
	doPlayerAddMoney(cid,prize*1000)
	doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTERS] You killed hunted player, so you gained the reward!')
end	
---- BOUNTY HUNTERS END -----
end
return TRUE
end

Open file talkactions.xml in talkactions and paste inside
Code:
<talkaction access="0" log="no" filter="word" words="!hunt" script="bh-add.lua" />

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Commands:
!hunt [prize],[nick]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bounty Hunters on WWW
It will work on all Account makers

Create file bounty-hunters.php and paste inside:
Code:
   <?php
@mysql_connect("localhost","user","password");
@mysql_select_db("database");

$main_content .= '<P ALIGN=CENTER>
    <br>
    <FONT SIZE=5 COLOR=#CFF00C>
        How to use...
    </FONT>
    <br>
    <br>
    <FONT SIZE=2 COLOR=#CFF00C>
    * !hunt [prize],[nick] :
        <FONT SIZE=1 COLOR=#FCC33F>
            Wysyla ogloszenie o huncie dla postaci. Cena w tysiacach.<br>
            Przyklad: !hunt 100,Infinity
        </FONT><br>
    </FONT>
</P>
<br>
<br>
    <center>
        <h1>
            Bounty Hunters
        </h1>
    </center>
        <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
            <TR BGCOLOR="#505050">
                <TD CLASS=white width=30%>
                    <center><B>Zlecil</B></center>
                </TD>
                <TD CLASS=white width=30%>
                    <center><B>Nagroda</B></center>
                </TD>
                <TD CLASS=white width=30%>
                    <center><B>Ofiara</B></center>
                </TD>
                <TD CLASS=white width=10%>
                    <center><B>Zabity przez</B></center>
                </TD>
            </TR>';
 $inv = @mysql_query("SELECT * FROM `bounty_hunters` ORDER BY `added` DESC");
$num = 0;
$color=$config['site']['darkborder'];
while($tab = @mysql_fetch_array($inv)){
if($num%2 == 0){$color=$config['site']['darkborder'];}else{$color=$config['site']['lightborder'];}
$pid = $tab['fp_id'];
$sid = $tab['sp_id'];
$kid = $tab['k_id'];
$killed = $tab['killed'];
$prize = $tab['prize']*1000;
if($killed == 0){
$kill = '<font color="red">Nobody!</font>';
}else{
$k = @mysql_query("SELECT * FROM `players` WHERE `id` = ".$kid."");
$k1 = @mysql_fetch_array($k);
$kill_name = $k1['name'];
$kill = '<a href="index.php?subtopic=characters&name='.$kill_name.'">'.$kill_name.'</a>';
}
$f = @mysql_query("SELECT * FROM `players` WHERE `id` = ".$pid."");
$f1 = @mysql_fetch_array($f);
$s = @mysql_query("SELECT * FROM `players` WHERE `id` = ".$sid."");
$s1 = @mysql_fetch_array($s);
$fn = $f1['name'];
$sn = $s1['name'];

$main_content .= '
        <TR BGCOLOR="'.$color.'">
            <TD>
                <center>
                    <b>
                        <a href="index.php?subtopic=characters&name='.$fn.'">'.$fn.'</a>
                    </b>
                </center>
            </TD>
            <TD>
                <center>
                    <b>
                        '.$prize.' gp
                    </b>
                </center>
            </TD>
            <TD>
                <center>
                    <b>
                        <a href="index.php?subtopic=characters&name='.$sn.'">'.$sn.'</a>
                    </b>
                </center>
            </TD>
            <TD>
                <center>
                    <b>
                        '.$kill.'
                    </b>
                </center>
            </TD>
        </TR>';
$num++;
}
if($num == 0){
        $main_content.='<TR BGCOLOR="'.$color.'">
            <TD colspan=4>
                <center>
                    Currently there are not any bounty hunter offer.
                </center>
            </TD>
        </TR>';
}
        $main_content .='</TABLE><div align="right">Copyright &copy; <a href="http://otibia.net">oTibia.net</a>.</div>';
?>

After, open index.php and after:
PHP:
    case "guilds";
        $topic = "Guilds";
        $subtopic = "guilds";
        include("guilds.php");
    break;
paste this

PHP:
    case "bounty-hunters";
        $topic = "Bounty Hunters";
        $subtopic = "characters";
        include("bounty-hunters.php");
    break;

Open the file layout.php in layouts/tibiacom and then find:
Code:
<a href='index.php?subtopic=guilds'>
  <div id='submenu_guilds' class='Submenuitem' onMouseOver='MouseOverSubmenuItem(this)' onMouseOut='MouseOutSubmenuItem(this)'>
    <div class='LeftChain' style='background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);'></div>

    <div id='ActiveSubmenuItemIcon_guilds' class='ActiveSubmenuItemIcon' style='background-image:url(<?PHP echo $layout_name; ?>/images/menu/icon-activesubmenu.gif);'></div>
    <div class='SubmenuitemLabel'>Guilds</div>
    <div class='RightChain' style='background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);'></div>
  </div>

and after add:
Code:
<a href='index.php?subtopic=bounty-hunters'>
  <div id='submenu_bounty' class='Submenuitem' onMouseOver='MouseOverSubmenuItem(this)' onMouseOut='MouseOutSubmenuItem(this)'>
    <div class='LeftChain' style='background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);'></div>

    <div id='ActiveSubmenuItemIcon_biunty' class='ActiveSubmenuItemIcon' style='background-image:url(<?PHP echo $layout_name; ?>/images/menu/icon-activesubmenu.gif);'></div>
    <div class='SubmenuitemLabel'>Bounty Hunters</div>
    <div class='RightChain' style='background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);'></div>
  </div>

And its all.
In first file you have to edit MySQL settings for connection!



WARNING! Bounty Hunter System will not work with SQLite! (only MySQL)

NPC Punisher - good for RPG OTServers
This NPC adds announcements to the website instead of command!

data/npc/Punisher.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Punisher" script="data/npc/scripts/bountyhunters.lua" walkinterval="2000" floorchange="3">
	<health now="150" max="150"/>
	<look type="9" head="0" body="0" legs="0" feet="0" addons="0"/>
	<parameters>
		<parameter key="message_greet" value="Hello! I can announce to other people some offers of hunting players. Of course you have to pay. Do you want to hunt somebody today?" />
	</parameters>
</npc>

data/npc/scripts/bountyhunters.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                         npcHandler:onThink() end
-- OTServ event handling functions end
local talkState = {}
local huntN = {}
local huntP = {}

local function checkName(player)
	local sp_id = getPlayerGUIDByName(player)
	if sp_id == nil then
		return FALSE
	end
	
	local id = 0
	local result_plr = db.getResult("SELECT * FROM `bounty_hunters` WHERE `sp_id` = "..sp_id.." AND `killed` = 0;")
    if(result_plr:getID() ~= -1) then
		id = tonumber(result_plr:getDataInt("sp_id"))
		result_plr:free()
    end
	
	if id ~= sp_id then
		return TRUE
	end
return FALSE
end

local function huntPlayer(cid,player,cost)
local guid = tonumber(getPlayerGUID(cid))
local player = tonumber(getPlayerGUIDByName(player))
local cost = tonumber(cost)

if guid == nil or player == nil or cost == nil then 
	return FALSE
end
	db.executeQuery("INSERT INTO `bounty_hunters` VALUES (NULL,"..guid..","..player..",0," .. os.time() .. ","..cost..",0,0);")
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Hunt has been added successfuly!")
	return TRUE
end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
if(not(npcHandler:isFocused(cid))) then
	return false
end
	if talkState[cid] == nil then
		talkState[cid] = 0
	end
        if (msgcontains(msg, 'tak') or msgcontains(msg, 'yes') or msgcontains(msg, 'hunt')) and talkState[cid] == 0 then
			selfSay('Oh, you want to kill somebody, don`t you? Tell me, what is his name.',cid)
			talkState[cid] = 1
		elseif talkState[cid]==1 then
			talkState[cid] = 0
			if checkName(msg) == TRUE then
				huntN[cid] = msg
				selfSay('Okay. You can hunt him. Tell me, how much {thousands} {of} {gold} {coins} will you pay to the killer.',cid)
				talkState[cid] = 2
			else
				selfSay('Sorry, this player is already hunted or does not exist. Really sorry!',cid)
			end
		elseif talkState[cid] == 2 then
				talkState[cid] = 0
				kwota = tonumber(msg)
				if kwota == nil then
					selfSay('What? I don`t understand you.', cid)
				elseif kwota > 10000000 then
					selfSay('Sorry, the maximum amount of gold coins is 10 000 000K.', cid)
				elseif kwota < 1 then
					selfSay('Sorry, the minimum amount of gold coins is 1 000.', cid)
				else
					huntP[cid] =  kwota
					selfSay('Do you want to hunt the player {'..huntN[cid]..'} for {'..huntP[cid]..'K} gold coins?', cid)
					talkState[cid] = 3
				end
		elseif talkState[cid] == 3 then
					if msgcontains(msg, 'yes') then
						if doPlayerRemoveMoney(cid,huntP[cid]*1000) then
						
						if huntPlayer(cid,huntN[cid],huntP[cid]*1000) == TRUE then
							selfSay('You have added the hunt announcement of killing the player {'..huntN[cid]..'} for {'..huntP[cid]..'K} gold coins!', cid)
							else
								selfSay('Maybe next time.',cid)
							end

						else
							selfSay('Sorry, you do not have enough money. Maybe next time!',cid)
						end
					else
						selfSay('Maybe next time.',cid)
					end
					talkState[cid]=0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Thanks! ;)

[TODO]
Bounty Hunters in Account Maker (100%)
NPC Punisher (100%)
~~
Waiting for suggestions.

I can update this, but you must suggest me, what is needed ;)

Yours,
Infinity


Fixed problem with script on www!

8 August
Improved some bugs in script.
Added NPC Punisher

All credits to me (http://otibia.net).
 
Last edited:
Very nice, I can see a whole lot other uses for a script like this, thanks for sharing :) rep++
 
I fixed the problem with script on www. Now it's working fine (I think). If any extra function is needed, just write about this here. :>
 
In my script there is no bugs, it only depends on other things like background of your site and just all page. I will change one thing in script (automatic colors from layout settings)

It is fine, I think :|
 
i got an error!

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Niklas\documents\xampplite\htdocs\bounty-hunters.php on line 41
 
i got an error!

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Niklas\documents\xampplite\htdocs\bounty-hunters.php on line 41

edit this to your data.

Code:
mysql_connect("localhost","user","password");
mysql_select_db("database");
 
Well, it's working.. but not all of it.

I write in-game;
17:40 Mies: !hunt,100 Hans
17:40 [BOUNTY HUNTERS] Hunt has been added!

Then I check the website;
"Currently there are not any bounty hunter offers."

Then I check the phpmyadmin, and it clearly does show the line.
5 268458299 23 0 1238427646 100 0 0

When I kill the target, I do receive the cash... but the website is really important to see which targets are available..

Hope you can help me, since it's a great system!

Sincerely,
UpAndDown!
 
Ah yeah, I knew that! :p
Well I recopied, and now everything is working perfectly. Thanks alot!
 
everything almost OK but into sp_id it doesnt add player id that made hunt

@edit
PHP:
fp_id = getPlayerGUID(cid)
db.executeQuery("INSERT INTO `bounty_hunters` VALUES (NULL,"..fp_id..","..sp_id..",0," .. os.time() .. ","..prize..",0,0);")
 
Last edited:
and in creturescripts/scripts/kill.lua it should be

PHP:
kill_id = getPlayerGUID(cid)
    db.executeQuery("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..kill_id..", `kill_time` = " .. os.time() .. " WHERE `id`  = "..bid..";")
 
Ahh, awesome release. Been looking for this a long while.

I want to return and become active again. :(
 
Everything works fine excepot one thing, I got problem with the "Bounty Hunters" section showing in my website. Any idea how to fix that? Btw, Nice script and rep++ ofc!
 
Last edited:
I say !hunt 1000, adam

and I get no response what so ever?

Not sure what I did wrong can anyone help? Iam using tfs mystic spirt
 
Back
Top