· 8 years ago · Jul 01, 2018, 12:36 AM
1-- Alignment System by Zelix
2
3local charactersSQL = [[
4CREATE TABLE IF NOT EXISTS `character_alignment` (
5 `guid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Global Unique Identifier',
6 `name` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
7 `score` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Score',
8 `standing` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
9 `purity` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Purity',
10 PRIMARY KEY (`guid`)
11)
12COMMENT='Stores Alignment Scores for Characters.'
13COLLATE='latin1_swedish_ci'
14ENGINE=InnoDB;
15]]
16CharDBQuery(charactersSQL)
17
18local worldSQL = [[
19CREATE TABLE IF NOT EXISTS `item_alignment` (
20 `id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Item ID',
21 `Name` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
22 `ReqStanding` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
23 `ReqPurity` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Required Purity',
24 PRIMARY KEY (`id`)
25)
26COMMENT='Stores Alignment Requirements for Items.'
27COLLATE='latin1_swedish_ci'
28ENGINE=InnoDB;
29]]
30WorldDBQuery(worldSQL)
31
32-- Send Certain Broadcasts to Player for Debugging
33local verbose = 1
34-- Increase or Decrease amount of Alignment Gain, Globally.
35local bonus = 1
36-- Wrong Item Equipped Penlty, 1 = Break Item, 2 = Remove & Replace (Removes Enchants / Crashy), 3 = Remove & Don't Replace.
37local WIEP = 1
38-- Class Mods (NYI) ??
39
40
41-- local Pure_Neutral = 1000
42-- local Pure_Good = 2000
43-- local Pure_Evil = 0
44-- local Evil_Threshold = 500
45-- local Good_Threshold = 1500
46
47function ALogin(event, player)
48 local pguid = player:GetGUIDLow()
49 local pname = player:GetName()
50 local pstanding = "Neutral"
51 local sql = CharDBQuery("SELECT * FROM character_alignment WHERE guid="..pguid.."")
52 if (verbose >= 1 and sql) then player:SendBroadcastMessage("You're already in the Database.") end
53 if (not sql) then CharDBExecute("INSERT INTO character_alignment (guid, name, score, standing, purity) VALUES ("..pguid..", '"..pname.."', 1000, '"..pstanding.."', 1)") end
54end
55
56function Modscore(player, side, amount)
57 amount = amount*bonus
58 if (verbose >= 1) then player:SendBroadcastMessage("Cheating Alignment ("..side..")") end
59 local pguid = player:GetGUIDLow()
60 local sql = CharDBQuery("SELECT * FROM character_alignment WHERE guid="..pguid.."")
61 local currentscore = sql:GetUInt32(2)
62 if (side == "Good") then
63 if (currentscore < 2000) then
64 currentscore = currentscore + amount
65 if (currentscore > 2000) then currentscore = 2000 end
66 else player:SendBroadcastMessage("You cannot become anymore Good.") end
67 else
68 if (currentscore > 0) then
69 currentscore = currentscore - amount
70 if (currentscore < 0) then currentscore = 0 end
71 else player:SendBroadcastMessage("You cannot become anymore Evil.") end
72 end
73 player:SendBroadcastMessage("You've gained "..amount.." Alignment towards "..side.."!")
74 CharDBQuery("UPDATE character_alignment SET score="..currentscore.." WHERE guid="..pguid.."")
75 SetStanding(player)
76end
77
78function SetStanding(player)
79 local pguid = player:GetGUIDLow()
80 local sql = CharDBQuery("SELECT * FROM character_alignment WHERE guid="..pguid.."")
81 local currentscore = sql:GetUInt32(2)
82 local oldstanding = sql:GetString(3)
83 local pstanding = ""
84 if(currentscore < 501) then pstanding = "Evil" end
85 if(currentscore > 500 and currentscore < 1000) then pstanding = "Neutral" end
86 if(currentscore > 1000 and currentscore < 1500) then pstanding = "Neutral" end
87 if(currentscore > 1499) then pstanding = "Good" end
88 if(currentscore == 0 or currentscore == 1000 or currentscore == 2000) then
89 CharDBQuery("UPDATE character_alignment SET purity=1 WHERE guid="..pguid.."")
90 else
91 CharDBQuery("UPDATE character_alignment SET purity=0 WHERE guid="..pguid.."")
92 end
93 if (pstanding ~= oldstanding) then
94 player:SendBroadcastMessage("Your Alignment standing is now "..pstanding.."!")
95 CharDBQuery("UPDATE character_alignment SET standing='"..pstanding.."' WHERE guid="..pguid.."")
96 end
97end
98
99function BreakItem(player, item, slot)
100 if (verbose >= 1) then player:SendBroadcastMessage("Breaking Item: "..item:GetEntry().."") end
101 if (WIEP == 1) then player:DurabilityPointsLoss(item, 1000) end
102 if (WIEP > 1) then player:RemoveItem(item, 1) end
103 if (WIEP == 2) then player:AddItem(item:GetEntry(), 1) end
104 player:SendNotification("You're not the correct Alignment to use this Item, causing it shatter!")
105end
106
107function ACheckItem(player, item, istanding, pstanding, slot)
108 if (verbose >= 1) then player:SendBroadcastMessage("Checking Item: "..item:GetEntry().."") end
109 local isql = WorldDBQuery("SELECT * FROM item_alignment WHERE id="..item:GetEntry().."")
110 if (isql) then
111 local psql = CharDBQuery("SELECT * FROM character_alignment WHERE guid="..player:GetGUIDLow().."")
112 local istanding = isql:GetString(2)
113 local pstanding = psql:GetString(3)
114 if (verbose >= 1) then player:SendBroadcastMessage("Item Standing: "..istanding.."; Player Standing: "..pstanding.."") end
115 if (pstanding ~= istanding) then BreakItem(player, item, slot) end
116 end
117end
118
119function AAntiCheat(event, player, item, slot)
120 if (verbose >= 1) then player:SendBroadcastMessage("Checking due to event "..event..".") end
121 local psql = CharDBQuery("SELECT * FROM character_alignment WHERE guid="..player:GetGUIDLow().."")
122 if (event == 29) then
123 local isql = WorldDBQuery("SELECT * FROM item_alignment WHERE id="..item:GetEntry().."")
124 if (isql) then ACheckItem(player, item, isql:GetString(2), psql:GetString(3), slot) end
125 else
126 for i=0, 18, 1 do
127 if (verbose >= 1) then player:SendBroadcastMessage("Checking Slot#: "..i.."") end
128 if (player:GetEquippedItemBySlot(i) ~= nil) then
129 local item = player:GetEquippedItemBySlot(i)
130 local isql = WorldDBQuery("SELECT * FROM item_alignment WHERE id="..player:GetEquippedItemBySlot(i):GetEntry().."")
131 if (isql) then ACheckItem(player, item, isql:GetString(2), psql:GetString(3), i) end
132 end
133 end
134 end
135end
136
137function AChat(event, player, msg, Type, lang)
138 if (msg == "ainfo") then
139 local pguid = player:GetGUIDLow()
140 local sql = CharDBQuery("SELECT * FROM character_alignment WHERE guid="..pguid.."")
141 local pscore = sql:GetUInt32(2)
142 local pstanding = sql:GetString(3)
143 local ppurity = sql:GetUInt32(4)
144 player:SendBroadcastMessage("Alignment System: GUID = "..pguid.."")
145 player:SendBroadcastMessage("Alignment System: Score = "..pscore.."")
146 player:SendBroadcastMessage("Alignment System: Standing = "..pstanding.."")
147 player:SendBroadcastMessage("Alignment System: Purity = "..ppurity.."")
148 end
149 if (msg == "agood") then Modscore(player, "Good", 500) end
150 if (msg == "aevil") then Modscore(player, "Evil", 500) end
151end
152
153RegisterPlayerEvent(3, ALogin)
154RegisterPlayerEvent(18, AChat)
155RegisterPlayerEvent(27, function(event, player, newZone, Newarea) AAntiCheat(event, player) end)
156RegisterPlayerEvent(29, function(event, player, item, bag, slot) AAntiCheat(event, player, item, slot) end)
157-- RegisterPlayerEvent(5, function(event, player, spell, skipCheck) AAntiCheat(event, player) end)