Advertisement
TechOFreak

Episode 33 Functions

Feb 5th, 2021
1,725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 KB | None | 0 0
  1. //From my Amnesia Rebirth Tutorial Series
  2. //Episode 33 Puzzles Pt.1! Breaking Doors!
  3. //https://www.youtube.com/playlist?list=PL4KkjlmOwLwwMVqedCNpi6caUxhgyf8Qr
  4. //-----------------------------------------------------------
  5.  
  6. ///////////////////////////////////////////////////
  7. // Functions used in today's episode
  8. //////////////////////////////////////////////////
  9.  
  10. //Make sure you include the prop helper functions at the top of your script
  11. #include "helpers/helper_props.hps"
  12.  
  13. //Get the entity object of an entity using it's name
  14. Map_GetEntity("hammer_1");
  15. //entityName (String)- the name of the entity as it appears in your level editor.
  16.  
  17. //Assuming we save the entity object to a variable called pEnt...
  18. iLuxEntity@ pEnt = Map_GetEntity("hammer_1");
  19.  
  20. //Gets the physics body object attached to the entity
  21. pEnt.GetMainBody()
  22.  
  23. //Gets the linear velocity that the physics body is applying to entity as a cVector3f object
  24. pEnt.GetMainBody().GetLinearVelocity();
  25.  
  26. //Saves the above vector to a variable we decided to call hammerVelocity
  27. cVector3f hammerVelocity = pEnt.GetMainBody().GetLinearVelocity();
  28.  
  29. //Gets the x, y and z velocities from our vector above
  30. hammerVelocity.x
  31. hammerVelocity.y
  32. hammerVelocity.z
  33.  
  34. //Changes our decimal number (our float) into a string so that we can print it
  35. cString_ToString(hammerVelocity.x);
  36. //floatNumber (float)- the number you wish to convert into a string
  37. //The next 2 values below are optional
  38. //decimalPlaces (int)- the number of decimal places you want to capture
  39. //removeZeros (bool)- should zeros be removed from the end of the number (true or false).
  40.  
  41. //Set the health of an object/prop to something else
  42. Prop_SetHealth("door_1", 0.f);
  43. //propName (String)- the name of the object/prop as it appears in your level editor
  44. //health (float)- the health that the prop should be set to.
  45.  
  46. //Deletes an entity from the map (cannot be recreated, use Entity_SetActive(false) if you plan to make the object reappear)
  47. Entity_Destroy("hammer_1");
  48. //entityName (String)- the name of the entity as it appears in your level editor.
  49.  
  50. ///////////////////////////////////////////////////
  51. // Entire callback we wrote in today's episode
  52. //////////////////////////////////////////////////
  53.  
  54. bool OnCollide_HammerBreakArea(const tString &in asParent, const tString &in asChild, int alState)
  55. {
  56.     if(alState == 1){
  57.         if(asChild == "hammer_1" && Player_IsInteracting()){
  58.             iLuxEntity@ pEnt = Map_GetEntity("hammer_1");
  59.             cVector3f hammerVelocity = pEnt.GetMainBody().GetLinearVelocity();
  60.             cLux_AddDebugMessage(cString_ToString(hammerVelocity.x));
  61.             cLux_AddDebugMessage(cString_ToString(hammerVelocity.y));
  62.             cLux_AddDebugMessage(cString_ToString(hammerVelocity.z));
  63.             if(hammerVelocity.z > 4.0f){
  64.                 Prop_SetHealth("door_1", 0.f);
  65.                 Entity_Destroy("hammer_1");
  66.                 return false;
  67.             }
  68.         }
  69.     }
  70.     return true;
  71. }
  72.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement