1. #1
    The Patient Buttonmasher's Avatar
    10+ Year Old Account
    Join Date
    May 2013
    Location
    Seattle, the land where we have good internet.
    Posts
    278

    (Joke Addon) How do I make it so that when you bonus roll AP, your WoW does ForceQuit

    I want to make a quick joke addon because somebody said, "i want to write an addon that forces wow to close whenever i bonus roll artifact power."

    I can't test it because I don't have any bonus rolls and can't guarantee they'd hit AP, so I wanted to verify that this indeed would work with more knowledgeable people:
    Code:
    local frame = CreateFrame("FRAME");
    
    function frame:OnEvent(event, arg1)
    	local rewardType
    	if (event == "BONUS_ROLL_RESULT") then
    		if rewardType == "artifact_power" then
    			ForceQuit()
    		end
    	end
    end
    
    
    frame:RegisterEvent("BONUS_ROLL_RESULT");

  2. #2
    Deleted
    I would've expected ForceQuit to require a hardware event, but that doesn't seem to be the case, so I guess this should work.

    Code:
    local frame = CreateFrame("Frame")
    
    frame:RegisterEvent("BONUS_ROLL_RESULT")
    
    frame:SetScript("OnEvent", function(self, event, rewardType)
    	if rewardType == "artifact_power" then
    		ForceQuit()
    	end
    end)
    I'm not sure about the possible values of rewardType, but I assume that you did your research and "artifact_power" is right.

    Event handlers (OnShow, OnUpdate, OnEvent, etc.) are set with the SetScript method, or hooked with HookScript. The corresponding arguments are passed to the function. Since there's only 1 event registered, there's no need to see which event triggered the function.

    Code:
    local rewardType
    This just creates a local variable with nil value. Even if rewardType had some value in the global scope, it would now be overwritten by the nil value in the local scope. It's equivalent to:

    Code:
    local rewardType = nil

  3. #3
    Try this:

    Code:
    local frame = CreateFrame("FRAME");
    
    function frame:OnEvent(self, event, ...)
    	if (event == "BONUS_ROLL_RESULT") then
               local rewardType = ...;
    		if rewardType == "artifact_power" then
    			ForceQuit()
    		end
    	end
    end
    
    
    frame:RegisterEvent("BONUS_ROLL_RESULT");

  4. #4
    Deleted
    Quote Originally Posted by SpaceDuck View Post
    Try this:

    Code:
    local frame = CreateFrame("FRAME");
    
    function frame:OnEvent(self, event, ...)
    	if (event == "BONUS_ROLL_RESULT") then
               local rewardType = ...;
    		if rewardType == "artifact_power" then
    			ForceQuit()
    		end
    	end
    end
    
    
    frame:RegisterEvent("BONUS_ROLL_RESULT");
    I think you meant:

    Code:
    local frame = CreateFrame("FRAME");
    
    function frame:OnEvent(self, event, ...)
      if (self == "BONUS_ROLL_RESULT") then
        local rewardType = event;
        if rewardType == "artifact_power" then
          ForceQuit()
        end
      end
    end
    
    frame:SetScript("OnEvent", frame.OnEvent);
    
    frame:RegisterEvent("BONUS_ROLL_RESULT");
    I'll let you figure out yourself why this would work, but what you posted wouldn't. It has something to do with explicit method declarations and syntactic sugar.

  5. #5
    Quote Originally Posted by Kalolt View Post
    I think you meant:

    Code:
    local frame = CreateFrame("FRAME");
    
    function frame:OnEvent(self, event, ...)
      if (self == "BONUS_ROLL_RESULT") then
        local rewardType = event;
        if rewardType == "artifact_power" then
          ForceQuit()
        end
      end
    end
    
    frame:SetScript("OnEvent", frame.OnEvent);
    
    frame:RegisterEvent("BONUS_ROLL_RESULT");
    I'll let you figure out yourself why this would work, but what you posted wouldn't. It has something to do with explicit method declarations and syntactic sugar.
    I'm going to take your comment as a challenge, so I think you meant this:

    Code:
    local f=CreateFrame('frame')
    f:RegisterEvent('BONUS_ROLL_RESULT')
    f:SetScript('OnEvent',function(_,_,rewardtype)
        if rewardtype=='artifact_power' then ForceQuit() end
    end)
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

  6. #6
    Deleted
    Quote Originally Posted by Kanegasi View Post
    I'm going to take your comment as a challenge, so I think you meant this:

    Code:
    local f=CreateFrame('frame')
    f:RegisterEvent('BONUS_ROLL_RESULT')
    f:SetScript('OnEvent',function(_,_,rewardtype)
        if rewardtype=='artifact_power' then ForceQuit() end
    end)
    Well, if you look at the first reply to this thread, that is basically exactly the same thing I posted, although in a slightly more compact form.

    In my later reply I was just jokingly making a point about how the arguments in the code SpaceDuck posted are seemingly shifted (thus self == "BONUS_ROLL_RESULT" and rewardType = event).

  7. #7
    Quote Originally Posted by Kalolt View Post
    Well, if you look at the first reply to this thread, that is basically exactly the same thing I posted, although in a slightly more compact form.

    In my later reply I was just jokingly making a point about how the arguments in the code SpaceDuck posted are seemingly shifted (thus self == "BONUS_ROLL_RESULT" and rewardType = event).
    Ahh, I see. I need to read further before replying next time.
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •