User Tools

Site Tools


change_scripts

Change already existing Wolfpack scripts without touching standard scripts

I guess you always want to keep updated to Wolfpack script changes (due to bugfixes etc.), but also implement your own changes in standard scripts. So if you edit the standard scripts, there'll be probably an problem everytime you try to update your scripts by using SVN. And to implement these updates in your heavily costumized scripts by hand is always difficult and takes much time.

I'll try to show you this on an example.
Let's examine you have a vampire race. This race should not be able to eat normal food. So what would you do? Of course, open your food.py script and implement your code in the onUse function. This would work of course, but as mentioned this could lead to errors when updating your scripts (or you could lose your changes when overwriting this file). There's a better way to do this.

First step: Creating needed directory and files

Create a new directory in the Wolfpack root, e.g. “myownscripts”. In this new directory, create a file named “preload.xml”. This file will include all scripts we load before the standard Wolfpack scripts. In your “preload.xml” write the following:

<definitions>
    <script>myownscripts.overrides</script>
</definition>

Now we need a file named “overrides.py”, also in our “myownscripts” directory. This is our python script, where we will implement our changes done in already existing standard Wolfpack scripts. (NOTE: You will also need an “init.py” file in order to run your scripts successfully (can be empty).)

Second step: Load our new files

Now that we have our scripts created (still without function), we need to implement the “overrides” script, so Wolfpack can read it. Script changes (which we want to implement in our “overrides.py”) must be loaded before the standard Wolfpack scripts. In order to reach this, you must edit your “wolfpack.xml”. Search for the option key “Definitions”. You must add your “preload.xml” before the standard “index.xml”. So this line should look like that:

<option key="Definitions" value="myownscripts/preload.xml;definitions/index.xml />

Well done, your server should start now without any error. But we have nothing changed yet.

Third step: Our changes

Now the changes. We want to reach, that players with the tag “race” and the tagvalue “vampire” can't eat normal food. Open your “overrides.py” and implement the following code:

#!python
import food
org_onUsefood = food.onUse
def food_onUse(char, item): # This is our new function which will be called instead of food.onUse
    if char.gettag('race') == 'vampire':
        char.socket.sysmessage( "You cannot eat this." )
        return True
    return org_onUsefood(char, item) # return the standard function (we are no vampire, so we can eat normally)
food.onUse = food_onUse # standard onUse function is overwritten by our new one

This works and you didn't touch the Wolfpack scripts. That's all. Sounds easy, doesn't it?

Summary:
If you want to change functions, the script including your new functions which overwrites the existing one must be loaded before the Wolfpack scripts. You can implement all your changes in “overrides.py”, but in my opinion it would be difficult to differentiate all your changes. You can easily create more “override” scripts, but don't forget to include them in your “preload.xml”

Note:
There often need to be functions changed in the Wolfpack scripts in order to implement your own changes (e.g. your change would be simple, but the function is very long). So don't be shy to contact a developer (forum, e-mail) who can split a function into two, so you can implement your changes easily. Don't forget to tell him what you want to change, so he knows what he has to do!

change_scripts.txt · Last modified: 2014/03/04 19:30 by thooge

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki