function compareCharDist(atk, def)
if Characters[atk].Position.x < Characters[def].Position.x and (Characters[def].Position.x - Characters[atk].Position.x) <= 100 then
-- hit (attacker is on left)
elseif if Characters[atk].Position.x > Characters[def].Position.x and (Characters[atk].Position.x - Characters[def].Position.x) <= 100 then
-- hit (attacker is on right)
end
end
compareCharDist("Tom", "Harry")
I've been trying that setDelay example to see if I could detect when a character is in range and it seems to work well BUT I'm really not sure if its a good idea to have it running for an extended period of time also the range depends on how fast the delay runs.Hence check directly via the relevant animation frame. Why bother with delays, when you can sync much easier by checking on the relevant animation frames?a delay of 250ms is enough if you check for a a character 50px away..
startAnimation(Characters[def].CurrentOutfit.CharacterAnimations["hurt"])
function compareCharDist(MC,opponent)
NearOpponentStandingRight = getObject("Conditions[NearOpponentStandingRight]")
NearOpponentStandingLeft = getObject("Conditions[NearOpponentStandingLeft]")
if Characters[MC].Position.x < Characters[opponent].Position.x and (Characters[opponent].Position.x - Characters[MC].Position.x) <= 100 then
setCondition("nearEnough", true)
NearOpponentStandingLeft:setValue(VConditionValue, true)
NearOpponentStandingRight:setValue(VConditionValue, false)
-- hit (attacker is on left)
elseif
Characters[MC].Position.x > Characters[opponent].Position.x and (Characters[MC].Position.x - Characters[opponent].Position.x) <= 100 then
setCondition("nearEnough", true)
NearOpponentStandingRight:setValue(VConditionValue, true)
NearOpponentStandingLeft:setValue(VConditionValue, false)
-- hit (attacker is on right)
end
end
compareCharDist("MC", "opponent")
function distanceScriptTry (mc, opponent)
standingRight = getObject("Conditions[standingRight]")
standingLeft = getObject("Conditions[standingLeft]")
mc = getObject("Characters[MC]")
opponent = getObject("Characters[opponent]")
if mc.Position.x + opponent.Position.x >=1
and
mc.Position.x + opponent.Position.x <=300
then
standingRight:setValue(VConditionValue, true)
else
standingRight:setValue(VConditionValue, false)
end
if mc.Position.x - opponent.Position.x <=-1
and
mc.Position.x - opponent.Position.x >=-300
then
standingLeft:setValue(VConditionValue, true)
else
standingLeft:setValue(VConditionValue, false)
end
end
function distanceScriptTry (mc, opponent)
standingRight = getObject("Conditions[standingRight]")
standingLeft = getObject("Conditions[standingLeft]")
mc = getObject("Characters[MC]")
opponent = getObject("Characters[opponent]")
if mc.Position.x < opponent.Position.x
and
mc.Position.x - opponent.Position.x >=-300
then
standingLeft:setValue(VConditionValue, true)
else
standingLeft:setValue(VConditionValue, false)
end
if mc.Position.x > opponent.Position.x
and
mc.Position.x - opponent.Position.x <=300
then
standingRight:setValue(VConditionValue, true)
else
standingRight:setValue(VConditionValue, false)
end
end