游戏精英
 
- 贡献度
- 382
- 金元
- 47605
- 积分
- 6289
- 精华
- 0
- 注册时间
- 2009-2-25
|
Custom Player Items In Single Player
随便转的,有兴趣就看看吧
http://social.bioware.com/5339/blog/576/
来自官网社区
So here is a short, step by step showing how to create and add custom items to the player character in the single player campaign using the Dragon Age Toolset. I will go through the creation of my test addon, hopefully this will serve as a helpful starting point for others.
Creating a new module
First of all, we have to create a new modul in the Toolset that we can later load from the game:
Click File -> Manage Modules, create a New... module and watch the Object Inspector pop up
In the Name field, type in the desired name of your module: "Might of The Queen" (without quotes)
In the UID field, put in the identifier of your module, in my case "mdu_velvet"
From the Extended Module dropdown, select Single Player, since we want to add extended content to the Single Player campaign.
Click OK and close this window.
Open the module.
- Go back to the Manage Modules window. Select our new module, click Hierarchy..., put a tick next to Single Player. Then click OK.
It is important that in step 3) you use an identifier that no other module uses. This is the name you will refer to your modul later on in the toolset. Also notice the value in the Script field, module_core. This will be important later on.
Adding our custom item to the modul
Once we have created our modul, we can start adding items to it. Look for the Palette Window. If you can not find it, you can open it through View -> Palette.
Click on the small sword icon representing the items.
Right click anywhere on the tree view and select New -> Item. The Create New Resource pop up should pop up 
In the Resource name window, type in an identifier for your item. I used "wep_mel_gsw_velvet" representing a melee greatsword weapon for my character, Velvet.
Because we want to create an item that can be used by the player later on, we have to make sure that it is part of the core game resources; from the Module dropdown, select Core Game Resources.
The Owner Modul should be the name of our module, in my case: Might of Queen Velvet.
- We are done here, click OK, close this window and see the magic happen.
If everything went according the plan ( and why should it not... ) you should stare at the properties window of our newly created item. Let us go through the more important fields on this list and create a nice Greatsword.
Base Item Type: This field defines the type of the item we will have. We want a greatsword, from the dropdown menu select Weapon - Greatsword.
Description: You can set here the in game description of the item you can see whenever you inspect it. For example: "Fabled Greatsword of Warden Commander Velvet"
Icon: Click on ... to open up a file open dialog and look for a nice icon for your item. I used ico_greatsword.dds. (All icons start with ico_ prefix!
Inventory Subgroup: Set this to 204000. I will be honest, I am not exactly sure what this number represents, but this is what other greatswords use in the game. I will throw an assumption on the table here, it probably means that it should show up in the weapon inventory tab in the game.
Item Variation: In this dropdown you can select from the available variations of the models used for greatswords. I picked Greatsword 4, that looked the most fitting to a Queen! 
MaterialProgression & Material Type: These define the quality (tiers) of your items. Tier 7 is Dragonbone, Tier 6 would be Silverite. The rest is up to you to figure out! I choose Weapon, Dragonbone.
Name: This is the actual name you will see in game, like "Might of The Queen".
Tag: This field will be used later on to refer to our item. I use the exact same thing I used for the resource name which can be found in the field just above this one: "wep_mel_gsw_velvet".
Cost: This is the price of the item in copper. 100 is one silver, etc
Item Properties: This is where you can add different special attributes to your items.
- OnHit Effect & OnHit Power: Similarly to the previous, they are used to add another special ability to your weapon that is used when you hit with the sword. For example, +10 extra damage vs. darkspawn.
If you want to know more about material types and how they affect the outcome of your item, or simply want to be able to calculate the item stats without loading your mod in game, look no further: The Secret Behind Item Statistics
All right! We are done setting up our sword. We won't have to touch this anymore. On the palette window, right click on your item and select check in. This will load it into the database.
Adding the item to the player's inventory
Now comes the hard part. Even though we have an item in our module, we have to tell the game to give it to our player somehow. This is where scripts come into play. From the Palette Window, select the little file icon with the horizontal lines in it.
Just like previously, create a new script resource.
Resource Name: The identifier of out script, I called it "velvet_additemonload".
Module & Owner Module: Make sure that this time, both of them point at the name of your module, or in my case "Might of Queen Velvet".
- Click OK and wait for the script editor to pop up.
Now if you paid attention in the beginning, we noticed that the module uses the module_core script by default. This seems to point at the default script that will get called whenever the module receives an event.
We have to to back and change this to our script so when some events are passed to our addon, we can run the neccessary instructions and add the sword to our players inventory.
Open File -> Manage Modules
Select our module, in my case "Might of Queen Velvet". and click on Properties...
Look for the Script field and change it to our script identifier, "velvet_additemonload"
- Click OK.
All what's left is writing the script itself. The programming language that the Dragon Age Toolset uses is C++, not the easiest language to start with for beginners. Here is the actual script with some comments inside. You can copy paste this into your toolset if you wish:

// ---------- Script Starts Here ----------
// Includes for utility functions and event definitons
#include "utility_h"
#include "wrappers_h"
#include "events_h"
void main()
{
// We need to retrieve the event that called our script
// and only act if it is the one we are waiting for
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
// We also need the object representing the player's main character.
object oPC = GetHero();
// We use the VELVET_GS_GIVEN variable to check whether we already run the
// script in this play session and gave the sword to the player!
// This is an arbitrary variable name chosen by me, you could
// chose something else if you wished so.
int nDoOnce = GetLocalInt(OBJECT_SELF, "VELVET_GS_GIVEN");
// If we have not run the script yet:
if ( nDoOnce != 1 )
{
// We look for the even that we need
switch(nEventType)
{
// If our modul just loaded - which happenessomewhere during
// the loading of a savegame or resuming an old game -
// we add the sword to the player during the loading screen
case EVENT_TYPE_MODULE_LOAD:
{
// First we make sure that we don't have the item yet
// fro manother gameplay session!
int nHas = CountItemsByTag(oPC, "wep_mel_gsw_velvet");
// If we do not, then we add it to the inventory
if ( nHas == 0 )
UT_AddItemToInventory(R"wep_mel_gsw_velvet.uti");
break;
}
}
// We update our VELVET_GS_GIVEN variable to signal that the script
// finished properly and does not have to run again during this session.
SetLocalInt(OBJECT_SELF,"VELVET_GS_GIVEN", 1);
}
// Once we are done with all our stuff, we pass the stuff back to the
// original script, so it can deal with the rest of the core functions.
// FIX: Commented out the HandleEvent line. It seems that this refers to
// this script itself - not the module script of the single player // campaign - causing issues with doubling stuff later on.
// HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE);
}
// ---------- Script Ends Here ----------
After this is done, you can check this in too. We are almost done. The only thing that's left is exporting our module into Dragon Age: Origins.
Find your item you created earlier in the palette tool (switch to items using the sword) and right click on it.
From the popup menu select Export->Export without dependent resources. We can do this because we only used resources that were already part of the core package.
Repeat the above two steppes for our script too.
- After this, from the toolbar, Tools->Export->Generate Module XML & Generate Module Manifest.
At this point, if you boot up Dragon Age: Origins, you should see your modules in the downloadable content section and upon starting the game, 'Might of The Queen' should show up in your inventory.
If you want to distribute your module among other people, it might worth to build a package from it. You can do this very easily:
From the toolbar, Tools->Builder->Builder To Player Package. It will ask for your manufest file. In this example, it should be at: DocumentsBioWareDragon AgeAddInsmdu_velvetmoduleoverride
After this a huge window opens with a tree view. You can untick the whole section starting from packages. All we need is the mdu_velvet tree and everything under it.
Click OK and save your very first Dragon Age: Origins Package file.
- Drink a beer and celebrate!
You can also download the finished addon and take a look at it yourself.
PLEASE USE THIS DISCUSSION BOARD FOR ANY KIND OF QUESTIONS IN REGARDS TO THE ADDON, the blog comment section is not too good to keep the conversation organized. Thanks! |
|