Help with spawning script

I recently took a interest in the game again after some years and decided to do some modding on it.
What i want to do: a script that is activated by a item or a spell that spawns (not summon) a follower creature that will fight for the player.

So far i got:

void main()
{
location lLoc = GetItemActivatedTargetLocation();
CreateObject(OBJECT_TYPE_CREATURE,“urukmelee01”,lLoc);
ActionSpeakString(“Uruk warrior spawned.”);
}

I have no idea on how to attach this to a spell or item (whatever is the easiest) and how to make the creature follow and fight for me. Pls help.

1 Like

The first thing is the item activation, probably best handled as a tag-based script.

Then if you want the creature to act as a henchman, the basics are here. There might be a better tutorial these days.

If that’s more than you need, maybe this guide to summoning a chicken might do.

Alternatively, if you want a summoned creature that vanishes on rest, have a look at the Bioware creature summoning spells.

Thank you. It worked. But now there’s another problem.
Is there any way to make them follow the player (in and out of interiors too) without the need for me to hire them through the dialog? As soon as they spawn?

ActionForceFollowObject

Not quite so reliable as henchman following - you will need to reissue the command after events that clear actions, such a combat or conversation.

I wouldn’t consider this easiest in terms of learning curve. If it works - great, but when I need a fast & dirty way of activating test scripts, I put this as OnPlayerChat handler (in module preferences):

void main()
{
    ExecuteScript(GetPCChatMessage(), GetPCChatSpeaker());
}

@Gyugas Type the script name into chat line and hit enter to make the PC execute it.


// get PC and henchman
object oPC = GetFirstPC();
object oHenchman = GetObjectByTag("MY_HENCH");
// check if oHenchman does not have a master already
if(!GetIsObjectValid(GetMaster(oHenchman)))
{
    // add oHenchman as follower of oPC
    AddHenchman(oPC, oHenchman);
    // make henchman responsive to PC commands
    SetListening(oHenchman, TRUE);
    SetAssociateListenPatterns(oHenchman);
    SetListenPattern(oHenchman, "inventory",101);
    SetListenPattern(oHenchman, "pick",102);
    SetListenPattern(oHenchman, "trap", 103);
}

You will also need a set of scripts for the creature - copy them from any built-in NPC henchman, line Linu, Tomi, etc (they are in the “other” group). If you do this, the “make henchman responsive to PC commands” part will be done for you.

The ActionForceFollowObject worked. I didn’t before because i didn’t know that you need to start a new game to see changes to the module. I added it to OnSpawn and OnHeartbeat and everything is working fine. Thank you both.