Jump to content
Korean Random
Sign in to follow this  
Okxa

Showing XP left to elite tank as a percentage? (carousel)

Recommended Posts

I am trying to show how much it takes to elite a tank as a progress bar. However, because it's not a percentage the bar is almost (when xpleft<width of the cell) always too long:

0V2EIhq.png

Is there a way to convert it to a ratio?

 

My code:

// XP to Elite

// Progress Bar
{ "x": 4, "y": 78, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "width": "{{v.xpToEliteLeft}}", "height": 2, "bgColor": "{{v.c_damageRating}}" },
//Text
{ "x": 0, "y": 28, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "alpha": "{{v.xpToEliteLeft?100|0}}", "format": "<font size='10' color='#D4D4D4'>XP to Elite:" },
{ "x": 1, "y": 40, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "format": "<font size='10' color='{{v.c_battles}}'><font face='Arial'>{{v.xpToEliteLeft}}</font>" },

Also is there a way to colorize it by the amount of xp left? I tried to make a custom color macro but I couldn't get it to work.

Share this post


Link to post

Short link
Share on other sites
{ "x": 4, "y": 78, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}},{{v.xpToEliteLeft}})}},{{v.xpToElite}})}},160)}}", "height": 2, "bgColor": "{{v.c_damageRating}}" },

math.zip

  • Upvote 1

Share this post


Link to post

Short link
Share on other sites

What's wrong? I get the following in XVM log:

2016-10-14 13:58:51: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.py", line 49, in literal_eval
  File "scripts/common/Lib/ast.py", line 37, in parse
  File "<unknown>", line 1
    (,)
     ^
SyntaxError: invalid syntax
arg='math.sub(,)'
2016-10-14 13:58:51: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.py", line 80, in literal_eval
  File "scripts/common/Lib/ast.py", line 58, in _convert
  File "scripts/common/Lib/ast.py", line 79, in _convert
ValueError: malformed string
arg='math.div(null,)'
2016-10-14 13:58:51: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.py", line 80, in literal_eval
  File "scripts/common/Lib/ast.py", line 58, in _convert
  File "scripts/common/Lib/ast.py", line 79, in _convert
ValueError: malformed string
arg='math.mul(null,160)'
2016-10-14 13:58:52: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 155, in process_python_macro
  File "xvm_main/python_macro.py", line 148, in <lambda>
TypeError: math_sub() takes exactly 2 arguments (1 given)
arg='math.sub(440,)'
2016-10-14 13:58:52: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.p

Is it because?:

TypeError: math_sub() takes exactly 2 arguments (1 given)
Even though it should have 2 arguments.

 

Or do I have files required? Is the math.py required in somewhere specific place or is the one in "res_mods\configs\xvm\py_macro" enough?

 

EDIT:

Or is the reason that it requires other than 0 (as elited tanks have 0 xp required)? By doing this the bars show up (incorrectly so I get still errors).

"width": "{{v.xpToEliteLeft}}?{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}},{{v.xpToEliteLeft}})}},{{v.xpToElite}})}},160)}|0}",
But I still get this in XVM.log:

2016-10-14 14:21:01: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.py", line 49, in literal_eval
  File "scripts/common/Lib/ast.py", line 37, in parse
  File "<unknown>", line 1
    (,)
     ^
SyntaxError: invalid syntax
arg='math.sub(,)'
2016-10-14 14:21:01: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.py", line 80, in literal_eval
  File "scripts/common/Lib/ast.py", line 58, in _convert
  File "scripts/common/Lib/ast.py", line 79, in _convert
ValueError: malformed string
arg='math.div(null,)'
2016-10-14 14:21:01: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 155, in process_python_macro
  File "xvm_main/python_macro.py", line 148, in <lambda>
TypeError: math_sub() takes exactly 2 arguments (1 given)
arg='math.sub(440,)'
2016-10-14 14:21:01: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 154, in process_python_macro
  File "xvm_main/python_macro.py", line 142, in get_function
  File "scripts/common/Lib/ast.py", line 80, in literal_eval
  File "scripts/common/Lib/ast.py", line 58, in _convert
  File "scripts/common/Lib/ast.py", line 79, in _convert
ValueError: malformed string
arg='math.div(null,440)'
Edited by Okxa

Share this post


Link to post

Short link
Share on other sites

But do you see any bars? Do they vary in length depending on remaining XP to elite? Or doesn't it work for you at all?

I didn't check the log, because it worked for me, though there are indeed some errors. But if it works, why bother with errors? ;)

Edited by konrad509

Share this post


Link to post

Short link
Share on other sites

With your code, no I dont see any bars.

However, when I manually set alpha to 100, there are bars on elited tanks

 

KFpbr9j.png

Theres something strange going on with python? but what?

Share this post


Link to post

Short link
Share on other sites

This is how it looks for me

post-30086-0-03783300-1476532945_thumb.jpg

 

But yeah, with alpha set to 100, the bars are displayed for elited tanks. Although not for all.

Share this post


Link to post

Short link
Share on other sites

Do you have any errors about this in XVM.log? If not then I have something wrong with my xvm?

 

Also what xvm version are you on?

I couldn't get this to work on the latest release build XVM 6.4.6.2 (6577) I got the errors mentioned earlier to my XVM.log.

Share this post


Link to post

Short link
Share on other sites

The calculation of the length of the progress bar isn't easy ... :/

 

I think the calculation must be this way:

160 * (100 - (100 * v.xpToEliteLeft / v.xpToElite)) / 100 = width

Who will integrate this in a script file? :)

 

 

EDIT:

 

This will not work:

"width": "{{py.math.div({{py.math.sub(100,{{py.math.div(100,{{py.math.div({{py.math.mul({{v.xpToEliteLeft}},{{v.ToElite}})}})}})}})}})}}",

But i am not a programmer.

Edited by huepper

Share this post


Link to post

Short link
Share on other sites

Hello,

 

it works like konrad509 said, this is what i have now.

      // XP to Elite
		// Progress Bar
		{ "x": 2, "y": 97, "layer": "top", "alpha": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 100)}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 160)}}", "height": 2, "bgColor": "#FF6600" },
		//Text
		{ "x": 80, "y": 2, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#D4D4D4' face='$FieldFont'>XP to Elite:</font></b>" ,
		"shadow": ${ "def.textFieldShadow" }
		},
		{ "x": 80, "y": 14, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#FF6600' face='$FieldFont'>{{v.xpToEliteLeft}} / {{v.xpToElite}}</font></b>" ,
		"shadow": ${ "def.textFieldShadow" }
		},

As you see, i use the same line for alpha, but with 100 at the end of line.

 

post-38178-0-84463900-1477487513.jpg

 

Share this post


Link to post

Short link
Share on other sites

Hello,

 

it works like konrad509 said, this is what i have now.

      // XP to Elite
		// Progress Bar
		{ "x": 2, "y": 97, "layer": "top", "alpha": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 100)}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 160)}}", "height": 2, "bgColor": "#FF6600" },
		//Text
		{ "x": 80, "y": 2, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#D4D4D4' face='$FieldFont'>XP to Elite:</font></b>" ,
		"shadow": ${ "def.textFieldShadow" }
		},
		{ "x": 80, "y": 14, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#FF6600' face='$FieldFont'>{{v.xpToEliteLeft}} / {{v.xpToElite}}</font></b>" ,
		"shadow": ${ "def.textFieldShadow" }
		},

As you see, i use the same line for alpha, but with 100 at the end of line.

 

attachicon.gifalpha.jpg

Try to change alpha:100 for this:

"alpha" : "{{v.elite?0|100}}",

It will show You Text, Only on Not Elite Tank

Share this post


Link to post

Short link
Share on other sites

Try to change alpha:100 for this:

"alpha" : "{{v.elite?0|100}}",

It will show You Text, Only on Not Elite Tank

 

Thanks, this works perfect. :)

      // XP to Elite
		// Progress Bar
		{ "x": 2, "y": 97, "layer": "top", "alpha": "{{v.elite?0|100}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 160)}}", "height": 2, "bgColor": "#FF6600" },
		//Text
		{ "x": 80, "y": 2, "align": "center", "layer": "top", "alpha": "{{v.elite?0|100}}", "format": "<b><font size='11' color='#D4D4D4' face='$FieldFont'>XP to Elite:</font></b>" ,
		"shadow": ${ "def.textFieldShadow" }
		},
		{ "x": 80, "y": 14, "align": "center", "layer": "top", "alpha": "{{v.elite?0|100}}", "format": "<b><font size='11' color='#FF6600' face='$FieldFont'>{{v.xpToEliteLeft}} / {{v.xpToElite}}</font></b>" ,
		"shadow": ${ "def.textFieldShadow" }
		},

Share this post


Link to post

Short link
Share on other sites

Hello,sorry ny english,  I would like to add this thing, But I am ignorant on the subject.

I tried to copy / paste at the end of strings carousel.xc, but it does not work and it is I who am wrong.

Where they copy these strings, in what position?

thank you so much for what you do.

Share this post


Link to post

Short link
Share on other sites

So I cant get it to work... I even updated to the latest xvm (XVM-6.4.7.1)

Code, alpha is always 100 for testing purposes:

// XP to Elite
{ "x": 2, "y": 79, "layer": "top", "alpha": "{{v.elite?100|100}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 126)}}", "height": 2, "bgColor": "#FF6600" },

Here's what it still looks like:
z0Ar37K.png
 
I still get the same errors to my XVM.log, whats wrong?

2016-10-27 13:36:42: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 156, in process_python_macro
  File "xvm_main/python_macro.py", line 144, in get_function
  File "scripts/common/Lib/ast.py", line 49, in literal_eval
  File "scripts/common/Lib/ast.py", line 37, in parse
  File "<unknown>", line 1
    (, )
     ^
SyntaxError: invalid syntax
arg='math.sub(, )'
2016-10-27 13:36:42: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 156, in process_python_macro
  File "xvm_main/python_macro.py", line 144, in get_function
  File "scripts/common/Lib/ast.py", line 49, in literal_eval
  File "scripts/common/Lib/ast.py", line 37, in parse
  File "<unknown>", line 1
    (, )
     ^
SyntaxError: invalid syntax
arg='math.div(, )'
2016-10-27 13:36:42: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 156, in process_python_macro
  File "xvm_main/python_macro.py", line 144, in get_function
  File "scripts/common/Lib/ast.py", line 49, in literal_eval
  File "scripts/common/Lib/ast.py", line 37, in parse
  File "<unknown>", line 1
    (, 126)
     ^
SyntaxError: invalid syntax
arg='math.mul(, 126)'
2016-10-27 13:36:43: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 157, in process_python_macro
  File "xvm_main/python_macro.py", line 150, in <lambda>
TypeError: math_sub() takes exactly 2 arguments (1 given)
arg='math.sub(440, )'
2016-10-27 13:36:43: [ERROR] Traceback (most recent call last):
  File "xvm_main/python_macro.py", line 156, in pr

 

There are also my full XVM.log and my carousel config file attached, if that would help you.

Or could you test it with my carousel file?

XVM.log

carouselNormal.xc

Share this post


Link to post

Short link
Share on other sites

Did you replace the original file math.py with the one from the archive I attached?

 

I forgot that each time you update XVM, the folder py_macro is overwritten, so you lose any changes made to the files in it.

My knowledge about Python is very, very basic, but I think this modified function can moved to a different file, so you don't need to worry about overwriting it while updating XVM.

^

(This sentence is still true :swt3:)

 

Yes, it can be done.

Unpack it into py_macro folder and in the config change py:math.div to py:fdiv.div.

fdiv.zip

 

Here's ready file carouselNormal.xc

Edited by konrad509

Share this post


Link to post

Short link
Share on other sites

Oh I didn't realize that you had modified a function, so I just though the math.py you provided wasn't required....

 

Now it's working perfect.

Share this post


Link to post

Short link
Share on other sites

really nice thx for this code snipped.

i found i bug/problem and hope it could be fixed...

the blueprints are not included in this calculation..my 7% less exp isn't added.

Share this post


Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...