Jump to content

Delete from mysql after kick


Recommended Posts

Hi, 

I want to make CharacterKill script. I think the easiest way is kick and delete row with character from database. I tried, but it doesn't works. This script doesn't delete character from db.

This is server-side

	function ckPlayer(player, cmd, ...)
    if getElementData(player,"char >> dead",true) then
        if  not (...) then
            outputChatBox("#32b3efUŻYCIE:#FFFFFF /" .. cmd .. " [powód zgonu]", player, 255, 194, 14, true)
        else
                    local accid = getElementData(player,"acc >> id");
                    
                    info = table.concat({...}, " ")
                    local cked = setElementData(player,"char >> cked", true);
                    kickPlayer(player, "CK: " ..info..".");
                end
            end
end
addCommandHandler("ck", ckPlayer)
	addEventHandler("onPlayerQuit",getRootElement(),"Kicked",function() 
    local accid = getElementData(source,"acc >> id");
    if accid and accid > 0 then 
        if getElementData(source,"char >> cked") == "true" then 
            dbExec(sql,"DELETE FROM characters WHERE id=?",accid)
        end
    end
end);

Please, help

Link to comment

First of all, this is wrong syntax:

addEventHandler("onPlayerQuit",getRootElement(),"Kicked",function()

but more importantly, why not just dbExec(sql,"DELETE FROM characters WHERE id=?",accid) within ckPlayer(player, cmd, ...) right after kickPlayer(player, "CK: " ..info..".")?

Link to comment
14 hours ago, Addlibs said:

but more importantly, why not just dbExec(sql,"DELETE FROM characters WHERE id=?",accid) within ckPlayer(player, cmd, ...) right after kickPlayer(player, "CK: " ..info..".")?

That's a good point. It may look like a matter of taste, but there is a difference which may have big implications.

If you call dbExec from within the command handler of "ck", right after kickPlayer, then the character only gets deleted when the player uses that command.

If you call dbExec whenever the player gets kicked, the character gets deleted even if the player gets kicked by other means. The consequences may be very undesirable if there's some progress associated with a character. Suppose you have an AFK kicker script. The player stays idle for a few minutes, gets kicked - all progress they've made on that character is gone.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...