• 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 Perfect Bounty Hunters System with PHP for M-AAC (TFS 0.4)

Pheenix

Mr.Plain Awesome
Joined
Mar 28, 2011
Messages
152
Reaction score
14
Location
Sweden
This is my First "Release" so be gentle :$



Most of the code is copied from http://otland.net/f81/bounty-hunters-system-player-hunt-system-27721/ <-- Awesome, i just altered it a bit :rolleyes:

This script will be put in action when someone types !hunt,/hunt,!bounty,/bounty [prize],[nick].

Gold will be automatically subtracted from the player(1) who is putting the bounty on the other players(2) head and the player(3) who kills the bountied player(2) will get the bounty automatically.

Lets get started!

Goto your otserver database in phpmyadmin and add the following query:
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;

It should look like this:

sql.png


Press Go and if the result is:

sql1.png


Move on to the next step.. \/

Go to /tfs/data/creaturescripts/scripts/ and create a file named bounty.lua

Open bounty.lua and paste this:
Code:
function onKill(cid, target) 
if isPlayer(target) == TRUE then 
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)
	doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,"[Bounty System]: You killed "..getPlayerName(target).."! You gained the bounty that was put on his/her head!")
	doSendMagicEffect(getCreaturePosition(cid), 27) 
	doBroadcastMessage("[Bounty System]: "..getPlayerName(cid).." killed "..getPlayerName(target).." and gained the bounty! ("..prize.." gold)", MESSAGE_EVENT_ADVANCE)
end
end return TRUE
end

Save file.


Go to /tfs/data/creaturescripts/scripts/ and open login.lua

in login.lua find this line:
Code:
	registerCreatureEvent(cid, "GuildMotd")
and after it add a line with this:
Code:
	registerCreatureEvent(cid, "Bounty")

Save file.

Go to /tfs/data/creaturescripts/ and open creaturescripts.xml

in creaturescripts.xml find:
Code:
	<event type="login" name="PlayerLogin" event="script" value="login.lua"/>
and after it add:
Code:
	<event type="kill" name="Bounty" script="bounty.lua"/>

Save file.

Done with creaturescripts. Lets move on to talkactions!



Go to /tfs/data/talkactions/scripts/ and create a file called tbounty.lua

Open tbounty.lua and paste this:
Code:
function onSay(cid, words, param)
if(param == "") then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Bounty System]: Usage: \"!bounty [gold],[nick]\" where gold is at least 10000.")
		return TRUE
	end
	local t = string.explode(param, ",")
	if(not t[2]) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Bounty System]: Usage: \"!bounty [gold],[nick]\" where gold is at least 10000.")
		return TRUE
	end
	
	local sp_id = getPlayerGUIDByName(t[2])
	if sp_id == nil then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Bounty System]: You cant put a bounty on imaginary people, your target doesn't exist.")
		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 < 10000) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Bounty System]: Usage: \"!bounty [gold],[nick]\" where gold is at least 10000.")
		return TRUE
	end
	
	if(prize >= 999999999) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[Bounty System]: Sorry, bounty limit is at 999.9 million gold!")
		return TRUE
	end if is ~= 0 then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "[Bounty System]: "..t[2].." has already got a bounty on his/her head.")
		return TRUE
	end
	
		if doPlayerRemoveMoney(cid, prize) == 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_RED, "[Bounty System]: Bounty on "..t[2].."s head has been added successfully!")
			doBroadcastMessage("[Bounty System]: A bounty of "..prize.." gold for "..t[2].."s head has been submitted by "..getPlayerName(cid)..". The first one to kill "..t[2].." will get the gold!", MESSAGE_EVENT_ADVANCE)
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[Bounty System]: You dont have enough gold!")
		end
	
	
	return 1
end

Save file.

go to /tfs/data/talkactions/ and open talkactions.xml

find the line saying:
Code:
 	<!-- Players -->
and after it add:
Code:
	<talkaction words="/bounty;!bounty;!hunt;/hunt" script="tbounty.lua" />

Save file.


If you dont have any <!-- Players --> line, just paste it wherever you want between <talkactions> and </talkactions>.

ex.
Code:
<talkactions>
	<talkaction words="/bounty;!bounty;!hunt;/hunt" script="tbounty.lua" />
</talkactions>

Done!

Now try it!

Error Codes:

bountyc1.png



Successfully added bounty:
successl.png


Bountied player killed:

killed.png


M-AAC Page

Go to your MAAC homepage, login and enter administration, click pages, create a new page called bountysystem and paste this in the text field:
PHP:
<?php

#########################
# BOUNTY HUNTERS SCRIPT #
#  MADE FOR MODERN AAC  #
#      BY ARCHEZ        #
#########################
#  HTTP://ARCHEZOT.COM  #
#########################
#  RESPECT THE CREDITS  #
#########################

require("config.php");
$ots = POT::getInstance();
$ots->connect(POT::DB_MYSQL, connection());
$SQL = $ots->getDBHandle();

# Tables
$a = '#c6c6c6';
$b = '#d5d5d5';
$c = '#e4e4e4';

# Data
$list = $SQL->query('SELECT * FROM `bounty_hunters` ORDER by `id` DESC');

echo '<table border="0" cellspacing="1" width="100%">
<tr bgcolor="'.$a.'"><td width="3%">#</td><td width="20%"><b>Hunted by</b></td><td width="15%" colspan="2"><b>Reward</b></td><td width="20%"><b>Hunted player</b></td><td width="20%"><b>Killed by</b></td></tr>';

$datalist = 0;
foreach($list as $data) {
    if(is_int($datalist / 2))
        $bgcolor = $b;
            else
        $bgcolor = $c;
$datalist++;

$huntedby = $SQL->query('SELECT * FROM `players` WHERE `id` = '.$data['fp_id'].'')->fetch();
$huntedplayer = $SQL->query('SELECT * FROM `players` WHERE `id` = '.$data['sp_id'].'')->fetch();
$killedby = $SQL->query('SELECT * FROM `players` WHERE `id` = '.$data['k_id'].'')->fetch();

if($killedby == 0) { $killedby['name'] = 'STILL ALIVE'; }

echo '<tr bgcolor="'.$bgcolor.'"><td><span style="font-size:11px;color:#a8a8a8;">'.$datalist.'</span></td><td><a href="/index.php/character/view/'.strtolower($huntedby['name']).'"><span style="font-size:11px;">'.strtoupper($huntedby['name']).'</span></a></td><td><span style="font-size:11px;color:#909090;">'.$data['prize'].'</span></td><td><span style="font-size:11px;">GOLD</span></td><td><a href="/index.php/character/view/'.strtolower($huntedplayer['name']).'"><span style="font-size:11px;">'.strtoupper($huntedplayer['name']).'</a></td><td><a href="/index.php/character/view/'.strtolower($killedby['name']).'"><span style="font-size:11px;">'.strtoupper($killedby['name']).'</a></td></tr>';
}
echo '</table>';

?>

Press Edit Page. (PHP script from: http://otland.net/f118/modern-aac-bounty-hunters-91623/)

Go to the root folder of your maac ex. /www/ and open config.php, Search for: /*Restricted Names*/ and add "still alive"


And voila, page is done.

The link to view the page is:
Code:
http://yourwebsite.com//index.php/p/v/bountysystem

or if you want to create a link in your template:
Code:
{$site}/index.php/p/v/bountysystem


Rep++? :rolleyes: Post here if you get any errors.
 
Last edited:
Can you change PHP colours? like not all white, like all different colours =p

Code:
# Tables
$a = '#c6c6c6';
$b = '#d5d5d5';
$c = '#e4e4e4';

'<tr bgcolor="'.$bgcolor.'"><td><span style="font-size:11px;color:#a8a8a8;">'.$datalist.'</span></td><td><a href="/index.php/character/view/'.strtolower($huntedby['name']).'"><span style="font-size:11px;">'.strtoupper($huntedby['name']).'</span></a></td><td><span style="font-size:11px;color:#909090;">


all codes with #somenumbers/letters is colors, you can change them to any color you want (must be #hexadecimal)
 
Shoop da whoop, any improvements i can make? Any suggestions?
 
Aff, when people die don't recive his reward and the website doesn't works too. appears that in console:

Code:
[05/09/2011 19:23:04] mysql_real_query(): SELECT * FROM `bounty_hunters` WHERE `sp_id` = 46 AND `killed` = 0; - MYSQL ERROR: Unknown column 'sp_id' in 'where clause' (1054)
[05/09/2011 19:23:04] mysql_real_query(): INSERT INTO `bounty_hunters` VALUES (NULL,44,46,0,1315243384,10000,0,0); - MYSQL ERROR: Column count doesn't match value count at row 1 (1136)
 
i tried it but im getting target does not exit.
!bounty [10000], [Killme]
/bounty [10000], [Killme]
!hunt
 
is there a way to make a command thats like !bountylist and it will show Everyonewho has a bounty, prize, and the person who put the bounty out ?
So example
!bountylist
Mastermind, 100000gp, Issued by Jill
 
Back
Top