You are not logged in.

Applications: [GameMaster: OPEN] | [Volunteer Testers: OPEN]


This forum will be permanently shut down on Friday 13.07.2018
Please copy or save all important information from old forum before they will be deactivated
We have moved to new board. https://forum.runesofmagic.gameforge.com/Come join us.

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

1

Tuesday, December 20th 2011, 11:06am

Invite to Guild addon

Hello all,

I'm trying to create my first addon, one where if a player whispers you a certain phrase they get an invite to the guild. My end goal is to have a basic UI where you can turn it on and off, and change the phrase that you need to be whispered. For now though, I'm just trying to get it to work with a predefined phrase in the code and it's always on. This is what I have in my lua:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local GuildAutoInvite = {}
_G.GuildAutoInvite = GuildAutoInvite
local frame=_G.GuildAutoInvite_Frame

function GuildAutoInvite_OnLoad(frame)
	frame:RegisterEvent("CHAT_MSG_WHISPER")
end

function GuildAutoInvite:OnEvent(event, frame)
	if (event=="CHAT_MSG_WHISPER") then
		if (arg1=="inviteme") then
			GuildInvite(arg4);
		end
	end
end


and then my XML looks like this:

Source code

1
2
3
4
5
6
7
8
9
<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="GuildAutoInvite_Frame">
	 <Scripts>
		<OnEvent>
		      GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
		</OnEvent>
	 </Scripts>
    </Frame>
</Ui>


I honestly have almost no clue how to do this, and this is as far as I've been able to get using online tutorials and what little C I know. Can anyone help me get this functional?

Thank you

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

2

Tuesday, December 20th 2011, 12:12pm

Quoted from "potato221;495268"

Hello all,

I'm trying to create my first addon, one where if a player whispers you a certain phrase they get an invite to the guild. My end goal is to have a basic UI where you can turn it on and off, and change the phrase that you need to be whispered. For now though, I'm just trying to get it to work with a predefined phrase in the code and it's always on. This is what I have in my lua:

[highlight]...snip...[/highlight]

I honestly have almost no clue how to do this, and this is as far as I've been able to get using online tutorials and what little C I know. Can anyone help me get this functional?

Thank you


You've got a bit of a problem with how you are calling and defining your OnEvent callback.

You use this in the XML:

Source code

1
GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)

but you are defining the function itself with:

Source code

1
function GuildAutoInvite:OnEvent(event, frame)

The problem here is twofold. First, you aren't sending the arg1 to arg9 parameters, the second, though not a real problem, you are using the colon version for the function definition and the function call. This will add a hidden parameter called self as the first parameter. This will refer to the object itself, in this case the frame.

Also, instead of doing a call to GuildInvite(), have it simply display the parameters so that you can see what the values are. This will allow you to see if the event is in fact being triggered. Re-enable the actual GuildInvite() call once you know the values are what you expect, and the event is in fact triggered.

My suggestion is to change your OnEvent function definition to:

Source code

1
2
3
4
5
6
7
function GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
    if (event=="CHAT_MSG_WHISPER") then
        if (arg1=="inviteme") then
            --GuildInvite(arg4);
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper received, arg4 = "..(arg4 or "nil"))
        end
    end


Finally, you never declared the OnLoad callback and therefore never actually have the frame register for the CHAT_MSG_WHISPER event. Change the XML to:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
<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="GuildAutoInvite_Frame">
        <Scripts>
            <OnEvent>
                GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
            </OnEvent>
            <OnLoad>
                GuildAutoInvite_OnLoad(this)
            </OnLoad>
        </Scripts>
    </Frame>
</Ui>

In the above, the this variable is defined by the game to be the frame itself when in the frame code snippets. It can be a little confusing when viewed in conjunction with the self variable used by Lua. Treat this as a variable declared by the game though.

You didn't mention which guides you used, but you might be interested in my frame guides if you haven't already been looking at them, as well as some of the other Lua guides (links in my sig).
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

3

Tuesday, December 20th 2011, 6:53pm

Ok, I see what I did wrong, but for some reason after I changed my lua and xml so it looks like what you posted, I get no chat message at all, where it looks like I should be getting the value of arg4 or the word nil.

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

4

Tuesday, December 20th 2011, 11:13pm

Quoted from "potato221;495385"

Ok, I see what I did wrong, but for some reason after I changed my lua and xml so it looks like what you posted, I get no chat message at all, where it looks like I should be getting the value of arg4 or the word nil.


Add more debug messages to your event callback. Like this:

Source code

1
2
3
4
5
6
7
8
9
10
function GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
    DEFAULT_CHAT_FRAME:AddMessage("OnEvent called, event was "..(event or "nil"))
    if (event=="CHAT_MSG_WHISPER") then
        DEFAULT_CHAT_FRAME:AddMessage("in first if, arg1 is "..(arg1 or "nil"))
        if (arg1=="inviteme") then
            --GuildInvite(arg4);
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper received, arg4 = "..(arg4 or "nil"))
        end
    end
end


Also can add a message in the XML part like this:

Source code

1
2
3
4
            <OnEvent>
                DEFAULT_CHAT_FRAME:AddMessage("in frame's OnEvent snippet. Relevant paarams are "..(event or "nil")..", "..(arg1 or "nil")..", "..(arg4 or "nil"))
                GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
            </OnEvent>

if you don't even get the first message, then it is likely that the event isn't fired by the game (not all events listed on the RoM Wiki are).
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

5

Wednesday, December 21st 2011, 1:02am

Yea, it's not being triggered at all, so I guess I need to find a new event to trigger it.

EDIT: I just took a look at GroupInvite and I see that they use that same event (CHAT_MSG_WHISPER). Not sure what I'm doing wrong.

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

6

Wednesday, December 21st 2011, 12:20pm

Quoted from "potato221;495513"

Yea, it's not being triggered at all, so I guess I need to find a new event to trigger it.

EDIT: I just took a look at GroupInvite and I see that they use that same event (CHAT_MSG_WHISPER). Not sure what I'm doing wrong.


Put a debug message or play a sound effect in GuildAutoInvite_OnLoad() to ensure it is getting called (I suggest the sound effect since it may be too early in the game loading process to get any messages) . Use PlaySoundByPath() to play a sound.

Also, I've sometimes had trouble using functions with the same name as a frame's callback. So try changing the name of GuildAutoInvite:OnEvent() to something like GuildAutoInvite:OnEventHandler() (change all relevant calls to the new name) and see if that does get called.

Lastly, make sure that the Lua file is loaded before the XML file in your TOC. Otherwise, the game won't know what your functions are when it goes through the XML file.
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

7

Wednesday, January 25th 2012, 6:32am

Ok for a while it wasn't working at all, no feedback messages or anything, then today I created a new char and all of a sudden I was getting feedback messages. This is the code I used:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local GuildAutoInvite = {}_G.GuildAutoInvite = GuildAutoInvite
local frame=_G.GuildAutoInvite_Frame


function GuildAutoInvite_OnLoad(frame)
    frame:RegisterEvent("CHAT_MSG_WHISPER_INFORM")
end


function GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
    DEFAULT_CHAT_FRAME:AddMessage("OnEvent called, event was "..(event or "nil"))
    if (event=="CHAT_MSG_WHISPER_INFORM") then
        DEFAULT_CHAT_FRAME:AddMessage("in first if, arg1 is "..(arg1 or "nil"))
        if (arg1=="ginvite") then
            --GuildInvite(arg4);
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg1 or "nil1"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg2 or "nil2"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg3 or "nil3"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg4 or "nil4"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg5 or "nil5"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg6 or "nil6"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg7 or "nil7"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg8 or "nil8"))
            DEFAULT_CHAT_FRAME:AddMessage("Invite whisper recieved, arg4= "..(arg9 or "nil9"))
        end
    end
end


and XML:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
<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="GuildAutoInvite_Frame">
     <Scripts>
        <OnEvent>
            DEFAULT_CHAT_FRAME:AddMessage("in frame's OnEvent snippet.  Relevant params are "..(event or "nil")..","..(arg1 or "nil")..","..(arg4 or "nil"))
              GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
        </OnEvent>
        <OnLoad>
            GuildAutoInvite_OnLoad(this)
        </OnLoad>
     </Scripts>
    </Frame>
</Ui>


I ended up getting this feedback when I whispered ginvite to someone else (first pic, the blacked out are all the same name): http://imgur.com/a/q7lIo

The second pic is of the error message I got when I switched from CHAT_MSG_WHISPER_INFORM to CHAT_MSG_WHISPER (and I did change it both times in the lua).

The first one would be perfect if it occurred when someone else whispered me instead of me whispering them.

Not sure where to go now, any feedback is appreciated.

EDIT: Ok when I switched back from reni server to govinda I now get the same error message as in the second pic when using CHAT_MSG_WHISPER_INFORM. Don't know what's up with that, so I'm kinda very lost.

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

8

Wednesday, January 25th 2012, 11:49pm

What order are you loading the Lua and XML files in the TOC? It should be Lua file first, then XML since you are referring to some Lua functions from within the XML.

Edit:
BTW, you can get rid of the line

Source code

1
local frame=_G.GuildAutoInvite_Frame

it is redundant in this context since it never actually gets used. Inside each function you use this name, it is passed as a parameter to those functions, and it isn't used elsewhere.

Further, since the Lua file should be loaded first, GuildAutoInvite_Frame doesn't yet exist when the Lua file is first loaded and so it would merely set it to nil.
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

9

Thursday, January 26th 2012, 5:45am

I had xml first for some reason, coulda sworn I checked that yesterday and it had lua first. Ah well, it works now thanks to your help! Now to see if I can't work in an on off switch and a way to change the phrase from in game using slash commands till I get that working then after that is trying to make a basic UI to let you do that. But for right now I'm happy it works at all!

Thank you so much for your help!

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

10

Friday, January 27th 2012, 2:14am

Ok, on/off is now up and working, and I have a general idea about how to edit the phrase while in game, but with most of the threads in this area deleted I can't find how to do this one thing. Is there any way to recognize more then the first string after the initial slash command? So like the user types in "/gai phrase hi". I know how to recognize the string "phrase", and have that working for the on/off commands, but I don't know how to recognize the string "hi".

What I plan on having it do is having /gai phrase set off an if where I change a variable to the string after phrase in the slash command, then putting the variable in the place of the set ginvite that I currently have.

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

11

Friday, January 27th 2012, 3:48am

Got it, took a line of code from another addon and set the strings so that first string was first variable in an array, second was second in array etc.

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

12

Friday, January 27th 2012, 4:15am

You'll need to extract each word inside your slash command handler.

Here's an little example that should do the trick

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SLASH_GetArguments1 = "/getargs"
SlashCmdList['GetArguments'] = function (ebox, msg)
    -- Extract each space seperated argument from parameter list
    local args = {}
    local nextarg, idx, argcount
    idx = 0
    repeat 
        _, idx, nextarg = string.find((msg or ""), "([^%s]+)", idx+1)


        -- Strip off any leading or trailing spaces, then add to argument table
        if nextarg then
            _, _, nextarg = string.find(nextarg, "^%s*(.-)%s*$")
            args[#args+1] = nextarg
        end
    until (not idx)
    
    -- Show all arguments given
    for i = 1, #args do
        DEFAULT_CHAT_FRAME:AddMessage("args['..i..'] = "..args[i])
    end    
end

The above will create an array called args with parameter in it. The code as shown will merely print out the array the the chat window, but that is just to show the contents.
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

13

Friday, January 27th 2012, 4:31am

This is what I have right now:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local GuildAutoInvite = {}_G.GuildAutoInvite = GuildAutoInvite
local frame=_G.GuildAutoInvite_Frame


local words = {}
local disable = "false"
local phrase = "ginvite"


SLASH_Disable1 = "/GAI"
SLASH_Disable2 = "/gai"
SlashCmdList['Disable'] = function(editBox, msg)
words = {}
for arg in msg:gmatch("%a+")do
	words[#words+1] = arg:lower();
end
	if words[1] == "off" then
		disable = "true"
		DEFAULT_CHAT_FRAME:AddMessage("Guild Auto Invite turned off")
	elseif words[1] == "on" then
		disable = "false"
		DEFAULT_CHAT_FRAME:AddMessage("Guild Auto Invite turned on")
	elseif words[1] == "pass" then
		phrase = words[2]
		DEFAUL_CHAT_FRAME:AddMessage("Invite password changed to "..(phrase))
	else
		DEFAULT_CHAT_FRAME:AddMessage("Please specify on or off")
	end
end


function GuildAutoInvite_OnLoad(frame)
	frame:RegisterEvent("CHAT_MSG_WHISPER")
end


function GuildAutoInvite:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)


	if (disable=="false") then


	if (event=="CHAT_MSG_WHISPER") then


		if (arg1==phrase) then
			GuildInvite(arg4);
		end
	end
	
	end
end


The on/off works, and ginvite works, but whenever I try /gai pass hi when I hit enter the game acts like I haven't hit enter. No error messages come up, but it's the same even when I try /gai pass. Everything else works and will bring up DEFAULT_CHAT_FRAME:AddMessage("Please specify on or off"), it's only pass where it gets stuck.

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

14

Friday, January 27th 2012, 5:22am

Well you are missing a T in the following line:

Source code

1
DEFAUL_CHAT_FRAME:AddMessage("Invite password changed to "..(phrase))
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

15

Friday, January 27th 2012, 6:01am

That was it. Now I feel stupid for not catching that.

Ok, another newbie question. What license is normally used when uploading an addon to curseforge, and why?

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

16

Friday, January 27th 2012, 11:43am

Your choice. I always used Public Domain, but I don't really care if people use my code.

Many use a Creative Commons (By-Nc-Sa 3.0), others use an MIT or MIT variant license. Your best bet is to go read the various licenses and pick the one you are comfortable with.
2013... The year from hell....

potato221

Trainee

  • "potato221" started this thread

Posts: 98

Location: In America

Occupation: Student

Mood: Smile

  • Send private message

17

Saturday, January 28th 2012, 3:00am

Quoted from "Peryl;505589"

Your choice. I always used Public Domain, but I don't really care if people use my code.

Many use a Creative Commons (By-Nc-Sa 3.0), others use an MIT or MIT variant license. Your best bet is to go read the various licenses and pick the one you are comfortable with.


Ok, so I've decided that I want to use Creative Commons (By-Nc-Sa 3.0), but it is not in the drop down menu for licenses on curseforge. To use Creative Commons (By-Nc-Sa 3.0) do you just do custom and then copy and paste the terms of the license in the Custom License text box?