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

Delete from mysql when kill

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
Looking this system:
https://otland.net/threads/bounty-list-on-npc.246375/

I saw 3 things unnecessary saved on DB
Who Kill
Who kill id again
Date when have killed

So i delete it from MYSQL
Using:
PHP:
ALTER TABLE `bounty_hunters` DROP `kill_time`;
ALTER TABLE `bounty_hunters` DROP `killed`;
ALTER TABLE `bounty_hunters` DROP `k_id`;

Now what i need to change here in onkill event script to dont save this things and delete
PHP:
function onKill(cid, target)
if isPlayer(target) == TRUE then
---- BOUNTY HUNTERS START -----
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/2)
   doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTERS] You killed hunted player, so you gained the reward!')
end  
---- BOUNTY HUNTERS END -----
end
return TRUE
end

It's just changes here?
PHP:
db.executeQuery("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..getPlayerGUID(cid)..", `kill_time` = " .. os.time() .. " WHERE `id`  = "..bid..";")
 
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,"..cost..");")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())
 
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,"..cost..");")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())

Thank you!
 
It's incomplete...
Anyone could help me to complete?

I make it looking in others codes, but it's not work, where i fail?

Code:
ALTER TABLE `bounty_hunters` CHANGE `added` `date` INT(15) NOT NULL;

bountyhunters.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..","os.time()","..cost..");")
  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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())

Code:
function onStartup()
    local result = db.getResult("SELECT `id`, `fp_id`, `sp_id`, `date`,  `prize`  FROM `bounty_hunters` ORDER by `date` ASC;")
    local days = 1*3600*1
    --local days = 30*3600*24
    local nowtime = os.date('*t')
    if(result:getID() ~= -1) then
        while(true) do
            local id = result:getDataInt("id")
            local date = result:getDataInt("date")
            local player = result:getDataInt("fp_id")
            local prize = result:getDataInt("prize")
            local time = os.time(nowtime) - date
            local duedate = time - days
            if duedate >= 0 then
                -- send money back
                local tid = getPlayerByGUID(buy:getDataInt("player"))
                if(isPlayer(tid)) then
                    doPlayerSetBalance(tid, getPlayerBalance(tid) + prize)
                else
                    db.executeQuery("UPDATE `players` SET `balance` = `balance` + " .. prize .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
                end
                -- delete item
                db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
            end
            if not(result:next()) then
                break
            end
        end
        result:free()
    end
end
 
NPC with date
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..","..os.date()..,"..cost..");")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())
 
NPC with date
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..","..os.date()..,"..cost..");")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())

You just change him os.time for os.date?
Whats the right?

You know how to make that globalevent to clean?
 
Alright, try this out.

NPC
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..","..os.date("*t")..,"..cost..");")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())
 
Code:
[15:48:44.615] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.615] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.615] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.669] [Spawn::addMonster] Cannot find "Hellish Tortoise"
[15:48:44.688] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.688] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.688] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.740] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','

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..","..os.date("*t")..,"..cost..")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())
 
Code:
[15:48:44.615] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.615] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.615] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.669] [Spawn::addMonster] Cannot find "Hellish Tortoise"
[15:48:44.688] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.688] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.688] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.740] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','

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..","..os.date("*t")..,"..cost..")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())


???
 
Code:
[15:48:44.615] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.615] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.615] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.669] [Spawn::addMonster] Cannot find "Hellish Tortoise"
[15:48:44.688] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.688] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.688] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.740] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','

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..","..os.date("*t")..,"..cost..")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())

???
 
Code:
[15:48:44.615] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.615] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.615] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.669] [Spawn::addMonster] Cannot find "Hellish Tortoise"
[15:48:44.688] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.688] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.688] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Error - LuaInterface::loadFile] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','
[15:48:44.740] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/bountyhunters.lua
[15:48:44.740] data/npc/scripts/bountyhunters.lua:41: unexpected symbol near ','

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..","..os.date("*t")..,"..cost..")
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
       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 {".. getPlayerNameByGUID(bountyname) .."} Hunted by: {"..getPlayerNameByGUID(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

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())

???
 
Back
Top