Look, this is the part where we change looktype of target monster.
Code:
target:addCondition(condition)
You said it changes the looktype of every monster who receives it, right? You want it to make sure only monsters with X looktype can change, right?
What can you do? I briefly went over that in my post above. I said, we need a check to see if a creature (in my 2nd post, it was caster; in this case, it needs to be target, right?) has X looktype.
Let's scroll up and see what I said
creature can be a Creature userdata/metatable, meaning it is an object that represents a creature and has a load of methods (functions).
You can see all kinds of methods (functions) that are available for use here:
https://github.com/otland/forgottenserver/wiki/Metatable:Creature
So, to your case, target.
We can see in
@Moj mistrz's script that target is defined as such:
Code:
local target = creature:getTarget()
The :getTarget() function returns the target creature, which is more specifically, a Creature userdata/metatable.
Which again, means it is an object that represents a creature and has a load of methods (functions).
You can see all kinds of methods (functions) that are available for use here:
https://github.com/otland/forgottenserver/wiki/Metatable:Creature
Just in-case you can't assume that getTarget() returns a creature (if there is such target), then feel free to check the sources in luascript.cpp:
https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp#L7364
Now, up to this point, we know target can be a Creature userdata, which means we can perform a bunch of methods (as linked twice above).
We want to know if this target has X looktype, right?
In my first post, I provided an example of how to check for the looktype of a creature, see picture above.
Or, I can just copy it right here:
Code:
if creature:getOutfit().lookType == X then
end
But we need to change it because we want to get the looktype of target, not creature.
Code:
if target:getOutfit().lookType == X then
end
Now we have a conditional statement that means:
if target has X looktype, do this
What is the 'do this' that we wanted to do? We wanted to change the looktype of that target if they have X looktype, right?
In
@Moj mistrz's script above, you can find the part where it changes the looktype here:
Code:
target:addCondition(condition)
By the way, just in-case you don't know what the condition we're adding to the target, you can follow the condition definition at the top of his script.
Code:
local condition = Condition(CONDITION_OUTFIT)
condition:setTicks(900) -- 900 miliseconds
condition:setOutfit({lookType = 62, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookAddons = 0, lookMount = 0 })
This basically is a condition that changes the outfit to looktype 62 for 900 miliseconds.
Okay, so we found the part that changes the target's looktype, we want it so it only happens when the target has X looktype, right?
We figured out that conditional statement here:
Code:
if target:getOutfit().lookType == X then
end
We also found the part that changes the target's outfit here:
Code:
target:addCondition(condition)
We want the latter part inside the conditional statement that way it can only be reached when target has X looktype.
Code:
if target:getOutfit().lookType == X then
target:addCondition(condition)
end
BAM! KABAM! Simply-doo!
So, as a result, modifying
@Moj mistrz's script with the newly added check, we will get:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)
local condition = Condition(CONDITION_OUTFIT)
condition:setTicks(900) -- 900 miliseconds
condition:setOutfit({lookType = 62, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookAddons = 0, lookMount = 0 })
function onGetFormulaValues(player, level, maglevel)
min = -((level / 5) + (maglevel * 1.4) + 8)
max = -((level / 5) + (maglevel * 2.2) + 14)
return min, max
end
combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
local prevOutfit = creature:getOutfit()
local target = creature:getTarget()
local newOutfit = {lookType = 131}
if prevOutfit.lookType == 128 and target ~= nil then
addEvent(function(cid, prev)
local creature = Creature(cid)
if not creature then
return
end
creature:setOutfit(prev)
end, 900, creature:getId(), prevOutfit)
creature:setOutfit(newOutfit)
if not target then
return
end
if target:getOutfit().lookType == 128 then
target:addCondition(condition)
end
return combat:execute(creature, var)
else
return combat:execute(creature, var)
end
end
Hope that clears it all for you; any questions, ask.