GetResRef(object)

Returns the ResRef of an object.

string GetResRef(
    object oObject
);

Parameters

oObject

Object to return the ResRef of.


Description

Returns the ResRef (resource reference) of oObject. The ResRef is what identifies an object on the palette, since it refers to the name of the file that contains the info about the object on the palette. For instance, you must use the ResRef, not tag, when creating objects. Thus, you can use GetResRef to create a copy of an object (though you won’t need to, now that we have CopyObject).

Returns an empty string ("") on error.



Remarks

Does not return the ResRef of an area object; returns an empty string ("") instead.

Since a patch some time ago, this function will now also return the ResRef of items that have been brought in from other modules, and thus don't exist in the current module. This can be done because the ResRef is actually stored in the item's properties. However, you of course won't be able to do a CreateObject with the obtained ResRef, but the same result can be obtained with CopyItem and CopyObject.

Players have null resrefs, and are thusly blank strings, "", as are any PC objects tag.


Known Bugs

In game, if a stacked item is split, only one of the new stacks will have a resref - the resref for the other stack will be an empty string. Also, restacking them will keep the ResRef of the stack being added into, so it is very possible to end up with items without ResRefs when dealing with stackable items.


Version

1.62

Example

// Put this OnDeath of a creature to respawn it at the

// waypoint tagged "wp_respawn". Note that the creature on
// the palette must be identical to the creature dying, as
// the respawning creature is actually a new creature from the
// palette. Lilac Soul.
void main()
{
     string sRes=GetResRef(OBJECT_SELF);
     object oTarget=GetWaypointByTag("wp_respawn");
     location lLoc=GetLocation(oTarget);
     CreateObject(OBJECT_TYPE_CREATURE, sRes, lLoc);
}

// An all round script for a useful use for GetResRef, provided
// by Windbourne. Place or add into a creatures On Death event,
// and as long as the "SpawnMeHere" variable is set to a tag of
// a waypoint or any other object which you want it to respawn
// at, it will do forever (EG: A rat at a sewer grate continually 
// respawning)

void main()
{
    // Get the place to respawn at
    string sSpawnMe = GetLocalString(OBJECT_SELF, "SpawnMeHere");
    // Get creature to respawn (a copy of myself!)
    string sRes=GetResRef(OBJECT_SELF);

    // Get where to create the new creature
    object oTarget=GetObjectByTag(sSpawnMe);
    location lLoc=GetLocation(oTarget);

    // Create the new creature. This should happen forever!
    CreateObject(OBJECT_TYPE_CREATURE, sRes, lLoc);
}

See Also

categories: Get Data from Object Functions


 author: Charles Feduke, editor: Jasperre, additional contributor(s): Harald Schuster, Christopher Smith, Mike Hodgkinson, Lilac Soul, Jasperre