• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Wanted system!

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
This is a old script but still working on TFS 0.3.6, i neve had idea when i created it but i found in my pc today so i release it.

I am using luasql, becuase luasql is more safe, easy and fast than actual SQL system in tfs. So to use you have to download it:
http://mockthebear.googlecode.com/svn/trunk/Resources/luasql/luasql.rar

unpack all in your server root folder and in functions.lua add:
Code:
require('luasql.mysql')
or if you want just convert the script to actual TFS sql functions.

Now in data/lib create an file called wanted.lua
with this inside:
Lua:
---Script By Mock the bear  - [email][email protected][/email]
dofile("config.lua")
function connect_db()
	local env,con
	if sqlType == "mysql" then
		env = assert(luasql.mysql())
		con = assert(env:connect(sql_db or sqlDatabase, sql_user or sqlUser, sql_pass or sqlPass, sql_host or sqlHost, sql_port or sqlPort))
	elseif sqlType == 'sqlite' then
		env = assert(luasql.sqlite3())
		con = assert(env:connect(sql_db or sqliteDatabase or sqlFile))
	else
		error('You cant execute on XML mode.')
	end
	return	con,env
end

function addUser(cid,name,time,cost,hide)
	local hunted_id = assert(getPlayerGUIDByName(name),'Player dont found')
	local how_want = getPlayerGUID(cid)
	time = time or os.time()+3600*24*30
	cost = cost or 10000
	hide = hide or 0
	local con,env = connect_db()
	local _1,err = assert(con:execute(string.format([[INSERT INTO wanted (
`hunted_id` ,
`price` ,
`how_want` ,
`expire` ,
`hide`
)
VALUES (
'%d', '%d', '%d', '%d', '%d'
)
]],hunted_id,cost,how_want,time,hide)))
	con:close()
	env:close()
	return true

end

function returnWanted()
	local con,env = connect_db()
	local b = con:execute([[SELECT * FROM `wanted`]])
	local k = 1
	local back = {}
	local c = b:fetch({}, "a")
	if c then
		repeat
			table.insert(back,k,{hunted_id=c.hunted_id,price=c.price,how_want=c.how_want,expire=c.expire,hide=c.hide})
		if k > 20 then break end
		c = b:fetch({}, "a")
		until not c
		b:close()
		con:close()
		env:close()
	end
	return back
end

function checkWanted(i)
	local con,env = connect_db()
	local b = con:execute([[SELECT * FROM `wanted` WHERE `hunted_id`=']]..i..[[']])
	if not b then
		return false, con:close(),env:close()
	end
	local k = b:fetch({}, "a")
	b:close()
	if not k then
		return false, con:close(),env:close()
	end
	b:close()
	if k then
		return k, con:close(),env:close()
	end
end
function deleteWanted(i)
	local con,env = connect_db()
	local b,a = con:execute([[DELETE FROM `wanted` WHERE `hunted_id` = ]]..i..[[]])
	con:close()
	env:close()
	return b,a
end

Now in actions.lua add it:
Code:
<action itemid="1810" event="script" value="wanted_window.lua"/>
	<action itemid="1811" event="script" value="wanted_window.lua"/>

the item 1811 is an writeable black board and 1810 is only readable.
Better you check...
in wanted_window.lua add:
Lua:
function onUse(cid, item, frompos, item2, topos)
	if item.actionid ~= 0 then
		if item.itemid == 1810 then
			local k = returnWanted()
			local str = "Wanted peoples:\n\n"
			for i,b in pairs(k) do
				if tonumber(b.expire) >= os.time() then
					str = str..''..getPlayerNameByGUID(b.hunted_id)..' is wanted.\n  payment '..b.price..' GPs.\n  Expires: '..os.date('%d/%m/%y %H:%M:%S',tonumber(b.expire))..'\n'
				else
					local con,env = connect_db()
					local _1,err = assert(con:execute('DELETE FROM `limaosvrs`.`wanted` WHERE `wanted`.`hunted_id` = '..b.hunted_id))
					print(getPlayerNameByGUID(b.hunted_id)..' deleted.')
					con:close()
					env:close()
				end
			end
			doShowTextDialog(cid, 7726,str)
		else
			doPlayerPopupFYI(cid, 'Write here name of player to be wanted and reward. Like this:\nPlayer, 100000')
			return false
		end
	end
	return false
end

Now in creaturescripts.xml

Code:
<event type="textedit" name="wanted" event="script" value="wanted_window.lua"/>

in creaturescripts/scripts/wanted_window.lua add:
Lua:
--Script by mock
--  config
minPrice = 10000 -- 10k
expire_delay = 3600*24*30 -- 1 week
---

function onTextEdit(cid, item, newText)
	if item.itemid == 1811 and item.actionid ~= 0 then
		if newText:match('(.-)%s*,%s*(%d+).*') then
			local p,money = newText:match('(.-)%s*,%s*(%d+).*')
			local guid = getPlayerGUIDByName(p)
			if guid then
				if checkWanted(guid) then
					doPlayerPopupFYI(cid,'This guy its already wanted!')
				else
					money = tonumber(money) or minPrice
					if money < minPrice then
						doPlayerPopupFYI(cid,'The minimum reward is 10000.')
					else
						if getPlayerMoney(cid) >= money then
							if getPlayerGUIDByName(p) ~=  getPlayerGUID(cid) then
								doPlayerRemoveMoney(cid, money)
								addUser(cid,p,os.time()+expire_delay,money,1)
								doPlayerPopupFYI(cid,p..' now is wanted!\nReward to kill him is '..money..' GPs.')
							else
								doPlayerPopupFYI(cid,'You cannot hunt yourself.')
							end
						else
							doPlayerPopupFYI(cid,'You dont have to much money.')
						end
					end
				end
			else
				doPlayerPopupFYI(cid,p..' no such name.')
			end
		else
			doPlayerPopupFYI(cid, 'Please write like this:\nPlayer name, 5000')
		end
		return false
	else
		return true
	end
end



And in your preparedeath file just add this piece of code
Lua:
local w = checkWanted(getPlayerGUID(cid))
		if w and tonumber(w.expire) >= os.time() then
			local pl = {}
			for i,b in pairs(aa) do
				if isPlayer(b) then
					table.insert(pl,1,b)
				end
			end
			if #pl >= 1 then
				local money = tonumber(w.price)/#pl
				for i,b in pairs(pl) do
					doPlayerAddMoney(b,money)
					doPlayerSendTextMessage(b,25,'You killed  '..getCreatureName(cid)..' and taken '..math.floor(money)..' gps.')
				end
				deleteWanted(getPlayerGUID(cid))
			end
		end

Then run it on your DB
Code:
CREATE TABLE `wanted` (
`hunted_id` INT( 11 ) NOT NULL ,
`price` INT( 20 ) NOT NULL ,
`how_want` INT( 11 ) NOT NULL ,
`expire` INT( 11 ) NOT NULL ,
`hide` INT( 11 ) NOT NULL
) ENGINE = MYISAM ;



So then is easy to use. Create the two blackboards, onse side by side. In the first 1810 you use and see who is wanted. In the second you use and add it:


Player name, 10000
So will be taken 10k form your bag and will show in second backboard who is hunted by you. If some one kill him will receive the money.
 
Back
Top