Page 1 of 1

help on passing table values to functions (or otherwise?)

Posted: Fri Oct 05, 2012 12:59 pm
by jenx
Ok, here is what I want to do:

I am writing an addon that displays chance to hit when various talents are activated, or for simple hits. So for example, for a simple melee attack, it displays this for my lvl2 Doomed, Bumper, wearing no armor:

>> Accuracy (21) of Poison Ivy against Defense (0) of Bumper gives 100 percent chance to hit

Then, the poison ivy tries to poison Bumper, and Bumper's attempt to shrug it off is shown as:

>> Physical save (7) of Bumper against ??? (21) of Poisoned gives 15 percent to shrug off.

"Poisoned" here is the status name.

My trouble is with the ???. What I want, is the origin of the attack from the attacker. So for the stunned effect from Gestures of Pain, I want "Mind Power" instead of ???.

Here is the code, and you'll see my problems:

Code: Select all

function _M:on_set_temporary_effect(eff_id, e, p)
	if p.apply_power and (save_for_effects[e.type] or p.apply_save) then
		<snip>

		if e.status == "detrimental" and p.dur > 0 then
			self:checkHitVB(save, p.apply_power, 0, 95, p.save_string, "???", e.desc, "to shrug off")

			if self:checkHit(save, p.apply_power, 0, 95) then
				game.logSeen(self, "#ORANGE#%s shrugs off the effect '%s'!", self.name:capitalize(), e.desc)
				p.dur = 0
			end
		end

		p.apply_power = nil
	end
The function checkHitVB() is my own function, simply a variation of checkHit():

Code: Select all

--Used for verbose output just to give info on attacking
function _M:checkHitVB(atk, def, min, max, atktype, deftype, targetname, result)
	if atk < 0 then atk = 0 end
	if def < 0 then def = 0 end
	local min = min or 0
	local max = max or 100
	local hit = math.ceil(50 + 2.5 * (atk - def))
	hit = util.bound(hit, min, max)

	local srcname = self.name:capitalize() or "Unknown Attacker"
	local targetname = targetname or "Unknown Defender"
	local atktype = atktype or "Unknown Attack"
	local deftype = deftype or "Unknown Defence"
	local result = result or "to hit"
	game.logSeen(self, "#ORCHID#>> %s (%d) of %s against %s (%d) of %s gives %d percent chance %s", atktype, atk, srcname, deftype, def, targetname, hit, result)
end
As you can see, in _M:on_set_temporary_effect(), I call checkHitVB(), but this function doesn't know the *origin* of the p.apply_power (at least I don't think it does).

For example, take Gestures of Pain:

Code: Select all

if rng.percent(stunChance) then
	target:setEffect(target.EFF_STUNNED, 3, {apply_power=self:combatMindpower()})
end
In this case, even though it is stun, the origin is the Mind power of the attacker, but only the value of this is sent to setEffect (which calls on set temporary effect), not the type "Mind power".

setEffect receives as the third variable p, which seems to be a table of values:

Code: Select all

function _M:setEffect(eff_id, dur, p, silent)
and then passes this on to:

Code: Select all

function _M:on_set_temporary_effect(eff_id, e, p)
So I thought I could solve this by passing in the name of the attack type, but it doesn't work.

That is, I tried this without success:

in gestures.lua:

Code: Select all

target:setEffect(target.EFF_STUNNED, 3, {apply_power=self:combatMindpower(), vb="Mind power"})
and then in Actor.lua and on_set_temporary_effect:

Code: Select all

self:checkHitVB(save, p.apply_power, 0, 95, p.save_string, p.vb, e.desc, "to shrug off")
and hence checkHitVB would print out for stunned from Gesture of Pain:

>>> Physical save (7) of Giant white rat against Mind power (20) of Bumper gives 17 percent chance to shrug off.

But as I said, it doesn't work.

So my question is, what am I doing wrong, and how can I display the type of power that is used in on_set_temporary_effect? Do I need to send it in from the origin, as I tried with gestures.lua, and if so, how? and if not, where can I retrieve it from?

Hope this makes sense!!