Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.79 KB | None | 0 0
  1. #using scripts\codescripts\struct;
  2. #using scripts\shared\util_shared;
  3. #using scripts\shared\array_shared;
  4.  
  5. #insert scripts\zm\_zm_utility.gsh;
  6. #insert scripts\zm\_espi_minigames.gsh;
  7.  
  8. #using scripts\zm\_zm_utility;
  9.  
  10. #namespace espi_minigames;
  11.  
  12. #precache( "model", "p7_boat_life_preserver" );
  13. #precache( "model", "n_0" );
  14. #precache( "model", "n_1" );
  15. #precache( "model", "n_2" );
  16. #precache( "model", "n_3" );
  17. #precache( "model", "n_4" );
  18. #precache( "model", "n_5" );
  19. #precache( "model", "n_6" );
  20. #precache( "model", "n_7" );
  21. #precache( "model", "n_8" );
  22. #precache( "model", "n_9" );
  23.  
  24. function main()
  25. {
  26. level._minigames = [];
  27. add_minigame("firing_range", "fr_score", &firing_range_think, &firing_range_init);
  28. add_minigame("attack_tooth", "at_score", &attack_tooth_think, &attack_tooth_init);
  29. //add_minigame("water_gun", "wg_score", &water_gun_think, &water_gun_init);
  30. thread minigames();
  31. }
  32.  
  33. function add_minigame(name, score_ent, func, func_init)
  34. {
  35. minigame = SpawnStruct();
  36. minigame.name = name;
  37. minigame.score_ent = score_ent;
  38. minigame.func = func;
  39. minigame.func_init = func_init;
  40. minigame.record = 0;
  41. level._minigames[name] = minigame;
  42. }
  43.  
  44. function minigames()
  45. {
  46. keys = GetArrayKeys(level._minigames);
  47. foreach(key in keys)
  48. level._minigames[key] thread start_minigame();
  49. }
  50.  
  51. function start_minigame()
  52. {
  53. trigger = GetEnt(self.name + "_trig", "targetname");
  54. trigger endon("delete");
  55. trigger SetHintString("Press to start");
  56. thread show_score(0, false, self.score_ent);
  57. while(1)
  58. {
  59. if(IsDefined(self.func_init))
  60. self [[self.func_init]]();
  61. trigger waittill("trigger", player);
  62. if(!zm_utility::is_player_valid( player ))
  63. continue;
  64. if(!IsDefined(player._minigames_score))
  65. player._minigames_score = [];
  66. player._minigames_score[self.name] = 0;
  67. thread show_score(0, false, self.score_ent);
  68. trigger TriggerEnable(false);
  69. player teleport_set_ignoreme(true);
  70. player teleportToStartPos(self.name + "_tp_player");
  71. wait 0.1;
  72. player [[self.func]]();
  73. if(player._minigames_score[self.name] > self.record)
  74. {
  75. self.record = player._minigames_score[self.name];
  76. thread show_score(self.record, true, self.score_ent);
  77. wait 2;
  78. }
  79. wait 0.1;
  80. player unlink();
  81. trigger TriggerEnable(true);
  82. }
  83. }
  84.  
  85. function firing_range_init()
  86. {
  87. if(!IsDefined(self.sound_org))
  88. {
  89. orgs = struct::get_array( "s", "targetname" );
  90. org = (0, 0, 0);
  91. foreach(o in orgs)
  92. org += o.origin;
  93. org /= orgs.size;
  94. self.sound_org = org;
  95. self.model_gallery = util::spawn_model( "p7_boat_life_preserver", (0, 0, -1000), (0, 0, 0) );
  96. self.model_gallery.angle_init = stringToAngles(FIRING_RANGE_ANGLE_INIT);
  97. self.model_gallery.angle_end = stringToAngles(FIRING_RANGE_ANGLE_END);
  98. self.model_gallery hide();
  99. self.model_gallery SetCanDamage(true);
  100. }
  101. else
  102. self.model_gallery hide();
  103. }
  104.  
  105. function firing_range_think()
  106. {
  107. base = level._minigames["firing_range"];
  108. model = base.model_gallery;
  109. PlaySoundAtPosition("gallery_start", base.sound_org);
  110. orgs = struct::get_array( "s", "targetname" );
  111. order = [];
  112. for(i=0;i<FIRING_RANGE_NUM;i++)
  113. order[i] = orgs[randomint(orgs.size)];
  114. num = 0;
  115. targets = 0;
  116. while(num < FIRING_RANGE_NUM)
  117. {
  118. model notify("move_target");
  119. model.origin = order[num].origin;
  120. model.angles = model.angle_init;
  121. model show();
  122. PlaySoundAtPosition("gallery_blanco", model.origin);
  123. model RotateTo(model.angle_end, FIRING_RANGE_ROTATE_TIME);
  124. wait 0.1;
  125. model thread target_timeout();
  126. nt = model util::waittill_any_return("damage", "timeout");
  127. if(nt != "timeout" || !IsDefined(nt))
  128. {
  129. self._minigames_score[base.name]++;
  130. thread show_score(self._minigames_score[base.name], false, base.name);
  131. model RotateTo(model.angle_init, FIRING_RANGE_ROTATE_TIME/10);
  132. wait (FIRING_RANGE_ROTATE_TIME/10);
  133. }
  134. else
  135. {
  136. model RotateTo(model.angle_init, FIRING_RANGE_ROTATE_TIME/2);
  137. wait (FIRING_RANGE_ROTATE_TIME/2);
  138. }
  139. model hide();
  140. wait FIRING_RANGE_BETWEEN_TIME;
  141. num++;
  142. }
  143. }
  144.  
  145. function target_timeout()
  146. {
  147. self endon("damage");
  148. self endon("move_target");
  149. wait (FIRING_RANGE_ROTATE_TIME + FIRING_RANGE_TIMEOUT - 0.1);
  150. self notify("timeout");
  151. }
  152.  
  153. function attack_tooth_init()
  154. {
  155. teeth = GetEntArray("tooth", "targetname");
  156. foreach(tooth in teeth)
  157. {
  158. if(!IsDefined(tooth.real_origin))
  159. {
  160. tooth.real_origin = spawn("script_model", tooth.origin + (0, 0, ATTACK_TOOTH_Z));
  161. tooth.initial_angles = tooth.real_origin.angles;
  162. tooth.end_angles = stringToAngles(ATTACK_TOOTH_ANGLE_END);
  163. tooth LinkTo(tooth.real_origin);
  164. tooth.maxhealth = 100000;
  165. tooth.health = tooth.maxhealth;
  166. tooth SetCanDamage(true);
  167. }
  168. else
  169. {
  170. if(tooth.real_origin.angles != tooth.initial_angles)
  171. tooth.real_origin RotateTo(tooth.initial_angles, ATTACK_TOOTH_ROTATE_TIME/3);
  172. tooth.health = tooth.maxhealth;
  173. }
  174. }
  175. }
  176.  
  177. function attack_tooth_think()
  178. {
  179. self._minigames_score["attack_tooth"] = 0;
  180. teeth = GetEntArray("tooth", "targetname");
  181. trigger = GetEnt("attack_tooth_trig", "targetname");
  182. array::thread_all(teeth, &initGameAttackTooth, self, trigger);
  183. self thread AttackToothTries();
  184. self waittill("attack_tooth_end");
  185. }
  186.  
  187. function initGameAttackTooth(player, trig)
  188. {
  189. player endon("attack_tooth_end");
  190. while(1)
  191. {
  192. self waittill( "damage", amount, attacker, direction_vec, point, type, tagName, modelName, partName, weapon );
  193. if(attacker != player)
  194. continue;
  195. /*if(weapon != ATTACK_TOOTH_WEAPON)
  196. continue;*/
  197. player._at_impact = true;
  198. player._at_impact_time = GetTime();
  199. self.real_origin RotateTo(self.end_angles, ATTACK_TOOTH_ROTATE_TIME);
  200. iprintlnbold("golpeado");
  201. return;
  202. }
  203. }
  204.  
  205. function AttackToothTries()
  206. {
  207. self endon("attack_tooth_end");
  208. self._at_impact_time = 0;
  209. self._at_impact = false;
  210. tries = ATTACK_TOOTH_TRIES;
  211. total = GetEntArray("tooth", "targetname").size;
  212. while(1)
  213. {
  214. self waittill("grenade_fire", grenade, weapon);
  215. if( !self HasWeapon( weapon ) )
  216. {
  217. self GiveWeapon( weapon );
  218. self SetWeaponAmmoClip( weapon, 4 );
  219. }
  220. /*if(weapon != ATTACK_TOOTH_WEAPON)
  221. continue;*/
  222. wait 2.5;
  223. grenade delete();
  224. if(GetTime() - self._at_impact_time <= 2500 && self._at_impact)
  225. {
  226. self._minigames_score["attack_tooth"]++;
  227. thread show_score(self._minigames_score["attack_tooth"], false, "at_score");
  228. iprintlnbold("tocado con granada");
  229. }
  230. else
  231. {
  232. tries--;
  233. iprintlnbold("fallo con granada");
  234. }
  235. if(tries == 0)
  236. {
  237. self SetMiniGameScore("attack_tooth", self._minigames_score["attack_tooth"]);
  238. self notify("attack_tooth_end");
  239. }
  240. if(total == self._minigames_score["attack_tooth"])
  241. {
  242. self._minigames_score["attack_tooth"] = 0;
  243. self SetMiniGameScore("attack_tooth", total);
  244. self [[self.func_init]]();
  245. }
  246. self._at_impact_time = 0;
  247. self._at_impact = false;
  248. }
  249. }
  250.  
  251. function water_gun_init()
  252. {
  253.  
  254. }
  255.  
  256. function water_gun_think()
  257. {
  258.  
  259. }
  260.  
  261. function teleport_set_ignoreme( b_ignoreme )
  262. {
  263. //DEFAULT(self.teleport_ignore,false);
  264. if ( b_ignoreme != self.teleport_ignore )
  265. {
  266. self.teleport_ignore = b_ignoreme;
  267. if ( b_ignoreme )
  268. self zm_utility::increment_ignoreme();
  269. else
  270. self zm_utility::decrement_ignoreme();
  271. }
  272. }
  273.  
  274. function teleportToStartPos(name)
  275. {
  276. new_player_pos = struct::get(name, "targetname");
  277. if(!IsDefined(self._mgames_pos))
  278. {
  279. self._mgames_pos = util::spawn_model( "tag_origin", new_player_pos.origin, new_player_pos.angles );
  280. self._mgames_pos hide();
  281. }
  282. else
  283. {
  284. self._mgames_pos.origin = new_player_pos.origin;
  285. self._mgames_pos.angles = new_player_pos.angles;
  286. }
  287. self PlayerLinkToDelta(self._mgames_pos, "tag_origin", 0, 70,70,70,70);
  288. self.origin = self.origin;
  289. }
  290.  
  291. function stringToAngles(str, sep = " ")
  292. {
  293. a = strTok(str, sep);
  294. return (int(a[0]), int(a[1]), int(a[2]));
  295. }
  296.  
  297.  
  298. function show_score(score, record, name)
  299. {
  300. ns1 = struct::get(name + "1", "targetname");
  301. ns2 = struct::get(name + "2", "targetname");
  302. decenas = int(score/10);
  303. unidades = score - decenas*10;
  304. if(!IsDefined(ns1.decenas))
  305. {
  306. ns1.decenas = spawn("script_model", ns1.origin);
  307. ns1.decenas.angles = ns1.angles;
  308. }
  309. if(!IsDefined(ns2.unidades))
  310. {
  311. ns2.unidades = spawn("script_model", ns2.origin);
  312. ns2.unidades.angles = ns2.angles;
  313. }
  314.  
  315. ns1.decenas SetModel("n_"+decenas);
  316. ns2.unidades SetModel("n_"+unidades);
  317. if(record)
  318. {
  319. for(i=0;i<5;i++)
  320. {
  321. wait 0.33;
  322. ns1.decenas hide();
  323. ns2.unidades hide();
  324. wait 0.33;
  325. ns1.decenas show();
  326. ns2.unidades show();
  327. }
  328. }
  329. }
  330.  
  331. function SetMiniGameScore(name, score)
  332. {
  333. if(!IsDefined(self._minigames_total_score))
  334. self._minigames_total_score = [];
  335. if(!IsDefined(self._minigames_total_score[name]))
  336. self._minigames_total_score[name] = 0;
  337. self._minigames_total_score[name] += score;
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement