Saturday, April 21, 2012

Checking for combat

I was wondering if anyone has any idea on how to determine a) whether or not a player is in combat and if so b) if the unit they are attacking/being attacked by is an npc boss, like an in instance. I'm trying to create an auto-reply system for whispers but I can't get UnitAffectingCombat to work. Sorry if that was confusing, and thanks in advance.|||Quote:








I was wondering if anyone has any idea on how to determine a) whether or not a player is in combat and if so b) if the unit they are attacking/being attacked by is an npc boss, like an in instance. I'm trying to create an auto-reply system for whispers but I can't get UnitAffectingCombat to work. Sorry if that was confusing, and thanks in advance.




There has always been an option in AlphaMap to hide the map during combat, (and re-open it when combat is over).

It does this by monitoring for the "PLAYER_REGEN_DISABLED" and "PLAYER_REGEN_ENABLED" events, and has always seemed pretty reliable to me. I haven't tested what happens when a player has special buffs/abilities that allow some regeneration during combat, but I suspect they will still receive these events.



For determining target details you could try the following :

UnitClassification should report "worldboss", "rareelite", "elite", "rare",........

http://www.wowwiki.com/API_UnitClassification

and

UnitLevel should report -1 when unit is a special boss (whatever that means...)

http://www.wowwiki.com/API_UnitLevel



Other people may have better suggestions :)|||Quote:




UnitLevel should report -1 when unit is a special boss (whatever that means...)




If I remember correctly this means that the target is a "Skull" level monster so it should work for what you're trying to detect here.

For reference, the skull means it pretends to be three levels above you regardless of your level (in terms of hit/resist chances but its health/mana/damage/etc stay the same).|||Not sure if it will work in all situations but I'm currently using InCombatLockdown() to check for combat status.|||I can't remember the name of the mod right now, but there is an answering machine type addon that takes your messages when afk, but also auto-replies to tells during combat. The one I saw replied with the name of the boss you were fighting as well. Anyone remember the name of that mod?|||Thank you for the help, I've managed to detect whether the player is in combat with a boss in order to determine if an auto-reply is needed. I've been working on a few keyboard replacements (eg %HP for Boss Health Percent) but can't seem to get it work right.


Code:
autoreply=string.gsub(autoreply,"$B" , UnitName("target"));
autoreply=string.gsub(autoreply,"$P", UnitName("player"));
autoreply=string.gsub(autoreply,"$HP",((UnitHealth("target")/UnitHealthMax("target"))*100).." %");

Which returns the correct number as a percentage, and allows for other things to be added after it, but the % sign is always mysteriously missing, any ideas?

For example, if you type "$P is fighting $B, who has $HP health left. Try again later."

This is returned: "Dinarin is fighting Pygmy Venom Web Spider, who has 100 . health left. Try again later."|||Since it is a pattern do you need to code it this way, with an extra % sign? Pattern matching confuses me so I am just guessing since % is a "magic" character.


Code:
autoreply=string.gsub(autoreply,"$HP",((UnitHealth("target")/UnitHealthMax("target"))*100).." %%");
|||Yes, you need to escape it somehow, but I'm not certain on how you do that in Lua.|||Quote:








Since it is a pattern do you need to code it this way, with an extra % sign? Pattern matching confuses me so I am just guessing since % is a "magic" character.


Code:
autoreply=string.gsub(autoreply,"$HP",((UnitHealth("target")/UnitHealthMax("target"))*100).." %%");






That did it, thank you very much. Now I just have to make sure my conditions to test for raid/5-man bosses are correct lol.|||I think this is the problem... Some "magic characters" (such as %) have special uses in LUA. These are:

^ $ ( ) % . [ ] * + - ?

To use these in a pattern you have to precede them with a % symbol. So for example, "%%" would match a single %... lol, just saw that Jumpy beat me to this:)

No comments:

Post a Comment