• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua [Spell] Spell Damage affected by TARGET's variable stats? +Repping

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Reaction score
13
Location
Caracas, Venezuela
Hello all. It's been a while since I last posted here (or did anything OT related) but it seems like some nice improvements have been made :)

Anyway, I started doing some lua stuff to get back on my feet on an old OT I was making before going inactive and now I have a doubt that I just cant seem to solve by myself.

(Note: Seems like the old Rep points/bars are gone with this new design so my "+Repping" offer isnt really worth that much now, so it is only a little something to thank any helpful responses :))

The question is what title says:

How can I make it so the spell's damage is affected by the TARGET's variable stats?

It might sound kind of confusing so here is an example:

If I were to make a Rune with Actions instead of Spells, this would be easier since it would be something like:

Final_Damage_of_Rune = Damage_Formula - X_Stat_From_Target

If this "x stat" is defined by a storage value:

Final_Damage_of_Rune = Damage_Formula - getPlayerStorageValue(item2.uid, whatever_storage)

So as you can see there, if I were to make a Rune that is only "single target" it would be an easy task to vary the damage of it depending on the "target's stat" because the "target" is defined as item2.uid, and therefore I can get anything I want off of it, like a storage value or just anything I need.

But if I wanted to make this Rune deal AoE (Area of Effect) damage, then everything is screwed because 1. Im unsure of how to make areas on Action Runes and 2. item2.uid is no longer the target, since item2.uid is only the "place" where the Rune is "applied", and even if I did use it on someone, there are many "other targets" who might be hit by the AoE, so I no longer know how to get anything off of them all.

So, the only thing I can solve from those 2 is the #1, the AoE is easier to make if the Rune is made in Spells instead of Actions.

But in Spells, the function is:

function onCastSpell(cid, var)

So I fall even deeper in this ignorance hole by not even having item2-ish type of params on the function to play around with, Im left only with cid and var, which means Im left only with var, which I have no idea how to workaround for it to do or mean anything.

So, after all this explaining, my question is:

How, using Spells (aka "function onCastSpell(cid, var)"), can I get information such as a Storage from the people HIT by the AoE of the Spell itself (in the same fashion of how "target = item2.uid" would work for Single Targetted Action Runes)?

Is it even possible to do this?

And what exactly is the var on this function? How can I get anything off of it or how does it work?

Sorry for the wall of text, but this is really bothering me since I have no idea what to do about it! And I guess I didnt know how else to explain it so if you read it all, thanks.

Well, thanks in advance, Ill +rep any helpful response of course.

PS: If for some reason you need this info, Im using TFS 0.3.6pl1. Also, didnt know where else to post this, there used to be a Support sub-forum only for LUA related issues but I cant seem to find it now lol so I guess here is the place now.
 
First remove the line with setAttackFormula/setCombatFormula from your script.

Then add something like this instead:
Lua:
function onTargetCreature(cid, target)
	local min = minimum_damage_formula
	local max = maximum_damage_formula

	local dmg = math.random(min, max)

	if isPlayer(target) then
		dmg = dmg - getPlayerStorageValue(target, whatever_storage)
	end

	doTargetCombatHealth(cid, target, COMBAT_ENERGYDAMAGE, -dmg, -dmg, CONST_ME_NONE)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

Simple as that, I guess.
 
First remove the line with setAttackFormula/setCombatFormula from your script.

Then add something like this instead:
Lua:
function onTargetCreature(cid, target)
	local min = minimum_damage_formula
	local max = maximum_damage_formula

	local dmg = math.random(min, max)

	if isPlayer(target) then
		dmg = dmg - getPlayerStorageValue(target, whatever_storage)
	end

	doTargetCombatHealth(cid, target, COMBAT_ENERGYDAMAGE, -dmg, -dmg, CONST_ME_NONE)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

Simple as that, I guess.

I was hoping for you to see the thread :)

Thanks a lot Cyko it worked and tweaking it a bit also made me learn a lot of other useful stuff so thanks again! <3
 
Back
Top