xXBlasterXx Posted April 16, 2021 Share Posted April 16, 2021 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
Addlibs Posted April 17, 2021 Share Posted April 17, 2021 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
Tekken Posted April 18, 2021 Share Posted April 18, 2021 onPlayerQuit has an argument quitType you can check if quitType == "Kicked" and dbExec after ? Link to comment
DiSaMe Posted April 18, 2021 Share Posted April 18, 2021 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now