Forums
Games
Cyberpunk 2077 Thronebreaker: The Witcher Tales GWENT®: The Witcher Card Game The Witcher 3: Wild Hunt The Witcher 2: Assassins of Kings The Witcher The Witcher Adventure Game
Jobs Store Support Log in Register
Forums - CD PROJEKT RED
Menu
Forums - CD PROJEKT RED
  • Hot Topics
  • NEWS
  • GENERAL
    THE WITCHER ADVENTURE GAME
  • STORY
    THE WITCHER THE WITCHER 2 THE WITCHER 3 THE WITCHER TALES
  • GAMEPLAY
    THE WITCHER THE WITCHER 2 THE WITCHER 3 MODS (THE WITCHER) MODS (THE WITCHER 2) MODS (THE WITCHER 3)
  • TECHNICAL
    THE WITCHER THE WITCHER 2 (PC) THE WITCHER 2 (XBOX) THE WITCHER 3 (PC) THE WITCHER 3 (PLAYSTATION) THE WITCHER 3 (XBOX) THE WITCHER 3 (SWITCH)
  • COMMUNITY
    FAN ART (THE WITCHER UNIVERSE) FAN ART (CYBERPUNK UNIVERSE) OTHER GAMES
  • RED Tracker
    The Witcher Series Cyberpunk GWENT
THE WITCHER
THE WITCHER 2
THE WITCHER 3
MODS (THE WITCHER)
MODS (THE WITCHER 2)
MODS (THE WITCHER 3)
Menu

Register

Simple AI companion spawn mod tutorial

+

Guest 2364765

Guest
#1
Aug 16, 2015
Simple AI companion spawn mod tutorial

As a prerequisite, you're required to have console enabler installed (unless you wish to bind the function to button).

This tutorial mod will spawn an AI companion which will follow us around, attack our enemies and optionally appear on HUD as a companion with his health bar.
Since we want this function to be executable from console, best place for it is in scripts\game\temp.ws

Inside we're going to add a new function:
exec function SimpleComp(optional wanthud : bool)
{
var hud : CR4ScriptedHud; //For the companion module
var template : CEntityTemplate; //For spawning functionality
var pos : Vector; //For spawning functionality
var rot : EulerAngles; //For spawning functionality
var ent : CEntity; //For spawning functionality
var l_aiTree : CAIFollowSideBySideAction; //For follower behavior
var ModuleComp : CR4HudModuleCompanion; //For the companion module

ModuleComp = (CR4HudModuleCompanion)hud.GetHudModule( "CompanionModule" ); //Find companion module
pos = thePlayer.GetWorldPosition() + VecRingRand(1.f,2.f); // Determine position for spawning the companion
rot = VecToRotation(thePlayer.GetWorldPosition() - pos); // Determine spawn rotation
template = (CEntityTemplate)LoadResource("sword1h_super_hard"); // Determine what we spawn, replace with any NPC template you wish
ent = theGame.CreateEntity(template, pos, rot ); // This directly handles the spawning
l_aiTree = new CAIFollowSideBySideAction in ent; // Initialize follower behavior

l_aiTree.OnCreated(); // Once we're done initializing behavior tree
((CActor)ent).ForceAIBehavior( l_aiTree, BTAP_AboveEmergency2); // Force the follower behavior tree onto the spawned NPC
((CActor)ent).SetTemporaryAttitudeGroup( 'player', AGP_Default ); // Put the NPC into same attitude group as player to share friendlies/enemies
((CActor)ent).SetAttitude( thePlayer, AIA_Friendly ); // Just to make sure it's always friendly to us
ent.AddTag( 'InPlayerParty' ); // add companion tag
if(!wanthud)
{
return; // Do nothing
}
else
{
hud = (CR4ScriptedHud)theGame.GetHud();
ModuleComp = (CR4HudModuleCompanion)hud.GetHudModule( "CompanionModule" );
ModuleComp.ShowCompanion(true, 'InPlayerParty');module
}
}
Click to expand...
Usage is simple, open console and call SimpleComp(), this will spawn your companion without the HUD module as will SimpleComp(0). Using SimpleComp(1) will spawn companion with the companion module.

However there may be cases where we actually want to remove a companion, here's a function which will deal with that:
{
var npcname : CNewNPC; // Declare NPC we're looking for
var hud : CR4ScriptedHud; // Declare HUD to find companion module
var ModuleComp : CR4HudModuleCompanion; // Declare companion module for direct access

npcname = theGame.GetNPCByTag( 'InPlayerParty' ); // Find our companion
npcname.RemoveTag( 'InPlayerParty' ); // Remove tag
npcname.Kill(1); // Force kill, 1 in bracket ignores immortality
hud = (CR4ScriptedHud)theGame.GetHud(); // find our HUD
ModuleComp = (CR4HudModuleCompanion)hud.GetHudModule( "CompanionModule" ); // find our module
ModuleComp.ShowElement(false, false); // No companion at the moment, kill the module
ModuleComp.SetEnabled(false); // same as above
hud.UpdateHudConfig('CompanionModule', true); // force hud refresh
}
Click to expand...
Limitations:
-Companion can only walk, literally walk. No running, no sprinting. By the looks of it "CAIFollowSideBySideAction" should work as "variable speed" following mode where NPC adjusts to our speed, however it's either broken or i can't use it properly Actually i think this functionality may be broken, because even official debug commands like MoveToPlayer do nothing.
-Certain NPCs can't die, even if killed with immortality override, some NPCs (like civilians or Yennefer) only get knocked out and will keep following you once they get back up, for now i see no way around this.

Enjoy!

//
P.S: You can get extended implementation of this script here
 
Last edited by a moderator: Aug 16, 2015
  • RED Point
Reactions: Holgar82, PrincessMassacre and Scryar
P

PrincessMassacre

Senior user
#2
Aug 16, 2015
another step in the direction of a working ME3 mod. ;o
 
R

Richiesname

Rookie
#3
Aug 16, 2015
While this is awesome, I'm going to be leaving having companions alone until Redkit comes out or someone figures out a way to script in dialogue and we can hack quests together.
 

Guest 2364765

Guest
#4
Aug 16, 2015
I totally can't figure out how to force NPC to run/sprint instead of walking.

I wish that Script Studio worked, or CDPR gave us some documentation as the available scripts seem to be more of a selected vertical slice rather than dump of all available scripts.

//
Actually i think this functionality may be broken, because even official debug commands like MoveToPlayer do nothing.
 
Last edited by a moderator: Aug 16, 2015
M

MrPanda92

Rookie
#5
Aug 16, 2015
I tried it out but it didn't really work for me cause having them arround like a dog is not a great thing :). This is why i think a post main-story content made by @cdprojekt RED will be a better idea:

1) Put main characters back in the post main-story with interactions like: dialogs, hunt/training Ciri, romance for Yenn/Triss and other interactions like qwent or drinking with all of the main characters. This way Geralt and we will have more time to spent with them. (I'm not asking for a lot of dialogs just a few to be able to talk with them).

2) Let us decide when we want to end the game for expample we've ended all secondary quests, all treasure hunting, all contracts in Ciris company, we've explored all the world and we are tired of Yenn or Triss ok, AT this point there should be a quest like some one suggested that can be activated when we want that will end the game with a cutscene and will take us in a NG+.

3) I think the expansions shoul work in the post main-story, this way we don't need to start the game again just po play 10 hours.
Oh and I am sure that a post main-story content with characters interactions would give all players much more playtime then only the expansions.

This way in a future when REDKit for TW3 will come out modders will have a pre-set world with main characters in, that have their own dialogs and interactions and it will be much easier to make NEW quests that involve the main characters, like hunt and contracts for Ciri and other stuff for the others.
 
Share:
Facebook Twitter Reddit Pinterest Tumblr WhatsApp Email Link
  • English
    English Polski (Polish) Deutsch (German) Русский (Russian) Français (French) Português brasileiro (Brazilian Portuguese) Italiano (Italian) 日本語 (Japanese) Español (Spanish)

STAY CONNECTED

Facebook Twitter YouTube
CDProjekt RED Mature 17+
  • Contact administration
  • User agreement
  • Privacy policy
  • Cookie policy
  • Press Center
© 2018 CD PROJEKT S.A. ALL RIGHTS RESERVED

The Witcher® is a trademark of CD PROJEKT S. A. The Witcher game © CD PROJEKT S. A. All rights reserved. The Witcher game is based on the prose of Andrzej Sapkowski. All other copyrights and trademarks are the property of their respective owners.

Forum software by XenForo® © 2010-2020 XenForo Ltd.