1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Arithmetic & Decimals

Discussion in 'Skript' started by xGrow, Mar 1, 2017.

Thread Status:
Not open for further replies.
  1. xGrow

    xGrow Member

    Joined:
    Feb 26, 2017
    Messages:
    10
    Likes Received:
    1
    So, i'm coding a system of KDR:
    CODE:
    Code (Skript):
    1. on every second:
    2.     set {kdr.%player%} to {kills.%player%}/{deaths.%player%}
    And, if the result give to player a giant number i want reducing to 2 decimals like: "0,435687548" to "0,43"
     
    #1 xGrow, Mar 1, 2017
    Last edited: Mar 1, 2017
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    Skript has an option in the config.sk to select how much decimal digits will be displayed on a number, it's the number accuracy.
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    If you cannot use "number accuracy" in config.sk for some reason, try rounding down multiplied number.
    Code (Skript):
    1. on every second:
    2.     set {kdr.%player%} to (rounded down ({kills.%player%}*100)/{deaths.%player%})/100
    3.  
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    that would give an integer without decimals, and why are you multiplying it by 100 then dividing it by 100, I don't see the logic on that.

    Also, I wouldn't use the periodical event for this kind of things, or even set a variable for it such as it's useless when all that you have to do is divide the kills by the deaths, setting a local variable where you need it would be better, other thing, you should use list variables instead of the regular ones for this kind of stuff. For example, a day you want to do a top kills & top deaths, then on this case, if you use variables like:
    Code (Skript):
    1.  
    2. {kills::%player%} & {deaths::%player%}
    3.  
    instead of:
    Code (Skript):
    1.  
    2. {kills.%player%} & {deaths.%player%}
    3.  
    will do it a lot easier, such as you'll be able to loop that list and get the value & index from that list, which is a thing that you will not be able to do with the regular variables.
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    The thing is, config.sk is global, and people want accuracy in some script and approximation in another one. An expression in Skript or in skUtilities would be good. Unless Java has some functions I don't know of, the solution is kinda archaic, because it involves substring/subtext. Can't detail it rn, but if anyone is down for using subtext/substring, name sure to post it here.
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    Code (Skript):
    1.  
    2. set {_kdr::*} to split "%{kills.%player%}/{deaths.%player%}%" by "."
    3. set {_kdr} to "%{_kdr::1}%.%first 2 characters of {_kdr::2}%" parsed as num #You can remove the parsed as num if you want.
    4.  
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    I think this code will cause parse error if the KDR was natunal number.

    ↓ test script
    Code (Skript):
    1.  
    2. command /testkdr <number> <number>:
    3.     trigger:
    4.         set {_kdr} to (rounded down (arg-1*100)/arg-2)/100
    5.         message "%{_kdr}%"
    6.  
    7.  
    8. command /testkdr2 <number> <number>:
    9.     trigger:
    10.         set {_kdr::*} to split "%arg-1/arg-2%" by "."
    11.         set {_kdr} to "%{_kdr::1}%.%first 2 characters of {_kdr::2}%" parsed as num #You can remove the parsed as num if you want.
    12.         message "%{_kdr}%"
    13.  
     
Thread Status:
Not open for further replies.

Share This Page

Loading...