Thread Tools Display Modes
02-15-15, 04:14 PM   #1
Kraiven
A Deviate Faerie Dragon
 
Kraiven's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2015
Posts: 10
Help with my own addon, need some LUA guidance.

I'm attempting to write my first addon while trying to learn LUA. I'm having trouble finding the exact API data to move forward with my code. I'd like to write it myself, but I'm wondering if someone can point me in the right direction with some better examples. Currently I'm trying to make a very simple code that when you enter a LFG, it compares your active spec(tank, healer, damage) to your Queued selected role(tank, healer, damage), and if they don't match, prints a message in chat saying you are in the wrong spec. Some of the "get(functions)" I've been looking at in the WoW API are incomplete for data and explanations. Any pointers?

Here's my current codewhich I'm sorry if it's noobish, but I'm currently learning Python)

Code:
-- Spec Check load on Instance
local f = CreateFrame("Frame")
local role = UnitGroupRolesAssigned("player")
local isAssigned = GetPartyAssignment("assignment", "player")

f:RegisterEvent(PLAYER_ROLES_ASSIGNED);
--f:RegisterEvent(ending event);


-- Check Active Role Vs. Assigned Role
f:SetScript("OnEvent", function(self, event, ...)
	if event == "PLAYER_ROLES_ASSIGNED" and role ~= isassigned then
		print("Your current Talent Spec is set Wrong, switch specs!")
	end

end)
Thank you for any tips, I'm just doing this for fun.
  Reply With Quote
02-15-15, 07:41 PM   #2
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
you comparing 2 different things
http://wowprogramming.com/docs/api/U...pRolesAssigned
http://wowprogramming.com/docs/api/GetPartyAssignment

try with http://wow.gamepedia.com/API_GetSpecializationRoleByID
  Reply With Quote
02-15-15, 08:15 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, you're only checking roles once when your addon first loads during login. At that point, role information is probably not available yet, even if you're reloading the UI and already had a role assigned in your group. Calling a function and assigning its return value to a variable sets the value of that variable to whatever was returned by the function at that time. If the function would return a different value at some other time, it doesn't matter -- your variable still contains the original value. If you want to get the new value, you have to call the function again.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-16-15, 12:45 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Here's applying the fixes suggested by the other posters. I'm not sure if PLAYER_ROLES_ASSIGNED is the event you're looking for. I don't know enough about your intentions to suggest one.
Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("PLAYER_ROLES_ASSIGNED");
  3.  
  4. f:SetScript("OnEvent", function(self, event, ...)
  5.     if event == "PLAYER_ROLES_ASSIGNED" then
  6.         local assigned = UnitGroupRolesAssigned("player")-- Role selected in LFD or assigned in raid
  7.         local current = GetSpecializationRoleByID(GetSpecialization())--    Role from specialization
  8.         if assigned ~= current then
  9.             print("Your current Talent Spec is set Wrong, switch specs!")
  10.         end
  11.     end
  12. end)
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-16-15 at 12:54 AM.
  Reply With Quote
02-16-15, 01:43 PM   #5
Kraiven
A Deviate Faerie Dragon
 
Kraiven's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2015
Posts: 10
Got it working

Thanks for the help. After an all day attempt to get the functions to work right I was finally able to get my results. One more question, is there a way to get the "currentSpecName" to show up in a pop up message window? I got it to work under print(blah blah), but not in the message(blah blah).

Code:
if role ~= specRole then
	playSound()
	message("|cffFF4500You are in the wrong Specialization!|r \n \n |cffffff00Change your Current Specialization before Combat!")
	print("|cff00ccffYour current Specialization:|r", currentSpecName)
end
if role == specRole then
	print("|cff00ccffYour current Specialization:|r", currentSpecName)
end


Edit: I added a little comment to my addon thanking all of you. If you would like me to leave you out just let me know. Thank you all again.

Last edited by Kraiven : 02-16-15 at 02:53 PM.
  Reply With Quote
02-16-15, 05:28 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
print automatically concatenates multiple arguments together with a space. message (and most other functions) do not -- you have to do the concatenation yourself:

local name = UnitName("player")
print("Hello", name) <-- shows "Hello Kraiven"
message("Hello", name) <-- probably shows just "Hello"
message("Hello " .. name) <-- now it shows "Hello Kraiven"
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-16-15, 09:15 PM   #7
Kraiven
A Deviate Faerie Dragon
 
Kraiven's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2015
Posts: 10
Originally Posted by Phanx View Post
message("Hello " .. name) <-- now it shows "Hello Kraiven"
Worked perfectly, Seems I need to do some more tutorials. Thanks for the quick tips.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Help with my own addon, need some LUA guidance.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off