WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Macro Help (https://www.wowinterface.com/forums/forumdisplay.php?f=140)
-   -   Script conditionals? (https://www.wowinterface.com/forums/showthread.php?t=46165)

kittykatmax 04-03-13 09:58 AM

Script conditionals?
 
I dual box and use two addons for it at this point. The script below works so I can tell my focus character to follow me (for the addon Useful Extras) even if they're from another realm or not in party/raid. The /followme in line 2 is for party members for the Hydra addon, which doesn't work cross realm or with characters not in party. My problem is that when I use this script and don't have a focus, it bugs and I get an error message stating, "SendChatMessage(): Whisper message missing target player!".

Is there a way to edit the initial script with some kind of [exists, help] conditional to fix this so I won't get errors when there's no focus or I have an enemy focus?

Thanks!


/run local n,r=UnitName"focus"n=n and n..(r and"-"..r or"")or""SendChatMessage("followme","WHISPER",nil,n);
/followme

Clamsoda 04-03-13 11:08 AM

1] There is a way to add macro conditionals to a bit of Lua, and that is through the SecureCmdOptionParse function. I've only used it once, so I don't know that I could provide much insight, but here is the WoWWiki link.

2] You can check for the existence of a unit in two ways: through the UnitExists() function, or by checking that your variable exists. For example,

UnitName("focus") doesn't return anything if the unit doesn't exist, and as such can be used as a sort of conditional.

Lua Code:
  1. if UnitName("focus") then
  2.     -- Unit exists, do stuff.
  3. end

Edit: Here is what I came up. I've got to be off soon, so I didn't have time to login to WoW to test it, but all I did was add a check for the existence of "n" to merit continuing, and I added your realm check logic to later in the macro. Should be sub 255. Let me know if it works!

Lua Code:
  1. /run local n, r = UnitName("focus") if n then SendChatMessage("followme", "WHISPER", nil, n..(r and "-"..r or "")) end

Edit 2: Just kidding, guys get ready in 40 seconds. I tested without a focus, with me as the focus, and with someone cross-realm as the focus, and it worked every time. Enjoy!

kittykatmax 04-04-13 09:01 AM

Quote:

Originally Posted by Clamsoda (Post 275742)
1] There is a way to add macro conditionals to a bit of Lua, and that is through the SecureCmdOptionParse function. I've only used it once, so I don't know that I could provide much insight, but here is the WoWWiki link.

2] You can check for the existence of a unit in two ways: through the UnitExists() function, or by checking that your variable exists. For example,

UnitName("focus") doesn't return anything if the unit doesn't exist, and as such can be used as a sort of conditional.

Lua Code:
  1. if UnitName("focus") then
  2.     -- Unit exists, do stuff.
  3. end

Edit: Here is what I came up. I've got to be off soon, so I didn't have time to login to WoW to test it, but all I did was add a check for the existence of "n" to merit continuing, and I added your realm check logic to later in the macro. Should be sub 255. Let me know if it works!

Lua Code:
  1. /run local n, r = UnitName("focus") if n then SendChatMessage("followme", "WHISPER", nil, n..(r and "-"..r or "")) end

Edit 2: Just kidding, guys get ready in 40 seconds. I tested without a focus, with me as the focus, and with someone cross-realm as the focus, and it worked every time. Enjoy!



Thanks so much! Haven't had a chance to play much but it seems to work.

And, it's so unfair that men can get ready so quickly. /grrrrrrr

Clamsoda 04-04-13 09:52 AM

I re-read your post and realized that I forgot to add any sort of check for your focus being a player, and a friendly one at that. This should do the trick.

Lua Code:
  1. /run local n, r = UnitName("focus") if n and UnitIsPlayer("focus") and not UnitIsEnemy("player", "focus") then SendChatMessage("followme", "WHISPER", nil, n..(r and "-"..r or "")) end

kittykatmax 04-04-13 11:12 AM

Quote:

Originally Posted by Clamsoda (Post 275773)
I re-read your post and realized that I forgot to add any sort of check for your focus being a player, and a friendly one at that. This should do the trick.

Lua Code:
  1. /run local n, r = UnitName("focus") if n and UnitIsPlayer("focus") and not UnitIsEnemy("player", "focus") then SendChatMessage("followme", "WHISPER", nil, n..(r and "-"..r or "")) end

Thank you again! :)


All times are GMT -6. The time now is 01:19 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI