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

Lua Bounty list on NPC

caquinha

Member
Joined
Aug 8, 2016
Messages
248
Solutions
1
Reaction score
24
I using this Bounty Hunter system:
https://otland.net/threads/bounty-hunters-system-player-hunt-system.27721/
With NPC system...
Just need website to check who is hunted, but its nothing RPG...

@Nothxbye made to show only player ID
When i say... hi, list show only: 1

Anyone know how to show:
Code:
PlayerName | Value | PlayerWhoPay\n

data/npc/script/bountyhunter.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, 'list')) then
local str = {}

local bountyList = db.getResult("SELECT * FROM `bounty_hunters` WHERE `id` > 0")
if(bountyList:getID() ~= -1) then
repeat
ids = tonumber(bountyList:getDataInt("id"))
table.insert(str, ids)
until not bountyList:next()
end

if str == nil then
npcHandler:say("No heads prize.", cid)
else
doShowTextDialog(cid, 2175, table.concat(str, ", "))
end
end
if (msgcontains(msg, 'hunted') or msgcontains(msg, 'yes') or msgcontains(msg, 'hunt')) and talkState[cid] == 0 then
if(getPlayerLevel(cid) < 50) then
selfSay('Oh man you are just a kid, come back after take level 50 or more!',cid)
talkState[cid] = 0
return true
end
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. Tell me, how much 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 > 100000000 then
selfSay('Sorry, the maximum amount of gold coins is 100.000.000.', cid)
elseif kwota < 10000 then
selfSay('Sorry, the minimum amount of gold coins is 10.000.', cid)
else
huntP[cid] = kwota
selfSay('Do you want to hunt the player {'..huntN[cid]..'} for {'..huntP[cid]..'} gold coins?', cid)
talkState[cid] = 3
end
elseif talkState[cid] == 3 then
if msgcontains(msg, 'yes') then
if doPlayerRemoveMoney(cid,huntP[cid]) then

if huntPlayer(cid,huntN[cid],huntP[cid]) == TRUE then
selfSay('You have added the hunt announcement of killing the player {'..huntN[cid]..'} for {'..huntP[cid]..'} 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())
 
No one know? I think its should be useful for every ot owners who use this system :(
I am sure people do know, they are just not eager to help someone who doesn't even try, no offense.

Rather than obtaining the list from an npc use the same window you would with spells, I believe that is how it is done in other versions? I don't know I have not even looked at the code you linked to.
 
I am sure people do know, they are just not eager to help someone who doesn't even try, no offense.

Rather than obtaining the list from an npc use the same window you would with spells, I believe that is how it is done in other versions? I don't know I have not even looked at the code you linked to.

No, it's not to easy...
This script got players ids in the TextDialog, need to convert that ids to player names...
If i knew how to do it there isnt reason to wait here for 10 days..
You are who even dont look the script, i just dont know how to do it /\
 
No, it's not to easy...
This script got players ids in the TextDialog, need to convert that ids to player names...
If i knew how to do it there isnt reason to wait here for 10 days..
You are who even dont look the script, i just dont know how to do it /\

In this function here the name of the player is passed which is converted to the GUID and stored in the database.
Code:
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
So now you just need to reverse that and you can use this function below to do that.
Code:
-- getPlayerNameByGUID(guid[, multiworld = false[, displayError = true]])
-- call it like this
getPlayerNameByGUID(guid)
 
Last edited:
In this function here the name of the player is passed which is converted to the GUID and stored in the database.
Code:
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
So now you just need to reverse that and you can use this function below to do that.
Code:
-- getPlayerNameByGUID(guid[, multiworld = false[, displayError = true]])
-- call it like this
getPlayerNameByGUID(guid)

I don't understand, how should work the sintaxy?

Code:
if (msgcontains(msg, 'list')) then
   local str = {}

   local bountyList = db.getResult("SELECT * FROM `bounty_hunters` WHERE `id` > 0")
   if(bountyList:getID() ~= -1) then
       repeat
       local bountyname = tonumber(bountyList:getDataInt("sp_id"))
       local payername = tonumber(bountyList:getDataInt("fp_id"))
       local price = tonumber(bountyList:getDataInt("prize"))
       table.insert(str, tostring("Player Hunted {".. bountyname .."} Hunted by: {"..payername.."} Reward: {"..price.."}.\n\n") )
       until not bountyList:next()
   end
   if str == nil then
       npcHandler:say("No heads prize.", cid)
   else
       doShowTextDialog(cid, 2175, table.concat(str, ", "))
   end
end
 
I don't understand, how should work the sintaxy?

Code:
if (msgcontains(msg, 'list')) then
   local str = {}

   local bountyList = db.getResult("SELECT * FROM `bounty_hunters` WHERE `id` > 0")
   if(bountyList:getID() ~= -1) then
       repeat
       local bountyname = tonumber(bountyList:getDataInt("sp_id"))
       local payername = tonumber(bountyList:getDataInt("fp_id"))
       local price = tonumber(bountyList:getDataInt("prize"))
       table.insert(str, tostring("Player Hunted {".. bountyname .."} Hunted by: {"..payername.."} Reward: {"..price.."}.\n\n") )
       until not bountyList:next()
   end
   if str == nil then
       npcHandler:say("No heads prize.", cid)
   else
       doShowTextDialog(cid, 2175, table.concat(str, ", "))
   end
end
Code:
getPlayerNameByGUID(bountyname)
getPlayerNameByGUID(payername)
 

Similar threads

Back
Top