Skip to content

Miscellaneous Features

Amp63 edited this page Dec 22, 2025 · 2 revisions

Importing from Code

You can import existing templates from their built code using the from_code method:

from dfpyre import *

template_code = 'H4sIAGVyIGYC/3WOMQ7CMAxFz4LnDsw5AhITI6qQSaw2IrGrxkJCVe5eh3boAJP9n/Kfs8AziX8VcPcFYgC3Zej26YDexGoZvUZhAxeJ3PI8WMtKSrnV+1q7P4op4Yfmx244qG7E4Uql4EA/jNv2Jc3qJU/2KqBiY4yZjI6UkpzAjkNJouDO1X7S1xUDaGUl2QAAAA=='
t = DFTemplate.from_code(template_code)
# Do stuff with the template here

Script Generation

You can generate an equivalent Python script for a template from a template object:

from dfpyre import *

template_code = 'H4sIAGVyIGYC/3WOMQ7CMAxFz4LnDsw5AhITI6qQSaw2IrGrxkJCVe5eh3boAJP9n/Kfs8AziX8VcPcFYgC3Zej26YDexGoZvUZhAxeJ3PI8WMtKSrnV+1q7P4op4Yfmx244qG7E4Uql4EA/jNv2Jc3qJU/2KqBiY4yZjI6UkpzAjkNJouDO1X7S1xUDaGUl2QAAAA=='
t = DFTemplate.from_code(template_code)

# Generated python script will be written to 'my_template.py'
with open('my_template.py', 'w') as f:
    script = t.generate_script()
    f.write(script)

Inserting Codeblocks

Use the insert method to insert additional codeblocks into an existing template. By default, codeblocks will be added to the end of the template.

from dfpyre import *

my_template = PlayerEvent.Join([
    PlayerAction.SendMessage('%default has joined!', target=Target.ALL_PLAYERS)
])
my_template.insert(PlayerAction.SendMessage('Welcome!'))  # Adds a new codeblock to the end of the template