First, read this:
http://social.biowar...ipting_tutorialDragon Age handles most in-game interaction through scripting, and in fact just about everything in the game uses scripts, making the game extremely moddable for those who actually know what they're doing. Scripts can be linked to each other by using the #include declaration at the top of a script. This means that you will gain access to everything in a given script when you include it. You will need to include both your own scripts and BioWare's core scripts quite often to get a script to do what you want.
Events are one of the most fundamental things to learn, and are created by the engine and sent to individual objects. For example, a script assigned to an area will intercept area-related events - by default, this handles all the game functionality. What you need to do to create custom content is intercept events and then write functions that perform various actions.
An easy example is checking if enemies are killed in an area. Let's take this:
#include "events_h"
#include "plt_clear_The_hut"
#include "wrappers_h"
void main()
{
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
switch(nEventType)
{
case EVENT_TYPE_TEAM_DESTROYED:
{
if(GetEventInteger(ev,0) == 1)
{
WR_SetPlotFlag(PLT_CLEAR_THE_HUT, MONSTERS_SLAIN, TRUE);
}
break;
}
}
HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);
}
This is directly from the DA Builder Wiki.
The three #includes at the top tell the game to include the events_h and wrappers_h scripts (containing more constants, functions, etc.) and plt_clear_The_hut is a plot file, where the plot flag names are used as constants, allowing you to update them in a script rather than a conversation.
void main() is C syntax which says that a function does not want to receive any arguments from any other outside script (additional info, like specific variables). This is what you will use most often, except for plot scripts, where you will want to use void StartingConditional() instead. In C and C++, there are a lot more things you can do (see
http://faq.cprogramm...swer=1044841143) but for Toolset scripting purposes, it'll be one of these two in most cases. Just remember, when in doubt, look at BioWare's own scripts to see how they did something.
switch(nEventType) runs through all events intercepted - the nEventType, as you can see in the variable declarations above, gets the event type for the current event.
case EVENT_TYPE_TEAM_DESTROYED checks specifically for the team destroyed event, which is sent by the engine to the current area script every time a team is killed (creatures, in 99% of cases, but theoretically it can work for placeables too).
if(GetEventInteger(ev,0) == 1) is an if statement checking to see whether the relevant plot flag is being updated properly - in this case, we're checking if it's 1 and only executing then (so if the plot flag is set to 0, it won't trigger the same code). Usually this check isn't really necessary and is just done for safety's sake.
WR_SetPlotFlag(PLT_CLEAR_THE_HUT, MONSTERS_SLAIN, TRUE); is a function included in wrappers_h, and lets you update a given plot flag to true or false. Note that you can also add another true or false at the end to call the script associated with that plot (so if you want, say, an NPC to talk to the player after the player kills some enemies, you can handle that in the plot script rather than the area script).
The break; statement tells the game to exit from a switch() statement. If you have a switch, you will always need to use a break, usually under each case you have, otherwise the script will go on to perform other actions you probably don't want.
HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE); is standard code that you will want to use in most scripts, but the script you specify (here shown as a constant) will change based on application. This function effectively tells the game to "handle" any other events by passing them to the area_core script that contains all the default code the game needs to make areas work, as it were. In other words, anything "standard" that you need to do should be passed to the applicable core script; anything custom you want to do needs to be written in your own script.
I cannot overstate the importance of learning syntax. C is not that hard, but if you approach it purely from a scripting perspective you will learn much more slowly. I highly recommend doing just a bit of reading on C syntax, because it will help you immensely in understanding how the game works and how you can do your own scripting to achieve your goals. There are a lot of things you can do that many beginners pass up, even stuff like use of arrays and loops, which the Builder Wiki doesn't really cover but can be indispensable. For instance:
object[] oStatues = GetTeam(100, OBJECT_TYPE_CREATURE);
int nSize = GetArraySize(oStatues);
int index;
for (index = 0; index < nSize; index++)
{
SetCreatureIsStatue(oStatues[index], TRUE);
}
vs.
object oPC = GetHero();
object oStatue1 = UT_GetNearestObjectByTag(oPC, "statue_1");
object oStatue2 = UT_GetNearestObjectByTag(oPC, "statue_2");
object oStatue3 = UT_GetNearestObjectByTag(oPC, "statue_3");
object oStatue4 = UT_GetNearestObjectByTag(oPC, "statue_4");
object oStatue5 = UT_GetNearestObjectByTag(oPC, "statue_5");
object oStatue6 = UT_GetNearestObjectByTag(oPC, "statue_6");
object oStatue7 = UT_GetNearestObjectByTag(oPC, "statue_7");
SetCreatureIsStatue(oStatue1, TRUE);
SetCreatureIsStatue(oStatue2, TRUE);
SetCreatureIsStatue(oStatue3, TRUE);
SetCreatureIsStatue(oStatue4, TRUE);
SetCreatureIsStatue(oStatue5, TRUE);
SetCreatureIsStatue(oStatue6, TRUE);
SetCreatureIsStatue(oStatue7, TRUE);
You tell me which one looks quicker, cleaner and more flexible (hint: the first one).
I also recommend you look at BioWare's own scripts. Find a simple plot in the main campaign module, like for one of the random encounters, and then check its associated script to see how BioWare handled it. The vast majority of things you will be doing script-wise will be related to plot scripts, because that's where most of the gameplay/story stuff happens, and thankfully there are template scripts available (like plot_h, if I recall) that you can simply modify to your own needs.
Modifié par sea-, 04 août 2012 - 03:49 .