Advertisement
Guest User

Untitled

a guest
Oct 18th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. #ifndef __DISGUISE__
  2. #define __DISGUISE__
  3.  
  4. object playertools_disguise : player_tools {
  5. void init();
  6. void update(entity userEntity);
  7. void disguise(entity userEntity);
  8. void undisguise(entity userEntity);
  9. void setdefault(entity userEntity);
  10. void inventoryUse(entity userEntity, entity frobbedEntity, float buttonState);
  11.  
  12. float _overlayHandle;
  13. float _updateThread;
  14.  
  15. string player_head_model;
  16. string player_head_skin;
  17. float player_team;
  18. float player_rank;
  19. float player_gender;
  20. float player_type;
  21.  
  22. boolean active;
  23. float strength;
  24. };
  25.  
  26. void playertools_disguise::init() {}
  27.  
  28. void playertools_disguise::update(entity userEntity)
  29. {
  30. eachFrame
  31. {
  32. // Add the fixed regeneration rate of the disguise, frametime corrected
  33. strength = strength + getFloatKey("regen") * sys.getFrameTime();
  34.  
  35. entity ent;
  36. do
  37. {
  38. // Loop through all AI related to the team who are within valid distance of the wearer, effects stack up with more affected guards
  39. // The disguise wears out with distance, multiplied by the visual rate of AI visual acuity, multiplied by alert rate of AI alert level
  40. // To check if the player is being seen by the AI, use findFriendlyAI when disguised (same team) or findEnemyAI if not disguised (different team)
  41. ent = sys.getNextEntity("AIUse", "AIUSE_PERSON", ent);
  42. if(ent != $null_entity && ent.getAcuity("vis") > 0 && sys.getRelation(ent.getTeam(), getFloatKey("team")) > 0)
  43. {
  44. ai ent_ai = ent;
  45. float dist = 1 - ent_ai.distanceTo(userEntity) / (ent_ai.getAcuity("vis") * getFloatKey("distance"));
  46. if(dist > 0 && ((active && ent_ai.findFriendlyAI(getFloatKey("team")) == userEntity) || (!active && ent_ai.findEnemyAI(true) == userEntity)))
  47. strength = strength - dist * getFloatKey("rate") * (1 + ent_ai.AI_AlertLevel * getFloatKey("rate_alert")) * sys.getFrameTime();
  48. }
  49. }
  50. while(ent != $null_entity);
  51.  
  52. if(strength <= 0)
  53. {
  54. strength = 0;
  55. undisguise(userEntity);
  56. }
  57. else if(strength >= 1)
  58. {
  59. strength = 1;
  60. disguise(userEntity);
  61. }
  62. userEntity.setGuiFloat(_overlayHandle, "DisguiseStrength", strength);
  63. }
  64. }
  65.  
  66. void playertools_disguise::disguise(entity userEntity)
  67. {
  68. // Activate the disguise
  69. if(active)
  70. return;
  71. active = true;
  72.  
  73. // Changing the head is currently disabled due to bug #6326, https://bugs.thedarkmod.com/view.php?id=6326
  74. //entity head = userEntity.getHead();
  75. //head.setModel(getKey("model_head"));
  76. //head.setSkin(getKey("skin_head"));
  77. userEntity.setTeam(getFloatKey("team"));
  78. userEntity.setKey("rank", getFloatKey("rank"));
  79. userEntity.setKey("personGender", getFloatKey("personGender"));
  80. userEntity.setKey("personType", getFloatKey("personType"));
  81. userEntity.setGuiInt(_overlayHandle, "DisguiseActive", 1);
  82. }
  83.  
  84. void playertools_disguise::undisguise(entity userEntity)
  85. {
  86. // Deactivate the disguise
  87. if(!active)
  88. return;
  89. active = false;
  90.  
  91. // Changing the head is currently disabled due to bug #6326, https://bugs.thedarkmod.com/view.php?id=6326
  92. //entity head = userEntity.getHead();
  93. //head.setModel(player_head_model);
  94. //head.setSkin(player_head_skin);
  95. userEntity.setTeam(player_team);
  96. userEntity.setKey("rank", player_rank);
  97. userEntity.setKey("personGender", player_gender);
  98. userEntity.setKey("personType", player_type);
  99. userEntity.setGuiInt(_overlayHandle, "DisguiseActive", 0);
  100. }
  101.  
  102. void playertools_disguise::setdefault(entity userEntity)
  103. {
  104. // Remember the default player properties
  105. entity head = userEntity.getHead();
  106. player_head_model = head.getKey("model");
  107. player_head_skin = head.getKey("skin");
  108. player_team = userEntity.getTeam();
  109. player_rank = userEntity.getFloatKey("rank");
  110. player_gender = userEntity.getFloatKey("personGender");
  111. player_type = userEntity.getFloatKey("personType");
  112. }
  113.  
  114. void playertools_disguise::inventoryUse(entity userEntity, entity frobbedEntity, float buttonState)
  115. {
  116. // To prevent allowing multiple disguises simultaneously, only wear if no disguise is set and remove if matching disguise is set
  117. if(userEntity.getKey("disguise") == "")
  118. {
  119. // Wear the item
  120. strength = 0;
  121. setdefault(userEntity);
  122. _updateThread = thread update(userEntity);
  123. _overlayHandle = userEntity.createOverlay(getKey("gui"), 0);
  124. userEntity.setGuiString(_overlayHandle, "DisguiseOverlay", getKey("overlay"));
  125. userEntity.setGuiString(_overlayHandle, "DisguiseIcon", getKey("inv_icon"));
  126. userEntity.setGuiString(_overlayHandle, "DisguiseText", getKey("inv_name"));
  127. userEntity.setHinderance("disguise", getFloatKey("speed_move"), 1);
  128. userEntity.setTurnHinderance("disguise", getFloatKey("speed_turn"), 1);
  129. userEntity.startSoundShader(getKey("snd_wear"), SND_CHANNEL_ANY);
  130. userEntity.setKey("disguise", getKey("inv_name"));
  131. sys.fadeIn('0 0 0', 0.5);
  132. }
  133. else if(userEntity.getKey("disguise") == getKey("inv_name"))
  134. {
  135. // Take off the item
  136. sys.terminate(_updateThread);
  137. userEntity.destroyOverlay(_overlayHandle);
  138. userEntity.setHinderance("disguise", 1, 1);
  139. userEntity.setTurnHinderance("disguise", 1, 1);
  140. userEntity.startSoundShader(getKey("snd_remove"), SND_CHANNEL_ANY);
  141. userEntity.setKey("disguise", "");
  142. sys.fadeIn('0 0 0', 0.5);
  143. undisguise(userEntity);
  144. }
  145. }
  146.  
  147. #endif //__DISGUISE__
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement