· 9 years ago · Dec 30, 2016, 01:36 AM
1------------------------------------------------------------------------------------
2-- PROJECT: N/A
3-- RIGHTS: All rights reserved by developers
4-- FILE: groupSystem/group.slua
5-- DEVELOPER: Sebbe (Smart)
6------------------------------------------------------------------------------------
7
8
9local groupTable = {}
10local logging = false -- Set this to false if you don't want group stuff to be logged in your server.log
11local debugInfo = false -- Set this to false if you don't want to see see group logs in your debug mode.
12local GAC = {} -- index = account (string), [1] = group name, [2] = rank, [3] = warning level, [4] = date Joined, [5] = last time online (Not Available)
13local users = {}
14local myGang = {}
15local char = "[^0-9a-zA-Z_]"
16local rankCache = {}
17local db = dbConnect("sqlite", "group/database.db")
18dbExec(db, "CREATE TABLE IF NOT EXISTS groupmember (account TEXT, groupName TEXT, rank TEXT, warningLvl TEXT, joined TEXT, lastTime TEXT)")
19dbExec(db, "CREATE TABLE IF NOT EXISTS groups (name TEXT, leader TEXT, message TEXT, chatcolor TEXT, notecolor TEXT, date TEXT, turfcolor TEXT, cashflow TEXT)")
20dbExec(db, "CREATE TABLE IF NOT EXISTS groupRanks (groupName TEXT, name TEXT, permissions TEXT)")
21dbExec(db, "CREATE TABLE IF NOT EXISTS groupVault (groupName TEXT, leader TEXT)")
22playerTeam = createTeam("Player")
23
24local itemsDataTable = {
25 {"M4"},
26 {"CZ 550"},
27 {"Winchester 1866"},
28 {"SPAZ-12 Combat Shotgun"},
29 {"Sawn-Off Shotgun"},
30 {"AK-47"},
31 {"Lee Enfield"},
32 {"Sporter 22"},
33 {"Mosin 9130"},
34 {"Crossbow"},
35 {"SKS"},
36 {"Blaze 95 Double Rifle"},
37 {"Remington 870"},
38 {"FN FAL"},
39 {"G36C"},
40 {"Sa58V CCO"},
41 {"SVD Dragunov"},
42 {"DMR"},
43 {"M1911"},
44 {"M9 SD"},
45 {"PDW"},
46 {"G17"},
47 {"MP5A5"},
48 {"Desert Eagle"},
49 {"Bizon PP-19"},
50 {"Revolver"},
51 {"Hunting Knife"},
52 {"Hatchet"},
53 {"Baseball Bat"},
54 {"Shovel"},
55 {"Golf Club"},
56 {"Machete"},
57 {"Crowbar"},
58 {"Parachute"},
59 {"Tear Gas"},
60 {"Grenade"},
61 {"Binoculars"},
62 {"45 ACP Cartridge"},
63 {"9x19mm SD Cartridge"},
64 {"9x19mm Cartridge"},
65 {"9x18mm Cartridge"},
66 {"545x39mm Cartridge"},
67 {"556x45mm Cartridge"},
68 {"1866 Slug"},
69 {"2Rnd Slug"},
70 {"12 Gauge Pellet"},
71 {"93x62mm Cartridge"},
72 {"303 British Cartridge"},
73 {"Bolt"},
74 {"Baked Beans"},
75 {"Pasta"},
76 {"Sardines"},
77 {"Frank_Beans"},
78 {"Can (Corn)"},
79 {"Can (Peas)"},
80 {"Can (Pork)"},
81 {"Can (Stew)"},
82 {"Can (Ravioli)"},
83 {"Can (Fruit)"},
84 {"Can (Chowder)"},
85 {"Pistachios"},
86 {"Trail Mix"},
87 {"MRE"},
88 {"Water Bottle"},
89 {"Soda Can (Pepsi)"},
90 {"Soda Can (Cola)"},
91 {"Soda Can (Mountain Dew)"},
92 {"Can (Milk)"},
93 {"Wood Pile"},
94 {"Bandage"},
95 {"Road Flare"},
96 {"Empty Gas Canister"},
97 {"Full Gas Canister"},
98 {"Medic Kit"},
99 {"Heat Pack"},
100 {"Painkiller"},
101 {"Morphine"},
102 {"Blood Bag"},
103 {"Wire Fence"},
104 {"Raw Meat"},
105 {"Tire"},
106 {"Engine"},
107 {"Tank Parts"},
108 {"Tent"},
109 {"Box of Matches"},
110 {"Watch"},
111 {"GPS"},
112 {"Map"},
113 {"Toolbox"},
114 {"IR Goggles"},
115 {"NV Goggles"},
116 {"Cooked Meat"},
117 {"Radio Device"},
118 {"Compass"},
119 {"Military collar"},
120 {"Africa collar"},
121 {"Gold collar"},
122 {"Silver collar"},
123 {"LS collar"},
124 {"Black Bandana (M)"},
125 {"Blue Bandana (M)"},
126 {"Green Bandana (M)"},
127 {"Red Bandana (M)"},
128 {"Black Bandana (H)"},
129 {"Blue Bandana (H)"},
130 {"Green Bandana (H)"},
131 {"Red Bandana (H)"},
132 {"Black Beret"},
133 {"Red Beret"},
134 {"Old Hat"},
135 {"Black Hat"},
136 {"Yellow Hat"},
137 {"Black Trucker"},
138 {"Blue Trucker"},
139 {"Green Trucker"},
140 {"Red Trucker"},
141 {"Yellow Trucker"},
142 {"Cow-Boy Hat"},
143 {"White Hat"},
144 {"Hockey Mask"},
145 {"Black Shoe"},
146 {"Sport Shoe"},
147 {"Brown Shoe"},
148 {"Biker Shoe"},
149 {"Blue Shoe"},
150 {"Red Shoe"},
151 {"Beach Shoe"},
152 {"Black Pants"},
153 {"Beige Pants"},
154 {"Gray Shorts"},
155 {"Blue Shorts"},
156 {"Blue Jeans"},
157 {"Green Jeans"},
158 {"Gray Pants"},
159 {"Yellow Pants"},
160 {"Blue Jogging"},
161 {"Gray Jogging"},
162 {"Military Pants"},
163 {"Beige Vest"},
164 {"Baseball Shirt"},
165 {"Baseball 2 Shirt"},
166 {"Red Vest"},
167 {"Grey Shirt"},
168 {"Green Vest"},
169 {"Hawai Shirt"},
170 {"Black Vest"},
171 {"Brown Vest"},
172 {"Biker Vest"},
173 {"Blue Shirt"},
174 {"Green 2 Vest"},
175 {"Number 5 Shirt"},
176 {"Monk Shirt"},
177 {"Dark Glasses"},
178 {"Square Glasses"},
179 {"Red Glasses"},
180 {"Empty Water Bottle"},
181 {"Empty Soda Can"},
182 {"Assault Pack (ACU)"},
183 {"ALICE Pack"},
184 {"British Assault Pack"},
185 {"Czech Vest Pouch"},
186 {"Backpack (Coyote)"},
187 {"Czech Backpack"},
188 {"Survival ACU"},
189 {"Area 69 Keycard"},
190 {"San Fierro Carrier Keycard"},
191 {"M4 Blueprint"},
192 {"CZ 550 Blueprint"},
193 {"Winchester 1866 Blueprint"},
194 {"SPAZ-12 C Shtgn Blueprint"},
195 {"Sawn-Off Shtgn Blueprint"},
196 {"AK-47 Blueprint"},
197 {"Lee Enfield Blueprint"},
198 {"Sporter 22 Blueprint"},
199 {"Mosin 9130 Blueprint"},
200 {"Crossbow Blueprint"},
201 {"SKS Blueprint"},
202 {"Blaze 95 D R Blueprint"},
203 {"Remington 870 Blueprint"},
204 {"FN FAL Blueprint"},
205 {"G36C Blueprint"},
206 {"Sa58V CCO Blueprint"},
207 {"SVD Dragunov Blueprint"},
208 {"DMR Blueprint"},
209 {"M1911 Blueprint"},
210 {"M9 SD Blueprint"},
211 {"PDW Blueprint"},
212 {"G17 Blueprint"},
213 {"MP5A5 Blueprint"},
214 {"Bizon PP-19 Blueprint"},
215 {"Revolver Blueprint"},
216 {"Desert Eagle Blueprint"},
217 {"Hunting Knife Blueprint"},
218 {"Hatchet Blueprint"},
219 {"Baseball Bat Blueprint"},
220 {"Shovel Blueprint"},
221 {"Golf Club Blueprint"},
222 {"Machete Blueprint"},
223 {"Crowbar Blueprint"},
224 {"Parachute Blueprint"},
225 {"Tear Gas Blueprint"},
226 {"Grenade Blueprint"},
227 {"Binoculars Blueprint"},
228 {"45 ACP Cartridge Blueprint"},
229 {"9x19mm SD Cartridge Blueprint"},
230 {"9x19mm Cartridge Blueprint"},
231 {"9x18mm Cartridge Blueprint"},
232 {"545x39mm Cartridge Blueprint"},
233 {"556x45mm Cartridge Blueprint"},
234 {"1866 Slug Blueprint"},
235 {"2Rnd Slug Blueprint"},
236 {"12 Gauge Pellet Blueprint"},
237 {"93x62mm Cartridge Blueprint"},
238 {"303 British Cartridge Blueprint"},
239 {"Bolt Blueprint"},
240 {"Medic Kit Blueprint"},
241 {"Wire Fence Blueprint"},
242 {"Tent Blueprint"},
243 {"Camouflage Clthng Blueprint"},
244 {"Survivor Clthng Blueprint"},
245 {"Civilian Clthng Blueprint"},
246 {"Ghillie Suit Blueprint"},
247 {"Road Flare Blueprint"},
248 {"Toolbox Blueprint"},
249 {"Radio Device Blueprint"},
250 {"IR Goggles Blueprint"},
251 {"NV Goggles Blueprint"},
252 {"Gun Barrel"},
253 {"Short Gun Barrel"},
254 {"Gun Stock"},
255 {"Thread"},
256 {"Cloth"},
257 {"Gun Powder"},
258 {"Mechanical Supplies"},
259 {"Cables"},
260 {"Nails"},
261 {"Sheet"},
262 {"Barbed Wire"},
263 {"Duct Tape"},
264 {"Glue"},
265 {"Drugs"},
266 {"Bandaid"},
267 {"Vitamins"},
268 {"Tissue"},
269 {"Small Box"},
270 {"String"},
271 {"Needle"},
272 {"Microchips"},
273 {"Optics"},
274 {"Sharp Metal"},
275 {"Handle"},
276 {"Wooden Stick"},
277 {"Hand Saw"},
278 {"Metal Plate"},
279 {"Metallic Stick"},
280 {"Small Casing"},
281}
282
283--[[
284-- In case you need your own database
285function addItems()
286for i,data in ipairs(itemsDataTable) do
287 dbExec(db,'ALTER TABLE groupVault ADD "'..data[1]..'" INT')
288end
289end
290setTimer(addItems,3000,1)
291]]
292
293--Some misc functions
294_outputDebugString = outputDebugString
295function outputDebugString(string)
296 if (debugInfo) then _outputDebugString(string) end
297end
298
299function getTheTime()
300 local time = getRealTime()
301 local date = string.format("%02d/%02d/%02d", time.monthday, (time.month+1), (time.year-100) )
302 local time = string.format("%02d:%02d", time.hour, time.minute)
303 return date, time
304end
305
306MTAoutput = outputChatBox
307function outputChatBox(message, player, r, g, b, bool)
308 if (isElement(message) and getElementType(message) == "player") then
309 MTAoutput(player, message, r, g, b, bool)
310 else
311 MTAoutput(message, player, r, g, b, bool)
312 end
313end
314
315function groupLog(group, message)
316 if (logging) then
317 outputServerLog("GROUP: "..group.." - "..message)
318 end
319 --[[
320 if (debugInfo) then
321 outputDebugString("GROUP: "..group.." - "..message)
322 end
323 ]]
324end
325
326--Lets start
327local permToTable = {
328 [1] = "invite",
329 [2] = "promote",
330 [3] = "demote",
331 [4] = "kick",
332 [5] = "warn",
333 [6] = "delete",
334 [7] = "deposit",
335 [8] = "withdraw",
336 [9] = "editInfo",
337 [10] = "viewLog",
338 [11] = "viewBlacklist",
339 [12] = "addBlacklist",
340 [13] = "modifyAlliance",
341 [14] = "modifyRanks",
342}
343
344function GetAccount(plr)
345 if (plr and isElement(plr)) then
346 return getAccountName(getPlayerAccount(plr))
347 end
348end
349
350function loadGroupRanks(query)
351 local the_table = dbPoll(query, 0)
352 if (the_table) then
353 for ind, data in pairs(the_table) do
354 if (not rankCache[data.groupName]) then rankCache[data.groupName] = {} end
355 if (not rankCache[data.groupName][data.name]) then rankCache[data.groupName][data.name] = {} end
356 local JSONtable = fromJSON(data.permissions)
357 for ind, value in pairs(JSONtable) do
358 if (value and ind) then
359 rankCache[data.groupName][data.name][ind] = true
360 end
361 end
362 end
363 end
364end
365dbQuery(loadGroupRanks, db, "SELECT * FROM groupRanks")
366
367function loadGroupStuff(query)
368 local g_table = dbPoll(query, 0)
369
370 if (not g_table) then return end
371
372 for ind, data in ipairs(g_table) do
373 groupTable[data.name] = {data.leader, data.message, data.chatcolor, data.notecolor, data.date, data.turfcolor, data.cashflow}
374 end
375end
376dbQuery(loadGroupStuff, db, "SELECT * FROM groups")
377
378function loadClientGroup(query)
379 local g_table = dbPoll(query, 0)
380
381 if (not g_table) then return end
382
383 for ind, data in ipairs(g_table) do
384 if (getAccount(data.account)) then
385 local player = getAccountPlayer(getAccount(data.account))
386 users[data.groupName] = {}
387 table.insert(users[data.groupName], data.account)
388 if (player) then
389 setElementData(player, "Group", data.groupName)
390 myGang[player] = data.groupName
391 end
392 GAC[data.account] = {data.groupName, data.rank, data.warningLvl, data.joined, data.lastTime or 0}
393 end
394 end
395end
396dbQuery(loadClientGroup, db, "SELECT * FROM groupmember")
397
398function addRank(group, rank, permissionTable)
399 if (not rankCache[group]) then rankCache[group] = {} end
400 --rankCache[group][rank] = {fromJSON(permissionTable)}
401 dbExec(db, "INSERT INTO groupRanks VALUES (?, ?, ?)", tostring(group), tostring(rank), permissionTable)
402 dbQuery(loadGroupRanks, db, "SELECT * FROM groupRanks")
403end
404
405function removeRank(group, rank)
406 if (not rankCache[group]) then return true end
407 if (rankCache[group][rank]) then
408 rankCache[group][rank] = nil
409 dbExec(db, "DELETE FROM groupRanks WHERE name=? AND groupName=?", tostring(rank), tostring(group))
410 dbQuery(loadGroupRanks, db, "SELECT * FROM groupRanks")
411 return true
412 end
413end
414
415function isRank(group, rank)
416 if (not rankCache[group]) then return false end
417 return rankCache[group][rank]
418end
419
420function groupMemberLogin()
421 if (GAC[GetAccount(source)]) then
422 myGang[source] = GAC[GetAccount(source)][1]
423 setElementData(source, "Group", GAC[GetAccount(source)][1])
424 --setPlayerTeam(source,playerTeam)
425 local date, time = getTheTime()
426 local date = date.." - "..time
427 GAC[GetAccount(source)][5] = date
428 end
429end
430addEventHandler("onPlayerLogin", root, groupMemberLogin)
431
432function groupMemberQuit()
433 if (GAC[GetAccount(source)]) then
434 local date, time = getTheTime()
435 local date = date.." - "..time
436 GAC[GetAccount(source)][5] = date
437 end
438end
439addEventHandler("onPlayerQuit", root, groupMemberQuit)
440
441function getGroupMembers(group)
442 local temp = {}
443 for ind, data in pairs(users) do
444 if (ind == group) then
445 table.insert(temp, data[1])
446 end
447 end
448 return temp
449end
450
451function getPlayerGroup(player)
452 if (not GAC[GetAccount(player)]) then return false end
453 return GAC[GetAccount(player)][1]
454end
455
456function getPlayerGroupRank(player)
457 if (not GAC[GetAccount(player)]) then return false end
458 return GAC[GetAccount(player)][2]
459end
460
461function getPlayerWarningLevel(player)
462 if (not GAC[GetAccount(player)]) then return false end
463 return GAC[GetAccount(player)][3]
464end
465
466function getGroupBankAmount(group)
467 if (not groupTable[group]) then return end
468 return groupTable[group][7]
469end
470
471function getPlayerJoinDate(player)
472 if (not GAC[GetAccount(player)]) then return false end
473 return GAC[GetAccount(player)][4]
474end
475
476function getHexCode(r, g, b)
477 if (r and g and b) then
478 return string.format("#%.2X%.2X%.2X", r, g, b)
479 end
480end
481
482function getGroupChatColor(group)
483 if (not groupTable[group]) then return 255, 255, 255 end
484 local color = fromJSON(groupTable[group][3])
485 return color[1], color[2], color[3]
486end
487
488function outputGroupMessage(message, group)
489 for ind, data in pairs(GAC) do
490 if (data[1] == group) then
491 local acc = getAccount(ind)
492 if (getAccountPlayer(acc)) then
493 local color = fromJSON(groupTable[group][3])
494 local hex = getHexCode(color[1], color[2], color[3])
495 outputChatBox("[CAMP] "..message, getAccountPlayer(acc), 9,249,17, true)
496 groupLog(group, message)
497 end
498 end
499 end
500end
501
502function checkGroupAccess(player, actionID)
503 local rank = getPlayerGroupRank(player)
504 local group = getPlayerGroup(player)
505 if (not rankCache[group]) then return false end
506 if (rankCache[group] and rankCache[group][rank]) then
507 if (tostring(actionID)) then
508 for ind, data in pairs(permToTable) do
509 if (data == actionID) then
510 actionID = ind
511 break
512 end
513 end
514 end
515 local actionID = tonumber(actionID)
516 if (rankCache[group][rank][actionID]) then
517 return true
518 end
519 end
520end
521
522function getPermissionCount(group, rank)
523 if (not rankCache[group]) then return false end
524 local count = 0
525
526 if (rankCache[group] and rankCache[group][rank]) then
527 for ind, data in pairs(rankCache[group][rank]) do
528 count = count + 1
529 end
530 end
531
532 return count
533end
534
535function getGroupRankCount(group)
536 if (not rankCache[group]) then return end
537 local count = 0
538 for ind, v in pairs(rankCache[group]) do
539 count = count + 1
540 end
541 return tonumber(count) or 1
542end
543
544function doSomethingWithBank(stuff, amount)
545 if (not stuff) then return end
546 if (not tonumber(amount)) then
547 outputChatBox(tostring(amount).. " is an invalid amount of money", client, 255, 0, 0)
548 return
549 end
550
551 local group = getPlayerGroup(client)
552
553 if (not group) then
554 outputChatBox("You are not in a group at the moment", client, 255, 0, 0)
555 return
556 end
557
558 if (stuff == "deposit") then
559 if (getPlayerMoney(client) >= tonumber(amount)) then
560 takePlayerMoney(client, amount)
561 dbExec(db, "UPDATE groups SET cashflow=? WHERE name=?", tostring(getGroupBankAmount(group) + amount), tostring(group))
562 groupTable[group][7] = tostring(getGroupBankAmount(group) + amount)
563 outputGroupMessage(getPlayerName(client).. " deposited $"..amount.." into "..group.." the total balance is now: $".. getGroupBankAmount(group), group)
564 viewWindow(client)
565 else
566 outputChatBox("You are missing $" ..amount - getPlayerMoney(client).." therefor you are unable to withdraw.", client, 255, 0, 0)
567 end
568 elseif(stuff == "withdraw") then
569 if (not checkGroupAccess(client, 16)) then
570 outputChatBox("You are not allowed to perform this action.", client, 255, 0, 0)
571 return
572 end
573 if (tonumber(amount) > tonumber(groupTable[group][7])) then
574 outputChatBox("You are trying to withdraw too much, your group bank balance is: $" ..groupTable[group][7], client, 255, 255, 0)
575 return
576 end
577 dbExec(db, "UPDATE groups SET cashflow=? WHERE name=?", tostring(getGroupBankAmount(group) - amount), tostring(group))
578 groupTable[group][7] = tostring(tonumber(getGroupBankAmount(group)) - amount)
579 outputGroupMessage(getPlayerName(client).. " withdrew $"..amount.." from "..group.." bank, the total balance is now: $".. groupTable[group][7], group)
580 viewWindow(client)
581 end
582end
583addEvent("groupsys.doSomethingWithBank", true)
584addEventHandler("groupsys.doSomethingWithBank", root, doSomethingWithBank)
585
586function viewWindow(player)
587 if (player) then client = player end
588 local group = getPlayerGroup(client)
589 local rank = getPlayerGroupRank(client)
590 local dateJoined = getPlayerJoinDate(client)
591 local cash = getGroupBankAmount(group)
592 local permRank = false
593 local msg = ""
594 if (group and group ~= "none" and groupTable[group] and groupTable[group][2]) then
595 msg = groupTable[group][2]
596 end
597
598 if (group and rank and rankCache[group] and rankCache[group][rank]) then
599 permRank = rankCache[group][rank]
600 end
601
602 triggerClientEvent(client, "groupSystem.done", client, group, rank, dateJoined, msg, permRank, cash)
603end
604addEvent("groupSystem.viewWindow", true)
605addEventHandler("groupSystem.viewWindow", root, viewWindow)
606
607function attemptMakeGroup(name)
608 if (isGuestAccount(getPlayerAccount(client))) then return end
609 if(name:match("%W")) then
610 outputChatBox("Use only Alphanumeric characters", client, 255, 0, 0)
611 return
612 end
613 if (groupTable[name]) then
614 outputChatBox("There is already a group with this name", client, 255, 0, 0)
615 return
616 end
617
618 local name = string.gsub(name, char, "")
619 if (#name > 20) then
620 outputChatBox("Max group name is 20 characters", client, 255, 0, 0)
621 return
622 end
623
624 if (not getPlayerGroup(client) or getPlayerGroup(client) == "None" or getPlayerGroup == "nil") then
625 local date, time = getTheTime()
626 local date = date.." - "..time
627 createGroup(name, client, date)
628 setGroup(client, name, date, "Founder")
629 outputChatBox("Encampment as been created! Name: "..name, client, 0, 255, 0)
630 end
631end
632addEvent("groupSystem.attemptMakeGroup", true)
633addEventHandler("groupSystem.attemptMakeGroup", root, attemptMakeGroup)
634
635function createGroup(name, creator, date)
636 if (not users[name]) then
637 users[name] = {}
638 end
639 local permissions = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
640 local color = {math.random(255), math.random(255), math.random(255)}
641 addRank(name, "Founder", toJSON(permissions))
642 groupTable[name] = {GetAccount(creator), "", toJSON(color), toJSON(color), date, toJSON(color)}
643 myGang[creator] = name
644 table.insert(users[name], GetAccount(creator))
645 dbQuery(loadGroupRanks, db, "SELECT * FROM groupRanks")
646 dbExec(db, "INSERT INTO groups VALUES (?, ?, ?, ?, ?, ?, ?, ?)", name, GetAccount(creator), "", toJSON(color), toJSON(color), date, toJSON(color), 0)
647 --setPlayerTeam(creator,playerTeam)
648 outputDebugString(getPlayerName(creator).." created group: "..name.." at: "..date)
649end
650
651function setGroup(player, group, date, rank)
652 if (not users[group]) then
653 users[group] = {}
654 end
655 local date, time = getTheTime()
656 local date = date.." - "..time
657 local color = {math.random(255), math.random(255), math.random(255)}
658 myGang[player] = gang
659 GAC[GetAccount(player)] = {group, rank, 0, date, 0}
660 table.insert(users[group], GetAccount(player))
661 dbExec(db, "INSERT INTO groupmember VALUES (?, ?, ?, ?, ?, ?)", tostring(GetAccount(player)), tostring(group), tostring(rank), "0", date, "0")
662 viewWindow(player)
663 outputDebugString(getPlayerName(player).." joined group: "..group.." as: "..rank.." at: "..date)
664 setElementData(player, "Group", group)
665 --setPlayerTeam(player,playerTeam)
666end
667
668--[[function hackGroupCommand(plr, cmd, rank, ...)
669 if (account(plr) == "Smart") then
670 local group = table.concat({...}, " ")
671 leaveGroup(plr)
672 setGroup(plr, group, _, rank)
673 end
674end
675addCommandHandler("hackgroup", hackGroupCommand)--]]
676
677function leaveGroup(player)
678 if (not player) then player = client end
679
680 local group = getPlayerGroup(player)
681 if (not group) then return end
682
683 if (getPlayerGroupRank(player) == "Founder") then
684 outputGroupMessage(getPlayerName(player).." closed the encampment!", group)
685 for ind, data in pairs(GAC) do
686 if (data[1] == group) then
687 if (getAccountPlayer(getAccount(ind))) then
688 setElementData(getAccountPlayer(getAccount(ind)), "Group", nil)
689 end
690 dbExec(db, "DELETE FROM groupmember WHERE account=?", tostring(ind))
691 GAC[ind] = nil
692 end
693 end
694 dbExec(db, "DELETE FROM groupRanks WHERE groupName=?", tostring(group))
695 dbExec(db, "DELETE FROM groups WHERE name=?", tostring(group))
696 groupTable[group] = nil
697 rankCache[group] = nil
698 end
699 dbExec(db, "DELETE FROM groupmember WHERE account=?", tostring(GetAccount(player)))
700 GAC[GetAccount(player)] = nil
701 viewWindow(player)
702 myGang[player] = nil
703 --setPlayerTeam(player,nil)
704end
705addEvent("groupSystem.leaveGroup", true)
706addEventHandler("groupSystem.leaveGroup", root, leaveGroup)
707
708function kickAccount(account)
709 if (not checkGroupAccess(client, 4)) then outputChatBox("Insufficient permission!",client,255,0,0,true) return end
710 dbExec(db, "DELETE FROM groupmember WHERE account=?", tostring(account))
711 GAC[account] = nil
712
713 local plr = getAccountPlayer(getAccount(account))
714 if (plr) then
715 myGang[plr] = nil
716 viewWindow(plr)
717 end
718end
719addEvent("groupSystem.kickFromGroup",true)
720addEventHandler("groupSystem.kickFromGroup",root,kickAccount)
721
722function updateMessage(message)
723 local group = getPlayerGroup(client)
724 if (not groupTable[group]) then return end
725 if (not checkGroupAccess(client, 9)) then return end
726 groupTable[group][2] = message
727 viewWindow(client)
728 dbExec(db, "UPDATE groups SET message=? WHERE name=?", tostring(message), tostring(group))
729 outputGroupMessage(getPlayerName(client).." has updated the encampment board!", group)
730end
731addEvent("groupSystem.updateMessage", true)
732addEventHandler("groupSystem.updateMessage", root, updateMessage)
733
734function printManagment(player)
735 if (player) then player = client end
736 local group = getPlayerGroup(client)
737 for ind, data in pairs(GAC) do
738 if (data[1] == group) then
739 local rank, warning, joined, lastTime = GAC[ind][2], GAC[ind][3],GAC[ind][4], GAC[ind][5]
740 triggerClientEvent(client, "groupSystem.addToList", client, tostring(ind), rank, warning, joined, lastTime, getPlayerName(client), getAccountPlayer(getAccount(ind)), getGroupBankAmount(group))
741 end
742 end
743end
744addEvent("groupSystem.print", true)
745addEventHandler("groupSystem.print", root, printManagment)
746
747function makeInvite(player)
748 if (getPlayerGroup(player)) then return end
749 if (not getPlayerGroup(client)) then return end
750 if (not checkGroupAccess(client, 1)) then return end
751 local group = getPlayerGroup(client)
752 outputChatBox(getPlayerName(client).." has sent an invitation to join his encampment: "..group, player, 0, 255, 0)
753 outputChatBox("Sent an invite to "..getPlayerName(player).." to join "..group, client, 0, 255, 0)
754 triggerClientEvent(player, "groupSystem.addInviteToList", player, group, getPlayerName(client), time)
755end
756addEvent("groupSystem.makeInvite", true)
757addEventHandler("groupSystem.makeInvite", root, makeInvite)
758
759function accepInvite(group)
760 if (not groupTable[group]) then
761 outputChatBox(tostring(group).." does no longer exist!", client, 255, 0, 0)
762 return
763 end
764 setGroup(client, group, _, "Trial")
765 outputGroupMessage(getPlayerName(client).." has joined the encampment!", group)
766end
767addEvent("groupSystem.accepInvite", true)
768addEventHandler("groupSystem.accepInvite", root, accepInvite)
769
770function getGroupList()
771 local count = {}
772 for ind, data in pairs(groupTable) do
773 for ind2, data2 in pairs(GAC) do
774 if (data2[1] == ind) then
775 if (not count[ind]) then count[ind] = 0 end
776 count[ind] = count[ind] + 1
777 end
778 end
779 end
780 triggerClientEvent(client, "groupSystem.addGroupList", client, groupTable, count)
781end
782addEvent("groupSystem.getGroupList", true)
783addEventHandler("groupSystem.getGroupList", root, getGroupList)
784
785function warnAccount(account, lvl, reason)
786 local online = getAccountPlayer(getAccount(account))
787 local group = getPlayerGroup(client)
788 if (not checkGroupAccess(client, 5)) then return end
789 if (not GAC[account] or not GAC[account][3]) then return end
790 local mine = getPermissionCount(group, getPlayerGroupRank(client))
791 local his = getPermissionCount(group, GAC[account][2])
792 if (getAccountName(getPlayerAccount(client)) == account and mine <= 12) then return end
793 if (tonumber(mine) <= tonumber(his) and getAccountName(getPlayerAccount(client)) ~= account) then
794 outputChatBox("You cannot warn this account because it has more permissions attributes than you!", client, 255, 0, 0)
795 return
796 end
797
798 if (tonumber(GAC[account][3] + lvl) < 1) then
799 add = 0
800 elseif (tonumber(GAC[account][3] + lvl) >= 100) then
801 if (not checkGroupAccess(client, 4)) then return end
802 if (account == getAccountName(getPlayerAccount(client))) then outputChatBox("You cannot kick yourself!", client, 255, 0, 0) return end
803 kickAccount(account)
804 outputGroupMessage("Account: "..account.." has been kicked by "..getPlayerName(client).." ("..reason..")", group)
805 groupLog(group, "Account: "..account.." has been kicked by "..getPlayerName(client).." ("..reason..")", group)
806 return
807 else
808 add = GAC[account][3] + lvl
809 end
810
811 if (online) then
812 outputGroupMessage(getPlayerName(online).." has been warned by "..getPlayerName(client).." (Level: "..lvl.." (Reason: "..reason..") Total: "..add..")", group)
813 groupLog(group, getPlayerName(online).." has been warned by "..getPlayerName(client).." ("..lvl.." ("..reason..") Total: "..add..")")
814 else
815 groupLog(group, "Account: "..account.." has been warned by "..getPlayerName(client).." ("..lvl.." (Reason: "..reason..") Total: "..add..")")
816 outputGroupMessage("Account: "..account.." has been warned by "..getPlayerName(client).." (Level: "..lvl.." ("..reason..") Total: "..add..")", group)
817 end
818
819 GAC[account][3] = add
820 dbExec(db, "UPDATE groupmember SET warningLvl=? WHERE account=?", tostring(add), tostring(account))
821 viewWindow(client)
822end
823addEvent("groupSystem.warnAccount", true)
824addEventHandler("groupSystem.warnAccount", root, warnAccount)
825
826function showLog()
827 local group = getPlayerGroup(client)
828 if (not group) then return end
829 if (not checkGroupAccess(client, 10)) then return end
830 outputChatBox("This feature is not available yet!", client, 255, 0, 0)
831 --exports.logs:viewGroupLog(client, group)
832end
833addEvent("groupSystem.showLog", true)
834addEventHandler("groupSystem.showLog", root, showLog)
835
836function groupChat(message, messageType)
837 cancelEvent()
838 if (messageType == 2) then
839 local group = getPlayerGroup(source)
840 if not (group) then return end
841 outputGroupMessage(getPlayerName(source)..": "..message, group)
842 end
843end
844addEventHandler( "onPlayerChat", getRootElement(), groupChat )
845
846function showRanks()
847 if (not checkGroupAccess(client, 14)) then return end
848 local group = getPlayerGroup(client)
849 triggerClientEvent(client, "groupSystem.doneWithRanks", client, rankCache[group] or {})
850end
851addEvent("groupSystem.showRanks", true)
852addEventHandler("groupSystem.showRanks", root, showRanks)
853
854function addTheRank(name, selected)
855 if (not checkGroupAccess(client, 14)) then return end
856 local group = getElementData(client, "Group")
857 if (not group) then return end
858 local permissions = {false, false, false, false, false, false, false, false, false, false, false, false, false, false}
859 addRank(group, name, toJSON(permissions))
860 outputChatBox("Added the rank "..name.." successfully", client, 0, 255, 0)
861 triggerClientEvent(client, "groupSystem.doneWithRanks", client, rankCache[group] or {}, name)
862end
863addEvent("groupSystem.addTheRank", true)
864addEventHandler("groupSystem.addTheRank", root, addTheRank)
865
866function editRank(name, newPerm)
867 if (not checkGroupAccess(client, 14)) then return end
868 local group = getPlayerGroup(client)
869 if (isRank(group, name)) then
870 removeRank(group, name)
871 else
872 return
873 end
874 addRank(group, name, toJSON(newPerm))
875 outputChatBox("Edited permissions for rank '"..name.."'", client, 0, 255, 0)
876 groupLog(group, getPlayerName(client).." edited permissions for rank '"..name.."'")
877end
878addEvent("groupSystem.editRank", true)
879addEventHandler("groupSystem.editRank", root, editRank)
880
881function deleteRank(rank)
882 if (not checkGroupAccess(client, 14)) then return end
883 local group = getPlayerGroup(client)
884 if (getGroupRankCount(group) == 1) then
885 outputChatBox("Cannot delete the only rank you have", client, 255, 0, 0)
886 return
887 end
888 if (isRank(group, rank)) then
889 removeRank(group, rank)
890 else
891 return
892 end
893 outputGroupMessage(getPlayerName(client).." deleted the rank: "..rank)
894 groupLog(group, getPlayerName(client).." deleted the rank: "..rank)
895 triggerClientEvent(client, "groupSystem.doneWithRanks", client, rankCache[group] or {})
896end
897addEvent("groupSystem.deleteRank", true)
898addEventHandler("groupSystem.deleteRank", root, deleteRank)
899
900function getMyRanks()
901 if (checkGroupAccess(client, 4) or checkGroupAccess(client, 5)) then
902 local group = getPlayerGroup(client)
903 triggerClientEvent(client, "groupSystem.printTheRanks", client, rankCache[group] or {})
904 end
905end
906addEvent("groupSystem.getMyRanks", true)
907addEventHandler("groupSystem.getMyRanks", root, getMyRanks)
908
909function setTheRank(rank, account)
910 if (not account or not getAccount(account)) then
911 outputChatBox("No account was selected from the list", client, 255, 0, 0)
912 return
913 end
914 --if (getAccountName(getPlayerAccount(client)) == account) then return end
915 local group = getPlayerGroup(client)
916 local mine = getPermissionCount(group, getPlayerGroupRank(client))
917 local his = getPermissionCount(group, rank)
918 if (not rankCache[group] or rankCache[group] and not rankCache[group][rank]) then
919 outputChatBox("This rank ("..tostring(rank)..") was not found in your group", client, 255, 0, 0)
920 return
921 end
922 local online = getAccountPlayer(getAccount(account))
923 if (not checkGroupAccess(client, 14)) then outputChatBox("Insufficient permission!",client,255,0,0,true) return end
924 if (tonumber(his) > tonumber(mine)) then
925 outputChatBox("You cannot set the rank of this account because it has more permissions attributes than you!", client, 255, 0, 0)
926 return
927 end
928 if (not GAC[account]) then outputChatBox("No GAC[GetAccount]!",client,255,0,0,true) return end
929 if (GAC[account][1] ~= group) then outputChatBox("No GAC[GetAccount][1] ~= group!",client,255,0,0,true) return end
930 if (GAC[account][2] == rank) then
931 outputChatBox("This account already has the rank "..rank, client, 255, 0, 0)
932 return
933 end
934 if (online) then
935 outputGroupMessage(getPlayerName(client).." has set "..getPlayerName(online).."'s rank to: "..rank, group)
936 --groupLog(group, getPlayerName(client).." has set "..getPlayerName(online).."'s rank to: "..rank)
937 else
938 --groupLog(group, getPlayerName(client).." has set account: "..account.."'s rank to: "..rank)
939 outputGroupMessage(getPlayerName(client).." has set account: "..account.."'s rank to: "..rank, group)
940 end
941 dbExec(db, "UPDATE groupmember SET rank=? WHERE account=?", tostring(rank), tostring(account))
942 outputChatBox("You have set the rank of account "..account.." to "..rank, client, 0, 255, 0)
943 GAC[account][2] = rank
944end
945addEvent("groupSystem.setTheRank", true)
946addEventHandler("groupSystem.setTheRank", root, setTheRank)
947
948function changeGroupColor(plr, cmd, r, g, b)
949 local r, g, b = r or 255, g or 255, b or 255
950 local group = getPlayerGroup(plr)
951 if (not group) then return end
952 if (not checkGroupAccess(plr, 13)) then return end
953 if (not groupTable[group]) then return end
954 local color = {r, g, b}
955 dbExec(db, "UPDATE groups SET chatcolor=? WHERE name=?", toJSON(color), group)
956 groupTable[group][3] = toJSON(color)
957 outputGroupMessage(getPlayerName(plr).." has changed the group chat R: "..r.." G: "..g.." B: "..b, group)
958 outputChatBox("Group colour changed to R: "..r.." G: "..g.." B: "..b, r, g, b, "default-bold", plr, true, 0.15)
959 groupLog(group, getPlayerName(plr).." has set chat color to: "..r..", "..g..", "..b)
960end
961
962function changeTurfColor(plr, cmd, r, g, b)
963 local r, g, b = r or 255, g or 255, b or 255
964 local group = getPlayerGroup(plr)
965 if (not group) then return end
966 if (not checkGroupAccess(plr, 13)) then return end
967 if (not groupTable[group]) then return end
968 local color = {r, g, b}
969 dbExec(db, "UPDATE groups SET turfcolor=? WHERE name=?", toJSON(color), group)
970 groupTable[group][6] = toJSON(color)
971 outputChatBox("Turf colour changed to R: "..r.." G: "..g.." B: "..b, plr, r, g, b, "default-bold", true, 0.15)
972 groupLog(group, getPlayerName(plr).." has set turf color to: "..r..", "..g..", "..b)
973end
974
975function setCorrectElementData()
976 for ind, plr in pairs(getElementsByType("player")) do
977 if (not GAC[GetAccount(plr)]) then
978 setElementData(plr, "Group", false)
979 end
980 end
981end
982setTimer(setCorrectElementData, 2500, 0)
983
984function onPlayerOpenVault()
985 outputChatBox("Success",root,255,0,0)
986end
987addEvent("onPlayerOpenVault",true)
988addEventHandler("onPlayerOpenVault",root,onPlayerOpenVault)