ultra simple py-mod tutorial

Talk about Severance Blade of Darkness modifications and maps here. No tips or tech support questions please, use the forum above. Note that the game is rated 18 so some content may be unsuitable for younger readers.

Moderators: Ade, prospero

User avatar
cieply
Dragon
Posts: 326
Joined: Wed Jun 26, 2013 3:43 pm

ultra simple py-mod tutorial

Postby cieply » Wed Jul 10, 2013 1:31 pm

I'm looking for some ultra simple mod-tutorial that would tell how to alter in game functions with your own without changing original files
is there anything like that?
I've found many map tutorials on a net and in forum as well but I need the simplest possible mod tutorial, like for example:

I want change some in game function like InflictFireDamage(...) from Lib/Damage.py
normally I would have to bakcup Lib/Damage.py -> Lib/Damage.py.orig and edit Lib/Damage.py to alter function behaviour, then run a game with new file and see it works

but wouldn't it be better to make a mod that loads let's say InflictFireDamage(...) from $BOD/BODLoader/Mods/myMod1/myDamage.py that "overwrites" original InflictFireDamage() function and can be easily enabled/disabled from bodlader menu, depending whether I want to use it?!

that would be great
thanks in advance for answer
l'aria fresca,
vino puro, ...

User avatar
prospero
Ancient Dragon
Posts: 1725
Joined: Wed Nov 21, 2001 1:42 am
Location: United Kingdom

Re: ultra simple py-mod tutorial

Postby prospero » Wed Jul 10, 2013 11:20 pm

If you are just editing for you own use there is no reason not to edit the source files. Much easier than making a mod. As long as you have a backup of the original file so you can 'restore to default' at any time.

You can overwrite almost any game attribute from within a custom map without editing a source file. The changes will only apply while the map is running. Not so easy on orig RAS maps. Can be done, but very complicated. To be brief, you would need a line of code within the map you are running to execute some code within your mod. This means adding code to all maps you want the mod code to run in thus editing source files. Even if you put in fail safes clauses to catch exceptions it's still a clunky method. i did this once with an 'All Combos' mods and I think I replaced BladeInit.py with a modded version so as to execute the code without having to do all the maps. You have to be careful though and make it so the code won't cause exceptions.

There is a very good reason why mods should alter source files as a very last resort. While it is true that the BODLoader will restore replaced files in the Uninstall routine, the danger comes when you use this on more than one mod at a time. So you install one mods which overwrites say, Reference.py. Fine. But then you install another that does the same. The second mod will store a backup of not the orig file but the version that the first mod installed. Can of worms. :shock:

e.g. Someone installs my All Combos mod. All will work well until you install another mod that also replaces BladeInit.py. Nothing bad will happen except the All Combos mod will be disabled. Uninstall/Install All Combos will bring it back, but will disable the new mod. You can't use them both at the same time in other words.
See what I mean about complicated? :wink:

But as I say, edit away if it's just for your own devices. :mrgreen:

User avatar
cieply
Dragon
Posts: 326
Joined: Wed Jun 26, 2013 3:43 pm

Postby cieply » Thu Jul 11, 2013 12:19 pm

quick question loosely related (but related)
how can I dump console to the file? I have started making experience label and added few lines of code and game crashes (explodes, almost literally) - starts to load and disappears; I ran with ``-console'' but it haven't helped - console disappears as well
l'aria fresca,
vino puro, ...

User avatar
cieply
Dragon
Posts: 326
Joined: Wed Jun 26, 2013 3:43 pm

Re: ultra simple py-mod tutorial

Postby cieply » Thu Jul 11, 2013 12:33 pm

> See what I mean about complicated?
yeah. course of thinking s complicated enough apart from content itself


is there a way to do this:
$ cd Blade/BODLoader/Mods
$ ls myMod/
BladeInit.py
BLModInfo.py
myDamage.py

and in myDamage.py there is only InflictFireDamage() modified and works differently until I use ``myMod''
if python loads original modules first then InflictFireDamage() from myDamage.py would be loaded twice and second one would "overwrite" (in compiler of course, not in real file) first one.

is it possible?
l'aria fresca,
vino puro, ...

User avatar
prospero
Ancient Dragon
Posts: 1725
Joined: Wed Nov 21, 2001 1:42 am
Location: United Kingdom

Re: ultra simple py-mod tutorial

Postby prospero » Thu Jul 11, 2013 8:03 pm

When you want to do things like this you first have to unravel the methods.

In Damage.py the special damage funcs are contained in a dictionary:

Code: Select all

SpecialDamageFuncs={} SpecialDamageFuncs['Fire'] = InflictFireDamage SpecialDamageFuncs['Ice'] = InflictIceDamage SpecialDamageFuncs['Venom'] = InflictVenomDamage SpecialDamageFuncs['Drain'] = InflictDrainDamage SpecialDamageFuncs['Electric']= InflictElectricDamage SpecialDamageFuncs['Light'] = InflictLightDamage
So all you need do is divert the one you want to read your function:

Code: Select all

def MyNewInflictFireDamage(long, list, of, parameters): #new code........etc import Damage Damage.SpecialDamageFuncs['Fire'] = MyNewInflictFireDamage
You would have to put this code in the DefFuncs.py file of any map you wanted it to work in.

User avatar
cieply
Dragon
Posts: 326
Joined: Wed Jun 26, 2013 3:43 pm

Re: ultra simple py-mod tutorial

Postby cieply » Fri Jul 12, 2013 1:48 pm

... complicated

so, how actually BODLoader executes scripts?
can I set execution of function1() in myMod.py after function1() from Lib/Scorer.py (function1() is example function name) so game will execute mu code not original? and not cause "multiple definition" (don't know python that well although i'm learning)
l'aria fresca,
vino puro, ...

User avatar
prospero
Ancient Dragon
Posts: 1725
Joined: Wed Nov 21, 2001 1:42 am
Location: United Kingdom

Re: ultra simple py-mod tutorial

Postby prospero » Fri Jul 12, 2013 3:53 pm

The BODLoader will not execute external scripts. All it does is provide a user-friendly interface on top of the existing menu so custom maps/mods can be loaded. previously the only way to launch custom maps was a console command. Bladex.LoadLevel("MapName").

What you can do is initialise files from BladeInit.py by adding a line of code such as

Code: Select all

try: import MyNewFile except: pass
The try clause will prevent the game stalling if the MyNewFile.py does not exist. MyNewFile.py needs to be in either Scripts or Lib folder so as to be in the interpreter's scope. The tricky bit is putting it in the right place in the load sequence. This can be critical and depends on the nature of the new code you are trying to introduce.

Personally, I would avoid tinkering with the Scorer stuff thi way. I think I tried that once and couldn't find a way to make it work. :cry:

User avatar
cieply
Dragon
Posts: 326
Joined: Wed Jun 26, 2013 3:43 pm

Re: ultra simple py-mod tutorial

Postby cieply » Mon Jul 15, 2013 2:39 pm

i'll try it and see what it is able to.
l'aria fresca,
vino puro, ...


Return to “Severance BoD: Modding Community”

Who is online

Users browsing this forum: No registered users and 2 guests