The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Math problem - Percentage [SOLVED]
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#1
Math problem - Percentage [SOLVED]

Hello.

I'm trying to create a script that finds the percentage of something.

So I came up with this:

PHP Code: (Select All)
int PercentageXY(int &in xint &in y)
{
    return 
int((x/y)*100);


And I'm using it like this:

PHP Code: (Select All)
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.

Trying is the first step to success.
(This post was last modified: 08-30-2014, 02:23 AM by FlawlessHappiness.)
08-30-2014, 12:48 AM
Find


Messages In This Thread
Math problem - Percentage [SOLVED] - by FlawlessHappiness - 08-30-2014, 12:48 AM
RE: Math problem - Percentage - by Mudbill - 08-30-2014, 01:49 AM
RE: Math problem - Percentage - by MrBehemoth - 08-30-2014, 02:18 AM



Users browsing this thread: 1 Guest(s)