- Joined
- Jun 18, 2004
- Messages
- 119
Hello guys,
I've made a project for programming WC3 in Python located here:
Blimba/PyWC3
It translates user python code to lua, and includes it into the map. A summary of features includes:
Or, just use the even easier ITimer class:
Some more features:
Subclasses for units that have event functions that run on specific events.
I'm not planning on added each and every possible PlayerUnitEvent, so instead, you can add one yourself easily by following this example:
Object editing from the python code. Here's an example of how to add a modified "Channel" ability to a footman using a json formatted table:
It is still in early development, but please let me know if you are interested, or if you are having any issues using it!
Cheers,
inf
I've made a project for programming WC3 in Python located here:
Blimba/PyWC3
It translates user python code to lua, and includes it into the map. A summary of features includes:
- Preprocessing scripts (can be used for script based preplacing of doodads!)
- Object editing in python source code
- Code Completion & Syntax highlighting of your favourite IDE
- Support for maps as "folders" as well as "mpq"
- Quick maptesting through command line interface
- Expanding list of modules in the standard library (I welcome people to develop missing modules by pull requests!)
Python:
from std.index import *
from std.timer import Timer
def timeout():
t = Timer.get_expired()
print(t.data,t.data2)
t.destroy()
def test():
t = Timer(periodic=False)
t.data = 5
t.data2 = 3
t.start(1.0,timeout)
AddScriptHook(test,MAIN_AFTER)
Or, just use the even easier ITimer class:
Python:
"""
This small addition to the Timer class makes life a lot easier. Instead of having to track timer handles for simple
tasks, this scripts handles everything automatically, and passes whichever data you give the start function.
For example:
def timeout_function(timervar, data1, data2):
print(data1,data2)
ITimer.start(3.0, timeout_function, "hello", "from ITimer")
This script would print 'hello from ITimer' after 3 seconds. Please note how we do not require to destroy the timer
manually.
"""
from ..std.timer import *
class ITimer():
@staticmethod
def _timeout():
t = Timer.get_expired()
try: t._callback(t,*t._args)
except: print(Error)
t.destroy()
@staticmethod
def start(time,callback,*args):
t = Timer()
t._callback = callback
t._args = args
t.start(time,ITimer._timeout)
Some more features:
Subclasses for units that have event functions that run on specific events.
Python:
class MyUnit(Unit):
def on_death(self):
print(self.name,'dying')
def on_damaging(self,target):
print(self.name,'damaging',target.name)
def on_damaged(self,source):
print(self.name,'damaged by',source.name)
Python:
class MyUnit(Unit):
def on_attacked(self,attacker):
print(self.name,'attacked by',attacker.name)
# the following code will make the event available for ALL Units (note: only if they have been wrapped in the python wrapper!), as long as they have the on_attacked method, so only call it once!
PlayerUnitEvent(EVENT_PLAYER_UNIT_ATTACKED, "on_attacked", Unit.get_trigger, Unit.get_attacker)
Object editing from the python code. Here's an example of how to add a modified "Channel" ability to a footman using a json formatted table:
Python:
"""ObjEditor
{
"unit": {
"hfoo": {
"uabi": "A000"
}
},
"ability": {
"ANcl>A000": {
"aher": {
"value": 0,
"level": 0,
"pointer": 0
},
"Ncl3": {
"value": 1,
"level": 1,
"pointer": 3
}
}
}
}
"""
It is still in early development, but please let me know if you are interested, or if you are having any issues using it!
Cheers,
inf
Last edited: