Page 1 of 1

ultra simple py-mod tutorial

Posted: Wed Jul 10, 2013 1:31 pm
by cieply
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/
normally I would have to bakcup Lib/ -> Lib/ and edit Lib/ 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/ 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

Re: ultra simple py-mod tutorial

Posted: Wed Jul 10, 2013 11:20 pm
by prospero
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 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, 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 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:

Posted: Thu Jul 11, 2013 12:19 pm
by cieply
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

Re: ultra simple py-mod tutorial

Posted: Thu Jul 11, 2013 12:33 pm
by cieply
> 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/

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

is it possible?

Re: ultra simple py-mod tutorial

Posted: Thu Jul 11, 2013 8:03 pm
by prospero
When you want to do things like this you first have to unravel the methods.

In the special damage funcs are contained in a dictionary:

Code: Select all

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 file of any map you wanted it to work in.

Re: ultra simple py-mod tutorial

Posted: Fri Jul 12, 2013 1:48 pm
by cieply
... complicated

so, how actually BODLoader executes scripts?
can I set execution of function1() in after function1() from Lib/ (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)

Re: ultra simple py-mod tutorial

Posted: Fri Jul 12, 2013 3:53 pm
by prospero
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 by adding a line of code such as

Code: Select all

    import MyNewFile
The try clause will prevent the game stalling if the does not exist. 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:

Re: ultra simple py-mod tutorial

Posted: Mon Jul 15, 2013 2:39 pm
by cieply
i'll try it and see what it is able to.