• 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..";")
 
You have to remove the columns you deleted from the database. But its a bit more complicated than that because you will break the script.
 
You have to remove the columns you deleted from the database. But its a bit more complicated than that because you will break the script.

It isn't change this
PHP:
  db.executeQuery("UPDATE `bounty_hunters` SET `killed` = 1, `k_id`="..getPlayerGUID(cid)..", `kill_time` = " .. os.time() .. " WHERE `id`  = "..bid..";")

For a delete thing?
 
Better do bounty hunters based on storage

Why?
If is better, anyone could help me to do?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)     
NpcSystem.parseParameters(npcHandler)

local talkState = {}

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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
   return false   
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if msgcontains(msg:lower(), "list") then
   -- i dont know
elseif msgcontains(msg:lower(), "hunted, nametarget, price") 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
   local playertarget
   local price
   local storage = 2011174
   if getCreatureStorage(cid, storage ) < 1 then
       local newvalue = getCreatureStorage(cid, storage ) + price
       doCreatureSetStorage(playertarget, storage, newvalue)
   else
       doCreatureSetStorage(playertarget, storage, price)
   end
end

end  -- fim function
         

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Why?
If is better, anyone could help me to do?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)    
NpcSystem.parseParameters(npcHandler)

local talkState = {}

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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
   return false  
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if msgcontains(msg:lower(), "list") then
   -- i dont know
elseif msgcontains(msg:lower(), "hunted, nametarget, price") 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
   local playertarget
   local price
   local storage = 2011174
   if getCreatureStorage(cid, storage ) < 1 then
       local newvalue = getCreatureStorage(cid, storage ) + price
       doCreatureSetStorage(playertarget, storage, newvalue)
   else
       doCreatureSetStorage(playertarget, storage, price)
   end
end

end  -- fim function
        

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


I think it is impossible to show a list using this storage bounty hunt system
 
I think it is impossible to show a list using this storage bounty hunt system

I think again, and maybe it's possible to show players wanted online...
I think a loop to all players online and check the storage, but idk it's the best way to do, wait someone more experient
 
Code:
function onKill(cid, target)
if not isPlayer(target) then return TRUE end
if not isPlayer(cid) then return TRUE end
---- BOUNTY HUNTERS START -----
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
   doPlayerAddMoney(cid,prize/2)
   db.executeQuery("DELETE FROM `bounty_hunters` WHERE `sp_id`  = "..pid2..";")
   doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTERS] You killed hunted player, so you gained the reward!')
---- BOUNTY HUNTERS END -----
end
return TRUE
end
 
Code:
function onKill(cid, target)
if not isPlayer(target) then return TRUE end
if not isPlayer(cid) then return TRUE end
---- BOUNTY HUNTERS START -----
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
   doPlayerAddMoney(cid,prize/2)
   db.executeQuery("DELETE FROM `bounty_hunters` WHERE `sp_id`  = "..pid2..";")
   doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'[BOUNTY HUNTERS] You killed hunted player, so you gained the reward!')
---- BOUNTY HUNTERS END -----
end
return TRUE
end


Thank you!

I'm sorry, but how i need to edit the NPC script?
PHP:
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
       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())

Because i got this errors when i tried to add a new target and show list
Code:
[12:13:33.129] mysql_real_query(): SELECT * FROM `bounty_hunters` WHERE `sp_id` = 4 AND `killed` = 0; - MYSQL ERROR: Unknown column 'killed' in 'where clause' (1054)
[12:14:01.944] [8G]Tiago has logged in.
[12:21:24.230] mysql_real_query(): SELECT * FROM `bounty_hunters` WHERE `sp_id` = 4 AND `killed` = 0; - MYSQL ERROR: Unknown column 'killed' in 'where clause' (1054)
[12:21:31.379] mysql_real_query(): INSERT INTO `bounty_hunters` VALUES (NULL,2,4,0,1480429291,100000,0,0); - MYSQL ERROR: Column count doesn't match value count at row 1 (1136)

I think need change somethings in mysqls commands, but i scared to do some shit :S
 
Back
Top