View Single Post
04-11-20, 11:21 PM   #5
TransformedBG
A Fallenroot Satyr
Join Date: Oct 2010
Posts: 23
So i still have to be doing something wrong... when i call EventWatcher (/run EventWatcher("PLAYER_LEVEL_UP") i get the message as i am supposed to. I can see the addon loaded, etc.


Code:
--[[ Localise the Addon Wide Data Table ]]--
local addonName, addonData = ...

--[[ Localise any Addon Wide Sub Tables that are frequently accessed ]]--
local Translate = addonData.Translate

GLUA = {}
GLUA.GLUA_Frame = CreateFrame("Frame")
GLUA.GLUA_Frame:RegisterEvent("ADDON_LOADED")
GLUA.GLUA_Frame:RegisterEvent("PLAYER_ENTERING_WORLD")
GLUA.GLUA_Frame:RegisterEvent("PLAYER_LEVEL_UP")
GLUA.GLUA_Frame:RegisterEvent("CHAT_MSG_GUILD")
GLUA.GLUA_Frame:RegisterEvent("GUILD_ROSTER_UPDATE")

GLUA.GLUA_Frame:SetScript("OnEvent", function(self,event,...)--EventWatcher)
	EventWatcher(event,...)
end)

local me = UnitName("player") -- Gets players Name
local lvl = UnitLevel("player")+1 --Gets Current Player Level 
local race = UnitClass("player") --local varable to record what race you are.
local realm = GetRealmName(); -- Gets Realm name

--[[List to define chat channels]]--
channel_list = {}
channel_list["chan"] = {
"SAY",
"GUILD",
"PARTY",
"RAID",
"BATTLEGROUND",
}

--[[List to define different randomized quotes]]--
quote_this = {}
quote_this["level"] = {
"This has been a test of the Emergancy Ding System! "..me.."is now " ..lvl..".",
"My ding a ling. My ding a ling... looks like im level "..lvl.."!!!",
"DING, DING, DING... Looks like "..me.."just hit "..lvl.."!",
"Check this guys! Im now a level "..lvl.." "..race.."!",
"If you heard it once, you have heard it "..lvl.." times. DING!",
"Go ahead and just say grats alread! Cause i just hit level "..lvl.."!",
"Warning, Warnning,"..me.." You Just Hit Level "..lvl.."!",
"My microwave Dings and so do I! "..lvl.. " levels done!",
"Whats the difference between a rogue and a noob, they both pick locks! DING! That makes "..lvl.."!",
"This aint no AutoDing, okay well maybe a little... DING! now im level "..lvl.."!",
"Mama says every time a player Dings an angel gets its wings. DING level"..lvl.."!",
"Oh what is that noise? Sounds like someone just Dinged! Could it be "..me.."?! Woo hoo im level "..lvl.."!",
}

function GLUA_OnLoad()-- Loads on player login --
	DEFAULT_CHAT_FRAME:AddMessage("Guild Level Up Announcer has been initialized!")
	DEFAULT_CHAT_FRAME:AddMessage(" Ver. 1.13.14");
end

function GLUA_Message(quotes, channel)
	SendChatMessage(quotes, channel, nil, nil); --sends the chat message, party is just a filler for now testing
end

function GLUA_Channel()
	local num = 1 --you are Solo
		if UnitInParty("player")  then
			--print("party")
			num = 3 -- your in a party
		end
		if UnitInRaid("player") then
			--print("raid")
			num = 4 --Your in a raid group
		end
		if UnitInBattleground("player") then
			--print("Battleground")
			num = 5 --You are Battleground
		end
	return num
end

function GLUA_Quotes()
	local list = quote_this["level"]
	local quote = list[math.random(table.getn(list))]
	return quote
end

function GLUA_GUILD_CHECK(test)
	test = GetGuildInfo("player")
		if (test == nil)then
			test = false 
			return test
		end
   test = true
   return test
end

--[[ Monitor registered events ]]--
function EventWatcher(event,...)
	-- Store the arguments into an array to access when needed
    local args = { ... }
	
	if event == "PLAYER_ENTERING_WORLD" then
       -- Deal with player entering world
	   print("Someone did something in the world")
	end
    if event == "ADDON_LOADED" then
      -- Deal with any addons being loaded that you want to watch for ( args[1] is addon being loaded )
	  print("GLUA Addon Loaded")
	end
	if event == "PLAYER_LEVEL_UP" then --if a player levels up do the following
		print("Player Leveled Up = " .. event)
		local quote_to_share = GLUA_Quotes()
		local chanX = channel_list["chan"]
		local chan_number= GLUA_Channel()
			GLUA_Message(quote_to_share, chanX[chan_number]) -- send message to party or raid
		local check_guild = GLUA_GUILD_CHECK(check_guild)
		--[[if (check_guild == true) then
			print("not in a guild")
			GLUA_Message(quote_to_share, chanX[2]) -- return a second message to guild
		end]]--
	end
end
Code:
1x [ADDON_ACTION_BLOCKED] AddOn 'GLUA' tried to call the protected function 'UNKNOWN()'.
!BugGrabber\BugGrabber.lua:519: in function <!BugGrabber\BugGrabber.lua:519>
[C]: ?
[C]: in function `SendChatMessage'
GLUA\GLUA-1.0.1.1.lua:71: in function `GLUA_Message'
GLUA\GLUA-1.0.1.1.lua:124: in function `EventWatcher'
GLUA\GLUA-1.0.1.1.lua:30: in function <GLUA\GLUA.lua:29>

Locals:
InCombatSkipped
I noticed your template had the function as a local function.... is that needed? if i leave it like that i get the nil value error...

My problem seems to be when i call my GLUA_Message function, which calls to my table and randomly picks a quote, then says to send that message to self, party, bg, raid, and guild if in one. im getting the protected function unknown.... So from looking at your link it spears SendChatMessage is a protected function now...

Because i can get it to print "Player Leveled up = PLAYER_LEVEL_UP. meaning i get to line 121 of my code . I can add print("calling SendChatMessage with "..quote_to_share.." on channel number "..chan_number.."!") to line 126 unter ocal chan_number=GLUA_Channel() and see that its call the quote and level properly, just cant send the chat message. and by adding print(quotes) and print(channel) i can see that it passes the correct values to it..

The only thing i can think is that Locals:InCombatSkipped in the error, may not be letting me pass it to a secure function.. i guess i would need to check out of combat?
  Reply With Quote