void RunTimer(string &in asTimer)
{
if(asTimer == "LeaveBattle")
{
SetPlayerActive(false);
AfterBattle();
AddTimer("Exp", 1, "ExperienceTimer");
}
if(asTimer == "AttemptRun")
{
SetLocalVarInt("AttemptRunVar", RandInt(1,100));
if(GetGlobalVarInt("FriendlyMonsterLevel") > GetLocalVarInt("EnemyMonsterLevel"))
{
SetLocalVarInt("LevelDifferenceRun", Floor(PercentageXY(GetLocalVarInt("EnemyMonsterLevel"), GetGlobalVarInt("FriendlyMonsterLevel"))));
AddDebugMessage("Difference in percentage = "+GetLocalVarInt("LevelDifferenceRun"), false);
if(GetLocalVarInt("AttemptRunVar") < 50*((GetLocalVarInt("LevelDifferenceRun")/100)+1))
{
FadeIn(1);
TeleportPlayer("AfterBattle");
AfterBattle();
SetMessage("Messages", "RunSuccess", 0);
}
else
{
FadeIn(1);
TeleportPlayer("CantEscape");
SetEntityActive("AreaLeaveBattle", false);
SetMessage("Messages", "RunFailure", 0);
}
}
if(GetGlobalVarInt("FriendlyMonsterLevel") < GetLocalVarInt("EnemyMonsterLevel"))
{
SetLocalVarInt("LevelDifferenceRun", Floor(PercentageXY(GetGlobalVarInt("FriendlyMonsterLevel"), GetLocalVarInt("EnemyMonsterLevel"))));
AddDebugMessage("Difference in percentage = "+GetLocalVarInt("LevelDifferenceRun"), false);
AddDebugMessage(GetGlobalVarInt("FriendlyMonsterLevel")+"/"+GetLocalVarInt("EnemyMonsterLevel")+"* 100 = "+((GetGlobalVarInt("FriendlyMonsterLevel")/GetLocalVarInt("EnemyMonsterLevel"))*100), false);
if(GetLocalVarInt("AttemptRunVar") < 50*(GetLocalVarInt("LevelDifferenceRun")/100))
{
FadeIn(1);
TeleportPlayer("AfterBattle");
AfterBattle();
SetMessage("Messages", "RunSuccess", 0);
}
else
{
FadeIn(1);
TeleportPlayer("CantEscape");
SetEntityActive("AreaLeaveBattle", false);
SetMessage("Messages", "RunFailure", 0);
}
}
}
}