Page 1 of 2

AutoBuf

Posted: Sat Sep 27, 2014 8:45 am
by Draakje
Hey there, Im trying to make an addon that autobuffs ppl. Details: Person in party/raid types like "warlock" and the alt targets the person and casts the buff on the player.
I think my function is not correct, could someone have a look onto it?

Code: Select all

local disabled = false -- Starting value

SLASH_AutoBuffer1 = "/AutoBuffer"
SLASH_AutoBuffer2 = "/AB" -- Add as many variations as you like just increment the number
SlashCmdList["AutoBuffer"] = function(editBox, msg)
    if msg then
        msg = string.lower(msg)
        if msg == "on" then -- on
            disabled = false
        elseif msg == "off" then -- off
            disabled = true
        else
            disabled = not disabled -- Toggles addon if 'on' or 'off' is not used.
        end
        if disabled then
            SendSystemChat("AutoBuffer is disabled")
			SendChatMessage("|H|h|cffFF0000AutoBuffer has been deactivated|h", "party")
        else
            SendSystemChat("AutoBuffer is enabled")
			SendChatMessage("|H|h|cff16DC07AutoBuffer has been activated|h", "party")
        end
    end
end

local AutoBuffer = {} -- the AddOn namespace, all your functions should be placed inside here instead of as globals.
_G.AutoBuffer = AutoBuffer -- expose it to the global scope

function AutoBuffer.VN()
  for xx = 1 , 36 do
    if OnMessage(Player(SendChatMessage("Warlock", "Party"))) then
	  CastSpellByName("Sublimation Weave Curse")
	   end
	end
end;

-- Searches the target for a specified text.
-- Use "player", "target", "party3", "raid1" etc. for tgt parameter.
function OnMessage(Player,SendChatMessage)
  local counter=1
  local SendChatMessage="none"
  while Player ~= nil do
    SendChatMessage=text(player,msg)
   if message ~= nil then
      if string.find(string.lower(target),string.lower(message)) then
        return true
      else
        counter=counter+1
      end
    end
  end
  return false
end


local time_remaining = 1 -- in seconds
function AutoBuffer:OnUpdate(elapsed)
	if disabled == true then
		return
	end
    -- elapsed is the amount of time in seconds since the last frame tick

    time_remaining = time_remaining - elapsed
    if time_remaining > 0 then
        -- cut out early, we're not ready yet
        return
    end
    time_remaining = 1 -- reset to 2 seconds
    self.VN()
end

Re: AutoBuf

Posted: Sat Sep 27, 2014 9:16 am
by rock5
What happens? Have you tried adding some print messages to check values along the way?

Re: AutoBuf

Posted: Sat Sep 27, 2014 11:19 am
by Draakje
not sure what u meaning with addind print msg in :s
program saying this: lua: AutoBuffer.lua:69: 'end' expected (to close 'function' at line 28) near '<eof>'
quitting debugger

Re: AutoBuf

Posted: Sat Sep 27, 2014 11:28 am
by rock5
It didn't occur to you that it would be easier to find the problem with an error message? :P

The function at line 28 has 1 too many "end"s. I don't know if there are any other problems but that's what I see now.

Re: AutoBuf

Posted: Sat Sep 27, 2014 11:36 am
by Draakje
Ye i fixed prob was missing an end over there, but now atm addon is working ingame, but not how it should be :D
My char itself is trying to spam the word warlock all over ^^. While the word must be an activation for it to cast a skill xd

Re: AutoBuf

Posted: Sat Sep 27, 2014 11:50 am
by Draakje
umm is there a specific function to make it work?

Code: Select all

if OnMessage(Player(Message("Warlock", "Party"))) then
	  target(Player)
	  CastSpellByName("Sublimation Weave Curse")
on and off is working, but when i type Warlock in party chat nothing is going...

Re: AutoBuf

Posted: Sat Sep 27, 2014 12:52 pm
by rock5
At first glance there are a couple of functions I don't recognize, SendChatMessage and text, so I can't be sure what it does.

Do you have an xml file in your addon that runes the update function?

Re: AutoBuf

Posted: Sat Sep 27, 2014 1:27 pm
by Draakje
yes the update works also inside my xml file
its just I don't know a function to let the char use a skill when a player types in party chat example "warlock"
also let it target player aswell if possible

Re: AutoBuf

Posted: Sat Sep 27, 2014 1:52 pm
by rock5
You should monitor party chat, example in your xml onload have.

Code: Select all

this:RegisterEvent("CHAT_MSG_PARTY")
Then also add an onevent section, example

Code: Select all

<OnEvent>  AutoBuffer.OnEvent(event, arg1,arg2,arg3,arg4) </OnEvent>
Then add the function to your lua.

Code: Select all

function AutoBuffer.OnEvent(event, arg1, arg2, arg3, arg4)
    if event == "CHAT_MSG_PARTY" then
        if arg1 == "warlock" then
            -- Do stuff. Maybe ..
            self.VN()
        end
    end
end

Re: AutoBuf

Posted: Sat Sep 27, 2014 7:11 pm
by Draakje
I'm getting error in my party chat as soon i typed "warlock": call AutoBuffer_Frame's OnEvent, line: [string "?"]:34: attempt to index global 'self' (a nil value)
Something still missing in lua file?

Lua file

Code: Select all

local disabled = false -- Starting value

SLASH_AutoBuffer1 = "/AutoBuffer"
SLASH_AutoBuffer2 = "/AB" -- Add as many variations as you like just increment the number
SlashCmdList["AutoBuffer"] = function(editBox, msg)
    if msg then
        msg = string.lower(msg)
        if msg == "on" then -- on
            disabled = false
        elseif msg == "off" then -- off
            disabled = true
        else
            disabled = not disabled -- Toggles addon if 'on' or 'off' is not used.
        end
        if disabled then
            SendSystemChat("AutoBuffer is disabled")
			SendChatMessage("|H|h|cffFF0000AutoBuffer has been deactivated|h", "party")
        else
            SendSystemChat("AutoBuffer is enabled")
			SendChatMessage("|H|h|cff16DC07AutoBuffer has been activated|h", "party")
        end
    end
end

local AutoBuffer = {} -- the AddOn namespace, all your functions should be placed inside here instead of as globals.
_G.AutoBuffer = AutoBuffer -- expose it to the global scope


function AutoBuffer.OnEvent(event, arg1, arg2, arg3, arg4)
    if event == "CHAT_MSG_PARTY" then
        if arg1 == "warlock" then
            TargetUnit("player", "event")
			CastSpellByName("Sublimation Weave Curse")
            self.VN()
        end
    end
end


local time_remaining = 1 -- in seconds
function AutoBuffer:OnUpdate(elapsed)
	if disabled == true then
		return
	end
    -- elapsed is the amount of time in seconds since the last frame tick

    time_remaining = time_remaining - elapsed
    if time_remaining > 0 then
        -- cut out early, we're not ready yet
        return
    end
    time_remaining = 1 -- reset to 2 seconds
    AutoBuffer.VN()
end
Xml file

Code: Select all

<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">
    <Frame name="AutoBuffer_Frame">
        <Scripts>
			<OnLoad>
				this:RegisterEvent("CHAT_MSG_PARTY");
			</OnLoad>

			<OnEvent>
				AutoBuffer.OnEvent(event, arg1,arg2,arg3,arg4)
			</OnEvent>

            <OnUpdate>
                AutoBuffer:OnUpdate(elapsedTime)
            </OnUpdate>
        </Scripts>
    </Frame>
</Ui>

Re: AutoBuf

Posted: Sun Sep 28, 2014 3:29 am
by rock5
I'm guessing line 34 is "self.VN()". Try changing it to "self.VN()". That should have been obvious especially as you have self.VN() further in the file.

The reason it didn't work the way I wrote it is because the function was written with a dot (.) instead of a colon (:). So in this case self wouldn't work.

Re: AutoBuf

Posted: Sun Sep 28, 2014 7:44 am
by Draakje
still giving same error

Re: AutoBuf

Posted: Sun Sep 28, 2014 11:57 am
by rock5
You replaced "self" with "AutoBuffer" and you still get "attempt to index global 'self' (a nil value)"? Maybe you forgot to save it before trying again. Or maybe you forgot to restart the game to make the changes take affect. Instead of restarting the game you can issue the following command from chat line.

Code: Select all

/script ReloadUI()

Re: AutoBuf

Posted: Sun Sep 28, 2014 12:39 pm
by Draakje
yep still getting that message. Maybe u can rewrite the addon? cause i think mine getting totaly messed up or something >.>

Re: AutoBuf

Posted: Mon Sep 29, 2014 12:20 am
by rock5
Another possibility is you made a backup copy of the addon in the addons folder and it's still being loaded and overwriting the updated version. Make sure you only have 1 copy of the addon in the addons folder.

Re: AutoBuf

Posted: Mon Sep 29, 2014 7:47 am
by Draakje
yup i've checked, all old ones are deleted no duplicate or backup in addon files.
added file in attachments

Re: AutoBuf

Posted: Mon Sep 29, 2014 8:07 am
by rock5
Try

Re: AutoBuf

Posted: Mon Sep 29, 2014 8:27 am
by Draakje
yep get error in party chat again
maybe xml file wrong?

Code: Select all

<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">
    <Frame name="AutoBuffer_Frame">
        <Scripts>
			<OnLoad>
				this:RegisterEvent("CHAT_MSG_PARTY");
			</OnLoad>

			<OnEvent>
			AutoBuffer.OnEvent(event, arg1,arg2,arg3,arg4)
			</OnEvent>

            <OnUpdate>
                AutoBuffer:OnUpdate(elapsedTime)
            </OnUpdate>
        </Scripts>
    </Frame>
</Ui>

Re: AutoBuf

Posted: Mon Sep 29, 2014 9:10 am
by rock5
I don't see anything wrong. What error do you get?

Re: AutoBuf

Posted: Mon Sep 29, 2014 10:34 am
by Draakje
call AutoBuffer_Frame's OnEvent, line: [string "?"]:34: attempt to call field 'VN' (a nil value)