• 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 Improved Bounty-Hunter System by Tufte

Tufte

Member
Joined
Nov 19, 2007
Messages
652
Reaction score
24
Location
Norway
Hello

Yesterday, I tried to implant the Bounty-Hunter system by masteuszx, but when I saw how it was scripted, I decided to create a new system, because I think it was very clumsy scripted.

First, do an sql-query with the following code:
Code:
CREATE TABLE IF NOT EXISTS `bounty_hunters` (
  `id` int(11) NOT NULL auto_increment,
  `player_name` varchar(50) collate utf8_unicode_ci NOT NULL,
  `hunted_by` varchar(50) collate utf8_unicode_ci NOT NULL,
  `killed_by` varchar(11) collate utf8_unicode_ci NOT NULL,
  `added` int(15) NOT NULL,
  `prize` int(11) NOT NULL,
  `kill_time` int(15) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

So, lets start with our functions: Go to your lib/functions.lua
At the buttom of the file, add this:
PHP:
function warnPlayer(cid, msg) 
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
    return doPlayerSendCancel(cid, msg) 
end

function setExhaust(cid, storage)
	setPlayerStorageValue(cid, storage, os.time())
end
 
function isExhausted(cid, storage, exhaust)
	local exhaustTime = getPlayerStorageValue(cid, storage)
	if exhaustTime == -1 then
		return FALSE
	end
	local isExhausted = os.time() - exhaustTime < exhaust
	return isExhausted and 1 or 0
end

function getHuntedPlayer(name)
local result = db.getResult("SELECT `player_name` FROM `bounty_hunters` WHERE `player_name` = " .. db.escapeString(name) .. " AND `kill_time` < 1")
	if result:getID() ~= LUA_ERROR then
		local name = result:getDataString "player_name"
		if name ~= nil then
			result:free()
			return name
		end	
	end	
	return LUA_ERROR
end

function getHuntedPlayerPrize(name)
local result = db.getResult("SELECT `prize` FROM `bounty_hunters` WHERE `player_name` = " .. db.escapeString(name) .. " AND `kill_time` < 1")
	if result:getID() ~= LUA_ERROR then
		local prize = result:getDataInt "prize"
		if prize ~= nil then
			result:free()
			return prize
		end	
	end	
	return LUA_ERROR
end

You might already have some of those functions, if you do, dont add them again.

Now we are ready to put the talkaction:
talkaction.xml:
PHP:
<talkaction words="!hunt" event="script" value="bounty.lua" />
Create a file named bounty.lua in talkactions/scripts
PHP:
function onSay(cid, words, param)
	if(param ~= "") then
	local data = string.explode(param, ",")
	local hunt = (data[1])
	local prize = (tonumber(data[2]))
		if(isExhausted(cid, 23003, 60) ~= 1) then
			if(playerExists(hunt) == TRUE and string.lower(hunt) ~= string.lower(getCreatureName(cid))) then
				if(isNumber(prize) == TRUE) then
					if(prize >= 100000) then
						if(doPlayerRemoveMoney(cid, prize) == TRUE) then
							if(getHuntedPlayer(string.lower(hunt)) == FALSE) then
								doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are hunting " .. hunt .. " for " .. prize .. " gold.")
								db.executeQuery("INSERT INTO `bounty_hunters` (`id` ,`player_name` ,`hunted_by` ,`killed_by` ,`added` ,`prize` ,`kill_time` )VALUES (NULL , '" .. hunt .. "', '" .. getPlayerName(cid) .. "', '', '" .. os.time() .. "', '" .. prize .."', '');")
								doBroadcastMessage(hunt .. " is being hunted by " .. getPlayerName(cid) .. " for " .. prize .. " gold. The first who is able to kill " .. hunt .. " will get the prize.", 22)
								doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
								setExhaust(cid, 23003)
								return TRUE
							else
								warnPlayer(cid, "This player is already hunted.")
							end
						else
							warnPlayer(cid, "You don't have enough cash.")
						end
					else
						warnPlayer(cid, "Minimum prize is 100 000 gold.")
					end
				else
					warnPlayer(cid, "Prize must be number.")
				end
			else
				warnPlayer(cid, "A player with this name does not exist.")
			end
		else
			warnPlayer(cid, "You must wait 60 seconds before adding a new bounty.")
		end
	else
		warnPlayer(cid, "You need the following param: !hunt [name],[prize]")
	end
	return TRUE
end

Now, the last thing we must do in with our otserver-files, is to add the kill script.

Go to your creaturescripts.xml and add the following line:
PHP:
	<event type="kill" name="BountyHunter" event="script" value="bounty.lua"/>
Then we need to registrer this event so the player will run this script when he kill someone. Go to your creaturescripts/login.lua and add this line whereever you want:
PHP:
registerCreatureEvent(cid, "BountyHunter")

Now, we are ready to add the kill-script. Go to creaturescripts/scripts and create a file called bounty.lua
Add the following code to this file:
PHP:
function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
	local killerName = getCreatureName(cid)
	local name = getHuntedPlayer(getCreatureName(target))
		if(name ~= FALSE) then
		local prize = getHuntedPlayerPrize(name)
			db.executeQuery("UPDATE `bounty_hunters` SET `killed_by` = " .. db.escapeString(killerName) .. ",`kill_time` = " .. os.time() .. " WHERE `player_name` = " .. db.escapeString(name))
			doPlayerAddMoney(cid, prize)
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
			doBroadcastMessage(killerName .. " killed " .. name .. " and received " .. prize .. " gold from the Bounty-Hunter!", 22)
		end
	end
	return TRUE
end

Now you can add players to the database, and when someone kill them, they will receive the money you placed on their head.

If you want a php-script for your AAC, create a file in your xampp/htdocs named bounty.php and past this code into the file:
PHP:
<?
$main_content .= '<P ALIGN=CENTER>
    <br>
    <FONT SIZE=5 COLOR=#CFF00C>
        How to use...
    </FONT>
    <br>
    <br>
    <FONT SIZE=2 COLOR=#CFF00C>
    * !hunt [nick], [prize] :
        <FONT SIZE=1 COLOR=#FCC33F>
            Example: !hunt Mark, 120000<br>
            Minimum prize is 100k [100 000 gp]
        </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>Hunted</B></center>
                </TD>
                <TD CLASS=white width=15%>
                    <center><B>Prize</B></center>
                </TD>
                <TD CLASS=white width=30%>
                    <center><B>Hunted By</B></center>
                </TD>
                <TD CLASS=white width=30%>
                    <center><B>Killed By</B></center>
                </TD>
            </TR>';
$inv = $SQL->query("SELECT * FROM `bounty_hunters` ORDER BY `added` DESC");
$num = 0;
$color=$config['site']['darkborder'];
	while($tab = ($inv->fetch())){
		if($num%2 == 0)
			{$color=$config['site']['darkborder'];}
		else
			{$color=$config['site']['lightborder'];}
		$hunted = $tab['player_name'];
		$hunted_by = $tab['hunted_by'];
		$killed_by = $tab['killed_by'];
		$prize = $tab['prize']/1000;
		$killed = $tab['kill_time'];




$main_content .= '
        <TR BGCOLOR="'.$color.'">
            <TD>
                <center>
                    <b>
                        <a href="index.php?subtopic=characters&name='.$hunted.'">'.$hunted.'</a>
                    </b>
                </center>
            </TD>
            <TD>
                <center>
                    <b>
                        '.$prize.' k
                    </b>
                </center>
            </TD>
            <TD>
                <center>
                    <b>
                        <a href="index.php?subtopic=characters&name='.$hunted_by.'">'.$hunted_by.'</a>
                    </b>
                </center>
            </TD>
            <TD>
                <center>
                    <b>
                        <a href="index.php?subtopic=characters&name='.$killed_by.'">'.$killed_by.'</a>
                    </b>
                </center>
            </TD>
        </TR>';
$num++;
}
if($num == 0){
        $main_content.='<TR BGCOLOR="'.$color.'">
            <TD colspan=4>
                <center>
                    So far noone is hunted on The Otserver.
                </center>
            </TD>
        </TR>';
}
        $main_content .='</TABLE>';
?>
The basics of the PHP script is created by masteuszx, so credits to him. I made it shorter and suitable for the new database. I also made so you dont need to write phpmyadmin data into the file.

All I want in return, is some REP++
:D


Enjoy the improved Bounty-Hunter script!

EDIT: For those who are having problems with sql results.. replace your whole lib/database.lua with mine:
(It will not affect other scripts, its just improved by Colandus )
PHP:
if(result == nil) then
	print("> WARNING: Couldn't load database lib.")
	return
end

Result = createClass(nil)
Result:setAttributes({
	id = -1
})

function Result:getID()
	return self.id
end

function Result:setID(_id)
	self.id = _id
end

function Result:getQuery()
	return self.query
end

function Result:setQuery(_query)
	self.query = _query
end

function Result:create(_query)
	self:setQuery(_query)
	local _id = db.storeQuery(self:getQuery())
	if(_id) then
		self:setID(_id)
	end

	return self:getID()
end

function Result:getRows(free)
	if(self:getID() == -1) then
		error("[Result:getRows]: Result not set!")
	end

	local c = 0
	while true do
		if not self:next() then
			break
		end
		
		c = c + 1
	end

	if(free) then
		self:free()
	end

	return c
end

function Result:getDataInt(s)
	if(self:getID() == -1) then
		error("[Result:getDataInt]: Result not set!")
	end

	return result.getDataInt(self:getID(), s)
end

function Result:getDataLong(s)
	if(self:getID() == -1) then
		error("[Result:getDataLong]: Result not set!")
	end

	return result.getDataLong(self:getID(), s)
end

function Result:getDataString(s)
	if(self:getID() == -1) then
		error("[Result:getDataString]: Result not set!")
	end

	return result.getDataString(self:getID(), s)
end

function Result:getDataStream(s)
	if(self:getID() == -1) then
		error("[Result:getDataStream]: Result not set!")
	end

	return result.getDataStream(self:getID(), s)
end

function Result:next()
	if(self:getID() == -1) then
		error("[Result:next]: Result not set!")
	end

	return result.next(self:getID())
end

function Result:free()
	if(self:getID() == -1) then
		error("[Result:free]: Result not set!")
	end

	local ret = result.free(self:getID())
	self:setID(-1)
	return ret
end

Result.numRows = Result.getRows
function db.getResult(query)
	if(type(query) ~= 'string') then
		return nil
	end

	local res = Result:new()
	res:setID(db.storeQuery(query))
	return res
end
 
Last edited:
So rep goes to you :)
BTW. Nice Tags xD
 
i have a bug in function

Lua:
data/lib/database.lua:76: [Result:getDataString]: Result not set!
stack traceback:
        [C]: in function 'error'
        data/lib/database.lua:76: in function 'getDataString'
        data/lib/function.lua:709: in function 'getHuntedPlayer'
        data/talkactions/scripts/moje/bh-t.lua:11: in function <data/talkactions/scripts/moje/bh-t.lua:1>
 
im using --> TFS 0.4.x Crying Damson Patch Level 2
and I added that script to my server, ... the problem is, when I say:

"!hunt PLAYERNAME,PRIZE"​

it just says "you have to wait 60 seconds before you can add a new bounty"

any ideas why it wont works well?



EDIT:

Sorry I made a mistake. Ive got TFS 0.3.4 Crying Damson Patch Level 2

and it doesnt works. plx help
 
Last edited:
im using --> TFS 0.4.x Crying Damson Patch Level 2
and I added that script to my server, ... the problem is, when I say:

"!hunt PLAYERNAME,PRIZE"​

it just says "you have to wait 60 seconds before you can add a new bounty"

any ideas why it wont works well?



EDIT:

Sorry I made a mistake. Ive got TFS 0.3.4 Crying Damson Patch Level 2

and it doesnt works. plx help

bump...
so? :D
 
i have a bug in function

Lua:
data/lib/database.lua:76: [Result:getDataString]: Result not set!
stack traceback:
        [C]: in function 'error'
        data/lib/database.lua:76: in function 'getDataString'
        data/lib/function.lua:709: in function 'getHuntedPlayer'
        data/talkactions/scripts/moje/bh-t.lua:11: in function <data/talkactions/scripts/moje/bh-t.lua:1>
So have i.

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/bounty.lua:onSay

data/lib/database.lua:76: [Result:getDataString] Result not set!
stack traceback:
        [C]: in function 'error'
        data/lib/database.lua:76: in function 'getDataString'
        data/lib/function.lua:686: in function 'getHuntedPlayer'
        data/talkactions/scripts/bounty.lua:11: in function <data/talkactions/scripts/bounty.lua:1>
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
nevermind, I saw in creaturescripts it already recognizes a target.
:huh:
 
So have i.

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/bounty.lua:onSay

data/lib/database.lua:76: [Result:getDataString] Result not set!
stack traceback:
        [C]: in function 'error'
        data/lib/database.lua:76: in function 'getDataString'
        data/lib/function.lua:686: in function 'getHuntedPlayer'
        data/talkactions/scripts/bounty.lua:11: in function <data/talkactions/scripts/bounty.lua:1>

have you created the table in your database?
 
What's new in this script? Maybe you fixed the thing with debugging website if player says very high price(f.e.-99999999999) when hunting someone?
 
have you created the table in your database?

Ofcourse i have. Also when i use creaturescripts, my players can't die, they stay on black hp. All i did was copy and paste the whole script into my ot folder, added the website and sql queries. Using 0.3.4pl2 so no idea why it wouldn't work.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
player not dying is either that you dont return true in a ondeath script, or an error which should appear in your console
 
i am using 0.3.4 and...

[31/07/2009 18:22:03] Lua Script Error: [TalkAction Interface]
[31/07/2009 18:22:03] data/talkactions/scripts/bounty.lua:eek:nSay

[31/07/2009 18:22:03] data/lib/database.lua:76: [Result:getDataString] Result not set!
[31/07/2009 18:22:03] stack traceback:
[31/07/2009 18:22:03] [C]: in function 'error'
[31/07/2009 18:22:03] data/lib/database.lua:76: in function 'getDataString'
[31/07/2009 18:22:03] data/lib/function.lua:664: in function 'getHuntedPlayer'
[31/07/2009 18:22:04] data/talkactions/scripts/bounty.lua:11: in function <data/talkactions/scripts/bounty.lua:1>
 
@Tufte

-- I make all you say and added table on my db, but when i use a command !hunt Player, Prize this dont work and send a error on console, see thath:
PHP:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/F@bio/bounty.lua:onSay

data/lib/database.lua:76: [Result:getDataString] Result not set!
stack traceback:
        [C]: in function 'error'
        data/lib/database.lua:76: in function 'getDataString'
        data/lib/function.lua:772: in function 'getHuntedPlayer'
        data/talkactions/scripts/F@bio/bounty.lua:11: in function <data/talkacti
ons/scripts/F@bio/bounty.lua:1>

-- Plx help me to fix this for work fine... many thx...

Obs.: I'm using TFS 034-pl2
 
Thats pretty cool im trying to get the hunt system so it runs with my website :p
 
Back
Top