Rounding off. - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: Rounding off. (/thread-25947.html) Pages:
1
2
|
Rounding off. - FlawlessHappiness - 08-24-2014 Hello. I searched about rounding off. If I have decimal, say 2.4, I want to round it down to 2. If it's 2.7 it should also be rounded down to 2. I found this thread: https://www.frictionalgames.com/forum/thread-15621.html?highlight=round But did not understand the answer. Can you explain to me how it works? RE: Rounding off. - Romulator - 08-24-2014 Well, rounding down is known as "floor" in most codes. In the Math Functions page on the wiki, you can find this riiiiight down the bottom, which with a few clicks, is a copy+paste from the links you were looking at. PHP Code: int floor(float &in x) { return int(x); } Only problem is, I got no idea how to use it RE: Rounding off. - Mudbill - 08-24-2014 My guess would be for such a function to work like so: You input the floor(2.7f) into where you need it to be rounded, and it will return 2. For example: PHP Code: int iHealthRounded = floor(50.5f); //or whatever number you want to round. As you probably know, integers can't contain decimals, whereas floats can. It looks like this script simply converts the float (decimal) value to an integer, which kills off the decimal. I'm unsure if this conversion will automatically assume the closest full number or just ignore the decimal though. Don't forget to have that line Rom posted somewhere in your file. RE: Rounding off. - FlawlessHappiness - 08-24-2014 What, so the code PHP Code: int floor(float &in x) { return int(x); } Actually needs to be in my file, but with nothing editted into it? RE: Rounding off. - Mudbill - 08-24-2014 Pretty much. It doesn't even need to be named floor. Can be anything. Look at this: PHP Code: void Callback() RE: Rounding off. - FlawlessHappiness - 08-24-2014 If this works, my damage multiplier will be awesome! RE: Rounding off. - MrBehemoth - 08-24-2014 Can't you just use something like Code: iHealthRounded = int(50.5f); RE: Rounding off. - Daemian - 08-24-2014 Just go like this: PHP Code: int AttackType = ( 2.4 ); (.4 gets eaten, 2 survives the conversion) You can also do: PHP Code: float CATS = 2.5; What Behe said. RE: Rounding off. - MrBehemoth - 08-25-2014 Yup. Also, protip: if you want to round of to the nearest whole number, use Code: MyRoundedInt = int(MyFloat + 0.5f); Or if you want to round to a given number of decimal places: Code: NearestHundred = int((MyFloat + 0.5f) / 100) * 100; RE: Rounding off. - FlawlessHappiness - 08-25-2014 Ok, so this is interesting. This is how my script looks. Base damage PHP Code: if(GetGlobalVarString("Move") == "Dust") Damage calculation PHP Code: if(GetGlobalVarInt("FriendlyMonsterLevel") != GetLocalVarInt("EnemyMonsterLevel")) For some reason end damage = 0 It really shouldn't EDIT: NEVERMIND! I got it to work. |