Check if you have a particular skill using GMCP

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Check if you have a particular skill using GMCP

Post by Vadi »

There are two ways to do this - either request info on it specifically, or request the list of skills you have in a skillset. I'll show the first way.

The essence is the same as doing ab <skillset> <skill> command - if you get information about it back, then you have the skill.

Step one: ask for AB information by:
Code: [show] | [select all] lua
sendGMCP("Char.Skills.Get "..yajl.to_string({group = <skillset>, name = <skill>}))
Step two: connect an event handler to gmcp.Char.Skills.Info event. When you receive it, check if gmcp.Char.Skills.Info.info is "" or not - if it is, then you don't have that skill - if it's the description of the skill, then you have it.

ie, I have the skill:

Code: Select all

table {
  'group': 'discipline'
  'skill': 'focusbody'
  'info': 'Syntax: FOCUS BODY
Paralysis prevents you from doing anything, a nasty situation to be in. But all you need 
do is move your little toe before movement returns. By focusing your entire will upon 
your body, you can break out of paralysis, or the psionic ailments of leg lock or throat 
lock.
'
I don't have the skill:

Code: Select all

table {
  'group': 'arts'
  'skill': 'yellowtint'
  'info': ''
}
Pros: easy to check for specific skills.

Cons: skillsets like Tattoos will always tell you information about a skill, just like the ab command. Achaea also will always return the ABs.

The other way is via gmcp.Char.Skills.List - I'll let someone else post a tut on how to do that :)

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Check if you have a particular skill using GMCP

Post by tsuujin »

I'm having an issue with this. Sometimes the call works to populate the table, and sometimes it doesn't.

i can do:
sendGMCP([[Char.Skills.Get {group: "survival"}]])
and sometimes it'll populate the gmcp.Char.Skills table, and sometimes it won't. The problem is that the debug tells me that the GMCP event has been recieved, even though I can't see it populating.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Check if you have a particular skill using GMCP

Post by tsuujin »

Ah, nevermind. It doesn't work as I expected, but it does work. I expected sending Char.Skills.Get would result in an instant gmcp line from the mud, but it actually doesn't seem to come through until a timed tick or a new line from the mud.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Check if you have a particular skill using GMCP

Post by Vadi »

I would double-check this on a blank profile. The proper GMCP table is populated before the event - and hence the red debug gmcp line - are raised, if I understood your problem correctly.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Check if you have a particular skill using GMCP

Post by tsuujin »

I've tested it several times. I send the request, nothing happens. I type "look" and the table magically becomes populated properly.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Check if you have a particular skill using GMCP

Post by tsuujin »

For the record: I was trying to write a script that would parse through a list of skillsets looking for particular skills very quickly. This has now become far, far more complex if I have to wait for table population over a long period of time.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Check if you have a particular skill using GMCP

Post by Vadi »

What MUD?

I just completed my auto-setup of skills via GMCP today - by quering individual skills / checking a list, and it is instantaneous. Kaeus' makes use of GMCP for skills on Aetolia as well and he hasn't reported any issues.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Check if you have a particular skill using GMCP

Post by tsuujin »

Achaea

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Check if you have a particular skill using GMCP

Post by tsuujin »

Here's the alias body I'm using to test this:
Code: [show] | [select all] lua
function getSkillCheckTable(searchList)
	local sf = [[Char.Skills.Get {"group": "%s"}]]
	local has = {}
	for group,skillList in pairs(searchList) do
		msg.print("sending: "..sf:format(group))
		sendGMCP(sf:format(group))
		for _,skill in pairs(skillList) do
			has[skill] = false
			for _,x in pairs(gmcp.Char.Skills.List.list) do
				if x:lower() == skill:lower() then
					msg.print("yes")
					has[skill] = true
					break
				end
			end
		end
	end
	return has
end

tbl = nil
tbl = getSkillCheckTable({
	["twoarts"] = {"bladename"},
	["striking"] = {"constitution"}
})

display(tbl)
The function works fine, as long as the gmcp...List.List element is set -before- the function runs. otherwise it'll fail, and fail, and fail, until some text is recieved from the mud, and then one of the two tables will populate fine.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Check if you have a particular skill using GMCP

Post by Vadi »

um. it's 1am and it seems to be that you're expecting GMCP output within 1 function. it's asyncronous communication though, you're supposed to hook on the gmcp event and check the data inside the event handler.

Post Reply