helo guys im try or looking some mod to spawn enemy via hotkey,when i search in this forum i found this code here
code:
class KeyBinder
{
function Init()
{
theInput.RegisterListener(this, 'OnCallFunction', 'KBinderCallFunction');
}
event OnCallFunction( action : SInputAction )
{
if(IsPressed(action))
// Function you want to call. Like:
example();
}
function example()
{
spawnhermit('ghoul', 0, 0, true);
}
}
// copy your exec function here (for convenience), then delete "exec" from it
function spawnhermit(nam : name, optional quantity : int, optional distance : float, optional isHostile : 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();
if(nam != 'boat')
{
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(nam);
if ( nam == 'rider' )
horseTemplate = (CEntityTemplate)LoadResource('horse');
if(!template)
{
resourcePath = "characters\npc_entities\monsters";
resourcePath = resourcePath + NameToString(nam);
resourcePath = resourcePath + ".w2ent";
template = (CEntityTemplate)LoadResource( resourcePath, true );
}
if( nam == 'def' )
{
templateCSV = LoadCSV("gameplay\globals\temp_spawner.csv");
resourcePath = templateCSV.GetValueAt(0,0);
template = (CEntityTemplate)LoadResource( resourcePath, true );
}
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(nam == 'boat')
{
posFin.Z = 0.0f;
}
else
{
if(theGame.GetWorld().StaticTrace( posFin + Vector(0,0,5), posFin - Vector(0,0,5), posTemp, normal ))
{
posFin = posTemp;
}
}
if( nam == 'boat' )
{
ent = theGame.CreateEntity(template, posFin, rot, true, false, false, PM_Persist );
}
else
{
ent = theGame.CreateEntity(template, posFin, rot);
}
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( 'hostile_to_player', AGP_Default );
}
if ( level != 0 )
{
((CNewNPC)ent).SetLevel( level );
}
}
}
the problem is i can only spawn 1 enemy,i need to k1ll enemy then can spawn again,i want enemy keep spawning went i press the hotkey
code:
class KeyBinder
{
function Init()
{
theInput.RegisterListener(this, 'OnCallFunction', 'KBinderCallFunction');
}
event OnCallFunction( action : SInputAction )
{
if(IsPressed(action))
// Function you want to call. Like:
example();
}
function example()
{
spawnhermit('ghoul', 0, 0, true);
}
}
// copy your exec function here (for convenience), then delete "exec" from it
function spawnhermit(nam : name, optional quantity : int, optional distance : float, optional isHostile : 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();
if(nam != 'boat')
{
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(nam);
if ( nam == 'rider' )
horseTemplate = (CEntityTemplate)LoadResource('horse');
if(!template)
{
resourcePath = "characters\npc_entities\monsters";
resourcePath = resourcePath + NameToString(nam);
resourcePath = resourcePath + ".w2ent";
template = (CEntityTemplate)LoadResource( resourcePath, true );
}
if( nam == 'def' )
{
templateCSV = LoadCSV("gameplay\globals\temp_spawner.csv");
resourcePath = templateCSV.GetValueAt(0,0);
template = (CEntityTemplate)LoadResource( resourcePath, true );
}
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(nam == 'boat')
{
posFin.Z = 0.0f;
}
else
{
if(theGame.GetWorld().StaticTrace( posFin + Vector(0,0,5), posFin - Vector(0,0,5), posTemp, normal ))
{
posFin = posTemp;
}
}
if( nam == 'boat' )
{
ent = theGame.CreateEntity(template, posFin, rot, true, false, false, PM_Persist );
}
else
{
ent = theGame.CreateEntity(template, posFin, rot);
}
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( 'hostile_to_player', AGP_Default );
}
if ( level != 0 )
{
((CNewNPC)ent).SetLevel( level );
}
}
}
the problem is i can only spawn 1 enemy,i need to k1ll enemy then can spawn again,i want enemy keep spawning went i press the hotkey