scripting:snippets
This is an old revision of the document!
Snippets
Get a Entity
One of the most used commands is probably 'FindEntityByName'. Whevever you want to script something in the game, you should find its entity. This is simply done by the below line.
Notice the variable name 'soldier' and the entityname 'soldier_scripted' - You have to change these variables to reflect your entity ingame.
Example1: get the entity of a soldier with the name 'soldier_scripted'
GenericEntity soldier = GenericEntity.Cast(GetWorld().FindEntityByName("soldier_scripted"));
Example1: get the entity of a vehicle with the name 'BTR1'
GenericEntity btr = GenericEntity.Cast(GetWorld().FindEntityByName("BTR1"));
//Get the entity (soldier) GenericEntity soldier = GenericEntity.Cast(GetWorld().FindEntityByName("soldier_scripted")); //Control the Soldier. CharacterControllerComponent soldier_c = CharacterControllerComponent.Cast(soldier.FindComponent(CharacterControllerComponent)); // change stance soldier_c.SetStanceChange(ECharacterStanceChange.STANCECHANGE_TOCROUCH); // move soldier vector direction = {0,0,1}; soldier_c.SetMovement(2, direction); // shoot phase 1 soldier_c.SetWeaponRaised(true); soldier_c.SetSafety(false, true); // shoot phase 2 soldier_c.SetFireMode(2); soldier_c.SetFireWeaponWanted(1)
scripting/snippets.1660219997.txt.gz · Last modified: 2022/08/11 13:13 by jerryhopper