08-30-2014, 12:48 AM
Hello.
I'm trying to create a script that finds the percentage of something.
So I came up with this:
And I'm using it like this:
But no matter what the LevelDifferenceRun always returns 0, when it's supposed to return the difference between my level and the enemy level in percentage.
Is my math function wrong?
EDIT
OK I still need help!
Sorry about bumping this quick, but I had an edit that said I didn't need help anymore, but it turns out I still need help.
It's returnin 0 no matter what. Even the debug message returns 0.
I'm trying to create a script that finds the percentage of something.
So I came up with this:
PHP Code:
int PercentageXY(int &in x, int &in y)
{
return int((x/y)*100);
}
And I'm using it like this:
PHP Code:
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);
}
}
}
}
But no matter what the LevelDifferenceRun always returns 0, when it's supposed to return the difference between my level and the enemy level in percentage.
Is my math function wrong?
EDIT
OK I still need help!
Sorry about bumping this quick, but I had an edit that said I didn't need help anymore, but it turns out I still need help.
It's returnin 0 no matter what. Even the debug message returns 0.