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:
So, lets start with our functions: Go to your lib/functions.lua
At the buttom of the file, add this:
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:
Create a file named bounty.lua in talkactions/scripts
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:
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:
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:
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:
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++
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 )
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" />
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"/>
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>';
?>
All I want in return, is some REP++
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: