Hello everyone I have been playing around with npcs spawning commands, their attitudes and spawntrees, and tried to implement a custom exec function to spawn an entity on horse, like the 'Rider' spawn case. Here is the code
exec function spawnen(path : string, optional quantity : int, optional distance : float, optional isHostile : bool, optional wantimmortal : bool, optional level : int )
{
var ent : CEntity;
var horse : CEntity;
var pos, cameraDir, player, posFin, normal, posTemp : Vector;
var rot : EulerAngles;
var i, sign : int;
var s,r,x,y : float;
var template : CEntityTemplate;
var horseTemplate : CEntityTemplate;
var horseTag : array<name>;
var resourcePath : string;
var l_aiTree : CAIHorseDoNothingAction;
var templateCSV : C2dArray;
quantity = Max(quantity, 1);
rot = thePlayer.GetWorldRotation();
rot.Yaw += 180;
cameraDir = theCamera.GetCameraDirection();
if( distance == 0 ) distance = 3;
cameraDir.X *= distance;
cameraDir.Y *= distance;
player = thePlayer.GetWorldPosition();
pos = cameraDir + player;
pos.Z = player.Z;
posFin.Z = pos.Z;
s = quantity / 0.2;
r = SqrtF(s/Pi());
template = (CEntityTemplate)LoadResource(path,true);
if ( path == "quests\sidequests\novigrad\quest_files\sq312_ves\characters\sq312_commando_melee_rider.w2ent" )
horseTemplate = (CEntityTemplate)LoadResource('horse');
for(i=0; i<quantity; i+=1)
{
x = RandF() * r;
y = RandF() * (r - x);
if(RandRange(2))
sign = 1;
else
sign = -1;
posFin.X = pos.X + sign * x;
if(RandRange(2))
sign = 1;
else
sign = -1;
posFin.Y = pos.Y + sign * y;
if(theGame.GetWorld().StaticTrace( posFin + Vector(0,0,5), posFin - Vector(0,0,5), posTemp, normal ))
{
posFin = posTemp;
}
ent = theGame.CreateEntity(template, posFin, rot, true, false, false, PM_Persist );
if ( horseTemplate )
{
horseTag.PushBack('enemy_horse');
horse = theGame.CreateEntity(horseTemplate, posFin, rot,true,false,false,PM_DontPersist,horseTag);
l_aiTree = new CAIHorseDoNothingAction in ent;
l_aiTree.OnCreated();
((CActor)ent).ForceAIBehavior( l_aiTree, BTAP_AboveEmergency2, 'AI_Rider_Load_Forced' );
((CActor)ent).SignalGameplayEventParamInt( 'RidingManagerMountHorse', MT_instant | MT_fromScript );
}
if( isHostile )
{
((CActor)ent).SetTemporaryAttitudeGroup( 'monsters', AGP_Default );
}
if( wantimmortal )
{
((CActor)ent).SetImmortalityMode(AIM_Immortal, AIC_Default);
}
else
{
((CActor)ent).ForceVulnerable();
}
if ( level != 0 )
{
((CNewNPC)ent).SetLevel( level );
}
}
}
Unfortunately, it just spawns a horse and an npc nearby. It must be something to do with AIBehaviour line If anyone has any ideas, please let me know