sirrjohn Posted August 28, 2023 Share Posted August 28, 2023 (edited) Hey guys, I know this code is a mess, I've been messing around with it trying to get it to work but its not 100% working What does not work: - When player leaves the server its not saving his new "combattime" AccountData value to db (which if he was in combat mode when he left, it should be 1 when he logs back in, but its always 0) Appreciate any help server function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setAccountData(source,"combattime",0) end,5000,1,source) end function setAccount1(source) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount,"combattime",1) end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount1", true) function setAccount2(source) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount,"combattime",0) end addEventHandler("setAccount2", root, setAccount2) addEvent("setAccount2", true) function getAccount(source) local playerAccount = getPlayerAccount(source) getter = getAccountData(playerAccount,"combattime") end addEventHandler("getAccount", root, getAccount) addEvent("getAccount", true) client combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetColor(combatloglabel, 17, 249, 5) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) triggerServerEvent("getAccount", source) outputChatBox("getAccount OK") if getter == 0 then guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel,0,255,0) outputChatBox("getter == 0") else guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) outputChatBox("getter == 1") end setTimer(function(source) outputChatBox("timer") triggerServerEvent("setAccount2", source) end,10000,1,source) end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog) Edited August 28, 2023 by sirrjohn 1 Link to comment
FlorinSzasz Posted August 29, 2023 Share Posted August 29, 2023 16 hours ago, sirrjohn said: Hey guys, I know this code is a mess, I've been messing around with it trying to get it to work but its not 100% working What does not work: - When player leaves the server its not saving his new "combattime" AccountData value to db (which if he was in combat mode when he left, it should be 1 when he logs back in, but its always 0) Appreciate any help server function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setAccountData(source,"combattime",0) end,5000,1,source) end function setAccount1(source) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount,"combattime",1) end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount1", true) function setAccount2(source) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount,"combattime",0) end addEventHandler("setAccount2", root, setAccount2) addEvent("setAccount2", true) function getAccount(source) local playerAccount = getPlayerAccount(source) getter = getAccountData(playerAccount,"combattime") end addEventHandler("getAccount", root, getAccount) addEvent("getAccount", true) client combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetColor(combatloglabel, 17, 249, 5) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) triggerServerEvent("getAccount", source) outputChatBox("getAccount OK") if getter == 0 then guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel,0,255,0) outputChatBox("getter == 0") else guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) outputChatBox("getter == 1") end setTimer(function(source) outputChatBox("timer") triggerServerEvent("setAccount2", source) end,10000,1,source) end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog) function saveData() if source then local a = getPlayerAccount(source); if a then if not isGuestAccount(a) then setAccountData(a,"combattime",tonumber(getAccountData(a,"combattime"))) end end end end addEventHandler("onPlayerQuit",getRootElement(),saveData) This should work but i did not test it. Also here is a topic which might help you. -> https://forum.multitheftauto.com/topic/106193-help-save-account-data/ 1 Link to comment
sirrjohn Posted August 29, 2023 Author Share Posted August 29, 2023 (edited) didnt work but I think its something about "my" code thats not right... like [13:10:16] ERROR: Client (Sirr) triggered serverside event getAccount, but event is not added serverside [13:10:26] ERROR: Client (Sirr) triggered serverside event setAccount2, but event is not added serverside why does it says that if both events are in my server.lua file? 100% sure as you can see in the script above Edited August 29, 2023 by sirrjohn 1 Link to comment
FlorinSzasz Posted August 29, 2023 Share Posted August 29, 2023 (edited) 2 hours ago, sirrjohn said: didnt work but I think its something about "my" code thats not right... like [13:10:16] ERROR: Client (Sirr) triggered serverside event getAccount, but event is not added serverside [13:10:26] ERROR: Client (Sirr) triggered serverside event setAccount2, but event is not added serverside why does it says that if both events are in my server.lua file? 100% sure as you can see in the script above function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) else setElementData(source,"combattime",getAccountData(playerAccount,"combattime") or 0) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") -- exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setElementData(source,"combattime",0) end,5000,1,source) end addEvent("setAccount1",true) function setAccount1() if client then setElementData(client,"combattime",1) end end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount2", true) function setAccount2() if client then setElementData(client,"combattime",0) end end addEventHandler("setAccount2", root, setAccount2) function saveData() local a = getPlayerAccount(source); if a then outputDebugString(getElementData(source,"combattime")) setAccountData(a,"combattime",getElementData(source,"combattime")) end end addEventHandler("onPlayerQuit",getRootElement(),saveData) Server Here, Now client: combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) if source == localPlayer then guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) triggerServerEvent("setAccount1", localPlayer) setTimer(function(localPlayer) triggerServerEvent("setAccount2", localPlayer) guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end,10000,1,localPlayer) end end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog) It should work is tested now. Also when u trigger a server event always check for client because source can be some fake data and in more complicated scripts it can create problems. Thats why i used client when i trigger a server event! Edited August 29, 2023 by FlorinSzasz 1 Link to comment
sirrjohn Posted August 29, 2023 Author Share Posted August 29, 2023 (edited) 3 hours ago, FlorinSzasz said: function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) else setElementData(source,"combattime",getAccountData(playerAccount,"combattime") or 0) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") -- exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setElementData(source,"combattime",0) end,5000,1,source) end addEvent("setAccount1",true) function setAccount1() if client then setElementData(client,"combattime",1) end end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount2", true) function setAccount2() if client then setElementData(client,"combattime",0) end end addEventHandler("setAccount2", root, setAccount2) function saveData() local a = getPlayerAccount(source); if a then outputDebugString(getElementData(source,"combattime")) setAccountData(a,"combattime",getElementData(source,"combattime")) end end addEventHandler("onPlayerQuit",getRootElement(),saveData) Server Here, Now client: combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) if source == localPlayer then guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) triggerServerEvent("setAccount1", localPlayer) setTimer(function(localPlayer) triggerServerEvent("setAccount2", localPlayer) guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end,10000,1,localPlayer) end end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog) It should work is tested now. Also when u trigger a server event always check for client because source can be some fake data and in more complicated scripts it can create problems. Thats why i used client when i trigger a server event! Hey, same error [18:37:14] ERROR: Client (Sirr) triggered serverside event setAccount1, but event is not added serverside [18:37:24] ERROR: Client (Sirr) triggered serverside event setAccount2, but event is not added serverside I found out server was not even running thats why it says that message... i removed some other code i dont use from server.lua and it now works 100% !! thank you very much !!!! Edited August 29, 2023 by sirrjohn 1 Link to comment
scolen Posted August 30, 2023 Share Posted August 30, 2023 10 hours ago, FlorinSzasz said: function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) else setElementData(source,"combattime",getAccountData(playerAccount,"combattime") or 0) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") -- exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setElementData(source,"combattime",0) end,5000,1,source) end addEvent("setAccount1",true) function setAccount1() if client then setElementData(client,"combattime",1) end end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount2", true) function setAccount2() if client then setElementData(client,"combattime",0) end end addEventHandler("setAccount2", root, setAccount2) function saveData() local a = getPlayerAccount(source); if a then outputDebugString(getElementData(source,"combattime")) setAccountData(a,"combattime",getElementData(source,"combattime")) end end addEventHandler("onPlayerQuit",getRootElement(),saveData) Server Here, Now client: combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) if source == localPlayer then guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) triggerServerEvent("setAccount1", localPlayer) setTimer(function(localPlayer) triggerServerEvent("setAccount2", localPlayer) guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end,10000,1,localPlayer) end end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog) It should work is tested now. Also when u trigger a server event always check for client because source can be some fake data and in more complicated scripts it can create problems. Thats why i used client when i trigger a server event! help ! 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