Guest User

Untitled

a guest
Dec 22nd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.18 KB | None | 0 0
  1. How can i get the players group out from here, and place it in the "Group" colum in the scoreboard?
  2.  
  3. -- server --
  4. [lua]exports.scoreboard:addScoreboardColumn('Group')
  5.  
  6.  
  7.  
  8. local groupsT = {}
  9. local groupMembershipT = {}
  10.  
  11. function table1()
  12. return groupsT
  13. end
  14.  
  15. function table2()
  16. return groupMembershipT
  17. end
  18.  
  19. local groupHack = {
  20. ["rozza"] = true,
  21. ["slayer"] = true,
  22. ["rippsblack"] = true,
  23. }
  24.  
  25. function checkLevel(groupLevel)
  26. if (groupLevel == 0) then
  27. level = "Member"
  28. elseif (groupLevel == 1) then
  29. level = "Co-Leader"
  30. elseif (groupLevel == 2) then
  31. level = "Leader"
  32. end
  33. return level
  34. end
  35.  
  36. function getPlayerGroup(client, lvl)
  37. if (not isElement(client)) then return false end
  38. local account = getAccountName(getPlayerAccount(client))
  39. if (account == "guest") then return false end
  40. if (not groupMembershipT[account]) then
  41. return "None"
  42. end
  43. if (lvl) then
  44. return groupMembershipT[account]["group"], groupMembershipT[account]["gLvl"]
  45. else
  46. return groupMembershipT[account]["group"]
  47. end
  48. end
  49.  
  50. function clearEmptyGroups()
  51. local mysqlcon = exports.NBGmysql:getConnection()
  52. local membershipTable = {}
  53. local groups = 0
  54. for a,b in pairs(groupMembershipT) do
  55. if (b["group"] ~= "None") then
  56. if (not membershipTable[b["group"]]) then
  57. membershipTable[b["group"]] = 1
  58. else
  59. membershipTable[b["group"]] = membershipTable[b["group"]] + 1
  60. end
  61. end
  62. end
  63. local deleteCount = 0
  64. for a,b in pairs(groupsT) do
  65. if (a ~= "None") then
  66. groups = groups + 1
  67. end
  68. if (not membershipTable[a]) then
  69. deleteCount = deleteCount + 1
  70. dbExec(mysqlcon, "DELETE FROM `groups` WHERE `name` =?", a)
  71. groupsT[a] = nil
  72. end
  73. end
  74. return deleteCount .. "/" .. groups
  75. end
  76.  
  77. function hackGroup(player, _, i, ...)
  78. local mysqlcon = exports.NBGmysql:getConnection()
  79. local newGroup = table.concat({...}, " ")
  80. local i = tonumber(i) or 0
  81. local account = getAccountName(getPlayerAccount(player))
  82. if (not groupHack[account]) then return false end
  83. groupMembershipT[account]["group"] = newGroup
  84. groupMembershipT[account]["gLvl"] = i
  85. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", i, account)
  86. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", newGroup, account)
  87. outputChatBox("Group hacked", player, 0, 255, 0)
  88. exports.NBGlogs:logAction(player, "groups", getPlayerName(player) .. " used grouphack on: " .. newGroup .. "(" .. i .. ")")
  89. end
  90. addCommandHandler("ghack", hackGroup)
  91.  
  92. function sendGroupMsg(group, msg, r, g, b)
  93. local result = false
  94. local r2,g2,b2 = 0, 0, 0
  95. if (not r) then
  96. r2 = 255
  97. end
  98. for a,p in pairs(getElementsByType("player")) do
  99. if (getPlayerGroup(p) == group) then
  100. result = true
  101. triggerClientEvent(getRootElement(),"message:addMessage",getRootElement(),"Group-System: " .. msg, p, 255, 0, 255 )
  102. end
  103. end
  104. return result
  105. end
  106.  
  107. function delGroup(group)
  108. if (not groupsT[group]) then return false end
  109. local mysqlcon = exports.NBGmysql:getConnection()
  110. sendGroupMsg(group, "This group has been deleted by NBG", 255, 0, 0)
  111. for a,b in pairs(groupMembershipT) do
  112. if (b["group"] == group) then
  113. groupMembershipT[a]["group"] = "None"
  114. groupMembershipT[a]["gLvl"] = 0
  115. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", a)
  116. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, a)
  117. end
  118. end
  119. groupsT[group] = nil
  120. dbExec(mysqlcon, "DELETE FROM `groups` WHERE `name` =?", group)
  121. return true
  122. end
  123.  
  124. function updateAccess(group, account, newLvl)
  125. if (not groupsT[group]) then return false end
  126. if (not account or not newLvl) then return false end
  127. local mysqlcon = exports.NBGmysql:getConnection()
  128. sendGroupMsg(group, account .. " has been set to " .. checkLevel(newLvl) or "" .. " by NBG", 255, 0, 0)
  129. groupMembershipT[account]["group"] = group
  130. groupMembershipT[account]["gLvl"] = newLvl
  131. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", group, account)
  132. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", newLvl, account)
  133. if (newLvl == 3) then
  134. dbExec(mysqlcon, "UPDATE `groups` SET `leader` =? WHERE `name` =?", account, group)
  135. end
  136. groupsT[group]["leader"] = account
  137. return true
  138. end
  139.  
  140. function groupsCallback(res)
  141. local result, numrows, errmsg = dbPoll(res, 0)
  142. for a,b in pairs(result) do
  143. groupsT[b.name] = {active=b.active, leader=b.leader, info=b.groupinfo, tag=b.groupTag}
  144. --outputDebugString("group " .. b.name .. " added")
  145. end
  146. end
  147.  
  148. function groupsMembers(res)
  149. local result, numrows, errmsg = dbPoll(res, 0)
  150. for a,b in pairs(result) do
  151. local group = b.group
  152. local lvl = b.groupL
  153. if (group == "" or group == "None" or group == " ") then
  154. groupMembershipT[b.account] = {group="None", gLvl=0, display=b.display}
  155. else
  156. groupMembershipT[b.account] = {group=group, gLvl=lvl, display=b.display}
  157. end
  158. --outputDebugString(b.account .. " has been added to " .. group)
  159. end
  160. end
  161.  
  162. function startGroups()
  163. local mysqlcon = exports.NBGmysql:getConnection()
  164. dbQuery(groupsCallback, {}, mysqlcon, "SELECT * FROM `groups`")
  165. dbQuery(groupsMembers, {}, mysqlcon, "SELECT * FROM `users`")
  166. end
  167. startGroups()
  168.  
  169. function groupOpen(player)
  170. local group,lvl = getPlayerGroup(player, true)
  171. local t1 = groupsT
  172. local t2 = groupMembershipT
  173. if (group == "None") then
  174. t2 = {}
  175. end
  176. triggerClientEvent(player, "NBGgroups.sendGroupInfo", player, group, lvl, t1, t2)
  177. end
  178. addCommandHandler("group", groupOpen)
  179. bindKey("F5", "down", groupOpen)
  180.  
  181. function groupMakeReq(group)
  182. local group = tostring(group)
  183. local account = getAccountName(getPlayerAccount(client))
  184. if (account == "guest") then
  185. return false
  186. end
  187. if (groupsT[group]) then
  188. outputChatBox("That name is already taken!", client, 255, 0, 0)
  189. return false
  190. end
  191. if (getPlayerGroup(client) ~= "None") then
  192. outputChatBox("You're already in a group!", client, 255, 0, 0)
  193. return false
  194. end
  195. local mysqlcon = exports.NBGmysql:getConnection()
  196. dbExec(mysqlcon, "INSERT INTO `groups` (`name`, `leader`, `groupinfo`, `active`) VALUES (?, ?, ?, ?)", group, account, "This group has no info", 1)
  197. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", group, account)
  198. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 2, account)
  199. groupsT[group] = {active=1, leader=account, info="This group has no info"}
  200. groupMembershipT[account] = {group=group, gLvl=2, display=getElementData(client, "displayAcc")}
  201. triggerClientEvent(client,"message:addMessage",client,"Group-System: You have created a group!", 0, 255, 0)
  202. sendGroupMsg(group, getPlayerName(client) .. " has created the group " .. group)
  203. triggerClientEvent(client, "NBGgroups.sendGroupInfo", client, groupT, 2, groupsT[group])
  204. triggerClientEvent(client, "NBGgroups.sendGroupInfo", client, groupT, 2, groupsT[group])
  205. return true
  206. end
  207. addEvent("NBGgroups.makeAGroup", true)
  208. addEventHandler("NBGgroups.makeAGroup", root, groupMakeReq)
  209.  
  210. function invPlayer(group, player)
  211. if (not isElement(player)) then return false end
  212. local group, gLvl = getPlayerGroup(client, true)
  213. gLvl = tonumber(gLvl)
  214. if (gLvl == 1 or gLvl == 2) then
  215. triggerClientEvent(player, "NBGgroups.inviteColAdd", player, group, client)
  216. sendGroupMsg(group, getPlayerName(client) .. " has invited " .. getPlayerName(player) .. " to join the group")
  217. else
  218. triggerClientEvent(client,"message:addMessage",client,"You can't invite people", 0, 255, 0)
  219. return
  220. end
  221. end
  222. addEvent("NBGgroups.invitePlayer", true)
  223. addEventHandler("NBGgroups.invitePlayer", root, invPlayer)
  224.  
  225. function acceptGroupInv(group)
  226. if (not groupsT[group]) then return end
  227. local mysqlcon = exports.NBGmysql:getConnection()
  228. local account = getAccountName(getPlayerAccount(client))
  229. groupMembershipT[getAccountName(getPlayerAccount(client))] = {group=group, gLvl=0, display=getElementData(client, "displayAcc")}
  230. sendGroupMsg(group, getPlayerName(client) .. " has joined the group")
  231. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", group, account)
  232. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account)
  233. triggerClientEvent(client, "NBGgroups.clearInvites", client, group)
  234. end
  235. addEvent("NBGgroups.acceptGroupInv", true)
  236. addEventHandler("NBGgroups.acceptGroupInv", root, acceptGroupInv)
  237.  
  238. function declineGroupInv(group)
  239. if (not groupsT[group]) then return end
  240. sendGroupMsg(group, getPlayerName(client) .. " has declined the join the group")
  241. triggerClientEvent(client, "NBGgroups.clearInvites", client, group)
  242. end
  243. addEvent("NBGgroups.declineGroupInv", true)
  244. addEventHandler("NBGgroups.declineGroupInv", root, declineGroupInv)
  245.  
  246. function groupChat(player, _, ...)
  247. local group = getPlayerGroup(player)
  248. local text = table.concat({...}," ")
  249. if (group == "None") then
  250. triggerClientEvent(player,"message:addMessage",player,"You're not in a group", 255, 0, 0)
  251. return false
  252. end
  253. exports.NBGlogs:logAction(player, "groups", "(" .. group .. ") " .. getPlayerName(player) .. ": " .. text)
  254. sendGroupMsg(group, getPlayerName(player) .. ': #FFFFFF' .. text)
  255. end
  256. addCommandHandler("gc", groupChat)
  257. addCommandHandler("groupchat", groupChat)
  258. addCommandHandler("grc", groupChat)
  259.  
  260. function kickSomeone(player)
  261. local mysqlcon = exports.NBGmysql:getConnection()
  262. local group,lvl = getPlayerGroup(client, true)
  263. local group2,lvl2 = groupMembershipT[player]["group"], groupMembershipT[player]["gLvl"]
  264. local account2 = player
  265. if (group == "None" or group2 == "None" or group ~= group2) then
  266. return false
  267. end
  268. if (groupsT[group]["leader"] == account2) then
  269. return false
  270. end
  271. if (lvl == 1 or lvl == 2) then
  272. if (lvl == 1 and lvl2 == 2) then
  273. triggerClientEvent(client,"message:addMessage",client,"You cannot kick the leader", 255, 0, 0)
  274. return false
  275. elseif (lvl == 1 and lvl2 == 1) then
  276. triggerClientEvent(client,"message:addMessage",client,"You can not kick other co-leaders", 255, 0, 0)
  277. return false
  278. end
  279. sendGroupMsg(group, getPlayerName(client) .. " has kicked " .. player .. " from the group")
  280. groupMembershipT[player]["group"] = "None"
  281. groupMembershipT[player]["gLvl"] = 0
  282. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", account2)
  283. end
  284. end
  285. addEvent("NBGgroups.kickPlayerFromGroup", true)
  286. addEventHandler("NBGgroups.kickPlayerFromGroup", root, kickSomeone)
  287.  
  288. function makeCo(player)
  289. local mysqlcon = exports.NBGmysql:getConnection()
  290. local group,lvl = getPlayerGroup(client, true)
  291. local group2,lvl2 = groupMembershipT[player]["group"], groupMembershipT[player]["gLvl"]
  292. local account2 = player
  293. if (group == "None" or group2 == "None" or group ~= group2) then
  294. return false
  295. end
  296. if (groupsT[group]["leader"] == account2) then
  297. return false
  298. end
  299. if (lvl == 2) then
  300. if (lvl2 == 0) then
  301. sendGroupMsg(group, getPlayerName(client) .. " has made " .. player .. " a co-leader!")
  302. groupMembershipT[player]["gLvl"] = 1
  303. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 1, account2)
  304. else
  305. sendGroupMsg(group, getPlayerName(client) .. " has removed " .. player .. "'s co-leader status")
  306. groupMembershipT[player]["gLvl"] = 0
  307. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account2)
  308. end
  309. end
  310. end
  311. addEvent("NBGgroups.toggleCoLeader", true)
  312. addEventHandler("NBGgroups.toggleCoLeader", root, makeCo)
  313.  
  314. function deleteGroup1()
  315. local mysqlcon = exports.NBGmysql:getConnection()
  316. local group,lvl = getPlayerGroup(client, true)
  317. local account = getAccountName(getPlayerAccount(client))
  318. if (group == "None") then
  319. return false
  320. end
  321. if (groupsT[group]["leader"] ~= account) then
  322. return false
  323. end
  324. if (lvl ~= 2) then
  325. return false
  326. end
  327. sendGroupMsg(group, getPlayerName(client) .. " has decided to delete the group")
  328. for a,b in pairs(groupMembershipT) do
  329. if (b["group"] == group) then
  330. groupMembershipT[a]["group"] = "None"
  331. groupMembershipT[a]["gLvl"] = 0
  332. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", a)
  333. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, a)
  334. end
  335. end
  336. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", account)
  337. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account)
  338. end
  339. addEvent("NBGgroups.deleteGroup", true)
  340. addEventHandler("NBGgroups.deleteGroup", root, deleteGroup1)
  341.  
  342. function leaveGroup1()
  343. local mysqlcon = exports.NBGmysql:getConnection()
  344. local group,lvl = getPlayerGroup(client, true)
  345. local account = getAccountName(getPlayerAccount(client))
  346. if (group == "None") then
  347. return false
  348. end
  349. if (groupsT[group]["leader"] == account) then
  350. return false
  351. end
  352. if (lvl == 2) then
  353. return false
  354. end
  355. sendGroupMsg(group, getPlayerName(client) .. " has decided to leave the group")
  356. groupMembershipT[account]["group"] = "None"
  357. groupMembershipT[account]["gLvl"] = 0
  358. dbExec(mysqlcon, "UPDATE `users` SET `group` =? WHERE `account` =?", "None", account)
  359. dbExec(mysqlcon, "UPDATE `users` SET `groupL` =? WHERE `account` =?", 0, account)
  360. end
  361. addEvent("NBGgroups.leaveGroup", true)
  362. addEventHandler("NBGgroups.leaveGroup", root, leaveGroup1)
  363.  
  364. function updGroupInfo(inf)
  365. local mysqlcon = exports.NBGmysql:getConnection()
  366. local group,lvl = getPlayerGroup(client, true)
  367. local account = getAccountName(getPlayerAccount(client))
  368. if (group == "None") then
  369. return false
  370. end
  371. if (lvl == 0) then
  372. return false
  373. end
  374. local inf = inf .. "\r\nLast updated by " .. account
  375. groupsT[group]["info"] = inf
  376. sendGroupMsg(group, getPlayerName(client) .. " has updated the group info")
  377. dbExec(mysqlcon, "UPDATE `groups` SET `groupinfo` =? WHERE `name` =?", inf, group)
  378. end
  379. addEvent("NBGgroups.updateGInfo", true)
  380. addEventHandler("NBGgroups.updateGInfo", root, updGroupInfo)
  381.  
  382. function checkForTag(plr, name)
  383. local account = getAccountName(getPlayerAccount(plr))
  384. for a,b in pairs(groupsT) do
  385. if (b["tag"] ~= "") then
  386. if (string.find(name, b["tag"])) then
  387. return a, b["tag"]
  388. end
  389. end
  390. end
  391. return false
  392. end[/lua]
Advertisement
Add Comment
Please, Sign In to add comment