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

Help With MySQL!

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
I create a table called `hunts` with `id`, `player_hunted`, `hunted_by` and `hunt_price`.

I've used this code:

Code:
CREATE TABLE `hunts` (
  `id` int(11) NOT NULL,
  `player_hunted` varchar(255) NOT NULL,
  `hunted_by` varchar(255) NOT NULL,
  `hunt_price` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

This table was created to save if a players is hunted (With a command like Bounty Hunter System), for example if my player name is Darkhaos, and i want to hunt Elite Kox for 100,000 gold coins, then i say "!hunt Elite Kox, 100000" <- it saves this in the table: ["`id` = getPlayerGUID(target), `player_hunted` = Elite Kox, `hunted_by` = Darkhaos, `hunt_price` = 1000000]. All of this works perfectly but.. only with the first hunt.. because if other player want to hunt Elite Kox and say the command, this appear in the console:

Code:
mysql_real_query(): INSERT INTO `hunts` (`id`, `player_hunted`, `hunted_by`, `hunt_price`) VALUES (2, 'Elite Kox', 'DarkCartman', 60000); - MYSQL ERROR: Duplicate entry '2' for key 'PRIMARY'

These are the function that i'm using:
Code:
function getPlayerHuntPrice(cid)
    local Info = db.getResult("SELECT `hunt_price` FROM `hunts` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
        if Info:getID() ~= LUA_ERROR then
        local Price= Info:getDataInt("hunt_price")
        Info:free()
        return Price
    end
     return LUA_ERROR
end

function doPlayerAddHuntPrice(cid, price, hunter)
    local dif = getPlayerHuntPrice(cid) + price
    if dif >= 0 then
	db.executeQuery("INSERT INTO `hunts` (`id`, `player_hunted`, `hunted_by`, `hunt_price`) VALUES (" .. getPlayerGUID(cid) .. ", " .. db.escapeString(getCreatureName(cid)) .. ", " .. db.escapeString(hunter) .. ", " .. dif .. ");")
        return TRUE
    end
    return FALSE
end

Who can help me?

Note: I need a table as the one that mentions, that save the hunted players, the hunter and the price, this way to create a talkaction-script that shows the hunted players and his prices.
 
Back
Top