A ChangeModel

From ZDoom Wiki
Jump to navigation Jump to search

Actor

action native void A_ChangeModel(name modeldef, int modelindex = 0, string modelpath = "", name model = "", int skinindex = 0, string skinpath = "", name skin = "", int flags = 0, int generatorindex = -1, int animationindex = 0, string animationpath = "", name animation = "");

Usage

This can change the MODELDEF definition, model and skins of an actor.

You can add models to an actor to render by using generatorindex to tell your new model index to copy the behavior of another one. This does not actually generate any MODELDEF data, but does instruct the index to copy the behavior of the index you put for generatorindex. As a result, you may only copy the behavior of a model index already defined in your actor's current modeldef. To remove a model or skin, just pass "" to modeldef/model/skin parameter to revert to the default.

Parameters

  • name modeldef
This is the MODELDEF this actor will now load. Use "" to restore the default MODELDEF definition. If it's already using its default MODELDEF definition and you don't want to change it, use "" as well.
  • int modelindex
This is the model index where the new model should be attached or replaced. Default is 0.
  • String modelpath
This is the path for where to locate the new model. This must be a full path to the folder containing the model in your PK3 file (for example, "models/marine/shotgun"), the same way as the Path instruction in MODELDEF.
  • name model
The name of the model file to attach, for example "shotgun.iqm". This name is appended to the path, the same as the Model instruction in MODELDEF.
  • skinindex
This index specifies which model index must change it's skin. Default is 0.
  • skinpath
This is the path for where to locate the new skin. Works the same way as modelpath.
  • name skin
The name of the skin file to attach. Works the same way as model.
  • int flags
Allows the alteration of the function's behavior. Multiple flags can be combined with |. The following flags are available:
  • CMDL_WEAPONTOPLAYER — If used on a weapon, this instead change's the model on the player instead.
  • CMDL_HIDEMODEL — Hides the specified model index from rendering. Useful to temporary hide part of the model. Can be used with CMDL_WEAPONTOPLAYER.
  • CMDL_USESURFACESKINskinindex instead corresponds to the index of a surface to replace its skin.
  • int generatorindex
Instructs the model in modelindex to copy frame data from this index. Default is -1, which will not copy frame data from any index. Useful for attaching models with similar frames, like a gun to a player model.
  • int animationindex
This index specifies where the new animation should be attached or replaced. Default is 0.
  • String animationpath
This is the path for where to locate the new animation clip. Default is "".
  • name animation
This is the file name of the new animation clip. The extension is required. "" can be used to restore the default animation for this index. Default is "".

Examples

This actor alternates modeldefs every second.

class SwapModelDef : Actor
{
    Default
    {
        Height 16;
        Radius 8;
    }

    States
    {
    Spawn:
        PIST A 35;
        TNT1 A 0 A_ChangeModel("SwapModelDefHelper");
        PIST A 35;
        TNT1 A 0 A_ChangeModel("SwapModelDef");
        Loop;
    }
}

Another useful function of A_ChangeModel is the ability to change the player's appearance from the weapon itself. Note that index 0 represents the player model, while index 1 is attaching a gun to the player model.

class NewPistol : Pistol replaces Pistol
{
    States
    {
    Ready:
        PISG A 0 A_ChangeModel("", 1, "Models", "w_blaster.iqm", 1, "Models", "g_blaster.png", CMDL_WEAPONTOPLAYER, 0);
        PISG A 1 A_WeaponReady;
        Wait;
    }
}

See also