Main Menu

Site Home Page

Glossary of Terms

Current Class Mod Package

Divider

Help! My mod is corrupted!

Divider

Week of June 15th, 2009

Topics:

  • Getting Help
    • The "Assistance" windows
    • The Lexicon
    • The Forums
  • Variables
    • Type-casting and the types
    • Conventions
    • Constants
  • Who Dun' It?
    • Who Spoke?
    • Who Used the Placeable?
    • Who Activated the Item?
    • Who Crossed the Trigger? Who Entered the Area?
    • Was it a Player? a DM?
  • Creating Objects
    • Preparing the Object
      • The Resref
      • The Object Type
    • At a Waypoint
      • Find the Waypoint
      • Find the Location
    • Where the player is
      • Find the Location
    • Create the Object
      • Deciding on a Tag
      • Spawning in the Object
      • Doing Things to the Object after Creation
  • Tracking Variables
    • Local Variables
    • Persistent Variables
  • Some Useful Scripts
    • Making Changes to the Avatar When It Enters the Game
    • Fiddling with the Avatar's Inventory
    • Destroying the Inventory Items
    • Destroying "Non-Destroyable" Items
    • Taking Gold From the Player
    • Giving Gold To the Player
    • Giving General Inventory Items to the Player
    • Giving Equipable Items and Forcing an Equip Action
    • Random Walk

Homework: Dungeon and Quest

Divider

Week of June 7th, 2009

Topics:

  • Items
    • Properties
    • Building your own items
    • How to make an item have a conversation.
  • Creatures
    • Properties
    • Building your own
  • Triggers
    • Choosing the right one
    • Drawing a trigger
    • Trigger Properties
    • Trigger Events and Scripting Preview
    • Examples of Trigger Use
  • Waypoints
    • Waypoint Properties
    • Waypoint Directions
    • Uses for Waypoints
    • Scripting Preview
    • How to Set Up a Patrol Route
  • Conversations
    • How they're used
    • The basic tree.
    • Branching
    • Links (or "Loop backs")
    • Tokens: Built-in and Custom
    • Colorizing the Text
    • Including Other Speakers
    • "Actions Taken" and other events
    • Conditional Nodes
  • The Journal
    • Categories
    • Entries
    • Updating the Journal through Conversations
    • Updating the Journal through Scripting
  • How to Test Your Mod
    • The Build Module Option.
    • The Real Way
    • The Test Module Option

Homework:


Divider

Week of June 1st, 2009

Topics:

  • Areas
    • Area Properties
    • Module Properties
  • Tiles
    • Tile Properties
  • Names
    • Blueprint / Resref
    • Tag
    • Display Name
  • Doors
    • Door Properties
    • Transitions between doors
    • How to make a door close itself
    • How to have a transition without a door
  • Placeables
    • Placeable properties
    • Spawning placeables.
    • How to stack placeables
    • How to have a placeable hold a conversation

Homework:

Divider

May 27, 2009

Topics

Homework

 

 

GAME CONCEPT AND DESIGN
COSC 320.101_SU09
SUMMER 2009


Creating Objects

I don't know why this is the most magical part to me, but it is. Being able to create objects (items, placeables, monsters) through scripting is almost diety-like. It takes a little up front work, but it's definitly worth mastering.

Preparing the Object

The first thing you need to do is to know the resref of the object you're going to be spawning in. There's a few ways to do this:

  • If it's a custom object that you created, find it in the Custom palette. Right-click and select Edit. Locate the resref and jot it down.
  • If it's a standard item, you cannot do the above. The resref you see will be a fake one because the toolset thinks you're going to make a custom one. Instead, put the object on the map then right-click and Edit that object. The resref you see there will be the real one. Jot it down, then delete the object from the map.
  • If you're recovering the resref of an object through scripting, you can get its resref with something like: string sItemToSpawn = GetResRef(oTarget); Of course this assumes that earlier in your script you've "put your finger on" oTarget which is the object to be copied.

The Object Type

As we've learned in the last couple of weeks, there's lots of objects in the game that are considered to be "objects." Before you spawn in yours, you need to know what type of object it is: is it a placeable? an item? a creature? These are all constant values and look like this:

OBJECT_TYPE_PLACEABLE
OBJECT_TYPE_ITEM
OBJECT_TYPE_CREATURE

There's 11 object types that you can spawn in dynamically. To see them all, go to the scripting window, click the Constants button and search on "object_type" and you'll see them all.

At a Waypoint

You will often want to spawn your object in at the location of a waypoint. To do this, you'll need to tell the engine which waypoint and then determine where the waypoint is located. Let us assume that you want to spawn a creature named Bubba and you have a waypoint for him that you've tagged as "Bubba_Home".

First we locate that waypoint:

object oBubbaSpawnPoint = GetWaypointByTag("Bubba_Home");

Now, we'll get the location of that waypoint object:

location lBubbaSpawnPoint = GetLocation(oBubbaSpawnPoint);

There...now we have the location of that waypoint.

Notes: Typically, the location variable is only used briefly or is used repeatedly, so instead of typing out something long each time, we tend to just say location lLocation. It looks a bit odd and confusing at first, but makes sense when you grok it.

Where the Player Is

Or you may want to spawn the item to the player's location. Assuming you've identified the player earlier in your script (as, say, oPlayer), you can then recover his position similarly:

location lLocation = GetLocation(oPlayer);

Deciding on a Tag

When you create an object you have the option of giving it a tag of your choice. This is handy if you plan to use a script later on to do something else to that object (such as kill it, make it attack, or give it special actions). So think of a tag if you want to. If you don't use a tag, then the engine will use the default tag from the Properties Sheet.

Spawning in the Object

To spawn in your new object, you use the CreateObject( ) command. However, the command takes a number of arguments in order to work. Conveniently, the arguments are the things we've been talking about in this document. The template for the command is:

CreateObject(<object type>,<resref>,<location>,<appear animation>,<tag>);

The appear animation means that you can set some creatures up to do more than just "fade into view." Spiders fall from above, undead crawl up from the ground (I think...I could be wrong). So you can either have the special animation play or just let them fade in.

Now, let us suppose that we want to spawn in a monster at a waypoint. And let's say we've collected the following information:

  • Object type is creature.
  • resref is "gruntburpbelly"
  • location is his waypoint which is named "grunt_spawn"
  • I don't want an animation.
  • I will tag him as GruntBurpbelly.

The script sequence that gets him in the game looks like this:

object oWaypoint = GetWaypointByTag("grunt_spawn");
location lLocation = GetLocation(oWaypoint);

CreateObject(OBJECT_TYPE_CREATURE,"gruntburpbelly",lLocation,FALSE,"GruntBurpbelly");

Doing Things to the Object After Creation

You might want to do things to the object after you create it. This is easily done because CreateObject( ) actually returns a reference to the created object and puts that reference in a variable if you set it up to do so. So, let us say that we want create an orc (from the generic blueprint "nw_orca"), and we're going to give it a tag of "Fred". However, notice that the command has no way to set the display name of the orc. So we want to set it up so that when the player puts his mouse on the orc, it displays "Fred." Plus we want to give him 500 gold pieces.

object oWaypoint = GetWaypointByTag("fred_spawn");
location lLocation = GetLocation(oWaypoint);
object oCreature; //not setting it equal to anything, just getting ready.

oCreature = CreateObject(OBJECT_TYPE_CREATURE,"nw_orca",lLocation,FALSE,"Fred");
SetName(oCreature,"Fred");
GiveGoldToCreature(oCreature,500);

So you see that once the creature was created, the command put a reference to that creature in the variable oCreature. Then in subsequent commands, we just referred to oCreature and the game knew who we were talking about.