Code:
local VERSION = "1.5"
--[[====================================--
-- Rewardance NPC --
-- [ Fully Made by Claiver ] --
-- REPORT FEEDBACK AT MMOWNED.COM --
--======================================--
================================================================================================
=========== ( General Settings ) ===============================================================
================================================================================================
====]]local NPC_ID = 107107107 --[[-> This is the ID of the NPC whom contains the script. (Set Gossip Flags!)
====]]local ITEM_ID = 20770 --[[-> The Item EntryID of the GM Event Tool
====]]local DataFile = "scripts/EventData_AccessCodes.txt" --[[-> File the data is saved in. Be sure to have the file set-up before use.
================================================================================================
=========== ( Define the Rewards ) =============================================================
================================================================================================
-- RewardName , EnterCode , ItemID1, ItemCount1, ItemID2, ItemCount2, ... --
-- You can set the Global Password(usable by everyone!) , and add as many items as you want, --
-- as long as you have ItemID and ItemCount present! --
==============================================================================================]]
local Rewards =
{
{"Spectral Tiger", "PREMIUM-23", 11846, 5, 101001, 1, 14156, 1},
{"Bag", "KGI-23542-Z", 14156, 1, 11846, 1},
{"Candy", "DFIER356", 11846, 2},
{"Weapon", "G83JF-3JH", 11846, 5},
{"Token", "G92JD03D", 11846, 5},
{"Jukebox", "39FJK20F", 11846, 5},
}
-- ********************* END OF CONFIG | DO NOT EDIT BELOW THESE LINES ************************************* --
function RewardNPC_OnGossipTalk(pUnit, event, Player, pMisc)
local i = 0
if (Player:IsInCombat() == true) then
Player:SendAreaTriggerMessage("You are in combat! Please first leave combat!")
Player:SendBroadcastMessage("You are in combat! Please first leave combat!")
Player:GossipComplete()
else
pUnit:GossipCreateMenu(107107107, Player, 0)
for k,v in pairs(Rewards) do
i = i + 1
pUnit:GossipMenuAddItem(30, "I would like a "..v[1], i, 1)
end
pUnit:GossipSendMenu(Player)
end
end
function RewardNPC_OnGossipSelect(pUnit, event, Player, id, intid, Code, pMisc)
local i = 0
for k,v in pairs(Rewards) do
i = i + 1
if (intid == i) then
Check_Key(Player, Code)
if (KEY == "TRUE") or (Code == v[2]) then
Player:SendBroadcastMessage("Congratulations, you've entered a valid Code!")
for i = 4,#v,2 do
if (v[i] ~= nil) then
Player:AddItem(v[i-1],v[i])
end
end
Player:GossipComplete()
Set_CurrentKey(Player, Code, "False")
else
Check_Key(Player, Code)
if (KEY == "FALSE") then
Player:SendBroadcastMessage("[ERROR] Code: \'"..Code.."\' has already been used!")
else
Player:SendBroadcastMessage("[ERROR] Code: \'"..Code.."\' is invalid!")
end
Player:GossipComplete()
end
end
KEY = "FALSE"
end
end
RegisterUnitGossipEvent(NPC_ID, 1, "RewardNPC_OnGossipTalk")
RegisterUnitGossipEvent(NPC_ID, 2, "RewardNPC_OnGossipSelect")
--[[============================================================================================
=========== ( General Configuration ) ==========================================================
==============================================================================================]]
function GMEvent_OnUse(Item, event, Player)
GMEvent_Menu(Item, event, Player)
end
function GMEvent_Menu(Item, event, Player)
Player:SendAreaTriggerMessage("- GM LAUNCHER INITIATED -")
Item:GossipCreateMenu(7773, Player, 0)
Item:GossipMenuAddItem(10, "< LAUNCH >", 900, 0)
Item:GossipSendMenu(Player)
end
function GMEvent_OnSelect(Item, event, Player, id, intid, Code)
if(intid == 900) then
print (" ["..Player:GetName().."] has launched the GM_Event Tool.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Event: Launch Event Manager", 9754, 0)
Item:GossipMenuAddItem(10, " - Shut Down - ", 24340, 0)
Item:GossipSendMenu(Player)
end
if (intid == 24340) then
Player:SendAreaTriggerMessage("")
Player:GossipComplete()
end
if (intid == 9754) then
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "[Create] New Player Access-Key", 4389485, 0)
Item:GossipMenuAddItem(10, "[Lookup] Existing Player Access-Key", 2389485, 0)
Item:GossipMenuAddItem(10, "[Disable] Existing Player Access-Key", 2389486, 0)
Item:GossipMenuAddItem(10, "[Modify] Existing Player Access-Key", 2389487, 0)
Item:GossipMenuAddItem(10, "-> Return to Main Menu", 900, 0)
Item:GossipSendMenu(Player)
end
--| MODIFY PLAYERKEY
if (intid == 2389487) then
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "[+] Change Owner of Key.", 204005, 0)
Item:GossipMenuAddItem(10, "[+] Change Key of Player.", 204001, 0)
Item:GossipMenuAddItem(10, "-> Return to Main Menu", 900, 0)
Item:GossipSendMenu(Player)
end
if (intid == 204001) then
Player:SendBroadcastMessage("Please enter Player's name.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Enter PlayerName", 204002, 1)
Item:GossipSendMenu(Player)
end
if (intid == 204005) then
Player:SendBroadcastMessage("Please enter the Key you wish the owner of.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Enter Key", 204006, 1)
Item:GossipSendMenu(Player)
end
if (intid == 204006) then
Key = Code
Player:SendBroadcastMessage("Please enter current owner.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Current Owner", 204007, 1)
Item:GossipSendMenu(Player)
end
if (intid == 204007) then
CurrentOwner = Code
Player:SendBroadcastMessage("Please enter the new owner.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "New Owner", 204008, 1)
Item:GossipSendMenu(Player)
end
if (intid == 204008) then
NewOwner = Code
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[1] == CurrentOwner) and (v[2] == Key) then
v[1] = NewOwner
end
end
Save_File(Current_Table, DataFile)
Player:SendBroadcastMessage("[SUCCESS] Changed the new owner of Code '"..Key.."' to '"..NewOwner.."'")
Player:GossipComplete()
end
if (intid == 204002) then
PlayerName = Code
Player:SendBroadcastMessage("Please enter current Access-Key.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Current Key", 204003, 1)
Item:GossipSendMenu(Player)
end
if (intid == 204003) then
CurrentKey = Code
Player:SendBroadcastMessage("Please enter a new Access-Key.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "New Key", 204004, 1)
Item:GossipSendMenu(Player)
end
if (intid == 204004) then
NewKey = Code
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[1] == PlayerName) and (v[2] == CurrentKey) then
v[2] = NewKey
end
end
Save_File(Current_Table, DataFile)
Player:SendBroadcastMessage("[SUCCESS] Changed "..PlayerName.."'s Code: '"..CurrentKey.."' to '"..NewKey.."'")
Player:GossipComplete()
end
--| REMOVE PLAYERKEY
if (intid == 2389486) then
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "[+] Disable Access-Key by Name.", 203001, 0)
Item:GossipMenuAddItem(10, "[+] Disable Access-Key by Key.", 203002, 0)
Item:GossipMenuAddItem(10, "-> Return to Main Menu", 900, 0)
Item:GossipSendMenu(Player)
end
if (intid == 203001) then
Player:SendBroadcastMessage("Please enter Player's name.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Enter PlayerName", 203003, 1)
Item:GossipSendMenu(Player)
end
if (intid == 203003) then
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[1] == Code) then
v[3] = "False"
end
end
Save_File(Current_Table, DataFile)
Player:SendBroadcastMessage("[SUCCESS] All Keys for '"..Code.."' are disabled!")
Player:GossipComplete()
end
if (intid == 203002) then
Player:SendBroadcastMessage("Please enter Access-Key.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "Enter AccessKey", 203004, 1)
Item:GossipSendMenu(Player)
end
if (intid == 203004) then
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[2] == Code) then
v[3] = "False"
end
end
Save_File(Current_Table, DataFile)
Player:SendBroadcastMessage("[SUCCESS] All entries with code '"..Code.."' are disabled!")
Player:GossipComplete()
end
--| LOOKUP PLAYER
if (intid == 2389485) then
Player:SendBroadcastMessage("[1] Please enter name of Player you wish to look up.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "1) Please enter name of Player you wish to look up", 202001, 1)
Item:GossipSendMenu(Player)
end
if (intid == 202001) then
Player:SendBroadcastMessage("=== Access-Keys for Player '"..Code.."' ===")
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[1] == string.format("%s", Code)) then
Player:SendBroadcastMessage("o "..v[1].." - Key: ["..v[2].."], Usable: "..v[3].."")
end
end
Player:SendBroadcastMessage("")
Player:GossipComplete()
end
--| ADD PLAYER-KEY
if (intid == 4389485) then
Player:SendBroadcastMessage("[1] Please enter Player's name.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "1) Add PlayerName", 201001, 1)
Item:GossipSendMenu(Player)
end
if (intid == 201001) then
z1_Name = Code
Player:SendBroadcastMessage("[2] You have entered Player: "..z1_Name)
Player:SendBroadcastMessage("[3] Please enter the Key-Code.")
Item:GossipCreateMenu(3543, Player, 0)
Item:GossipMenuAddItem(10, "2) Add Access-Key", 201002, 1)
Item:GossipSendMenu(Player)
end
if (intid == 201002) then
z2_Key = Code
Code_Data = {z1_Name, z2_Key, "True"}
Item:GossipCreateMenu(3543, Player, 0)
Player:SendBroadcastMessage("[4] You have entered Code: "..z2_Key)
Player:SendBroadcastMessage("Please press 'Import Data' to finish.")
Item:GossipMenuAddItem(10, "3) Import Data", 201003, 0)
Item:GossipMenuAddItem(10, "-> Return to Main Menu", 900, 0)
Item:GossipSendMenu(Player)
end
if (intid == 201003) then
Add_NewKey(Code_Data)
Item:GossipCreateMenu(3543, Player, 0)
Player:SendBroadcastMessage("[5] Player \""..z1_Name.."\" may now use key: \""..z2_Key.."\"")
Item:GossipMenuAddItem(10, "-> Add Another Key", 4389485, 0)
Item:GossipMenuAddItem(10, "-> Return to Main Menu", 900, 0)
Item:GossipSendMenu(Player)
end
end
RegisterItemGossipEvent(ITEM_ID,1,"GMEvent_OnUse")
RegisterItemGossipEvent(ITEM_ID,2,"GMEvent_OnSelect")
--================================================================================================================--
--=== GLOBAL FUNCTIONS ==========================================================================================--
--================================================================================================================--
function Serialize_Table(tab)
local ser = {} -- Serialize Table
function ser.number (n)return tostring(n)end -- Serializes numbers
function ser.string (str)return ("%q"):format(str)end -- strings
function ser.boolean (b) return tostring(b) end -- booleans
function ser.thread (t)error "Threads are unsupported" end -- unsupported
ser["function"] = function (f) error "Functions are unsupported"end -- unsupported
ser["nil"] = function(n) return "nil" end -- nils
function ser.userdata(u) error "Userdatas are unsupported" end -- unsupported
local indent = 0
local indc = " "
local knowntabs = {}
function ser.table (tab)
if knowntabs[tab] then error("Cyclic table not allowed") end
knowntabs[tab] = true
local out = {"{\n"}--{"{\n"}
indent = indent + 1
local ind = indc:rep(indent)
local keys = {}
for i,v in pairs(tab) do
keys[#keys+1] = i -- ...
end
table.sort(keys,function(a,b)
if type(a)=="number" and type(b)=="number" then return a<b end
if type(a)=="number" then return true end
if type(b)=="number" then return false end
return tostring(a)<tostring(b)
end)
local n = 0
for i,v in ipairs(keys) do
local i,v = v,tab[v]
local key,value = ser[type(i)](i),ser[type(v)](v)
if n then
n = n + 1
if n == i then
out[#out+1] = ind..value..","--\n"
else
n = nil
out[#out+1] = ind.."["..key.."] = "..value..", \n"
end
else
out[#out+1] = ind.."["..key.."] = "..value..", \n"
end
end
indent = indent - 1
out[#out+1] = indc:rep(indent).."}"
return table.concat(out)
end
return "return "..ser.table(tab)
end
function Check_Key(_Player, _Code)
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[1] == _Player:GetName()) and (v[2] == _Code) then
if (v[3] == "False") then KEY="FALSE" return KEY end
if (v[3] == "True") then KEY="TRUE" return KEY end
if (v[3] == nil) then KEY="NONE" return KEY end
end
end
end
function Set_CurrentKey(_Player, _Code, _Status)
Current_Table = Load_File(DataFile)
for k,v in pairs(Current_Table) do
if (v[1] == _Player:GetName()) and (v[2] == _Code) then
v[3] = _Status
end
end
Save_File(Current_Table, DataFile)
end
function Add_NewKey(_Data)
Current_Table = Load_File(DataFile)
table.insert(Current_Table, _Data)
Save_File(Current_Table, DataFile)
end
function Save_File(tab, file)
local str = Serialize_Table(tab)
local fp = assert(io.open(file,"w"))
fp:write(str)
fp:close()
end
function Load_File(file)
return dofile(file)
end
print ("\n ====================================================")
print (" Loaded: \"Redeemer NPC\" (V"..VERSION..") by Claiver. ")
print (" NPC: "..NPC_ID.."")
print (" GM-EVENTTOOL: "..ITEM_ID.." \n")
print (" Make sure that the following file is existing: \n '"..DataFile.."'")
print (" ====================================================\n")