IK_NumPad0=(Action=KBinderCallFunction)
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()
{
GetCDProjektRed().SendMessage("gib redkit pls");
}
}
// copy your exec function here (for convenience), then delete "exec" from it
statemachine class W3PlayerWitcher extends CR4Player
{
var keyBinder : KeyBinder;
keyBinder = new KeyBinder in this;
keyBinder.Init();
Error [mod]1.ws(15): Could not find function 'GetCDProjektRed'
Warning [content0]engine\environment.ws(30): Global native function 'EnableDebugOverlayFilter' was not exported from C++ code.
Warning [content0]engine\environment.ws(32): Global native function 'EnableDebugPostProcess' was not exported from C++ code.
Warning [content0]engine\showflags.ws(11): Global native function 'DebugSetEShowFlag' was not exported from C++ 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()
{
spawn( cavetroll, 1, 1, false);
}
}
// copy your exec function here (for convenience), then delete "exec" from it
withspawn( cavetroll, 1, 1, false);
As this seems to be the proper syntax recommended for input in the console itself as well. However, I followed the instructions too and tried to bind a "buffme" function to Numpad0 and it doesn't work. So perhaps the whole setup is incorrect? However, it seemed to work for Wolfysge, as they did receive an error message, which means the game tried to execute the joke command and failed, while I get absolutely nothing.spawn('cavetroll', 1, 1, false);
Error [modharmthehermit]kbindercallfunction.ws(15): Cannot call exec function 'spawn' from scripts instead of the console.
exec function spawn(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 );
}
}
}
exec function buffme( type : EEffectType, optional duration : float, optional src : name )
{
var params : SCustomEffectParams;
if(duration > 0)
{
params.effectType = type;
params.sourceName = src;
params.duration = duration;
thePlayer.AddEffectCustom(params);
}
else
{
thePlayer.AddEffectDefault(type, NULL, src);
}
}
class KeyBinder
{
function Init()
{
theInput.RegisterListener(this, 'OnCallFunction', 'KBinderCallFunction');
}
event OnCallFunction( action : SInputAction )
{
if(IsPressed(action))
// Function you want to call. Like:
example();
example2();
}
function example()
{
var params : SCustomEffectParams;
params.effectType = EET_Mutagen21;
params.duration = 2400;
thePlayer.AddEffectCustom(params);
}
function example2()
{
var params : SCustomEffectParams;
params.effectType = EET_Mutagen04;
params.duration = 2400;
thePlayer.AddEffectCustom(params);
}
}
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('cavetroll', 1, 1, false);
}
}
// 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 );
}
}
}
IK_NumPad1=(Action=KBinderCallFunction2)
class KeyBinder
{
function Init()
{
theInput.RegisterListener(this, 'OnCallFunction', 'KBinderCallFunction2');
}