November 1, 20169 yr Hello, I tried this in my fightclass as a spell: t="raid"; nps=1; npe=GetNumGroupMembers(); if npe<=4 then nps=0; t="party"; end; print(t," ",npe) With the spell settings as: Combat only - False Not spell, is lua script - True I was hoping it would spam something like: "party 0" or "party nil" But instead I get nothing. Any suggestions on how to make this work? Eventually I hope to make a fightclass that can detect if I'm in a party or raid, then using the global var "t" have it run a loop for party2, raid1..40, etc.
November 2, 20169 yr Author Well, I figured out that my lua script wasn't working as a spell, but if I used it as a condition then it worked. Now I'm trying to pass "t" to another 'spell', with the below as a condition: <LuaScript>-- Find the unit with the largest health deficit, in range, that is alive, that doesn't have Rejuvenation print("t ",t) m=0; w=f; local SpellName = GetSpellInfo("Rejuvenation") for i=nps,npe do if i==0 then tt="player" else tt=t..i end; if UnitExists(tt) and IsSpellInRange(SpellName,tt) and not UnitIsDeadOrGhost(tt) and not UnitBuff(tt,SpellName,nil,"PLAYER") then a=UnitHealth(tt) / UnitHealthMax(tt); if a>m then m=a w=tt end end end; -- Heal the unit with the largest deficit if m <= .95 then CastSpellByName(SpellName, w) end </LuaScript> I get nothing, not print, not any action, etc. Suggestions?
November 2, 20169 yr Author I know it's not optimal, but I got it to work with this now: <LuaScript>m=0; w=f; local SpellName = GetSpellInfo("Rejuvenation") for i=nps,npe do if i==0 then tt="player" else tt=t..i end; ue=UnitExists(tt) print(ue) isir=IsSpellInRange(SpellName,tt) print(isir) uidog=UnitIsDeadOrGhost(tt) print(uidog) ub=UnitBuff(tt,SpellName,nil,"PLAYER") print(ub) print("----------------") if ue and isir and not uidog then print("TRUE") else print("FALSE") end print("----------------") if ue and isir and not uidog then a=UnitHealth(tt) / UnitHealthMax(tt); if a>m then m=a w=tt end end end; if m <= 1 and not ub then CastSpellByName(SpellName, w) end; </LuaScript> The part that is driving me crazy - otherwise I like solving puzzles - is that the results are not consistent. Sometimes it works, then other times it just doesn't.
November 2, 20169 yr Hello, you can test your lua script in tab "Tools" > "Development Tools" > past code in textbox and click on "Lua (...)".
November 6, 20169 yr Dont use global variables in LUA. Put a "local" in front of every new Variable ! Example:
November 8, 20169 yr Author Yea, I've kind of given up on this. It was a useful exercise. C# seems to be a more consistent method.
Create an account or sign in to comment