User Tools

Site Tools


scripting:snippets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
scripting:snippets [2022/08/11 13:46] jerryhopperscripting:snippets [2022/08/11 13:58] (current) jerryhopper
Line 2: Line 2:
  
  
 +<code>
  
-===== Basics : Get a Entity ===== 
  
-The examples below need a soldier with the name 'scripted_soldier' and a vehicle with the name 'BTR1'Make sure these two exists in your composition.+//Get the entity (soldier) 
 +GenericEntity soldier = GenericEntity.Cast(GetWorld().FindEntityByName("soldier_scripted"));
  
  
-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.+//Control the Soldier. 
 +CharacterControllerComponent soldier_c = CharacterControllerComponent.Cast(soldier.FindComponent(CharacterControllerComponent));
  
-Notice the variable name 'btr' and the entityname 'BTR1' - You have to change these variables to reflect your entity ingame.+// change stance 
 +soldier_c.SetStanceChange(ECharacterStanceChange.STANCECHANGE_TOCROUCH);
  
-==== Example ==== +// move soldier 
-  +vector direction {0,0,1}; 
-Get the entity of a vehicle with the name 'BTR1'+soldier_c.SetMovement(2, direction);
  
-  GenericEntity btr = GenericEntity.Cast(GetWorld().FindEntityByName("BTR1")); 
  
 +// shoot phase 1
 +soldier_c.SetWeaponRaised(true);
 +soldier_c.SetSafety(false, true);
  
-**Lets break down this line.** +// shoot phase 
- +soldier_c.SetFireMode(2); 
-This is where we declare our variablename and type, where the name is 'btr' and the type is 'GenericEntity'  +soldier_c.SetFireWeaponWanted(1
- +</code>
-  GenericEntity btr =  +
- +
- +
-So, the variable 'btr' wil contain the results of a combination of commands.  +
- +
-When we break it down you'll notice these 2 commands. +
-   +
-  GetWorld().FindEntityByName("BTR1"+
-   +
-  GenericEntity.Cast() +
- +
-Lets not get too technical, but what you need to know is that we search for the entity 'BTR1' - The result of this command is passed to the CAST function of the GenericEntity object. +
- +
-  GenericEntity.Cast(GetWorld().FindEntityByName("BTR1"));   +
- +
-What does that mean?  -  it means that the result of your FindEntityByName is 'casted' (*converted) to a GenericEntity Object. And with a genericEntity object we can do things... +
- +
- +
-So, the result of the above is that we have a variable with the name 'btr' which 'type' is 'GenericEntity' +
- +
- +
- +
- +
-==== Example ==== +
- +
-Lets try this with a soldier. +
- +
-So, we get the entity of a soldier with the name 'soldier_scripted' +
- +
-  GenericEntity soldier = GenericEntity.Cast(GetWorld().FindEntityByName("soldier_scripted")); +
-   +
-Now we have the 'GenericEntity' in the variable 'soldier' To control this soldier, we need a controller component. Because we know the entity is in fact a 'character' - we need to get the characterController. +
-This procedure is almost the same as you would get any other entity. +
- +
-  CharacterControllerComponent soldier_c = CharacterControllerComponent.Cast(soldier.FindComponent(CharacterControllerComponent)); +
- +
- +
-So here we have a variable with the name 'soldier_c'  ( this is a descriptive variable, we know its a soldier and by appending the '_c' we know this is the soldier controller component) which contains the CharacterControllerComponent for our specific entity. +
- +
-Now if we want to change the stance of the soldier, we can do so via this CharacterController. +
- +
-  soldier_c.SetStanceChange(ECharacterStanceChange.STANCECHANGE_TOCROUCH); +
- +
-That looks quite straightforward, aside from the variable passed to the function. The stances of the character are defined in [[scripting:ECharacterStanceChange.c]], but i will list them below. +
- +
-  * STANCECHANGE_NONE, +
-  * STANCECHANGE_TOERECTED, +
-  * STANCECHANGE_TOCROUCH, +
-  * STANCECHANGE_TOPRONE +
- +
- +
-Great!  You are now able to control a soldier's stance by script!+
  
scripting/snippets.1660221987.txt.gz · Last modified: 2022/08/11 13:46 by jerryhopper

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki