IsmaelRD Posted July 6, 2023 Share Posted July 6, 2023 if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." tried to ban you.", player, 255, 0, 0) local banner = getPlayerSerial(source) outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." has been banned. [Reason: attempting to ban a staff member]", root, 255, 0, 0) setTimer ( function () addBan ( nil, nil, banner , root, "You were banned for attempting to ban a staff member") end, 500, 1) return false end local reason = data or "" local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional) local bUseSerial = additional2 local isAnonAdmin = getElementData(source, "AnonAdmin") I want the first line of code, if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then be changed to, if getPlayerAccount(player) == "wilmertrobert" or getPlayerAccount(player) == "joan26" or getPlayerAccount(player) == "papotico02" then but at the moment of doing it it does not work or an error appears Link to comment
DiSaMe Posted July 10, 2023 Share Posted July 10, 2023 If you take a closer look at the first line, the part that retrieves the name looks like this: getAccountName(getPlayerAccount(player)) While in the new line, it looks like this: getPlayerAccount(player) getPlayerAccount function returns an account, which is a separate MTA data type, so comparing it to a string will always evaluate to false. You need to use getAccountName like the original line does, but to avoid retrieving the name multiple times, it's better to store it in a variable: local name = getAccountName(getPlayerAccount(player)) if name == "SomeStaffName" or name == "SomeOtherStaffName" or name == "YetAnotherStaffName" then -- code to execute if the name matches end Even better, you can put the names as keys into the table and do the lookup: -- outside the function local StaffNames = { SomeStaffName = true, ["Some Other Staff Name"] = true, -- both forms are valid but this one allows spaces and other symbols that cannot be used with the other form YetAnotherStaffName = true } -- inside the function local name = getAccountName(getPlayerAccount(player)) if StaffNames[name] then -- code to execute if the name matches end But a script that bans someone for attempting to ban someone else looks like a script that may have unintended consequences. Link to comment
ExMohmD Posted August 4, 2023 Share Posted August 4, 2023 It seems that you want to modify the first line of code to check if the player's account name is one of the specified names ("wilmertrobert," "joan26," or "papotico02") instead of checking if the player belongs to the "Console" ACL group. The code snippet provided is in Lua (used in some game frameworks like MTA:SA). To achieve the desired change, you can modify the first line like this: if getPlayerAccount(player) == "wilmertrobert" or getPlayerAccount(player) == "joan26" or getPlayerAccount(player) == "papotico02" then This line will now check if the player's account name is one of the specified names, and if it matches, the following code block will be executed. Here's the complete code with the change: local player = -- the player object you want to check local data = -- some data you might want to use for the ban reason local additional = -- additional information (maybe ban duration) local additional2 = -- additional information (maybe use serial) if getPlayerAccount(player) == "wilmertrobert" or getPlayerAccount(player) == "joan26" or getPlayerAccount(player) == "papotico02" then outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." tried to ban you.", player, 255, 0, 0) local banner = getPlayerSerial(source) outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." has been banned. [Reason: attempting to ban a staff member]", root, 255, 0, 0) setTimer ( function () addBan ( nil, nil, banner , root, "You were banned for attempting to ban a staff member") end, 500, 1) return false end local reason = data or "" local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional) local bUseSerial = additional2 local isAnonAdmin = getElementData(source, "AnonAdmin") Remember to replace the player, data, additional, and additional2 variables with appropriate values depending on your context. 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