ScriptUO
Scripting Resources & Utilities => Stealth Client => Stealth scripts => Topic started by: Boydon on August 17, 2012, 01:17:16 PM
-
This is a very fast and simple yet useful script that will sum up all the caracteristics of the items you are currently wearing in less that 60 rows of code. :)
Intended to be used with Python 3.x
""" This small script will calculate the summ of the suite your char is currentrly wearing.
This will only run in Python 3.x"""
import stealth
import re
uo_layers = (ArmsLayer(), BeardLayer(), BraceLayer(), CloakLayer(), EarLayer(), EggsLayer(), GlovesLayer(), HairLayer(), HatLayer(), LegsLayer(),
LhandLayer(), NeckLayer(), PantsLayer(), RhandLayer(), RingLayer(), RobeLayer(), ShirtLayer(), ShoesLayer(), TalismanLayer(), TorsoHLayer(),
TorsoLayer(), WaistLayer())
properties = {}
def to_sum_up(prop : 'string') -> 'Boolean':
""" This sub will be used to get rid of unwanted properties like 'Insured' or such.
As argument it is expecting a string and it will retur either True (if the property should not be ignored) or False"""
# strigs to be ignored in tooltip. Add new if missing
ignores = ['Insured', 'durability', 'Weight', 'artifact rarity', 'strength requirement', 'two-handed weapon', 'skill required']
for ignore in ignores:
if prop.find(ignore) != -1 or prop == '':
break
else:
return True
return False
def sum_props(dressed_layers : 'dict') -> 'dict':
""" This sub will sum all the properties together.
As argument it is expeting a dictionary in this format {layer:[raw properties,]}
It is returning another dictionary with this format {prop name : total value}"""
totals = {}
# Property regex
reProps = re.compile(r"([a-zA-Z ].+?)[+]{0,}([\d]{1,})(%{0,1})")
for layer in dressed_layers:
if dressed_layers[layer]:
item = dressed_layers[layer][0]
props = dressed_layers[layer][1:]
for prop in props:
match = reProps.search(prop)
if match:
prop_name = match.group(1).strip()
prop_value = match.group(2)
totals[prop_name] = totals.get(prop_name, 0) + int(prop_value)
return totals
for uo_layer in uo_layers:
weared = ObjAtLayer(uo_layer)
if weared > 0:
properties[hex(uo_layer)] = [] + [x.strip() for x in GetTooltip(weared).split(' | ') if to_sum_up(x)]
totals = sum_props(properties)
for prop in sorted(totals.keys(), key=str.lower):
print(prop + ' --> ' + str(totals[prop]))
-
Ooooh, nice. (boy Python makes my head hurt.....) heh
-
Yes, i understand the feeling; my first times at Python were like: "WTF!" :P
Then I hacked with it here and there and eventually read Learning Python (http://www.amazon.com/Learning-Python-Powerful-Object-Oriented-Programming/dp/0596158068/ref=sr_1_1?s=books&ie=UTF8&qid=1345242686&sr=1-1&keywords=learning+python) and now I believe that all scripting interfaces should be made in Python. ;)
How many lines would it take to make a suite totalizer in EUO? This is why Python is cool in my opinion...
-
How many lines would it take to make a suite totalizer in EUO? This is why Python is cool in my opinion...
http://www.scriptuo.com/index.php?topic=15.msg15#msg15
Exactly 993 in EUO. ;)
And I highly recommend that book too. It's how I learned as well. I'll try and find the other couple references I used since they were also pretty good.
-
Turns out I have a bunch of Python books, but the one I seem to always come back to for reference is:
Python in a Nutshell (http://www.amazon.com/Python-Nutshell-Second-Alex-Martelli/dp/0596100469/ref=sr_1_1?s=books&ie=UTF8&qid=1345313473&sr=1-1&keywords=python+in+a+nutshell)
Others include:
Programming Python (http://www.amazon.com/Programming-Python-Mark-Lutz/dp/0596009259/ref=sr_1_2?ie=UTF8&qid=1345313561&sr=8-2&keywords=programming+python)
and
Dive into Python (http://www.amazon.com/Dive-Into-Python-Publisher-Apress/dp/B004TBN2Z6/ref=sr_1_11?s=books&ie=UTF8&qid=1345313629&sr=1-11&keywords=dive+into+python)
-
Your script also has a menu, mine just prints out to the console. Yet I belive that with tkinter it would take much more less than 993 lines. ;)
Programming Python is the one I'm currently on. :)
-
Good Job boydon,
even when i hate Python :)
-
Hey Boydon, how far have you taken the GUI investigation within Python? Are you experimenting with that at all?
-
I didn't go so far in the end. I hacked a bit with both Wx and PyQt, but I'm uncertain 'bout what to do.
Wx would be my favorite choice cause i prefer it over PyQt, but the problem is that right now it is only available for Python 2.x. and I strongly believe that 3.x is the future. Probably both of them are too much overhead and the standard tkinter is all you need for simple graphic interfaces (think back to what you are used in EUO... Tkinter has all of it and more!).
My main problem is that I'm not very well confident with threads in Python and if you want GUIs you need them! GUI should use the main thread and script logic should run in a separate one in most of the cases. :)
-