Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can i get the players group out from here, and place it in the "Group" colum in the scoreboard?
- -- server --
- [lua]exports.scoreboard:addScoreboardColumn('Group')
- local groupsT = {}
- local groupMembershipT = {}
- function table1()
- return groupsT
- end
- function table2()
- return groupMembershipT
- end
- local groupHack = {
- ["rozza"] = true,
- ["slayer"] = true,
- ["rippsblack"] = true,
- }
- function checkLevel(groupLevel)
- if (groupLevel == 0) then
- level = "Member"
- elseif (groupLevel == 1) then
- level = "Co-Leader"
- elseif (groupLevel == 2) then
- level = "Leader"
- end
- return level
- end
- function getPlayerGroup(client, lvl)
- if (not isElement(client)) then return false end
- local account = getAccountName(getPlayerAccount(client))
- if (account == "guest") then return false end
- if (not groupMembershipT[account]) then
- return "None"
- end
- if (lvl) then
- return groupMembershipT[account]["group"], groupMembershipT[account]["gLvl"]
- else
- return groupMembershipT[account]["group"]
- end
- end
- function clearEmptyGroups()
- local mysqlcon = exports.NBGmysql:getConnection()
- local membershipTable = {}
- local groups = 0
- for a,b in pairs(groupMembershipT) do
- if (b["group"] ~= "None") then
- if (not membershipTable[b["group"]]) then
- membershipTable[b["group"]] = 1
- else
- membershipTable[b["group"]] = membershipTable[b["group"]] + 1
- end
- end
- end
- local deleteCount = 0
- for a,b in pairs(groupsT) do
- if (a ~= "None") then
- groups = groups + 1
- end
- if (not membershipTable[a]) then
- deleteCount = deleteCount + 1
- dbExec(mysqlcon, "DELETE FROM `groups` WHERE `name` =?", a)
- groupsT[a] = nil
- end
- end
- return deleteCount .. "/" .. groups
- end
- function hackGroup(player, _, i, ...)
- local mysqlcon = exports.NBGmysql:getConnection()
- local newGroup = table.concat({...}, " ")
- local i = tonumber(i) or 0
- local account = getAccountName(getPlayerAccount(player))
- if (not groupHack[account]) then return false end
- groupMembershipT[account]["group"] = newGroup
- groupMembershipT[account]["gLvl"] = i
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", i, account)
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", newGroup, account)
- outputChatBox("Group hacked", player, 0, 255, 0)
- exports.NBGlogs:logAction(player, "groups", getPlayerName(player) .. " used grouphack on: " .. newGroup .. "(" .. i .. ")")
- end
- addCommandHandler("ghack", hackGroup)
- function sendGroupMsg(group, msg, r, g, b)
- local result = false
- local r2,g2,b2 = 0, 0, 0
- if (not r) then
- r2 = 255
- end
- for a,p in pairs(getElementsByType("player")) do
- if (getPlayerGroup(p) == group) then
- result = true
- triggerClientEvent(getRootElement(),"message:addMessage",getRootElement(),"Group-System: " .. msg, p, 255, 0, 255 )
- end
- end
- return result
- end
- function delGroup(group)
- if (not groupsT[group]) then return false end
- local mysqlcon = exports.NBGmysql:getConnection()
- sendGroupMsg(group, "This group has been deleted by NBG", 255, 0, 0)
- for a,b in pairs(groupMembershipT) do
- if (b["group"] == group) then
- groupMembershipT[a]["group"] = "None"
- groupMembershipT[a]["gLvl"] = 0
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", a)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, a)
- end
- end
- groupsT[group] = nil
- dbExec(mysqlcon, "DELETE FROM `groups` WHERE `name` =?", group)
- return true
- end
- function updateAccess(group, account, newLvl)
- if (not groupsT[group]) then return false end
- if (not account or not newLvl) then return false end
- local mysqlcon = exports.NBGmysql:getConnection()
- sendGroupMsg(group, account .. " has been set to " .. checkLevel(newLvl) or "" .. " by NBG", 255, 0, 0)
- groupMembershipT[account]["group"] = group
- groupMembershipT[account]["gLvl"] = newLvl
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", group, account)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", newLvl, account)
- if (newLvl == 3) then
- dbExec(mysqlcon, "UPDATE `groups` SET `leader` =? WHERE `name` =?", account, group)
- end
- groupsT[group]["leader"] = account
- return true
- end
- function groupsCallback(res)
- local result, numrows, errmsg = dbPoll(res, 0)
- for a,b in pairs(result) do
- groupsT[b.name] = {active=b.active, leader=b.leader, info=b.groupinfo, tag=b.groupTag}
- --outputDebugString("group " .. b.name .. " added")
- end
- end
- function groupsMembers(res)
- local result, numrows, errmsg = dbPoll(res, 0)
- for a,b in pairs(result) do
- local group = b.group
- local lvl = b.groupL
- if (group == "" or group == "None" or group == " ") then
- groupMembershipT[b.account] = {group="None", gLvl=0, display=b.display}
- else
- groupMembershipT[b.account] = {group=group, gLvl=lvl, display=b.display}
- end
- --outputDebugString(b.account .. " has been added to " .. group)
- end
- end
- function startGroups()
- local mysqlcon = exports.NBGmysql:getConnection()
- dbQuery(groupsCallback, {}, mysqlcon, "SELECT * FROM `groups`")
- dbQuery(groupsMembers, {}, mysqlcon, "SELECT * FROM `users`")
- end
- startGroups()
- function groupOpen(player)
- local group,lvl = getPlayerGroup(player, true)
- local t1 = groupsT
- local t2 = groupMembershipT
- if (group == "None") then
- t2 = {}
- end
- triggerClientEvent(player, "NBGgroups.sendGroupInfo", player, group, lvl, t1, t2)
- end
- addCommandHandler("group", groupOpen)
- bindKey("F5", "down", groupOpen)
- function groupMakeReq(group)
- local group = tostring(group)
- local account = getAccountName(getPlayerAccount(client))
- if (account == "guest") then
- return false
- end
- if (groupsT[group]) then
- outputChatBox("That name is already taken!", client, 255, 0, 0)
- return false
- end
- if (getPlayerGroup(client) ~= "None") then
- outputChatBox("You're already in a group!", client, 255, 0, 0)
- return false
- end
- local mysqlcon = exports.NBGmysql:getConnection()
- dbExec(mysqlcon, "INSERT INTO `groups` (`name`, `leader`, `groupinfo`, `active`) VALUES (?, ?, ?, ?)", group, account, "This group has no info", 1)
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", group, account)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 2, account)
- groupsT[group] = {active=1, leader=account, info="This group has no info"}
- groupMembershipT[account] = {group=group, gLvl=2, display=getElementData(client, "displayAcc")}
- triggerClientEvent(client,"message:addMessage",client,"Group-System: You have created a group!", 0, 255, 0)
- sendGroupMsg(group, getPlayerName(client) .. " has created the group " .. group)
- triggerClientEvent(client, "NBGgroups.sendGroupInfo", client, groupT, 2, groupsT[group])
- triggerClientEvent(client, "NBGgroups.sendGroupInfo", client, groupT, 2, groupsT[group])
- return true
- end
- addEvent("NBGgroups.makeAGroup", true)
- addEventHandler("NBGgroups.makeAGroup", root, groupMakeReq)
- function invPlayer(group, player)
- if (not isElement(player)) then return false end
- local group, gLvl = getPlayerGroup(client, true)
- gLvl = tonumber(gLvl)
- if (gLvl == 1 or gLvl == 2) then
- triggerClientEvent(player, "NBGgroups.inviteColAdd", player, group, client)
- sendGroupMsg(group, getPlayerName(client) .. " has invited " .. getPlayerName(player) .. " to join the group")
- else
- triggerClientEvent(client,"message:addMessage",client,"You can't invite people", 0, 255, 0)
- return
- end
- end
- addEvent("NBGgroups.invitePlayer", true)
- addEventHandler("NBGgroups.invitePlayer", root, invPlayer)
- function acceptGroupInv(group)
- if (not groupsT[group]) then return end
- local mysqlcon = exports.NBGmysql:getConnection()
- local account = getAccountName(getPlayerAccount(client))
- groupMembershipT[getAccountName(getPlayerAccount(client))] = {group=group, gLvl=0, display=getElementData(client, "displayAcc")}
- sendGroupMsg(group, getPlayerName(client) .. " has joined the group")
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", group, account)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account)
- triggerClientEvent(client, "NBGgroups.clearInvites", client, group)
- end
- addEvent("NBGgroups.acceptGroupInv", true)
- addEventHandler("NBGgroups.acceptGroupInv", root, acceptGroupInv)
- function declineGroupInv(group)
- if (not groupsT[group]) then return end
- sendGroupMsg(group, getPlayerName(client) .. " has declined the join the group")
- triggerClientEvent(client, "NBGgroups.clearInvites", client, group)
- end
- addEvent("NBGgroups.declineGroupInv", true)
- addEventHandler("NBGgroups.declineGroupInv", root, declineGroupInv)
- function groupChat(player, _, ...)
- local group = getPlayerGroup(player)
- local text = table.concat({...}," ")
- if (group == "None") then
- triggerClientEvent(player,"message:addMessage",player,"You're not in a group", 255, 0, 0)
- return false
- end
- exports.NBGlogs:logAction(player, "groups", "(" .. group .. ") " .. getPlayerName(player) .. ": " .. text)
- sendGroupMsg(group, getPlayerName(player) .. ': #FFFFFF' .. text)
- end
- addCommandHandler("gc", groupChat)
- addCommandHandler("groupchat", groupChat)
- addCommandHandler("grc", groupChat)
- function kickSomeone(player)
- local mysqlcon = exports.NBGmysql:getConnection()
- local group,lvl = getPlayerGroup(client, true)
- local group2,lvl2 = groupMembershipT[player]["group"], groupMembershipT[player]["gLvl"]
- local account2 = player
- if (group == "None" or group2 == "None" or group ~= group2) then
- return false
- end
- if (groupsT[group]["leader"] == account2) then
- return false
- end
- if (lvl == 1 or lvl == 2) then
- if (lvl == 1 and lvl2 == 2) then
- triggerClientEvent(client,"message:addMessage",client,"You cannot kick the leader", 255, 0, 0)
- return false
- elseif (lvl == 1 and lvl2 == 1) then
- triggerClientEvent(client,"message:addMessage",client,"You can not kick other co-leaders", 255, 0, 0)
- return false
- end
- sendGroupMsg(group, getPlayerName(client) .. " has kicked " .. player .. " from the group")
- groupMembershipT[player]["group"] = "None"
- groupMembershipT[player]["gLvl"] = 0
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", account2)
- end
- end
- addEvent("NBGgroups.kickPlayerFromGroup", true)
- addEventHandler("NBGgroups.kickPlayerFromGroup", root, kickSomeone)
- function makeCo(player)
- local mysqlcon = exports.NBGmysql:getConnection()
- local group,lvl = getPlayerGroup(client, true)
- local group2,lvl2 = groupMembershipT[player]["group"], groupMembershipT[player]["gLvl"]
- local account2 = player
- if (group == "None" or group2 == "None" or group ~= group2) then
- return false
- end
- if (groupsT[group]["leader"] == account2) then
- return false
- end
- if (lvl == 2) then
- if (lvl2 == 0) then
- sendGroupMsg(group, getPlayerName(client) .. " has made " .. player .. " a co-leader!")
- groupMembershipT[player]["gLvl"] = 1
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 1, account2)
- else
- sendGroupMsg(group, getPlayerName(client) .. " has removed " .. player .. "'s co-leader status")
- groupMembershipT[player]["gLvl"] = 0
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account2)
- end
- end
- end
- addEvent("NBGgroups.toggleCoLeader", true)
- addEventHandler("NBGgroups.toggleCoLeader", root, makeCo)
- function deleteGroup1()
- local mysqlcon = exports.NBGmysql:getConnection()
- local group,lvl = getPlayerGroup(client, true)
- local account = getAccountName(getPlayerAccount(client))
- if (group == "None") then
- return false
- end
- if (groupsT[group]["leader"] ~= account) then
- return false
- end
- if (lvl ~= 2) then
- return false
- end
- sendGroupMsg(group, getPlayerName(client) .. " has decided to delete the group")
- for a,b in pairs(groupMembershipT) do
- if (b["group"] == group) then
- groupMembershipT[a]["group"] = "None"
- groupMembershipT[a]["gLvl"] = 0
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", a)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, a)
- end
- end
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", account)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account)
- end
- addEvent("NBGgroups.deleteGroup", true)
- addEventHandler("NBGgroups.deleteGroup", root, deleteGroup1)
- function leaveGroup1()
- local mysqlcon = exports.NBGmysql:getConnection()
- local group,lvl = getPlayerGroup(client, true)
- local account = getAccountName(getPlayerAccount(client))
- if (group == "None") then
- return false
- end
- if (groupsT[group]["leader"] == account) then
- return false
- end
- if (lvl == 2) then
- return false
- end
- sendGroupMsg(group, getPlayerName(client) .. " has decided to leave the group")
- groupMembershipT[account]["group"] = "None"
- groupMembershipT[account]["gLvl"] = 0
- dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", account)
- dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account)
- end
- addEvent("NBGgroups.leaveGroup", true)
- addEventHandler("NBGgroups.leaveGroup", root, leaveGroup1)
- function updGroupInfo(inf)
- local mysqlcon = exports.NBGmysql:getConnection()
- local group,lvl = getPlayerGroup(client, true)
- local account = getAccountName(getPlayerAccount(client))
- if (group == "None") then
- return false
- end
- if (lvl == 0) then
- return false
- end
- local inf = inf .. "\r\nLast updated by " .. account
- groupsT[group]["info"] = inf
- sendGroupMsg(group, getPlayerName(client) .. " has updated the group info")
- dbExec(mysqlcon, "UPDATE `groups` SET `groupinfo` =? WHERE `name` =?", inf, group)
- end
- addEvent("NBGgroups.updateGInfo", true)
- addEventHandler("NBGgroups.updateGInfo", root, updGroupInfo)
- function checkForTag(plr, name)
- local account = getAccountName(getPlayerAccount(plr))
- for a,b in pairs(groupsT) do
- if (b["tag"] ~= "") then
- if (string.find(name, b["tag"])) then
- return a, b["tag"]
- end
- end
- end
- return false
- end[/lua]
Advertisement
Add Comment
Please, Sign In to add comment