Bilal135 Posted December 10, 2018 Share Posted December 10, 2018 (edited) I just found out that there's a way to store multiple values in a table. So, I planned to make a custom punish system with it. Stored three values in the table, a rule id, a description for what it is, and it's punishment. I'd like to know how can I implement these, for example, if i typed /punish [player] [id], it should automatically derive it's description and punishment from the table, and punish the player. (and output description in the chat) rules = { {["ruleID"] = "1", ["description"] = "Trash talking", ["punishment"] = "kick"} } Thanks. Edited December 10, 2018 by Lynch Link to comment
Moderators Patrick Posted December 10, 2018 Moderators Share Posted December 10, 2018 -- SERVER SIDE rules = { [1] = {description = "Trash talking", punishment = "kick"}, [2] = {description = "Lot of trash talking", punishment = "ban"}, } addCommandHandler("punish", function(player, cmd, ruleID, targetPlayerName) local ruleID = tonumber(ruleID) if rules[ruleID] then -- valid rule id local targetPlayerElement = getPlayerFromName(targetPlayerName) if targetPlayerElement then -- target found local description = rules[ruleID].description local punishment = rules[ruleID].punishment local adminName = getPlayerName(player) if punishment == "kick" then kickPlayer(targetPlayerElement) outputChatBox(targetPlayerName.." kicked from server! (Reason: "..description..")", root) elseif punishment == "ban" then banPlayer(targetPlayerElement) outputChatBox(targetPlayerName.." banned from server! (Reason: "..description..")", root) end else outputChatBox("target player not found", player) end else outputChatBox("invalid rule id", player) end end) 1 Link to comment
Bilal135 Posted December 10, 2018 Author Share Posted December 10, 2018 Thanks a lot, @Patrick. Got the general concept as to how they can be implemented. 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