Would you like to react to this message? Create an account in a few clicks or log in to continue.

Official Community Forums
 
HomeHome  SearchSearch  Latest imagesLatest images  RegisterRegister  Log in  The Wiki  Website  github Project  

 

 Putting Templates into different Files and different folders

Go down 
4 posters
AuthorMessage
RoH_JamesProctor
Foundation Developer
RoH_JamesProctor


Posts : 7
Join date : 2012-01-05

Putting Templates into different Files and different folders Empty
PostSubject: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptySat 14 Jan - 0:37

Ok so I was looking at my Config files for Sample World last night. Having ALL of your templates in a single file is just NOT going to be doable! It's going to get very unmanageable very quickly. I attempted to create a Folder called templates right there in the Config folder. In that folder I added a __init__.py file and then added a templates.py file. In that file I created a class called TestTemplates and then from the TemplateHook class I created a new instance of the TestTemplates class which should have created all the templates. However when I start the server and enter the world none of the mobs or NPCs are showing up which tells me the templates were not created.

Any help or suggestions on this would be great!
Back to top Go down
RoH_JamesProctor
Foundation Developer
RoH_JamesProctor


Posts : 7
Join date : 2012-01-05

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptySat 14 Jan - 3:35

I have found a solution to this issue!

You are able to register different Activate Hooks from with in your Obj_Manager script located in your Common config folder.

objectManager.registerActivateHook(TemplateHook())
objectManager.registerActivateHook(ItemTemplateHook())

Then create a folder in your world's config folder where you will keep all of your template scripts.

Create a new Script (Name of the script doesn't matter).

And then in that new script create a class named whatever you registered so in my case ItemTemplateHook():

Code:

from multiverse.mars import *
from multiverse.mars.objects import *
from multiverse.mars.core import *
from multiverse.mars.events import *
from multiverse.mars.util import *
from multiverse.mars.plugins import *
from multiverse.server.plugins import *
from multiverse.server.math import *
from multiverse.server.events import *
from multiverse.server.objects import *
from multiverse.server.engine import *
from java.lang import *

True=1
False=0


class ItemTemplateHook(EnginePlugin.PluginActivateHook):
    def activate(self):
       
        #
        # Item Templates
        #
        item = Template("Wolf Skin")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
                "Interface\Icons\INV_hide_basic-pelt")
        ObjectManagerClient.registerTemplate(item)
       
        item = Template("Wolf Bones")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
                "Interface\Icons\INV_mined_ironore")
        ObjectManagerClient.registerTemplate(item)
       
        item = Template("Healing Potion")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
                "Interface\FantasyWorldIcons\ITEM_potion_A")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ACTIVATE_HOOK,
                AbilityActivateHook("heal potion"))
        ObjectManagerClient.registerTemplate(item)
       
        item = Template("Mana Potion")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
                "Interface\FantasyWorldIcons\ITEM_potion_A")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ACTIVATE_HOOK,
                AbilityActivateHook("restore mana potion"))
        ObjectManagerClient.registerTemplate(item)
       
        item = Template("Tome of Heal")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
                "Interface\FantasyWorldIcons\ITEM_book_C")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ACTIVATE_HOOK,
                AbilityActivateHook("teach self heal ability"))
        ObjectManagerClient.registerTemplate(item)
       
        item = Template("Tome of Fireball")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ICON,
                "Interface\FantasyWorldIcons\ITEM_book_A")
        item.put(InventoryClient.ITEM_NAMESPACE, InventoryClient.TEMPL_ACTIVATE_HOOK,
                AbilityActivateHook("teach self fireball ability"))
        ObjectManagerClient.registerTemplate(item)

Then you edit your batch file and include your new script so that it gets run:

Code:

echo Starting object manager
START /B java ^
    %JAVA_FLAGS% ^
    -Dmultiverse.loggername=objmgr ^
    multiverse.server.marshalling.Trampoline ^
    multiverse.server.engine.Engine ^
    -i wmgr_local1.py ^
    -i %MV_COMMON%\mvmessages.py ^
    -i %MV_WORLD%\worldmessages.py ^
    -m %MV_COMMON%\mvmarshallers.txt ^
    -m %MV_WORLD%\worldmarshallers.txt ^
    %MV_COMMON%\global_props.py ^
    %MV_WORLD%\global_props.py ^
    [b]%MV_WORLD%\scripts\StarterTemplates.py ^
    %MV_WORLD%\scripts\ItemTemplates.py ^[/b]
    %MV_COMMON%\obj_manager.py ^
    %MV_WORLD%\mobs_db.py ^
    %MV_WORLD%\items_db.py ^
    %MV_WORLD%\extensions_objmgr.py
Back to top Go down
Tristan
Administrator
Administrator
Tristan


Posts : 306
Join date : 2011-08-03
Location : Liverpool, UK

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptySat 14 Jan - 8:17

Congrats on finding the solution Jim!

At some point, we'll probably put this on the Wiki, so thanks for the fix.
Back to top Go down
http://www.3dmodeller.info
Delurin
Head of Platform Development
avatar


Posts : 424
Join date : 2011-08-03

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptySun 15 Jan - 10:29

Just as a warning you can not exceed 65535 bytes or around there for each template file.
Back to top Go down
awaredev
Experienced Newbie
Experienced Newbie
awaredev


Posts : 32
Join date : 2012-06-29
Location : Halifax, NS, Canada

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptyThu 5 Jul - 3:34

Hi folks-

Good to know we can split up the templates.

Also- Can the templates be registered using JAVA instead of Python, or is template registration done only via script?
Back to top Go down
Delurin
Head of Platform Development
avatar


Posts : 424
Join date : 2011-08-03

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptyFri 6 Jul - 3:43

there is no reason why they cant be registered in java but then you have to recompile the jar file every time you want to make a change in a quest which would probably be annoying.
Back to top Go down
awaredev
Experienced Newbie
Experienced Newbie
awaredev


Posts : 32
Join date : 2012-06-29
Location : Halifax, NS, Canada

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptyFri 6 Jul - 3:58

Thanks for the reply Smile

I'm actually looking at creating methods to register items, mobs, etc. from custom database tables rather than scripting or coding every template.

Am I correct in saying that Templates are registered only at the engine start? You can't dynamically register a new template while the server is running?

Thanks
Back to top Go down
Delurin
Head of Platform Development
avatar


Posts : 424
Join date : 2011-08-03

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptyFri 6 Jul - 4:13

As it currently stands there is not a way to add templates. But you could probably add a command to add new templates or a function that checks every once in awhile for new templates. If you do allow for template changes without restarting you probably will want to have a way to designate that a given template has changed: for example if you change the template on a sword you will need to update all of the characters with that change. It is even more important if you are doing mobs and quests so that a player who started a quest will not get stuck with aversion of a quest that cannot be completed.
Back to top Go down
awaredev
Experienced Newbie
Experienced Newbie
awaredev


Posts : 32
Join date : 2012-06-29
Location : Halifax, NS, Canada

Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders EmptyFri 6 Jul - 4:17

Ahh, yes. That makes sense, as the templates are registered via code. Adding new ones would be easy.

However, I see what you mean that there would need to be a system in place that checks any instance of the template currently active in-game.

It is really rather impressive that this can be done, as it would allow for a lot of dynamic game mechanics.

Thanks Again
Back to top Go down
Sponsored content





Putting Templates into different Files and different folders Empty
PostSubject: Re: Putting Templates into different Files and different folders   Putting Templates into different Files and different folders Empty

Back to top Go down
 
Putting Templates into different Files and different folders
Back to top 
Page 1 of 1
 Similar topics
-
» Noob Question: about accessing templates.py NAMESPACE variables from MarsContainer
» Server STARTUP FAILED >>> SOLVED
» STARTUP FAILED -- didnt complete after 120 seconds.
» Unable to run client
» Fantasy World Asset Repository files missing

Permissions in this forum:You cannot reply to topics in this forum
 :: Development :: Server Scripting and Development-
Jump to: