Guest User

_collectibles.gsc

a guest
Jan 21st, 2016
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 KB | None | 0 0
  1. #include common_scripts\utility;
  2. #include maps\_utility;
  3. #include maps\_hud_util;
  4. #include maps\_collectibles_game;
  5.  
  6. main()
  7. {
  8. precachestring( &"SCRIPT_COLLECTIBLE_OF_THIRTEEN" );
  9. precachestring( &"SCRIPT_COLLECTIBLE_STICKS_AND_STONES_UNLOCK" );
  10. precachestring( &"SCRIPT_COLLECTIBLE_VAMPIRE_UNLOCK" );
  11. precachestring( &"SCRIPT_COLLECTIBLE_BERSERKER_UNLOCK" );
  12. precachestring( &"SCRIPT_COLLECTIBLE_ZOMBIE_UNLOCK" );
  13. precachestring( &"SCRIPT_COLLECTIBLE_PAINTBALL_UNLOCK" );
  14. precachestring( &"SCRIPT_COLLECTIBLE_DIRTY_HARRY_UNLOCK" );
  15. precachestring( &"SCRIPT_COLLECTIBLE_MORPHINE_SHOT_UNLOCK" );
  16. precachestring( &"SCRIPT_COLLECTIBLE_THUNDER_UNLOCK" );
  17. precachestring( &"SCRIPT_COLLECTIBLE_FLAK_JACKET_UNLOCK" );
  18. precachestring( &"SCRIPT_COLLECTIBLE_HARDCORE_UNLOCK" );
  19. precachestring( &"SCRIPT_COLLECTIBLE_BODY_ARMOR_UNLOCK" );
  20. precachestring( &"SCRIPT_COLLECTIBLE_HARD_HEADED_UNLOCK" );
  21. precachestring( &"SCRIPT_COLLECTIBLE_COLD_DEAD_HANDS_UNLOCK" );
  22. precachestring( &"SCRIPT_COLLECTIBLE_USAGE" );
  23.  
  24. level._effect["thunder"] = loadfx("explosions/default_explosion");
  25.  
  26. level.collectible_dvar = "cheat_items_set1";
  27. level.host_options_dvar = "ui_hostOptions";
  28. level.host_options_enabled_dvar = "ui_hostOptionsEnabled";
  29.  
  30. level.collectible_table = "maps/_collectible_items.csv";
  31. level.collectible_table_unlock_col = 0;
  32. level.collectible_table_key_col = 1;
  33.  
  34. level.collectible_unlocks["collectible_sticksstones"] = 0;
  35. level.collectible_unlocks["collectible_vampire"] = 1;
  36. level.collectible_unlocks["collectible_berserker"] = 2;
  37. level.collectible_unlocks["collectible_zombie"] = 3;
  38. level.collectible_unlocks["collectible_paintball"] = 4;
  39. level.collectible_unlocks["collectible_dirtyharry"] = 5;
  40. level.collectible_unlocks["collectible_morphine"] = 6;
  41. level.collectible_unlocks["collectible_thunder"] = 7;
  42. level.collectible_unlocks["collectible_flak_jacket"] = 8;
  43. level.collectible_unlocks["collectible_hardcore"] = 9;
  44. level.collectible_unlocks["collectible_body_armor"] = 10;
  45. level.collectible_unlocks["collectible_hard_headed"] = 11;
  46. level.collectible_unlocks["collectible_dead_hands"] = 12;
  47.  
  48. level.collectible_save_restored = false;
  49. level.collectibles = collectible_init();
  50.  
  51. level thread onPlayerConnect();
  52.  
  53. setDvar( "ui_level_cheatpoints", level.collectibles.size );
  54.  
  55. for ( i = 0; i < level.collectibles.size; i++ )
  56. {
  57. level.collectibles[i] thread collectible_wait_for_pickup();
  58. }
  59. }
  60.  
  61.  
  62. onPlayerConnect()
  63. {
  64. for( ;; )
  65. {
  66. level waittill( "connecting", player );
  67. player thread onPlayerSpawned();
  68. }
  69. }
  70.  
  71.  
  72. onPlayerSpawned()
  73. {
  74. self endon( "disconnect" );
  75.  
  76. for( ;; )
  77. {
  78. self waittill( "spawned_player" );
  79.  
  80. if( IsDefined( self.player_inited ) && self.player_inited )
  81. {
  82. continue;
  83. }
  84.  
  85. host_options_init();
  86.  
  87. /#
  88. self thread host_options_development();
  89. #/
  90. }
  91. }
  92.  
  93.  
  94. onSaveRestored()
  95. {
  96. level notify ( "collectible_save_restored" );
  97. level.collectible_save_restored = true;
  98.  
  99. level.collectibles = collectible_init();
  100.  
  101. setDvar( "ui_level_cheatpoints", level.collectibles.size );
  102.  
  103. for ( i = 0; i < level.collectibles.size; i++ )
  104. {
  105. level.collectibles[i] thread collectible_wait_for_pickup();
  106. }
  107. }
  108.  
  109.  
  110. collectible_init()
  111. {
  112. collectibles = [];
  113. items = 0;
  114.  
  115. map_collectibles = getentarray ( "collectible", "targetname" );
  116.  
  117. for ( i = 0; i < map_collectibles.size; i++ )
  118. {
  119. map_collectibles[i].item = getent( map_collectibles[i].target, "targetname" );
  120. map_collectibles[i].unlock = collectible_get_unlock( map_collectibles[i].item );
  121.  
  122. if ( collectible_has_been_found( map_collectibles[i].unlock ) )
  123. {
  124. collectible_remove_found( map_collectibles[i] );
  125. continue;
  126. }
  127.  
  128. collectibles[items] = map_collectibles[i];
  129. items++;
  130. }
  131.  
  132. if ( !level.collectible_save_restored )
  133. RegisterClientSys( "collectibles" );
  134.  
  135. return collectibles;
  136. }
  137.  
  138.  
  139. host_options_init()
  140. {
  141. host_options = GetDvarInt( level.host_options_dvar );
  142. host_options_enabled = GetDvarInt( level.host_options_enabled_dvar );
  143.  
  144. if ( !IsDefined( host_options ) || host_options == 0 || host_options_enabled == 0 || level.script == "see2" )
  145. return;
  146.  
  147. keys = GetArrayKeys( level.collectible_unlocks );
  148. keys = array_reverse( keys );
  149.  
  150. for ( i = 0; i < level.collectible_unlocks.size; i++ )
  151. {
  152. if ( ( host_options & (1 << i) ) != 0 )
  153. {
  154. SetCollectible( keys[i] );
  155.  
  156. switch ( keys[i] )
  157. {
  158. case "collectible_vampire":
  159. self thread vampire_main();
  160. clientNotify( "vampire_start" );
  161. break;
  162.  
  163. case "collectible_berserker":
  164. self thread berserker_main();
  165. break;
  166.  
  167. case "collectible_sticksstones":
  168. self thread sticksstones_main();
  169. break;
  170.  
  171. case "collectible_hardcore":
  172. SetDvar( "player_lastStandBleedoutTime", "15" );
  173. break;
  174. }
  175. }
  176. }
  177. }
  178.  
  179.  
  180. has_collectible( collectible_name )
  181. {
  182. // MikeD (8/9/2008): Make sure the collectibles are defined... Fixes issues where an AI dies before _load is even ran.
  183. if( !IsDefined( level.collectible_unlocks ) )
  184. {
  185. return false;
  186. }
  187.  
  188. value = collectible_get_unlock_value( collectible_name );
  189. return HasCollectible( value );
  190. }
  191.  
  192.  
  193. collectible_remove_found( collectible_item )
  194. {
  195. collectible_item.item hide();
  196. collectible_item.item notsolid();
  197.  
  198. collectible_item trigger_off();
  199. collectible_item delete();
  200. }
  201.  
  202.  
  203. collectible_get_unlock_value( collectible_name )
  204. {
  205. assert( IsDefined( collectible_name ) );
  206.  
  207. if ( !IsDefined( level.collectible_unlocks[ collectible_name ] ) )
  208. {
  209. assertmsg( "Unknown collectible name: '" + collectible_name + "'" );
  210. }
  211.  
  212. collectible_value = level.collectible_unlocks[ collectible_name ];
  213. return collectible_value;
  214. }
  215.  
  216.  
  217. collectible_has_been_found( collectible_name )
  218. {
  219. if ( IsCoopEPD() )
  220. return true;
  221.  
  222. if ( coopGame() && collectible_coop_found() )
  223. return true;
  224.  
  225. if ( coopGame() )
  226. return false;
  227.  
  228. unlocks = GetDvarInt( level.collectible_dvar );
  229. collectible_value = collectible_get_unlock_value( collectible_name );
  230.  
  231. return ( ( unlocks & (1 << collectible_value) ) != 0 );
  232. }
  233.  
  234.  
  235. collectible_coop_found()
  236. {
  237. // returns true if this collectible has been found in a coop game, needed for checkpoint restores
  238. if ( level.collectible_save_restored == true && GetDvar( "coop_collectibles_found" ) == level.script )
  239. return true;
  240.  
  241. return false;
  242. }
  243.  
  244.  
  245. collectible_aquire_unlock( collectible_name, player )
  246. {
  247. collectible_value = collectible_get_unlock_value( collectible_name );
  248. SetClientSysState( "collectibles", collectible_value );
  249.  
  250. SetDvar( "coop_collectibles_found", level.script );
  251.  
  252. arcademode_assignpoints( "arcademode_score_generic500", player );
  253. }
  254.  
  255.  
  256. collectible_get_unlock( item )
  257. {
  258. origin_string = item.origin[0] + ", " + item.origin[1] + ", " + item.origin[2];
  259. key = level.script + ", " + origin_string;
  260.  
  261. unlock = TableLookup( level.collectible_table, level.collectible_table_key_col, key, level.collectible_table_unlock_col );
  262.  
  263. if ( !IsDefined( unlock ) || unlock == "" )
  264. {
  265. assertmsg( "Add the map name and origin of this collectible item ( " + origin_string + " ) to " + level.collectible_table + " file" );
  266. }
  267.  
  268. return unlock;
  269. }
  270.  
  271. collectible_get_unlock_message( unlock )
  272. {
  273. string = "";
  274.  
  275. switch( unlock )
  276. {
  277. case "collectible_sticksstones":
  278. string = &"SCRIPT_COLLECTIBLE_STICKS_AND_STONES_UNLOCK";
  279. break;
  280. case "collectible_vampire":
  281. string = &"SCRIPT_COLLECTIBLE_VAMPIRE_UNLOCK";
  282. break;
  283. case "collectible_berserker":
  284. string = &"SCRIPT_COLLECTIBLE_BERSERKER_UNLOCK";
  285. break;
  286. case "collectible_zombie":
  287. string = &"SCRIPT_COLLECTIBLE_ZOMBIE_UNLOCK";
  288. break;
  289. case "collectible_paintball":
  290. string = &"SCRIPT_COLLECTIBLE_PAINTBALL_UNLOCK";
  291. break;
  292. case "collectible_dirtyharry":
  293. string = &"SCRIPT_COLLECTIBLE_DIRTY_HARRY_UNLOCK";
  294. break;
  295. case "collectible_morphine":
  296. string = &"SCRIPT_COLLECTIBLE_MORPHINE_SHOT_UNLOCK";
  297. break;
  298. case "collectible_thunder":
  299. string = &"SCRIPT_COLLECTIBLE_THUNDER_UNLOCK";
  300. break;
  301. case "collectible_flak_jacket":
  302. string = &"SCRIPT_COLLECTIBLE_FLAK_JACKET_UNLOCK";
  303. break;
  304. case "collectible_hardcore":
  305. string = &"SCRIPT_COLLECTIBLE_HARDCORE_UNLOCK";
  306. break;
  307. case "collectible_body_armor":
  308. string = &"SCRIPT_COLLECTIBLE_BODY_ARMOR_UNLOCK";
  309. break;
  310. case "collectible_hard_headed":
  311. string = &"SCRIPT_COLLECTIBLE_HARD_HEADED_UNLOCK";
  312. break;
  313. case "collectible_dead_hands":
  314. string = &"SCRIPT_COLLECTIBLE_COLD_DEAD_HANDS_UNLOCK";
  315. break;
  316. default:
  317. assertmsg( "Collectible not found " + unlock );
  318. }
  319. return string;
  320. }
  321.  
  322.  
  323. collectible_wait_for_pickup()
  324. {
  325. level endon ( "collectible_save_restored" );
  326.  
  327. self setHintString ( &"SCRIPT_COLLECTIBLE_PICKUP" );
  328. self usetriggerrequirelookat();
  329.  
  330. self waittill( "trigger", player );
  331.  
  332. // this dvar is set in the client script
  333. if ( collectible_has_been_found( self.unlock ) )
  334. {
  335. num_found = GetDvarInt( "cheat_points" );
  336. }
  337. else
  338. {
  339. num_found = GetDvarInt( "cheat_points" ) + 1;
  340. }
  341.  
  342. if ( num_found > level.collectible_unlocks.size )
  343. {
  344. num_found = level.collectible_unlocks.size;
  345. }
  346.  
  347. collectible_aquire_unlock( self.unlock, player );
  348. collectible_remove_found( self );
  349.  
  350. player thread collectibleNotify( self.Unlock, num_found );
  351.  
  352. if ( CoopGame() )
  353. {
  354. // sends the message to all players who picked up the collectible
  355. CoopInfo( "msgcoop_collectible", player );
  356. }
  357. }
  358.  
  359. collectibleNotify( Unlock, num_found )
  360. {
  361. message = collectible_get_unlock_message( unlock );
  362.  
  363. notifyData = spawnStruct();
  364. notifyData.notifyText = num_found;
  365. notifyData.textLabel = &"SCRIPT_COLLECTIBLE_OF_THIRTEEN";
  366. notifyData.notifyText2 = message;
  367. notifyData.sound = undefined;
  368.  
  369. if ( !GetDvarInt( level.collectible_dvar ) )
  370. notifyData.notifyText3 = &"SCRIPT_COLLECTIBLE_USAGE";
  371.  
  372. if ( CoopGame() )
  373. {
  374. notifyData.notifyText = undefined;
  375. notifyData.textLabel = undefined;
  376. }
  377.  
  378. self maps\_hud_message::notifyMessage( notifyData );
  379. }
  380.  
  381.  
  382. // used to enable host options "on the fly" while playing the level
  383. host_options_development()
  384. {
  385. /#
  386. self endon( "disconnect" );
  387. self endon( "death" );
  388.  
  389. keys = GetArrayKeys( level.collectible_unlocks );
  390. keys = array_reverse( keys );
  391.  
  392. self.running_collectibles = [];
  393.  
  394. for ( ;; )
  395. {
  396. wait ( 1.0 );
  397.  
  398. host_options = GetDvarInt( level.host_options_dvar );
  399.  
  400. for ( i = 0; i < level.collectible_unlocks.size; i++ )
  401. {
  402. // assume if it's in the host options it's already running
  403. if ( ( host_options & (1 << i) ) != 0 )
  404. continue;
  405.  
  406. if ( HasCollectible( i ) && !IsDefined( self.running_collectibles[i] ) )
  407. {
  408. self.running_collectibles[i] = keys[i];
  409. iprintln( "Collectible Enabled: " + keys[i] );
  410.  
  411. switch ( keys[i] )
  412. {
  413. case "collectible_vampire":
  414. self thread vampire_main();
  415. clientNotify( "vampire_start" );
  416. break;
  417.  
  418. case "collectible_berserker":
  419. self thread berserker_main( true );
  420. break;
  421.  
  422. case "collectible_sticksstones":
  423. self thread sticksstones_main();
  424. break;
  425. }
  426. }
  427. else if ( !HasCollectible( i ) && IsDefined( self.running_collectibles[i] ) )
  428. {
  429. self.running_collectibles[i] = undefined;
  430. iprintln( "Collectible Disabled: " + keys[i] );
  431.  
  432. switch ( keys[i] )
  433. {
  434. case "collectible_vampire":
  435. self notify( "vampire_end" );
  436. break;
  437.  
  438. case "collectible_berserker":
  439. self notify( "berserker_end" );
  440. break;
  441.  
  442. case "collectible_sticksstones":
  443. self notify( "sticksstones_end" );
  444. break;
  445. }
  446. }
  447. }
  448. }
  449. #/
  450. }
Advertisement
Add Comment
Please, Sign In to add comment