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

[Error - mysql_real_query] Message: Duplicate entry '5' for key 'guildwar_kills_unique'

kubqq

Xyntera Global 8.60 - in progress
Joined
Aug 12, 2009
Messages
74
Solutions
1
Reaction score
4
Location
Sweden
Hello.
I have next problem with my war system.
I can invite, accept wars in game. Also on website is okey, but for example:

I make war between guild "Guild One" and "Guild Two"
War is accepted.
Player from Guild One kill player from Guild Two - The first score on website is added (1:0)
When I come back second player (from Guild Two) and Kill player from Guild One I dont have change in score on war and also have this error in console:

Lua:
[Error - mysql_real_query] Query: INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES ('Lole', 'Testbestiary', 4, 2, 1594112340, 5)
Message: Duplicate entry '5' for key 'guildwar_kills_unique'

I tried to update/make news tabels in database from tutorials but nothing fixed.
I also tried to found fix on the web(other forums) but also nothing fixed.

Meybe someone can help me or can give me all tabels and server files to this guild war?
Regards
 
Solution
I think you have 3 keys on the table, a primary key, a foreign key and a unique key. The unique key can probably be deleted.

1594733856585.png
Hello.
I have next problem with my war system.
I can invite, accept wars in game. Also on website is okey, but for example:

I make war between guild "Guild One" and "Guild Two"
War is accepted.
Player from Guild One kill player from Guild Two - The first score on website is added (1:0)
When I come back second player (from Guild Two) and Kill player from Guild One I dont have change in score on war and also have this error in console:

Lua:
[Error - mysql_real_query] Query: INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES ('Lole', 'Testbestiary', 4, 2, 1594112340, 5)
Message: Duplicate entry '5' for key 'guildwar_kills_unique'

I tried to update/make news tabels in database from tutorials but nothing fixed.
I also tried to found fix on the web(other forums) but also nothing fixed.

Meybe someone can help me or can give me all tabels and server files to this guild war?
Regards
Could you share the script file where it executes the mySQL query?
Somewhere in that file you might have made an mistake why it duplicates entry '5', guildwar_kills_unique table doesn't allow the same entry values.

But don't get me wrong, this return error is very bad to

Sincerely,
Ralumbi
 
I can't find in my server folder anything more than war.lua from talkactions:

Lua:
function onSay(cid, words, param)

    local player = Player(cid)
    local guild = player:getGuild()
    if(guild == nil) then
            player:sendCancelMessage("You need to be in a guild in order to execute this talkaction.")
            return false
    end

    local guild = getPlayerGuildId(cid)
    if not guild or (player:getGuildLevel() < 3) then
            player:sendCancelMessage("You cannot execute this talkaction.")
            return false
    end

    local t = string.split(param, ",")
    if(not t[2]) then  
            player:sendChannelMessage("", "Not enough param(s).", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
            return false
    end

    local enemy = getGuildId(t[2])
    if(not enemy) then
            player:sendChannelMessage("", "Guild \"" .. t[2] .. "\" does not exists.", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
            return false
    end


    if(enemy == guild) then
            player:sendChannelMessage("", "You cannot perform war action on your own guild.", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
            return false
    end

    local enemyName, tmp = "", db.storeQuery("SELECT `name` FROM `guilds` WHERE `id` = " .. enemy)
    if tmp ~= false then
            enemyName = result.getDataString(tmp, "name")
            result.free(tmp)
    end

    if(isInArray({"accept", "reject", "cancel"}, t[1])) then
            local query = "`guild1` = " .. enemy .. " AND `guild2` = " .. guild
            if(t[1] == "cancel") then
                    query = "`guild1` = " .. guild .. " AND `guild2` = " .. enemy
            end

            tmp = db.storeQuery("SELECT `id`, `started`, `ended`, `payment` FROM `guild_wars` WHERE " .. query .. " AND `status` = 0")
            if(tmp == false) then
                    player:sendChannelMessage("", "Currently there's no pending invitation for a war with " .. enemyName .. ".", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
                    return false
            end

            if(t[1] == "accept") then
                    local _tmp = db.storeQuery("SELECT `balance` FROM `guilds` WHERE `id` = " .. guild)
                    local state = result.getDataInt(_tmp, "balance") < result.getDataInt(tmp, "payment")

                    result.free(_tmp)
                    if(state) then
                            player:sendChannelMessage("", "Your guild balance is too low to accept this invitation.", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
                            return false
                    end

                    db.query("UPDATE `guilds` SET `balance` = `balance` - " .. result.getDataInt(tmp, "payment") .. " WHERE `id` = " .. guild)
            end

            query = "UPDATE `guild_wars` SET "
            local msg = "accepted " .. enemyName .. " invitation to war."
            if(t[1] == "reject") then
                    query = query .. "`ended` = " .. os.time() .. ", `status` = 2"
                    msg = "rejected " .. enemyName .. " invitation to war."
            elseif(t[1] == "cancel") then
                    query = query .. "`ended` = " .. os.time() .. ", `status` = 3"
                    msg = "canceled invitation to a war with " .. enemyName .. "."
            else
                    query = query .. "`started` = " .. os.time() .. ", `ended` = " .. (result.getDataInt(tmp, "ended") > 0 and (os.time() + ((result.getDataInt(tmp, "started") - result.getDataInt(tmp, "ended")) / 86400)) or 0) .. ", `status` = 1"
            end


            query = query .. " WHERE `id` = " .. result.getDataInt(tmp, "id")
            result.free(tmp)
            db.query(query)
            broadcastMessage(getPlayerGuildName(cid) .. " has " .. msg, MESSAGE_EVENT_ADVANCE)
            return false
    end

    if(t[1] == "invite") then
            local str = ""
            tmp = db.storeQuery("SELECT `guild1`, `status` FROM `guild_wars` WHERE `guild1` IN (" .. guild .. "," .. enemy .. ") AND `guild2` IN (" .. enemy .. "," .. guild .. ") AND `status` IN (0, 1)")
    if(tmp ~= false) then
               
                    if(result.getDataInt(tmp, "status") == 0) then
                            if(result.getDataInt(tmp, "guild1") == guild) then
                                    str = "You have already invited " .. enemyName .. " to war."
                            else
                                    str = enemyName .. " have already invited you to war."
                            end
                    else
                            str = "You are already on a war with " .. enemyName .. "."
                    end

                    result.free(tmp)
            end

            if(str ~= "") then
                    player:sendChannelMessage("", str, TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
                    return false
            end

            local frags = tonumber(t[3])
            if(frags ~= nil) then
                    frags = math.max(10, math.min(1000, frags))
            else
                    frags = 100
            end

            local payment = tonumber(t[4])
            if(payment ~= nil) then
                    payment = math.floor(payment)+1000
                    tmp = db.storeQuery("SELECT `balance` FROM `guilds` WHERE `id` = " .. guild)

                    local state = result.getDataInt(tmp, "balance") < payment
                    result.free(tmp)
                    if(state) then
                            player:sendChannelMessage("", "Your guild balance is too low for such payment.", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
                            return false
                    end

                    db.query("UPDATE `guilds` SET `balance` = `balance` - " .. payment .. " WHERE `id` = " .. guild)
            else
                    payment = 0
            end

            local begining, ending = os.time(), tonumber(t[5])
            if(ending ~= nil and ending ~= 0) then
                    ending = begining + (ending * 86400)
            else
                    ending = 0
            end

            db.query("INSERT INTO `guild_wars` (`guild1`, `guild2`, `started`, `ended`, `frags`, `payment`,`name1`,`name2`) VALUES (" .. guild .. ", " .. enemy .. ", " .. begining .. ", " .. ending .. ", " .. frags .. ", " .. payment .. ", '" .. getPlayerGuildName(cid) .."', '"..enemyName.."');")
            db.query("INSERT INTO `znote_guild_wars` (`limit`) VALUES ('"..frags.."');")
            broadcastMessage(getPlayerGuildName(cid) .. " has invited " .. enemyName .. " to war till " .. frags .. " frags.", MESSAGE_EVENT_ADVANCE)
            return false
    end

    if(not isInArray({"end", "finish"}, t[1])) then
            return false
    end

    local status = (t[1] == "end" and 1 or 4)
    tmp = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `guild1` = " .. guild .. " AND `guild2` = " .. enemy .. " AND `status` = " .. status)
    if(tmp ~= false) then
            local query = "UPDATE `guild_wars` SET `ended` = " .. os.time() .. ", `status` = 5 WHERE `id` = " .. result.getDataInt(tmp, "id")
            result.free(tmp)

            db.query(query)
            broadcastMessage(getPlayerGuildName(cid) .. " has " .. (status == 4 and "mend fences" or "ended up a war") .. " with " .. enemyName .. ".", MESSAGE_EVENT_ADVANCE)
            return false
    end

    if(status == 4) then
            player:sendChannelMessage("", "Currently there's no pending war truce from " .. enemyName .. ".", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
            return false
    end

    tmp = db.storeQuery("SELECT `id`, `ended` FROM `guild_wars` WHERE `guild1` = " .. enemy .. " AND `guild2` = " .. guild .. " AND `status` = 1")
    if(tmp ~= false) then
            if(result.getDataInt(tmp, "ended") > 0) then
                    result.free(tmp)
                    player:sendChannelMessage("", "You cannot request ending for war with " .. enemyName .. ".", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
                    return false
            end

            local query = "UPDATE `guild_wars` SET `status` = 4, `ended` = " .. os.time() .. " WHERE `id` = " .. result.getDataInt(tmp, "id")
            result.free(tmp)

            db.query(query)
            broadcastMessage(getPlayerGuildName(cid) .. " has signed an armstice declaration on a war with " .. enemyName .. ".", MESSAGE_EVENT_ADVANCE)
            return false
    end

    player:sendChannelMessage("", "Currently there's no active war with " .. enemyName .. ".", TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
    return false
end

and also guildwar.lua in Globalevents folder:

Code:
function onThink(interval)
    local time = os.time()
    db.query("UPDATE `guild_wars` SET `status` = 4, `ended` = " .. time .. " WHERE `status` = 1 AND (`started` + 5 * 60 * 60) < " .. time)
    return true
end


and I think meybe this is also for wars, playerdeath.lua:

Lua:
local deathListEnabled = true

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You are dead.')
    if player:getStorageValue(Storage.SvargrondArena.Pit) > 0 then
        player:setStorageValue(Storage.SvargrondArena.Pit, 0)
    end

    if not deathListEnabled then
        return
    end

    local byPlayer = 0
    local killerName
    if killer ~= nil then
        if killer:isPlayer() then
            byPlayer = 1
        else
            local master = killer:getMaster()
            if master and master ~= killer and master:isPlayer() then
                killer = master
                byPlayer = 1
            end
        end
        killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
    else
        killerName = 'field item'
    end

    local byPlayerMostDamage = 0
    local mostDamageKillerName
    if mostDamageKiller ~= nil then
        if mostDamageKiller:isPlayer() then
            byPlayerMostDamage = 1
        else
            local master = mostDamageKiller:getMaster()
            if master and master ~= mostDamageKiller and master:isPlayer() then
                mostDamageKiller = master
                byPlayerMostDamage = 1
            end
        end
        mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
    else
        mostDamageName = 'field item'
    end

    local playerGuid = player:getGuid()
    db.query('INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES (' .. playerGuid .. ', ' .. os.time() .. ', ' .. player:getLevel() .. ', ' .. db.escapeString(killerName) .. ', ' .. byPlayer .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ')')
    local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)

    local deathRecords = 0
    local tmpResultId = resultId
    while tmpResultId ~= false do
        tmpResultId = result.next(resultId)
        deathRecords = deathRecords + 1
    end

    if resultId ~= false then
        result.free(resultId)
    end

    if byPlayer == 1 then
        local targetGuild = player:getGuild()
        targetGuild = targetGuild and targetGuild:getId() or 0
        if targetGuild ~= 0 then
            local killerGuild = killer:getGuild()
            killerGuild = killerGuild and killerGuild:getId() or 0
            if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
                local warId = false
                resultId = db.storeQuery('SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = ' .. killerGuild .. ' AND `guild2` = ' .. targetGuild .. ') OR (`guild1` = ' .. targetGuild .. ' AND `guild2` = ' .. killerGuild .. '))')
                if resultId ~= false then
                    warId = result.getNumber(resultId, 'id')
                    result.free(resultId)
                end

                if warId ~= false then
                    db.asyncQuery('INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (' .. db.escapeString(killerName) .. ', ' .. db.escapeString(player:getName()) .. ', ' .. killerGuild .. ', ' .. targetGuild .. ', ' .. os.time() .. ', ' .. warId .. ')')
                end
            end
        end
    end
end

This is OTX server from Tibia King but there is also anything about fix that.... :( :( :(
 
Last edited:
There seems nothing wrong, all I can see is that the warid must be an unique value. This means that only one warid of '5' in this case may exist.
Try cleaning up your guildwar tables and try again :)
 
So if I good understand I can have only one war on my server? But if I have only one it's also don't works.

This is my database table guildwars_kills after clean:

Here is guild_wars:

and here is also my error (cleaning guildwars_kill dont fixed that :( ) :


This is little funny becasue after War starts the first frag always works good, without any errors and also on the website I see good score - All of the next frags (dasn't matter it is player from first guild or second guild) don't works...
 
Somebody can help me with that? I do not know how to fix this from last 5 days :(
 
Somebody can help me with that? I do not know how to fix this from last 5 days :(
can you check if warid is primary key or not ?, if it is just remove the key and test if not please go to guildwar_kills table from phpmyadmin then go to structure and send a screenshot
 
Hello.
I think this warid is primary key, but I can't delete this.

Its my ss from guildwars_kill



And here is error when I trying to delete primary key: (with translate from my language)



I dont know why in structure on the top table (guildwars_kill) next to ID I have golden key icon and next to WARID I have silver key icon... :(


Edit:

I delete Index's on the down - Guildwars_kills_unique and warid.
Now I have on site the score 1:1 but all of next frags also dont work.
Its screen with new error in console:


:(
 
Last edited:
Hello.
I think this warid is primary key, but I can't delete this.

Its my ss from guildwars_kill



And here is error when I trying to delete primary key: (with translate from my language)



I dont know why in structure on the top table (guildwars_kill) next to ID I have golden key icon and next to WARID I have silver key icon... :(


Edit:

I delete Index's on the down - Guildwars_kills_unique and warid.
Now I have on site the score 1:1 but all of next frags also dont work.
Its screen with new error in console:


:(
its not primary key, you shouldn't remove it (the silver key)
 
But I cant remove primary key also. Do you knows how to fix this system? I cant find any war system for tfs on forum

Bump

Bump. Still dont fixed

Bump

BUMP :(
 
I think you have 3 keys on the table, a primary key, a foreign key and a unique key. The unique key can probably be deleted.

1594733856585.png
 
Solution
Okey, now its work! Thanks a lot @Znote !!!!

Last question about that (I dont wanna make new thread)
The wars are not finish after X frags.
I make a war till 10 frags but after 10frags this war is not finished.
1594818150660.png

What I see here the war will finish after server save. Can somebody tell me how to setup wars to finish when frags are done ?
 
Bump
@Znote
Post automatically merged:

Okey, now its work! Thanks a lot @Znote !!!!

Last question about that (I dont wanna make new thread)
The wars are not finish after X frags.
I make a war till 10 frags but after 10frags this war is not finished.
View attachment 47523

What I see here the war will finish after server save. Can somebody tell me how to setup wars to finish when frags are done ?
How to fix this?
 
Back
Top