Advertisement
Guest User

Untitled

a guest
Sep 29th, 2010
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.78 KB | None | 0 0
  1. scriptPrintln( channel, msg )
  2. {
  3. setprintchannel( channel );
  4. println( msg );
  5. setprintchannel( "script" );
  6. }
  7.  
  8. debugPrintln( channel, msg )
  9. {
  10. setprintchannel( "script_debug" );
  11. println( msg );
  12. setprintchannel( "script" );
  13. }
  14.  
  15. draw_debug_line( start, end, timer )
  16. {
  17. for ( i = 0;i < timer * 20;i++ )
  18. {
  19. line( start, end, ( 1, 1, 0.5 ) );
  20. wait( 0.05 );
  21. }
  22. }
  23.  
  24. waittillend( msg )
  25. {
  26. self waittillmatch( msg, "end" );
  27. }
  28.  
  29. /*
  30. =============
  31. ///ScriptDocBegin
  32. "Name: noself_func( <func> , <parm1> , <parm2> , <parm3> , <parm4> )"
  33. "Summary: Runs a function from level.func, if it exists. Stand alone, doesn't run on anything. Useful for common scripts where a code function may not exist in one codebase or the other."
  34. "Module: Utility"
  35. "CallOn: An entity"
  36. "MandatoryArg: <func>: String reference to level.func array."
  37. "OptionalArg: <parm1>: "
  38. "OptionalArg: <parm2>: "
  39. "OptionalArg: <parm3>: "
  40. "OptionalArg: <parm4>: "
  41. "Example: noself_func( "setsaveddvar", "r_spotlightbrightness", maxVal );"
  42. "SPMP: both"
  43. ///ScriptDocEnd
  44. =============
  45. */
  46. noself_func( func, parm1, parm2, parm3, parm4 )
  47. {
  48. if ( !isdefined( level.func ) )
  49. return;
  50. if ( !isdefined( level.func[ func ] ) )
  51. return;
  52.  
  53. if ( !isdefined( parm1 ) )
  54. {
  55. call [[ level.func[ func ] ]]();
  56. return;
  57. }
  58.  
  59. if ( !isdefined( parm2 ) )
  60. {
  61. call [[ level.func[ func ] ]]( parm1 );
  62. return;
  63. }
  64. if ( !isdefined( parm3 ) )
  65. {
  66. call [[ level.func[ func ] ]]( parm1, parm2 );
  67. return;
  68. }
  69. if ( !isdefined( parm4 ) )
  70. {
  71. call [[ level.func[ func ] ]]( parm1, parm2, parm3 );
  72. return;
  73. }
  74.  
  75. call [[ level.func[ func ] ]]( parm1, parm2, parm3, parm4 );
  76. }
  77.  
  78. /*
  79. =============
  80. ///ScriptDocBegin
  81. "Name: self_func( <func> , <parm1> , <parm2> , <parm3> , <parm4> )"
  82. "Summary: Runs a function from level.func, if it exists. Runs on whatever calls it. Useful for common scripts where a code function may not exist in one codebase or the other."
  83. "Module: Utility"
  84. "CallOn: An entity"
  85. "MandatoryArg: <func>: String reference to level.func array."
  86. "OptionalArg: <parm1>: "
  87. "OptionalArg: <parm2>: "
  88. "OptionalArg: <parm3>: "
  89. "OptionalArg: <parm4>: "
  90. "Example: level.player self_func( "some_player_function", 1, 2 );"
  91. "SPMP: both"
  92. ///ScriptDocEnd
  93. =============
  94. */
  95. self_func( func, parm1, parm2, parm3, parm4 )
  96. {
  97. if ( !isdefined( level.func[ func ] ) )
  98. return;
  99.  
  100. if ( !isdefined( parm1 ) )
  101. {
  102. self call [[ level.func[ func ] ]]();
  103. return;
  104. }
  105.  
  106. if ( !isdefined( parm2 ) )
  107. {
  108. self call [[ level.func[ func ] ]]( parm1 );
  109. return;
  110. }
  111. if ( !isdefined( parm3 ) )
  112. {
  113. self call [[ level.func[ func ] ]]( parm1, parm2 );
  114. return;
  115. }
  116. if ( !isdefined( parm4 ) )
  117. {
  118. self call [[ level.func[ func ] ]]( parm1, parm2, parm3 );
  119. return;
  120. }
  121.  
  122. self call [[ level.func[ func ] ]]( parm1, parm2, parm3, parm4 );
  123. }
  124.  
  125. /*
  126. =============
  127. ///ScriptDocBegin
  128. "Name: randomvector( <num> )"
  129. "Summary: returns a random vector centered on <num>"
  130. "Module: Vector"
  131. "CallOn: Level"
  132. "MandatoryArg: <num>: "
  133. "Example: direction = randomvector( 1 )"
  134. "SPMP: both"
  135. ///ScriptDocEnd
  136. =============
  137. */
  138. randomvector( num )
  139. {
  140. return( randomfloat( num ) - num * 0.5, randomfloat( num ) - num * 0.5, randomfloat( num ) - num * 0.5 );
  141. }
  142.  
  143. /*
  144. =============
  145. ///ScriptDocBegin
  146. "Name: randomvectorrange( <num_min>, <num_max> )"
  147. "Summary: returns a random vector centered between <num_min> and <num_max>"
  148. "Module: Vector"
  149. "CallOn: Level"
  150. "MandatoryArg: <num_min>: "
  151. "MandatoryArg: <num_max>: "
  152. "Example: direction = randomvectorrange( 5, 10 )"
  153. "SPMP: both"
  154. ///ScriptDocEnd
  155. =============
  156. */
  157. randomvectorrange( num_min, num_max )
  158. {
  159. assert( isdefined( num_min ) );
  160. assert( isdefined( num_max ) );
  161.  
  162. x = randomfloatrange( num_min, num_max );
  163. if ( randomint( 2 ) == 0 )
  164. x *= -1;
  165.  
  166. y = randomfloatrange( num_min, num_max );
  167. if ( randomint( 2 ) == 0 )
  168. y *= -1;
  169.  
  170. z = randomfloatrange( num_min, num_max );
  171. if ( randomint( 2 ) == 0 )
  172. z *= -1;
  173.  
  174. return( x, y, z );
  175. }
  176.  
  177. angle_dif ( oldangle, newangle )
  178. {
  179. // returns the difference between two yaws
  180. if ( oldangle == newangle )
  181. return 0;
  182.  
  183. while ( newangle > 360 )
  184. newangle -= 360;
  185.  
  186. while ( newangle < 0 )
  187. newangle += 360;
  188.  
  189. while ( oldangle > 360 )
  190. oldangle -= 360;
  191.  
  192. while ( oldangle < 0 )
  193. oldangle += 360;
  194.  
  195. olddif = undefined;
  196. newdif = undefined;
  197.  
  198. if ( newangle > 180 )
  199. newdif = 360 - newangle;
  200. else
  201. newdif = newangle;
  202.  
  203. if ( oldangle > 180 )
  204. olddif = 360 - oldangle;
  205. else
  206. olddif = oldangle;
  207.  
  208. outerdif = newdif + olddif;
  209. innerdif = 0;
  210.  
  211. if ( newangle > oldangle )
  212. innerdif = newangle - oldangle;
  213. else
  214. innerdif = oldangle - newangle;
  215.  
  216. if ( innerdif < outerdif )
  217. return innerdif;
  218. else
  219. return outerdif;
  220. }
  221.  
  222.  
  223. sign( x )
  224. {
  225. if ( x >= 0 )
  226. return 1;
  227. return - 1;
  228. }
  229.  
  230.  
  231. track( spot_to_track )
  232. {
  233. if ( isdefined( self.current_target ) )
  234. {
  235. if ( spot_to_track == self.current_target )
  236. return;
  237. }
  238. self.current_target = spot_to_track;
  239. }
  240.  
  241. get_enemy_team( team )
  242. {
  243. assertEx( team != "neutral", "Team must be allies or axis" );
  244.  
  245. teams = [];
  246. teams[ "axis" ] = "allies";
  247. teams[ "allies" ] = "axis";
  248.  
  249. return teams[ team ];
  250. }
  251.  
  252.  
  253. clear_exception( type )
  254. {
  255. assert( isdefined( self.exception[ type ] ) );
  256. self.exception[ type ] = anim.defaultException;
  257. }
  258.  
  259. set_exception( type, func )
  260. {
  261. assert( isdefined( self.exception[ type ] ) );
  262. self.exception[ type ] = func;
  263. }
  264.  
  265. set_all_exceptions( exceptionFunc )
  266. {
  267. keys = getArrayKeys( self.exception );
  268. for ( i = 0; i < keys.size; i++ )
  269. {
  270. self.exception[ keys[ i ] ] = exceptionFunc;
  271. }
  272. }
  273.  
  274. /*
  275. =============
  276. ///ScriptDocBegin
  277. "Name: cointoss()"
  278. "Summary: 50/50 returns true"
  279. "Module: Utility"
  280. "CallOn: Level"
  281. "Example: if(cointoss())"
  282. "SPMP: both"
  283. ///ScriptDocEnd
  284. =============
  285. */
  286. cointoss()
  287. {
  288. return randomint( 100 ) >= 50 ;
  289. }
  290.  
  291.  
  292. choose_from_weighted_array( values, weights )
  293. {
  294. assert( values.size == weights.size );
  295.  
  296. randomval = randomint( weights[ weights.size - 1 ] + 1 );
  297.  
  298. for ( i = 0; i < weights.size; i++ )
  299. {
  300. if ( randomval <= weights[i] )
  301. return values[i];
  302. }
  303. }
  304.  
  305. get_cumulative_weights( weights )
  306. {
  307. cumulative_weights = [];
  308.  
  309. sum = 0;
  310. for ( i = 0; i < weights.size; i++ )
  311. {
  312. sum += weights[i];
  313. cumulative_weights[i] = sum;
  314. }
  315.  
  316. return cumulative_weights;
  317. }
  318.  
  319.  
  320. waittill_string( msg, ent )
  321. {
  322. if ( msg != "death" )
  323. self endon( "death" );
  324.  
  325. ent endon( "die" );
  326. self waittill( msg );
  327. ent notify( "returned", msg );
  328. }
  329.  
  330.  
  331. waittill_multiple( string1, string2, string3, string4, string5 )
  332. {
  333. self endon( "death" );
  334. ent = spawnstruct();
  335. ent.threads = 0;
  336.  
  337. if ( isdefined( string1 ) )
  338. {
  339. self thread waittill_string( string1, ent );
  340. ent.threads++;
  341. }
  342. if ( isdefined( string2 ) )
  343. {
  344. self thread waittill_string( string2, ent );
  345. ent.threads++;
  346. }
  347. if ( isdefined( string3 ) )
  348. {
  349. self thread waittill_string( string3, ent );
  350. ent.threads++;
  351. }
  352. if ( isdefined( string4 ) )
  353. {
  354. self thread waittill_string( string4, ent );
  355. ent.threads++;
  356. }
  357. if ( isdefined( string5 ) )
  358. {
  359. self thread waittill_string( string5, ent );
  360. ent.threads++;
  361. }
  362.  
  363. while ( ent.threads )
  364. {
  365. ent waittill( "returned" );
  366. ent.threads--;
  367. }
  368.  
  369. ent notify( "die" );
  370. }
  371.  
  372. waittill_multiple_ents( ent1, string1, ent2, string2, ent3, string3, ent4, string4 )
  373. {
  374. self endon( "death" );
  375. ent = spawnstruct();
  376. ent.threads = 0;
  377.  
  378. if ( isdefined( ent1 ) )
  379. {
  380. assert( isdefined( string1 ) );
  381. ent1 thread waittill_string( string1, ent );
  382. ent.threads++;
  383. }
  384. if ( isdefined( ent2 ) )
  385. {
  386. assert( isdefined( string2 ) );
  387. ent2 thread waittill_string( string2, ent );
  388. ent.threads++;
  389. }
  390. if ( isdefined( ent3 ) )
  391. {
  392. assert( isdefined( string3 ) );
  393. ent3 thread waittill_string( string3, ent );
  394. ent.threads++;
  395. }
  396. if ( isdefined( ent4 ) )
  397. {
  398. assert( isdefined( string4 ) );
  399. ent4 thread waittill_string( string4, ent );
  400. ent.threads++;
  401. }
  402.  
  403. while ( ent.threads )
  404. {
  405. ent waittill( "returned" );
  406. ent.threads--;
  407. }
  408.  
  409. ent notify( "die" );
  410. }
  411.  
  412. /*
  413. =============
  414. ///ScriptDocBegin
  415. "Name: waittill_any_return( <string1> , <string2> , <string3> , <string4> , <string5> )"
  416. "Summary: Waits for any of several messages then returns what it was."
  417. "Module: Utility"
  418. "MandatoryArg: <string1>: A string to wait on"
  419. "MandatoryArg: <string2>: A string to wait on"
  420. "OptionalArg: <string3>: A string to wait on"
  421. "OptionalArg: <string4>: A string to wait on"
  422. "OptionalArg: <string5>: A string to wait on"
  423. "Example: msg = level.player waittill_any_return( "weapon_fired", "player_flash", "player_frag" );"
  424. "SPMP: singleplayer"
  425. ///ScriptDocEnd
  426. =============
  427. */
  428. waittill_any_return( string1, string2, string3, string4, string5 )
  429. {
  430. if ( ( !isdefined( string1 ) || string1 != "death" ) &&
  431. ( !isdefined( string2 ) || string2 != "death" ) &&
  432. ( !isdefined( string3 ) || string3 != "death" ) &&
  433. ( !isdefined( string4 ) || string4 != "death" ) &&
  434. ( !isdefined( string5 ) || string5 != "death" ) )
  435. self endon( "death" );
  436.  
  437. ent = spawnstruct();
  438.  
  439. if ( isdefined( string1 ) )
  440. self thread waittill_string( string1, ent );
  441.  
  442. if ( isdefined( string2 ) )
  443. self thread waittill_string( string2, ent );
  444.  
  445. if ( isdefined( string3 ) )
  446. self thread waittill_string( string3, ent );
  447.  
  448. if ( isdefined( string4 ) )
  449. self thread waittill_string( string4, ent );
  450.  
  451. if ( isdefined( string5 ) )
  452. self thread waittill_string( string5, ent );
  453.  
  454. ent waittill( "returned", msg );
  455. ent notify( "die" );
  456. return msg;
  457. }
  458.  
  459. /*
  460. =============
  461. ///ScriptDocBegin
  462. "Name: waittill_any_timeout( <timeOut> , <string1> , <string2> , <string3> , <string4> , <string5> )"
  463. "Summary: "
  464. "Module: Entity"
  465. "CallOn: An entity"
  466. "MandatoryArg: <param1>: "
  467. "OptionalArg: <param2>: "
  468. "Example: "
  469. "SPMP: both"
  470. ///ScriptDocEnd
  471. =============
  472. */
  473. waittill_any_timeout( timeOut, string1, string2, string3, string4, string5 )
  474. {
  475. if ( ( !isdefined( string1 ) || string1 != "death" ) &&
  476. ( !isdefined( string2 ) || string2 != "death" ) &&
  477. ( !isdefined( string3 ) || string3 != "death" ) &&
  478. ( !isdefined( string4 ) || string4 != "death" ) &&
  479. ( !isdefined( string5 ) || string5 != "death" ) )
  480. self endon( "death" );
  481.  
  482. ent = spawnstruct();
  483.  
  484. if ( isdefined( string1 ) )
  485. self thread waittill_string( string1, ent );
  486.  
  487. if ( isdefined( string2 ) )
  488. self thread waittill_string( string2, ent );
  489.  
  490. if ( isdefined( string3 ) )
  491. self thread waittill_string( string3, ent );
  492.  
  493. if ( isdefined( string4 ) )
  494. self thread waittill_string( string4, ent );
  495.  
  496. if ( isdefined( string5 ) )
  497. self thread waittill_string( string5, ent );
  498.  
  499. ent thread _timeout( timeOut );
  500.  
  501. ent waittill( "returned", msg );
  502. ent notify( "die" );
  503. return msg;
  504. }
  505.  
  506.  
  507. _timeout( delay )
  508. {
  509. self endon( "die" );
  510.  
  511. wait( delay );
  512. self notify( "returned", "timeout" );
  513. }
  514.  
  515.  
  516. /*
  517. =============
  518. ///ScriptDocBegin
  519. "Name: waittill_any( <string1> , <string2> , <string3> , <string4> , <string5> , <string6> , <string7> , <string8> )"
  520. "Summary: "
  521. "Module: Entity"
  522. "CallOn: An entity"
  523. "MandatoryArg: <string1>: a notify on which the entity should wait"
  524. "OptionalArg: <string2> - <string8>: optional other notifies to wait for"
  525. "Example: "
  526. "SPMP: both"
  527. ///ScriptDocEnd
  528. =============
  529. */
  530. waittill_any( string1, string2, string3, string4, string5, string6, string7, string8 )
  531. {
  532. assert( isdefined( string1 ) );
  533.  
  534. if ( isdefined( string2 ) )
  535. self endon( string2 );
  536.  
  537. if ( isdefined( string3 ) )
  538. self endon( string3 );
  539.  
  540. if ( isdefined( string4 ) )
  541. self endon( string4 );
  542.  
  543. if ( isdefined( string5 ) )
  544. self endon( string5 );
  545.  
  546. if ( isdefined( string6 ) )
  547. self endon( string6 );
  548.  
  549. if ( isdefined( string7 ) )
  550. self endon( string7 );
  551.  
  552. if ( isdefined( string8 ) )
  553. self endon( string8 );
  554.  
  555. self waittill( string1 );
  556. }
  557.  
  558. waittill_any_ents( ent1, string1, ent2, string2, ent3, string3, ent4, string4, ent5, string5, ent6, string6, ent7, string7 )
  559. {
  560. assert( isdefined( ent1 ) );
  561. assert( isdefined( string1 ) );
  562.  
  563. if ( ( isdefined( ent2 ) ) && ( isdefined( string2 ) ) )
  564. ent2 endon( string2 );
  565.  
  566. if ( ( isdefined( ent3 ) ) && ( isdefined( string3 ) ) )
  567. ent3 endon( string3 );
  568.  
  569. if ( ( isdefined( ent4 ) ) && ( isdefined( string4 ) ) )
  570. ent4 endon( string4 );
  571.  
  572. if ( ( isdefined( ent5 ) ) && ( isdefined( string5 ) ) )
  573. ent5 endon( string5 );
  574.  
  575. if ( ( isdefined( ent6 ) ) && ( isdefined( string6 ) ) )
  576. ent6 endon( string6 );
  577.  
  578. if ( ( isdefined( ent7 ) ) && ( isdefined( string7 ) ) )
  579. ent7 endon( string7 );
  580.  
  581. ent1 waittill( string1 );
  582. }
  583.  
  584. /*
  585. =============
  586. ///ScriptDocBegin
  587. "Name: isFlashed()"
  588. "Summary: Returns true if the player or an AI is flashed"
  589. "Module: Utility"
  590. "CallOn: An AI"
  591. "Example: flashed = level.price isflashed();"
  592. "SPMP: both"
  593. ///ScriptDocEnd
  594. =============
  595. */
  596. isFlashed()
  597. {
  598. if ( !isdefined( self.flashEndTime ) )
  599. return false;
  600.  
  601. return gettime() < self.flashEndTime;
  602. }
  603.  
  604. /*
  605. =============
  606. ///ScriptDocBegin
  607. "Name: flag_exist( <flagname> )"
  608. "Summary: checks to see if a flag exists"
  609. "Module: Flag"
  610. "MandatoryArg: <flagname> : name of the flag to check"
  611. "Example: if( flag_exist( "hq_cleared" ) );"
  612. "SPMP: both"
  613. ///ScriptDocEnd
  614. =============
  615. */
  616. flag_exist( message )
  617. {
  618. return isdefined( level.flag[ message ] );
  619. }
  620.  
  621. /*
  622. =============
  623. ///ScriptDocBegin
  624. "Name: flag( <flagname>, <entity> )"
  625. "Summary: Checks if the flag is set. Returns true or false."
  626. "Module: Flag"
  627. "MandatoryArg: <flagname> : name of the flag to check"
  628. "OptionalArg: <entity> : You can check the flag settings for a specific entity by passing the entity"
  629. "Example: if ( flag( "hq_cleared" ) )"
  630. "SPMP: both"
  631. ///ScriptDocEnd
  632. =============
  633. */
  634.  
  635. flag( message )
  636. {
  637. assertEx( isdefined( message ), "Tried to check flag but the flag was not defined." );
  638. assertEx( isdefined( level.flag[ message ] ), "Tried to check flag " + message + " but the flag was not initialized." );
  639.  
  640. return level.flag[ message ];
  641. }
  642.  
  643.  
  644. init_flags()
  645. {
  646. level.flag = [];
  647. level.flags_lock = [];
  648. level.generic_index = 0;
  649.  
  650. if ( !isdefined( level.sp_stat_tracking_func ) )
  651. level.sp_stat_tracking_func = ::empty_init_func;
  652.  
  653. level.flag_struct = spawnstruct();
  654. level.flag_struct assign_unique_id();
  655. }
  656.  
  657. /*
  658. =============
  659. ///ScriptDocBegin
  660. "Name: flag_init( <flagname> )"
  661. "Summary: Initialize a flag to be used. All flags must be initialized before using flag_set or flag_wait"
  662. "Module: Flag"
  663. "CallOn: "
  664. "MandatoryArg: <flagname> : name of the flag to create"
  665. "Example: flag_init( "hq_cleared" );"
  666. "SPMP: both"
  667. ///ScriptDocEnd
  668. =============
  669. */
  670. flag_init( message )
  671. {
  672. if ( !isDefined( level.flag ) )
  673. {
  674. init_flags();
  675. }
  676.  
  677. /#
  678. if ( isdefined( level.first_frame ) && level.first_frame == -1 )
  679. assertEx( !isDefined( level.flag[ message ] ), "Attempt to reinitialize existing message: " + message );
  680. #/
  681.  
  682. level.flag[ message ] = false;
  683. /#
  684. // lock check
  685. #/
  686. if ( !isdefined( level.trigger_flags ) )
  687. {
  688. init_trigger_flags();
  689. level.trigger_flags[ message ] = [];
  690. }
  691. else
  692. if ( !isdefined( level.trigger_flags[ message ] ) )
  693. {
  694. level.trigger_flags[ message ] = [];
  695. }
  696.  
  697. if ( issuffix( message, "aa_" ) )
  698. {
  699. thread [[ level.sp_stat_tracking_func ]]( message );
  700. }
  701. }
  702.  
  703. empty_init_func( empty )
  704. {
  705. }
  706.  
  707. issuffix( msg, suffix )
  708. {
  709. if ( suffix.size > msg.size )
  710. return false;
  711.  
  712. for ( i = 0; i < suffix.size; i++ )
  713. {
  714. if ( msg[ i ] != suffix[ i ] )
  715. return false;
  716. }
  717. return true;
  718. }
  719. /*
  720. =============
  721. ///ScriptDocBegin
  722. "Name: flag_set( <flagname>, <setter> )"
  723. "Summary: Sets the specified flag, all scripts using flag_wait will now continue."
  724. "Module: Flag"
  725. "MandatoryArg: <flagname> : name of the flag to set"
  726. "OptionalArg: <setter> : Pass an entity with the flag_set"
  727. "Example: flag_set( "hq_broiled" );"
  728. "SPMP: both"
  729. ///ScriptDocEnd
  730. =============
  731. */
  732. flag_set( message, setter )
  733. {
  734. /#
  735. assertEx( isDefined( level.flag[ message ] ), "Attempt to set a flag before calling flag_init: " + message );
  736. //lock check
  737. #/
  738.  
  739. level.flag[ message ] = true;
  740. set_trigger_flag_permissions( message );
  741. if ( isdefined( setter ) )
  742. {
  743. level notify( message, setter );// notify needs to be very last thing called
  744. }
  745. else
  746. {
  747. level notify( message );// notify needs to be very last thing called
  748. }
  749. }
  750.  
  751. assign_unique_id()
  752. {
  753. self.unique_id = "generic" + level.generic_index;
  754. level.generic_index++;
  755. }
  756.  
  757. /*
  758. =============
  759. ///ScriptDocBegin
  760. "Name: flag_wait( <flagname>, <entity> )"
  761. "Summary: Waits until the specified flag is set."
  762. "Module: Flag"
  763. "MandatoryArg: <flagname> : name of the flag to wait on"
  764. "OptionalArg: <entity> : You can wait until a flag is set for a specific entity"
  765. "Example: flag_wait( "hq_cleared" );"
  766. "SPMP: both"
  767. ///ScriptDocEnd
  768. =============
  769. */
  770. flag_wait( msg, entity )
  771. {
  772. other = undefined;
  773. while ( !flag( msg ) )
  774. {
  775. other = undefined;
  776. level waittill( msg, other );
  777.  
  778. // if we're waiting for the flag on a specific entity then we have to check
  779. // to see if the flag is set on that specific entity
  780. if ( isdefined( entity ) && flag( msg, entity ) )
  781. break;
  782. }
  783. if ( isdefined( other ) )
  784. return other;
  785. }
  786.  
  787. /*
  788. =============
  789. ///ScriptDocBegin
  790. "Name: flag_clear( <flagname>, <entity> )"
  791. "Summary: Clears the specified flag."
  792. "Module: Flag"
  793. "MandatoryArg: <flagname> : name of the flag to clear"
  794. "Example: flag_clear( "hq_cleared" );"
  795. "SPMP: both"
  796. ///ScriptDocEnd
  797. =============
  798. */
  799. flag_clear( message )
  800. {
  801. /#
  802. assertEx( isDefined( level.flag[ message ] ), "Attempt to set a flag before calling flag_init: " + message );
  803. // lock implementation tbd
  804. #/
  805. //do this check so we don't unneccessarily send a notify
  806. if ( !flag( message ) )
  807. return;
  808.  
  809. level.flag[ message ] = false;
  810.  
  811. set_trigger_flag_permissions( message );
  812. level notify( message );// the notify needs to be the very last thing called in this function
  813. }
  814.  
  815. /*
  816. =============
  817. ///ScriptDocBegin
  818. "Name: flag_waitopen( <flagname> )"
  819. "Summary: Waits for the flag to open"
  820. "Module: Flag"
  821. "MandatoryArg: <flagname>: The flag"
  822. "Example: flag_waitopen( "get_me_bagels" );"
  823. "SPMP: both"
  824. ///ScriptDocEnd
  825. =============
  826. */
  827.  
  828. flag_waitopen( msg )
  829. {
  830. while ( flag( msg ) )
  831. level waittill( msg );
  832. }
  833.  
  834. /*
  835. =============
  836. ///ScriptDocBegin
  837. "Name: waittill_either( <msg1> , <msg2> )"
  838. "Summary: Waits until either message, on self"
  839. "Module: Utility"
  840. "CallOn: An entity or the level"
  841. "MandatoryArg: <msg1>: First msg to wait on"
  842. "MandatoryArg: <msg2>: Second msg to wait on"
  843. "Example: level waittill_either( "yo", "no" );"
  844. "SPMP: both"
  845. ///ScriptDocEnd
  846. =============
  847. */
  848. waittill_either( msg1, msg2 )
  849. {
  850. self endon( msg1 );
  851. self waittill( msg2 );
  852. }
  853.  
  854. /*
  855. =============
  856. ///ScriptDocBegin
  857. "Name: array_thread( <entities> , <process> , <var1> , <var2> , <var3> )"
  858. "Summary: Threads the < process > function on every entity in the < entities > array. The entity will become "self" in the specified function."
  859. "Module: Array"
  860. "CallOn: "
  861. "MandatoryArg: <entities> : array of entities to thread the process"
  862. "MandatoryArg: <process> : pointer to a script function"
  863. "OptionalArg: <var1> : parameter 1 to pass to the process"
  864. "OptionalArg: <var2> : parameter 2 to pass to the process"
  865. "OptionalArg: <var3> : parameter 3 to pass to the process"
  866. "Example: array_thread( array_of_guys, ::set_ignoreme, false );"
  867. "SPMP: both"
  868. ///ScriptDocEnd
  869. =============
  870. */
  871. array_thread( entities, process, var1, var2, var3, var4, var5, var6, var7, var8, var9 )
  872. {
  873. if ( !isdefined( var1 ) )
  874. {
  875. foreach ( ent in entities )
  876. ent thread [[ process ]]();
  877. return;
  878. }
  879.  
  880. if ( !isdefined( var2 ) )
  881. {
  882. foreach ( ent in entities )
  883. ent thread [[ process ]]( var1 );
  884. return;
  885. }
  886.  
  887. if ( !isdefined( var3 ) )
  888. {
  889. foreach ( ent in entities )
  890. ent thread [[ process ]]( var1, var2 );
  891. return;
  892. }
  893.  
  894. if ( !isdefined( var4 ) )
  895. {
  896. foreach ( ent in entities )
  897. ent thread [[ process ]]( var1, var2, var3 );
  898. return;
  899. }
  900.  
  901. if ( !isdefined( var5 ) )
  902. {
  903. foreach ( ent in entities )
  904. ent thread [[ process ]]( var1, var2, var3, var4 );
  905. return;
  906. }
  907.  
  908. if ( !isdefined( var6 ) )
  909. {
  910. foreach ( ent in entities )
  911. ent thread [[ process ]]( var1, var2, var3, var4, var5 );
  912. return;
  913. }
  914.  
  915. if ( !isdefined( var7 ) )
  916. {
  917. foreach ( ent in entities )
  918. ent thread [[ process ]]( var1, var2, var3, var4, var5, var6 );
  919. return;
  920. }
  921.  
  922. if ( !isdefined( var8 ) )
  923. {
  924. foreach ( ent in entities )
  925. ent thread [[ process ]]( var1, var2, var3, var4, var5, var6, var7 );
  926. return;
  927. }
  928.  
  929. if ( !isdefined( var9 ) )
  930. {
  931. foreach ( ent in entities )
  932. ent thread [[ process ]]( var1, var2, var3, var4, var5, var6, var7, var8 );
  933. return;
  934. }
  935.  
  936. foreach ( ent in entities )
  937. ent thread [[ process ]]( var1, var2, var3, var4, var5, var6, var7, var8, var9 );
  938. return;
  939. }
  940.  
  941. /*
  942. =============
  943. ///ScriptDocBegin
  944. "Name: array_call( <entities> , <process> , <var1> , <var2> , <var3> )"
  945. "Summary: Runs the code < process > function on every entity in the < entities > array. The entity will become "self" in the specified function."
  946. "Module: Array"
  947. "CallOn: "
  948. "MandatoryArg: <entities> : array of entities to thread the process"
  949. "MandatoryArg: <process> : pointer to a code function"
  950. "OptionalArg: <var1> : parameter 1 to pass to the process"
  951. "OptionalArg: <var2> : parameter 2 to pass to the process"
  952. "OptionalArg: <var3> : parameter 3 to pass to the process"
  953. "Example: array_call( array_of_guys, ::set_ignoreme, false );"
  954. "SPMP: both"
  955. ///ScriptDocEnd
  956. =============
  957. */
  958. array_call( entities, process, var1, var2, var3 )
  959. {
  960. if ( isdefined( var3 ) )
  961. {
  962. foreach ( ent in entities )
  963. ent call [[ process ]]( var1, var2, var3 );
  964.  
  965. return;
  966. }
  967.  
  968. if ( isdefined( var2 ) )
  969. {
  970. foreach ( ent in entities )
  971. ent call [[ process ]]( var1, var2 );
  972.  
  973. return;
  974. }
  975.  
  976. if ( isdefined( var1 ) )
  977. {
  978. foreach ( ent in entities )
  979. ent call [[ process ]]( var1 );
  980.  
  981. return;
  982. }
  983.  
  984. foreach ( ent in entities )
  985. ent call [[ process ]]();
  986. }
  987.  
  988. /*
  989. =============
  990. ///ScriptDocBegin
  991. "Name: array_thread4( <entities> , <process> , <var1> , <var2> , <var3> , <var4> )"
  992. "Summary: "
  993. "Module: Entity"
  994. "CallOn: An entity"
  995. "MandatoryArg: <param1>: "
  996. "OptionalArg: <param2>: "
  997. "Example: "
  998. "SPMP: both"
  999. ///ScriptDocEnd
  1000. =============
  1001. */
  1002. array_thread4( entities, process, var1, var2, var3, var4 )
  1003. {
  1004. array_thread( entities, process, var1, var2, var3, var4 );
  1005. }
  1006.  
  1007. /*
  1008. =============
  1009. ///ScriptDocBegin
  1010. "Name: array_thread5( <entities> , <process> , <var1> , <var2> , <var3> , <var4> , <var5> )"
  1011. "Summary: "
  1012. "Module: Entity"
  1013. "CallOn: An entity"
  1014. "MandatoryArg: <param1>: "
  1015. "OptionalArg: <param2>: "
  1016. "Example: "
  1017. "SPMP: both"
  1018. ///ScriptDocEnd
  1019. =============
  1020. */
  1021. array_thread5( entities, process, var1, var2, var3, var4, var5 )
  1022. {
  1023. array_thread( entities, process, var1, var2, var3, var4, var5 );
  1024. }
  1025.  
  1026. /*
  1027. =============
  1028. ///ScriptDocBegin
  1029. "Name: remove_undefined_from_array()"
  1030. "Summary: remove elements from an array that are undefined"
  1031. "Module: Array"
  1032. "CallOn: "
  1033. "MandatoryArg: <array>: array to clear out"
  1034. "Example: level.trigger_flags[ msg ] = remove_undefined_from_array( level.trigger_flags[ msg ] );"
  1035. "SPMP: both"
  1036. ///ScriptDocEnd
  1037. =============
  1038. */
  1039.  
  1040. remove_undefined_from_array( array )
  1041. {
  1042. newarray = [];
  1043. for ( i = 0; i < array.size; i++ )
  1044. {
  1045. if ( !isdefined( array[ i ] ) )
  1046. continue;
  1047. newarray[ newarray.size ] = array[ i ];
  1048. }
  1049. return newarray;
  1050. }
  1051.  
  1052. /*
  1053. =============
  1054. ///ScriptDocBegin
  1055. "Name: trigger_on( <name>, <type> )"
  1056. "Summary: Turns a trigger on. This only needs to be called if it was previously turned off"
  1057. "Module: Trigger"
  1058. "CallOn: A trigger"
  1059. "OptionalArg: <name> : the name corrisponding to a targetname or script_noteworthy to grab the trigger internally"
  1060. "OptionalArg: <type> : the type( targetname, or script_noteworthy ) corrisponding to a name to grab the trigger internally"
  1061. "Example: trigger trigger_on(); -or- trigger_on( "base_trigger", "targetname" )"
  1062. "SPMP: both"
  1063. ///ScriptDocEnd
  1064. =============
  1065. */
  1066. trigger_on( name, type )
  1067. {
  1068. if ( isdefined( name ) && isdefined( type ) )
  1069. {
  1070. ents = getentarray( name, type );
  1071. array_thread( ents, ::trigger_on_proc );
  1072. }
  1073. else
  1074. self trigger_on_proc();
  1075. }
  1076.  
  1077. trigger_on_proc()
  1078. {
  1079. if ( isDefined( self.realOrigin ) )
  1080. self.origin = self.realOrigin;
  1081. self.trigger_off = undefined;
  1082. }
  1083.  
  1084.  
  1085. /*
  1086. =============
  1087. ///ScriptDocBegin
  1088. "Name: trigger_off( <name>, <type> )"
  1089. "Summary: Turns a trigger off so it can no longer be triggered."
  1090. "Module: Trigger"
  1091. "CallOn: A trigger"
  1092. "OptionalArg: <name> : the name corrisponding to a targetname or script_noteworthy to grab the trigger internally"
  1093. "OptionalArg: <type> : the type( targetname, or script_noteworthy ) corrisponding to a name to grab the trigger internally"
  1094. "Example: trigger trigger_off();"
  1095. "SPMP: both"
  1096. ///ScriptDocEnd
  1097. =============
  1098. */
  1099. trigger_off( name, type )
  1100. {
  1101. if ( isdefined( name ) && isdefined( type ) )
  1102. {
  1103. ents = getentarray( name, type );
  1104. array_thread( ents, ::trigger_off_proc );
  1105. }
  1106. else
  1107. self trigger_off_proc();
  1108. }
  1109.  
  1110. trigger_off_proc()
  1111. {
  1112. if ( !isDefined( self.realOrigin ) )
  1113. self.realOrigin = self.origin;
  1114.  
  1115. if ( self.origin == self.realorigin )
  1116. self.origin += ( 0, 0, -10000 );
  1117. self.trigger_off = true;
  1118. }
  1119.  
  1120. set_trigger_flag_permissions( msg )
  1121. {
  1122. // turns triggers on or off depending on if they have the proper flags set, based on their shift-g menu settings
  1123.  
  1124. // this can be init before _load has run, thanks to AI.
  1125. if ( !isdefined( level.trigger_flags ) )
  1126. return;
  1127.  
  1128. // cheaper to do the upkeep at this time rather than with endons and waittills on the individual triggers
  1129. level.trigger_flags[ msg ] = remove_undefined_from_array( level.trigger_flags[ msg ] );
  1130. array_thread( level.trigger_flags[ msg ], ::update_trigger_based_on_flags );
  1131. }
  1132.  
  1133. update_trigger_based_on_flags()
  1134. {
  1135. true_on = true;
  1136. if ( isdefined( self.script_flag_true ) )
  1137. {
  1138. true_on = false;
  1139. tokens = create_flags_and_return_tokens( self.script_flag_true );
  1140.  
  1141. // stay off unless all the flags are false
  1142. foreach ( token in tokens )
  1143. {
  1144. if ( flag( token ) )
  1145. {
  1146. true_on = true;
  1147. break;
  1148. }
  1149. }
  1150. }
  1151.  
  1152. false_on = true;
  1153. if ( isdefined( self.script_flag_false ) )
  1154. {
  1155. tokens = create_flags_and_return_tokens( self.script_flag_false );
  1156.  
  1157. // stay off unless all the flags are false
  1158. foreach ( token in tokens )
  1159. {
  1160. if ( flag( token ) )
  1161. {
  1162. false_on = false;
  1163. break;
  1164. }
  1165. }
  1166. }
  1167.  
  1168. [[ level.trigger_func[ true_on && false_on ] ]]();
  1169. }
  1170.  
  1171. create_flags_and_return_tokens( flags )
  1172. {
  1173. tokens = strtok( flags, " " );
  1174.  
  1175. // create the flag if level script does not
  1176. for ( i = 0; i < tokens.size; i++ )
  1177. {
  1178. if ( !isdefined( level.flag[ tokens[ i ] ] ) )
  1179. {
  1180. flag_init( tokens[ i ] );
  1181. }
  1182. }
  1183.  
  1184. return tokens;
  1185. }
  1186.  
  1187. init_trigger_flags()
  1188. {
  1189. level.trigger_flags = [];
  1190. level.trigger_func[ true ] = ::trigger_on;
  1191. level.trigger_func[ false ] = ::trigger_off;
  1192. }
  1193.  
  1194. /*
  1195. =============
  1196. ///ScriptDocBegin
  1197. "Name: getstruct( <name> , <type> )"
  1198. "Summary: get a struct by target, targetname,script_noteworthy, or script_linkname types, must be called after maps\_load::main();"
  1199. "Module: Struct"
  1200. "CallOn: Level"
  1201. "MandatoryArg: <name>: name of key"
  1202. "MandatoryArg: <type>: key type"
  1203. "Example: position = getstruct("waypoint1","targetname");
  1204. "SPMP: both"
  1205. ///ScriptDocEnd
  1206. =============
  1207. */
  1208.  
  1209. getstruct( name, type )
  1210. {
  1211. assertex( isdefined( name ) && isdefined( type ), "Did not fill in name and type" );
  1212. assertEx( isdefined( level.struct_class_names ), "Tried to getstruct before the structs were init" );
  1213.  
  1214. array = level.struct_class_names[ type ][ name ];
  1215. if ( !isdefined( array ) )
  1216. {
  1217. return undefined;
  1218. }
  1219.  
  1220. if ( array.size > 1 )
  1221. {
  1222. assertMsg( "getstruct used for more than one struct of type " + type + " called " + name + "." );
  1223. return undefined;
  1224. }
  1225. return array[ 0 ];
  1226. }
  1227.  
  1228. /*
  1229. =============
  1230. ///ScriptDocBegin
  1231. "Name: getstructarray( <name> , <type )"
  1232. "Summary: gets an array of script_structs"
  1233. "Module: Array"
  1234. "CallOn: An entity"
  1235. "MandatoryArg: <name> : "
  1236. "MandatoryArg: <type> : "
  1237. "Example: fxemitters = getstructarray( "streetlights", "targetname" )"
  1238. "SPMP: both"
  1239. ///ScriptDocEnd
  1240. =============
  1241. */
  1242.  
  1243. getstructarray( name, type )
  1244. {
  1245. assertEx( isdefined( level.struct_class_names ), "Tried to getstruct before the structs were init" );
  1246.  
  1247. array = level.struct_class_names[ type ][ name ];
  1248. if ( !isdefined( array ) )
  1249. return [];
  1250. return array;
  1251. }
  1252.  
  1253. struct_class_init()
  1254. {
  1255. assertEx( !isdefined( level.struct_class_names ), "level.struct_class_names is being initialized in the wrong place! It shouldn't be initialized yet." );
  1256.  
  1257. level.struct_class_names = [];
  1258. level.struct_class_names[ "target" ] = [];
  1259. level.struct_class_names[ "targetname" ] = [];
  1260. level.struct_class_names[ "script_noteworthy" ] = [];
  1261. level.struct_class_names[ "script_linkname" ] = [];
  1262.  
  1263. foreach ( struct in level.struct )
  1264. {
  1265. if ( isdefined( struct.targetname ) )
  1266. {
  1267. if ( !isdefined( level.struct_class_names[ "targetname" ][ struct.targetname ] ) )
  1268. level.struct_class_names[ "targetname" ][ struct.targetname ] = [];
  1269.  
  1270. size = level.struct_class_names[ "targetname" ][ struct.targetname ].size;
  1271. level.struct_class_names[ "targetname" ][ struct.targetname ][ size ] = struct;
  1272. }
  1273. if ( isdefined( struct.target ) )
  1274. {
  1275. if ( !isdefined( level.struct_class_names[ "target" ][ struct.target ] ) )
  1276. level.struct_class_names[ "target" ][ struct.target ] = [];
  1277.  
  1278. size = level.struct_class_names[ "target" ][ struct.target ].size;
  1279. level.struct_class_names[ "target" ][ struct.target ][ size ] = struct;
  1280. }
  1281. if ( isdefined( struct.script_noteworthy ) )
  1282. {
  1283. if ( !isdefined( level.struct_class_names[ "script_noteworthy" ][ struct.script_noteworthy ] ) )
  1284. level.struct_class_names[ "script_noteworthy" ][ struct.script_noteworthy ] = [];
  1285.  
  1286. size = level.struct_class_names[ "script_noteworthy" ][ struct.script_noteworthy ].size;
  1287. level.struct_class_names[ "script_noteworthy" ][ struct.script_noteworthy ][ size ] = struct;
  1288. }
  1289. if ( isdefined( struct.script_linkname ) )
  1290. {
  1291. assertex( !isdefined( level.struct_class_names[ "script_linkname" ][ struct.script_linkname ] ), "Two structs have the same linkname" );
  1292. level.struct_class_names[ "script_linkname" ][ struct.script_linkname ][ 0 ] = struct;
  1293. }
  1294. }
  1295. }
  1296.  
  1297. fileprint_start( file )
  1298. {
  1299. /#
  1300. filename = file;
  1301. level.fileprint = 1;
  1302. level.fileprintlinecount = 0;
  1303. level.fileprint_filename = filename;
  1304. #/
  1305. }
  1306.  
  1307. /*
  1308. =============
  1309. ///ScriptDocBegin
  1310. "Name: fileprint_map_start( <filename> )"
  1311. "Summary: starts map export with the file trees\cod3\cod3\map_source\xenon_export\ < filename > .map adds header / worldspawn entity to the map. Use this if you want to start a .map export."
  1312. "Module: Fileprint"
  1313. "CallOn: Level"
  1314. "MandatoryArg: <param1> : "
  1315. "OptionalArg: <param2> : "
  1316. "Example: fileprint_map_start( filename );"
  1317. "SPMP: both"
  1318. ///ScriptDocEnd
  1319. =============
  1320. */
  1321.  
  1322. fileprint_map_start()
  1323. {
  1324. /#
  1325. // for the entity count
  1326. level.fileprint_mapentcount = 0;
  1327. fileprint_map_header( true );
  1328. #/
  1329.  
  1330. }
  1331.  
  1332. fileprint_map_header( bInclude_blank_worldspawn )
  1333. {
  1334. if ( !isdefined( bInclude_blank_worldspawn ) )
  1335. bInclude_blank_worldspawn = false;
  1336.  
  1337. /#
  1338. fileprint_launcher( "iwmap 6" );
  1339. fileprint_launcher( "\"000_Global\" flags active" );
  1340. fileprint_launcher( "\"The Map\" flags" );
  1341.  
  1342. if ( !bInclude_blank_worldspawn )
  1343. return;
  1344.  
  1345. fileprint_map_entity_start();
  1346. fileprint_map_keypairprint( "classname", "worldspawn" );
  1347. fileprint_map_entity_end();
  1348.  
  1349. #/
  1350. }
  1351.  
  1352. /*
  1353. =============
  1354. ///ScriptDocBegin
  1355. "Name: fileprint_map_keypairprint( <key1> , <key2> )"
  1356. "Summary: prints a pair of keys to the current open map( by fileprint_map_start() )"
  1357. "Module: Fileprint"
  1358. "CallOn: Level"
  1359. "MandatoryArg: <key1> : "
  1360. "MandatoryArg: <key2> : "
  1361. "Example: fileprint_map_keypairprint( "classname", "script_model" );"
  1362. "SPMP: both"
  1363. ///ScriptDocEnd
  1364. =============
  1365. */
  1366.  
  1367. fileprint_map_keypairprint( key1, key2 )
  1368. {
  1369. /#
  1370. fileprint_launcher( "\"" + key1 + "\" \"" + key2 + "\"" );
  1371. #/
  1372. }
  1373.  
  1374. /*
  1375. =============
  1376. ///ScriptDocBegin
  1377. "Name: fileprint_map_entity_start()"
  1378. "Summary: prints entity number and opening bracket to currently opened file"
  1379. "Module: Fileprint"
  1380. "CallOn: Level"
  1381. "Example: fileprint_map_entity_start();"
  1382. "SPMP: both"
  1383. ///ScriptDocEnd
  1384. =============
  1385. */
  1386.  
  1387. fileprint_map_entity_start()
  1388. {
  1389. /#
  1390. assert( isdefined( level.fileprint_mapentcount ), "need to start a map with fileprint_map_start() first" );
  1391. assert( !isdefined( level.fileprint_entitystart ) );
  1392. level.fileprint_entitystart = true;
  1393. fileprint_launcher( "entity " + level.fileprint_mapentcount );
  1394. fileprint_launcher( "{" );
  1395. level.fileprint_mapentcount++;
  1396. #/
  1397. }
  1398.  
  1399. /*
  1400. =============
  1401. ///ScriptDocBegin
  1402. "Name: fileprint_map_entity_end()"
  1403. "Summary: close brackets an entity, required for the next entity to begin"
  1404. "Module: Fileprint"
  1405. "CallOn: Level"
  1406. "Example: fileprint_map_entity_end();"
  1407. "SPMP: both"
  1408. ///ScriptDocEnd
  1409. =============
  1410. */
  1411.  
  1412. fileprint_map_entity_end()
  1413. {
  1414. /#
  1415. fileprint_launcher( "}" );
  1416. level.fileprint_entitystart = undefined;
  1417. #/
  1418. }
  1419.  
  1420.  
  1421. /*
  1422. =============
  1423. ///ScriptDocBegin
  1424. "Name: fileprint_radiant_vec( <vector> )"
  1425. "Summary: this converts a vector to a .map file readable format"
  1426. "Module: Fileprint"
  1427. "CallOn: An entity"
  1428. "MandatoryArg: <vector> : "
  1429. "Example: origin_string = fileprint_radiant_vec( vehicle.angles )"
  1430. "SPMP: both"
  1431. ///ScriptDocEnd
  1432. =============
  1433. */
  1434.  
  1435. fileprint_radiant_vec( vector )
  1436. {
  1437. /#
  1438. string = "" + vector[ 0 ] + " " + vector[ 1 ] + " " + vector[ 2 ] + "";
  1439. return string;
  1440. #/
  1441. }
  1442.  
  1443. /*
  1444. =============
  1445. ///ScriptDocBegin
  1446. "Name: vector_multiply( <vec> , <dif> )"
  1447. "Summary: multiply a vector"
  1448. "Module: Vector"
  1449. "CallOn: Level"
  1450. "MandatoryArg: <vec>: vector to multiply"
  1451. "MandatoryArg: <dif>: scale"
  1452. "Example: vec = vector_multiply( vec, magnitude );"
  1453. "SPMP: both"
  1454. ///ScriptDocEnd
  1455. =============
  1456. */
  1457. vector_multiply( vec, dif )
  1458. {
  1459. vec = ( vec[ 0 ] * dif, vec[ 1 ] * dif, vec[ 2 ] * dif );
  1460. return vec;
  1461. }
  1462.  
  1463. /*
  1464. =============
  1465. ///ScriptDocBegin
  1466. "Name: array_remove( <ents> , <remover> )"
  1467. "Summary: Returns < ents > array minus < remover > "
  1468. "Module: Array"
  1469. "CallOn: "
  1470. "MandatoryArg: <ents> : array to remove < remover > from"
  1471. "MandatoryArg: <remover> : entity to remove from the array"
  1472. "Example: ents = array_remove( ents, guy );"
  1473. "SPMP: both"
  1474. ///ScriptDocEnd
  1475. =============
  1476. */
  1477. array_remove( ents, remover )
  1478. {
  1479. newents = [];
  1480. foreach( index in ents )
  1481. {
  1482. if ( index != remover )
  1483. newents[ newents.size ] = index;
  1484. }
  1485.  
  1486. return newents;
  1487. }
  1488.  
  1489. /*
  1490. =============
  1491. ///ScriptDocBegin
  1492. "Name: array_remove_array( <ents> , <remover_array> )"
  1493. "Summary: "
  1494. "Module: Entity"
  1495. "CallOn: An entity"
  1496. "MandatoryArg: <param1>: "
  1497. "OptionalArg: <param2>: "
  1498. "Example: "
  1499. "SPMP: both"
  1500. ///ScriptDocEnd
  1501. =============
  1502. */
  1503. array_remove_array( ents, remover_array )
  1504. {
  1505. foreach( remover in remover_array )
  1506. ents = array_remove( ents, remover );
  1507.  
  1508. return ents;
  1509. }
  1510.  
  1511. /*
  1512. =============
  1513. ///ScriptDocBegin
  1514. "Name: array_removeUndefined( <array> )"
  1515. "Summary: Returns a new array of < array > minus the undefined indicies"
  1516. "Module: Array"
  1517. "CallOn: "
  1518. "MandatoryArg: <array> : The array to search for undefined indicies in."
  1519. "Example: ents = array_removeUndefined( ents );"
  1520. "SPMP: both"
  1521. ///ScriptDocEnd
  1522. =============
  1523. */
  1524. array_removeUndefined( array )
  1525. {
  1526. newArray = [];
  1527. for ( i = 0; i < array.size; i++ )
  1528. {
  1529. if ( !isdefined( array[ i ] ) )
  1530. continue;
  1531. newArray[ newArray.size ] = array[ i ];
  1532. }
  1533.  
  1534. return newArray;
  1535. }
  1536.  
  1537. /*
  1538. =============
  1539. ///ScriptDocBegin
  1540. "Name: array_levelthread( <entities> , <process> , <var1> , <var2> , <var3> )"
  1541. "Summary: Threads the < process > function for every entity in the < entities > array. The level calls the function and each entity of the array is passed as the first parameter to the process."
  1542. "Module: Array"
  1543. "CallOn: "
  1544. "MandatoryArg: <entities> : array of entities to thread the process"
  1545. "MandatoryArg: <process> : pointer to a script function"
  1546. "OptionalArg: <var1> : parameter 1 to pass to the process"
  1547. "OptionalArg: <var2> : parameter 2 to pass to the process"
  1548. "OptionalArg: <var3> : parameter 3 to pass to the process"
  1549. "Example: array_levelthread( getentarray( "palm", "targetname" ), ::palmTrees );"
  1550. "SPMP: both"
  1551. ///ScriptDocEnd
  1552. =============
  1553. */
  1554. array_levelthread( array, process, var1, var2, var3 )
  1555. {
  1556. if ( isdefined( var3 ) )
  1557. {
  1558. foreach ( ent in array )
  1559. thread [[ process ]]( ent, var1, var2, var3 );
  1560.  
  1561. return;
  1562. }
  1563.  
  1564. if ( isdefined( var2 ) )
  1565. {
  1566. foreach ( ent in array )
  1567. thread [[ process ]]( ent, var1, var2 );
  1568.  
  1569. return;
  1570. }
  1571.  
  1572. if ( isdefined( var1 ) )
  1573. {
  1574. foreach ( ent in array )
  1575. thread [[ process ]]( ent, var1 );
  1576.  
  1577. return;
  1578. }
  1579.  
  1580. foreach ( ent in array )
  1581. thread [[ process ]]( ent );
  1582. }
  1583.  
  1584. /*
  1585. =============
  1586. ///ScriptDocBegin
  1587. "Name: array_levelcall( <entities> , <process> , <var1> , <var2> , <var3> )"
  1588. "Summary: Calls the < process > function for every entity in the < entities > array. The level calls the function and each entity of the array is passed as the first parameter to the process."
  1589. "Module: Array"
  1590. "CallOn: "
  1591. "MandatoryArg: <entities> : array of entities to thread the process"
  1592. "MandatoryArg: <process> : pointer to a code function"
  1593. "OptionalArg: <var1> : parameter 1 to pass to the process"
  1594. "OptionalArg: <var2> : parameter 2 to pass to the process"
  1595. "OptionalArg: <var3> : parameter 3 to pass to the process"
  1596. "Example: array_levelthread( array_of_trees, ::palmTrees );"
  1597. "SPMP: both"
  1598. ///ScriptDocEnd
  1599. =============
  1600. */
  1601. array_levelcall( array, process, var1, var2, var3 )
  1602. {
  1603. if ( isdefined( var3 ) )
  1604. {
  1605. foreach ( ent in array )
  1606. call [[ process ]]( ent, var1, var2, var3 );
  1607.  
  1608. return;
  1609. }
  1610.  
  1611. if ( isdefined( var2 ) )
  1612. {
  1613. foreach ( ent in array )
  1614. call [[ process ]]( ent, var1, var2 );
  1615.  
  1616. return;
  1617. }
  1618.  
  1619. if ( isdefined( var1 ) )
  1620. {
  1621. foreach ( ent in array )
  1622. call [[ process ]]( ent, var1 );
  1623.  
  1624. return;
  1625. }
  1626.  
  1627. foreach ( ent in array )
  1628. call [[ process ]]( ent );
  1629. }
  1630.  
  1631. /*
  1632. =============
  1633. ///ScriptDocBegin
  1634. "Name: add_to_array( <array> , <ent> )"
  1635. "Summary: Adds < ent > to < array > and returns the new array."
  1636. "Module: Array"
  1637. "CallOn: "
  1638. "MandatoryArg: <array> : The array to add < ent > to."
  1639. "MandatoryArg: <ent> : The entity to be added."
  1640. "Example: nodes = add_to_array( nodes, new_node );"
  1641. "SPMP: both"
  1642. ///ScriptDocEnd
  1643. =============
  1644. */
  1645. add_to_array( array, ent )
  1646. {
  1647. if ( !isdefined( ent ) )
  1648. return array;
  1649.  
  1650. if ( !isdefined( array ) )
  1651. array[ 0 ] = ent;
  1652. else
  1653. array[ array.size ] = ent;
  1654.  
  1655. return array;
  1656. }
  1657.  
  1658.  
  1659.  
  1660. /*
  1661. =============
  1662. ///ScriptDocBegin
  1663. "Name: flag_assert( <msg> )"
  1664. "Summary: Asserts that a flag is clear. Useful for proving an assumption of a flag's state"
  1665. "Module: Entity"
  1666. "CallOn: An entity"
  1667. "MandatoryArg: <msg>: flag name"
  1668. "Example: flag_assert( "fairground_begins" );"
  1669. "SPMP: both"
  1670. ///ScriptDocEnd
  1671. =============
  1672. */
  1673. flag_assert( msg )
  1674. {
  1675. assertEx( !flag( msg ), "Flag " + msg + " set too soon!" );
  1676. }
  1677.  
  1678. /*
  1679. =============
  1680. ///ScriptDocBegin
  1681. "Name: flag_wait_either( <flagname1> , <flagname2> )"
  1682. "Summary: Waits until either of the the specified flags are set."
  1683. "Module: Flag"
  1684. "CallOn: "
  1685. "MandatoryArg: <flagname1> : name of one flag to wait on"
  1686. "MandatoryArg: <flagname2> : name of the other flag to wait on"
  1687. "Example: flag_wait( "hq_cleared", "hq_destroyed" );"
  1688. "SPMP: both"
  1689. ///ScriptDocEnd
  1690. =============
  1691. */
  1692. flag_wait_either( flag1, flag2 )
  1693. {
  1694. for ( ;; )
  1695. {
  1696. if ( flag( flag1 ) )
  1697. return;
  1698. if ( flag( flag2 ) )
  1699. return;
  1700.  
  1701. level waittill_either( flag1, flag2 );
  1702. }
  1703. }
  1704.  
  1705. /*
  1706. =============
  1707. ///ScriptDocBegin
  1708. "Name: flag_wait_either_return( <flagname1> , <flagname2> )"
  1709. "Summary: Waits until either of the the specified flags are set, and returns the first one it found."
  1710. "Module: Flag"
  1711. "CallOn: "
  1712. "MandatoryArg: <flagname1> : name of one flag to wait on"
  1713. "MandatoryArg: <flagname2> : name of the other flag to wait on"
  1714. "Example: flag_wait( "hq_cleared", "hq_destroyed" );"
  1715. "SPMP: both"
  1716. ///ScriptDocEnd
  1717. =============
  1718. */
  1719. flag_wait_either_return( flag1, flag2 )
  1720. {
  1721. for ( ;; )
  1722. {
  1723. if ( flag( flag1 ) )
  1724. return flag1;
  1725. if ( flag( flag2 ) )
  1726. return flag2;
  1727.  
  1728. msg = level waittill_any_return( flag1, flag2 );
  1729. return msg;
  1730. }
  1731. }
  1732.  
  1733. /*
  1734. =============
  1735. ///ScriptDocBegin
  1736. "Name: flag_wait_any( <flagname1> , <flagname2>, <flagname3> , <flagname4> , <flagname5> , <flagname6> )"
  1737. "Summary: Waits until any of the the specified flags are set."
  1738. "Module: Flag"
  1739. "CallOn: "
  1740. "MandatoryArg: <flagname1> : name of a flag to wait on"
  1741. "MandatoryArg: <flagname2> : name of a flag to wait on"
  1742. "OptionalArg: <flagname3> : name of a flag to wait on"
  1743. "OptionalArg: <flagname4> : name of a flag to wait on"
  1744. "Example: flag_wait_any( "hq_cleared", "hq_destroyed", "hq_overrun", "hq_skipped" );"
  1745. "SPMP: both"
  1746. ///ScriptDocEnd
  1747. =============
  1748. */
  1749. flag_wait_any( flag1, flag2, flag3, flag4, flag5, flag6 )
  1750. {
  1751. array = [];
  1752. if ( isdefined( flag6 ) )
  1753. {
  1754. array[ array.size ] = flag1;
  1755. array[ array.size ] = flag2;
  1756. array[ array.size ] = flag3;
  1757. array[ array.size ] = flag4;
  1758. array[ array.size ] = flag5;
  1759. array[ array.size ] = flag6;
  1760. }
  1761. else if ( isdefined( flag5 ) )
  1762. {
  1763. array[ array.size ] = flag1;
  1764. array[ array.size ] = flag2;
  1765. array[ array.size ] = flag3;
  1766. array[ array.size ] = flag4;
  1767. array[ array.size ] = flag5;
  1768. }
  1769. else if ( isdefined( flag4 ) )
  1770. {
  1771. array[ array.size ] = flag1;
  1772. array[ array.size ] = flag2;
  1773. array[ array.size ] = flag3;
  1774. array[ array.size ] = flag4;
  1775. }
  1776. else if ( isdefined( flag3 ) )
  1777. {
  1778. array[ array.size ] = flag1;
  1779. array[ array.size ] = flag2;
  1780. array[ array.size ] = flag3;
  1781. }
  1782. else if ( isdefined( flag2 ) )
  1783. {
  1784. flag_wait_either( flag1, flag2 );
  1785. return;
  1786. }
  1787. else
  1788. {
  1789. assertmsg( "flag_wait_any() needs at least 2 flags passed to it" );
  1790. return;
  1791. }
  1792.  
  1793. for ( ;; )
  1794. {
  1795. for ( i = 0; i < array.size; i++ )
  1796. {
  1797. if ( flag( array[ i ] ) )
  1798. return;
  1799. }
  1800.  
  1801. level waittill_any( flag1, flag2, flag3, flag4, flag5, flag6 );
  1802. }
  1803. }
  1804.  
  1805. /*
  1806. =============
  1807. ///ScriptDocBegin
  1808. "Name: flag_wait_any_return( <flagname1> , <flagname2>, <flagname3> , <flagname4> , <flagname5> , <flagname6> )"
  1809. "Summary: Waits until any of the the specified flags are set, and returns the first set flag that was found."
  1810. "Module: Flag"
  1811. "CallOn: "
  1812. "MandatoryArg: <flagname1> : name of a flag to wait on"
  1813. "MandatoryArg: <flagname2> : name of a flag to wait on"
  1814. "OptionalArg: <flagname3> : name of a flag to wait on"
  1815. "OptionalArg: <flagname4> : name of a flag to wait on"
  1816. "Example: returned = flag_wait_any_return( "hq_cleared", "hq_destroyed", "hq_overrun", "hq_skipped" );"
  1817. "SPMP: both"
  1818. ///ScriptDocEnd
  1819. =============
  1820. */
  1821. flag_wait_any_return( flag1, flag2, flag3, flag4, flag5, flag6 )
  1822. {
  1823. array = [];
  1824. if ( isdefined( flag6 ) )
  1825. {
  1826. array[ array.size ] = flag1;
  1827. array[ array.size ] = flag2;
  1828. array[ array.size ] = flag3;
  1829. array[ array.size ] = flag4;
  1830. array[ array.size ] = flag5;
  1831. array[ array.size ] = flag6;
  1832. }
  1833. else if ( isdefined( flag5 ) )
  1834. {
  1835. array[ array.size ] = flag1;
  1836. array[ array.size ] = flag2;
  1837. array[ array.size ] = flag3;
  1838. array[ array.size ] = flag4;
  1839. array[ array.size ] = flag5;
  1840. }
  1841. else if ( isdefined( flag4 ) )
  1842. {
  1843. array[ array.size ] = flag1;
  1844. array[ array.size ] = flag2;
  1845. array[ array.size ] = flag3;
  1846. array[ array.size ] = flag4;
  1847. }
  1848. else if ( isdefined( flag3 ) )
  1849. {
  1850. array[ array.size ] = flag1;
  1851. array[ array.size ] = flag2;
  1852. array[ array.size ] = flag3;
  1853. }
  1854. else if ( isdefined( flag2 ) )
  1855. {
  1856. msg = flag_wait_either_return( flag1, flag2 );
  1857. return msg;
  1858. }
  1859. else
  1860. {
  1861. assertmsg( "flag_wait_any_return() needs at least 2 flags passed to it" );
  1862. return;
  1863. }
  1864.  
  1865. for ( ;; )
  1866. {
  1867. for ( i = 0; i < array.size; i++ )
  1868. {
  1869. if ( flag( array[ i ] ) )
  1870. return array[ i ];
  1871. }
  1872.  
  1873. msg = level waittill_any_return( flag1, flag2, flag3, flag4, flag5, flag6 );
  1874. return msg;
  1875. }
  1876. }
  1877.  
  1878. /*
  1879. =============
  1880. ///ScriptDocBegin
  1881. "Name: flag_wait_all( <flagname1> , <flagname2>, <flagname3> , <flagname4> )"
  1882. "Summary: Waits until all of the the specified flags are set."
  1883. "Module: Flag"
  1884. "CallOn: "
  1885. "MandatoryArg: <flagname1> : name of a flag to wait on"
  1886. "MandatoryArg: <flagname2> : name of a flag to wait on"
  1887. "OptionalArg: <flagname3> : name of a flag to wait on"
  1888. "OptionalArg: <flagname4> : name of a flag to wait on"
  1889. "Example: flag_wait_any( "hq_cleared", "hq_destroyed", "hq_overrun", "hq_skipped" );"
  1890. "SPMP: both"
  1891. ///ScriptDocEnd
  1892. =============
  1893. */
  1894. flag_wait_all( flag1, flag2, flag3, flag4 )
  1895. {
  1896. if ( isdefined( flag1 ) )
  1897. flag_wait( flag1 );
  1898.  
  1899. if ( isdefined( flag2 ) )
  1900. flag_wait( flag2 );
  1901.  
  1902. if ( isdefined( flag3 ) )
  1903. flag_wait( flag3 );
  1904.  
  1905. if ( isdefined( flag4 ) )
  1906. flag_wait( flag4 );
  1907. }
  1908.  
  1909. /*
  1910. =============
  1911. ///ScriptDocBegin
  1912. "Name: flag_wait_or_timeout( <flagname> , <timer> )"
  1913. "Summary: Waits until either the flag gets set or the timer elapses."
  1914. "Module: Flag"
  1915. "CallOn: "
  1916. "MandatoryArg: <flagname1: Name of one flag to wait on"
  1917. "MandatoryArg: <timer> : Amount of time to wait before continuing regardless of flag."
  1918. "Example: flag_wait_or_timeout( "time_to_go", 3 );"
  1919. "SPMP: both"
  1920. ///ScriptDocEnd
  1921. =============
  1922. */
  1923. flag_wait_or_timeout( flagname, timer )
  1924. {
  1925. timerMS = timer * 1000;
  1926. start_time = GetTime();
  1927.  
  1928. for ( ;; )
  1929. {
  1930. if ( flag( flagname ) )
  1931. {
  1932. break;
  1933. }
  1934.  
  1935. if ( GetTime() >= start_time + timerMS )
  1936. {
  1937. break;
  1938. }
  1939.  
  1940. timeRemaining = timerMS - ( GetTime() - start_time ); // figure out how long we waited already, if at all
  1941. timeRemainingSecs = timeRemaining / 1000;
  1942. wait_for_flag_or_time_elapses( flagname, timeRemainingSecs );
  1943. }
  1944. }
  1945.  
  1946. /*
  1947. =============
  1948. ///ScriptDocBegin
  1949. "Name: flag_waitopen_or_timeout( <flagname> , <timer> )"
  1950. "Summary: Waits until either the flag gets cleared or the timer elapses."
  1951. "Module: Flag"
  1952. "CallOn: "
  1953. "MandatoryArg: <flagname1: Name of one flag to wait on"
  1954. "MandatoryArg: <timer> : Amount of time to wait before continuing regardless of flag."
  1955. "Example: flag_waitopen_or_timeout( "time_to_go", 3 );"
  1956. "SPMP: both"
  1957. ///ScriptDocEnd
  1958. =============
  1959. */
  1960. flag_waitopen_or_timeout( flagname, timer )
  1961. {
  1962. start_time = gettime();
  1963. for ( ;; )
  1964. {
  1965. if ( !flag( flagname ) )
  1966. break;
  1967.  
  1968. if ( gettime() >= start_time + timer * 1000 )
  1969. break;
  1970.  
  1971. wait_for_flag_or_time_elapses( flagname, timer );
  1972. }
  1973. }
  1974.  
  1975. wait_for_flag_or_time_elapses( flagname, timer )
  1976. {
  1977. level endon( flagname );
  1978. wait( timer );
  1979. }
  1980.  
  1981.  
  1982. /*
  1983. =============
  1984. ///ScriptDocBegin
  1985. "Name: delayCall( <delay> , <function> , <arg1> , <arg2> , <arg3> )"
  1986. "Summary: delayCall is cool! It saves you from having to write extra script for once off commands. Note you don?t have to thread it off. delaycall is that smart!"
  1987. "Module: Utility"
  1988. "MandatoryArg: <delay> : The delay before the function occurs"
  1989. "MandatoryArg: <function> : The function to run."
  1990. "OptionalArg: <arg1> : parameter 1 to pass to the process"
  1991. "OptionalArg: <arg2> : parameter 2 to pass to the process"
  1992. "OptionalArg: <arg3> : parameter 3 to pass to the process"
  1993. "OptionalArg: <arg4> : parameter 4 to pass to the process"
  1994. "Example: delayCall( ::flag_set, "player_can_rappel", 3 );"
  1995. "SPMP: both"
  1996. ///ScriptDocEnd
  1997. =============
  1998. */
  1999.  
  2000. delayCall( timer, func, param1, param2, param3, param4 )
  2001. {
  2002. // to thread it off
  2003. thread delayCall_proc( func, timer, param1, param2, param3, param4 );
  2004. }
  2005.  
  2006. delayCall_proc( func, timer, param1, param2, param3, param4 )
  2007. {
  2008. if ( isSP() )
  2009. self endon( "death" );
  2010.  
  2011. wait( timer );
  2012. if ( isdefined( param4 ) )
  2013. self call [[ func ]]( param1, param2, param3, param4 );
  2014. else
  2015. if ( isdefined( param3 ) )
  2016. self call [[ func ]]( param1, param2, param3 );
  2017. else
  2018. if ( isdefined( param2 ) )
  2019. self call [[ func ]]( param1, param2 );
  2020. else
  2021. if ( isdefined( param1 ) )
  2022. self call [[ func ]]( param1 );
  2023. else
  2024. self call [[ func ]]();
  2025. }
  2026.  
  2027. /*
  2028. =============
  2029. ///ScriptDocBegin
  2030. "Name: noself_delayCall( <delay> , <function> , <arg1> , <arg2> , <arg3>, <arg4> )"
  2031. "Summary: Calls a command with no self (some commands don't support having self)."
  2032. "Module: Utility"
  2033. "MandatoryArg: <delay> : The delay before the function occurs"
  2034. "MandatoryArg: <function> : The function to run."
  2035. "OptionalArg: <arg1> : parameter 1 to pass to the process"
  2036. "OptionalArg: <arg2> : parameter 2 to pass to the process"
  2037. "OptionalArg: <arg3> : parameter 3 to pass to the process"
  2038. "OptionalArg: <arg4> : parameter 4 to pass to the process"
  2039. "Example: noself_delayCall( ::setsaveddvar, "player_can_rappel", 1 );"
  2040. "SPMP: both"
  2041. ///ScriptDocEnd
  2042. =============
  2043. */
  2044.  
  2045. noself_delayCall( timer, func, param1, param2, param3, param4 )
  2046. {
  2047. // to thread it off
  2048. thread noself_delayCall_proc( func, timer, param1, param2, param3, param4 );
  2049. }
  2050.  
  2051. noself_delayCall_proc( func, timer, param1, param2, param3, param4 )
  2052. {
  2053. wait( timer );
  2054. if ( isdefined( param4 ) )
  2055. call [[ func ]]( param1, param2, param3, param4 );
  2056. else
  2057. if ( isdefined( param3 ) )
  2058. call [[ func ]]( param1, param2, param3 );
  2059. else
  2060. if ( isdefined( param2 ) )
  2061. call [[ func ]]( param1, param2 );
  2062. else
  2063. if ( isdefined( param1 ) )
  2064. call [[ func ]]( param1 );
  2065. else
  2066. call [[ func ]]();
  2067. }
  2068.  
  2069. /*
  2070. =============
  2071. ///ScriptDocBegin
  2072. "Name: isSP()"
  2073. "Summary: Returns false if the level name begins with mp_"
  2074. "Module: Utility"
  2075. "Example: if ( isSP() );"
  2076. "SPMP: both"
  2077. ///ScriptDocEnd
  2078. =============
  2079. */
  2080. isSP()
  2081. {
  2082. if ( !isdefined( level.isSP ) )
  2083. level.isSP = !( string_starts_with( getdvar( "mapname" ), "mp_" ) );
  2084.  
  2085. return level.isSP;
  2086. }
  2087.  
  2088.  
  2089. /*
  2090. =============
  2091. ///ScriptDocBegin
  2092. "Name: string_starts_with( <string>, <start> )"
  2093. "Summary: Returns true if the first string begins with the first string"
  2094. "Module: Utility"
  2095. "CallOn:"
  2096. "MandatoryArg: <string> String to check"
  2097. "MandatoryArg: <start> Beginning of string to check"
  2098. "Example: if ( string_starts_with( "somestring", "somest" ) )"
  2099. "SPMP: both"
  2100. ///ScriptDocEnd
  2101. =============
  2102. */
  2103. string_starts_with( string, start )
  2104. {
  2105. assert( isdefined( string ) );
  2106. assert( isdefined( start ) );
  2107. if ( string.size < start.size )
  2108. return false;
  2109.  
  2110. for ( i = 0 ; i < start.size ; i++ )
  2111. {
  2112. if ( tolower( string[ i ] ) != tolower( start[ i ] ) )
  2113. return false;
  2114. }
  2115.  
  2116. return true;
  2117. }
  2118.  
  2119. plot_points( plotpoints, r, g, b, timer )
  2120. {
  2121. lastpoint = plotpoints[ 0 ];
  2122. if ( !isdefined( r ) )
  2123. r = 1;
  2124. if ( !isdefined( g ) )
  2125. g = 1;
  2126. if ( !isdefined( b ) )
  2127. b = 1;
  2128. if ( !isdefined( timer ) )
  2129. timer = 0.05;
  2130. for ( i = 1;i < plotpoints.size;i++ )
  2131. {
  2132. thread draw_line_for_time( lastpoint, plotpoints[ i ], r, g, b, timer );
  2133. lastpoint = plotpoints[ i ];
  2134. }
  2135. }
  2136.  
  2137.  
  2138. /*
  2139. =============
  2140. ///ScriptDocBegin
  2141. "Name: draw_line_for_time( <org1> , <org2> , <r> , <g> , <b> , <timer> )"
  2142. "Summary: Draws a line from < org1 > to < org2 > in the specified color for the specified duration"
  2143. "Module: Debug"
  2144. "CallOn: "
  2145. "MandatoryArg: <org1> : starting origin for the line"
  2146. "MandatoryArg: <org2> : ending origin for the line"
  2147. "MandatoryArg: <r> : red color value( 0 to 1 )"
  2148. "MandatoryArg: <g> : green color value( 0 to 1 )"
  2149. "MandatoryArg: <b> : blue color value( 0 to 1 )"
  2150. "MandatoryArg: <timer> : time in seconds the line should last"
  2151. "Example: thread draw_line_for_time( level.player.origin, vehicle.origin, 1, 0, 0, 10.0 );"
  2152. "SPMP: both"
  2153. ///ScriptDocEnd
  2154. =============
  2155. */
  2156. draw_line_for_time( org1, org2, r, g, b, timer )
  2157. {
  2158. timer = gettime() + ( timer * 1000 );
  2159. while ( gettime() < timer )
  2160. {
  2161. line( org1, org2, ( r, g, b ), 1 );
  2162. wait .05;
  2163. }
  2164.  
  2165. }
  2166.  
  2167.  
  2168. /*
  2169. =============
  2170. ///ScriptDocBegin
  2171. "Name: array_combine( <array1> , <array2> )"
  2172. "Summary: Combines the two arrays and returns the resulting array. This function doesn't care if it produces duplicates in the array."
  2173. "Module: Array"
  2174. "CallOn: "
  2175. "MandatoryArg: <array1> : first array"
  2176. "MandatoryArg: <array2> : second array"
  2177. "Example: combinedArray = array_combine( array1, array2 );"
  2178. "SPMP: both"
  2179. ///ScriptDocEnd
  2180. =============
  2181. */
  2182. array_combine( array1, array2 )
  2183. {
  2184. array3 = [];
  2185. foreach ( item in array1 )
  2186. {
  2187. array3[ array3.size ] = item;
  2188. }
  2189. foreach ( item in array2 )
  2190. {
  2191. array3[ array3.size ] = item;
  2192. }
  2193. return array3;
  2194. }
  2195.  
  2196.  
  2197. /*
  2198. =============
  2199. ///ScriptDocBegin
  2200. "Name: flat_angle( <angle> )"
  2201. "Summary: Returns the specified angle as a flat angle.( 45, 90, 30 ) becomes( 0, 90, 30 ). Useful if you just need an angle around Y - axis."
  2202. "Module: Vector"
  2203. "CallOn: "
  2204. "MandatoryArg: <angle> : angles to flatten"
  2205. "Example: yaw = flat_angle( node.angles );"
  2206. "SPMP: both"
  2207. ///ScriptDocEnd
  2208. =============
  2209. */
  2210. flat_angle( angle )
  2211. {
  2212. rangle = ( 0, angle[ 1 ], 0 );
  2213. return rangle;
  2214. }
  2215.  
  2216. /*
  2217. =============
  2218. ///ScriptDocBegin
  2219. "Name: flat_origin( <org> )"
  2220. "Summary: Returns a flat origin of the specified origin. Moves Z corrdinate to 0.( x, y, z ) becomes( x, y, 0 )"
  2221. "Module: Vector"
  2222. "CallOn: "
  2223. "MandatoryArg: <org> : origin to flatten"
  2224. "Example: org = flat_origin( self.origin );"
  2225. "SPMP: both"
  2226. ///ScriptDocEnd
  2227. =============
  2228. */
  2229. flat_origin( org )
  2230. {
  2231. rorg = ( org[ 0 ], org[ 1 ], 0 );
  2232. return rorg;
  2233.  
  2234. }
  2235.  
  2236. /*
  2237. =============
  2238. ///ScriptDocBegin
  2239. "Name: draw_arrow_time( <start> , <end> , <color> , <duration> )"
  2240. "Summary: Draws an arrow pointing at < end > in the specified color for < duration > seconds."
  2241. "Module: Entity"
  2242. "CallOn: An entity"
  2243. "MandatoryArg: <start> : starting coordinate for the arrow"
  2244. "MandatoryArg: <end> : ending coordinate for the arrow"
  2245. "MandatoryArg: <color> :( r, g, b ) color array for the arrow"
  2246. "MandatoryArg: <duration> : time in seconds to draw the arrow"
  2247. "Example: thread draw_arrow_time( lasttarg.origin, targ.origin, ( 0, 0, 1 ), 5.0 );"
  2248. "SPMP: both"
  2249. ///ScriptDocEnd
  2250. =============
  2251. */
  2252. draw_arrow_time( start, end, color, duration )
  2253. {
  2254. level endon( "newpath" );
  2255. pts = [];
  2256. angles = vectortoangles( start - end );
  2257. right = anglestoright( angles );
  2258. forward = anglestoforward( angles );
  2259. up = anglestoup( angles );
  2260.  
  2261. dist = distance( start, end );
  2262. arrow = [];
  2263. range = 0.1;
  2264.  
  2265. arrow[ 0 ] = start;
  2266. arrow[ 1 ] = start + vector_multiply( right, dist * ( range ) ) + vector_multiply( forward, dist * - 0.1 );
  2267. arrow[ 2 ] = end;
  2268. arrow[ 3 ] = start + vector_multiply( right, dist * ( -1 * range ) ) + vector_multiply( forward, dist * - 0.1 );
  2269.  
  2270. arrow[ 4 ] = start;
  2271. arrow[ 5 ] = start + vector_multiply( up, dist * ( range ) ) + vector_multiply( forward, dist * - 0.1 );
  2272. arrow[ 6 ] = end;
  2273. arrow[ 7 ] = start + vector_multiply( up, dist * ( -1 * range ) ) + vector_multiply( forward, dist * - 0.1 );
  2274. arrow[ 8 ] = start;
  2275.  
  2276. r = color[ 0 ];
  2277. g = color[ 1 ];
  2278. b = color[ 2 ];
  2279.  
  2280. plot_points( arrow, r, g, b, duration );
  2281. }
  2282.  
  2283.  
  2284. /*
  2285. =============
  2286. ///ScriptDocBegin
  2287. "Name: get_linked_ents()"
  2288. "Summary: Returns an array of entities that SELF is linked to"
  2289. "Module: Utility"
  2290. "CallOn: An entity that links to other entities"
  2291. "Example: spawners = heli get_linked_ents()"
  2292. "SPMP: both"
  2293. ///ScriptDocEnd
  2294. =============
  2295. */
  2296. get_linked_ents()
  2297. {
  2298. array = [];
  2299.  
  2300. if ( isdefined( self.script_linkto ) )
  2301. {
  2302. linknames = get_links();
  2303. foreach ( name in linknames )
  2304. {
  2305. entities = getentarray( name, "script_linkname" );
  2306. if ( entities.size > 0 )
  2307. array = array_combine( array, entities );
  2308. }
  2309. }
  2310.  
  2311. return array;
  2312. }
  2313.  
  2314. /*
  2315. =============
  2316. ///ScriptDocBegin
  2317. "Name: get_linked_ent()"
  2318. "Summary: Returns a single entity that SELF is linked to"
  2319. "Module: Utility"
  2320. "CallOn: An entity that links to another entity"
  2321. "Example: spawner = heli get_linked_ent()"
  2322. "SPMP: both"
  2323. ///ScriptDocEnd
  2324. =============
  2325. */
  2326. get_linked_ent()
  2327. {
  2328. array = get_linked_ents();
  2329. assert( array.size == 1 );
  2330. assert( isdefined( array[ 0 ] ) );
  2331. return array[ 0 ];
  2332. }
  2333.  
  2334.  
  2335. /*
  2336. =============
  2337. ///ScriptDocBegin
  2338. "Name: get_links( <get_links> )"
  2339. "Summary: "
  2340. "Module: Entity"
  2341. "CallOn: An entity"
  2342. "MandatoryArg: <param1>: "
  2343. "OptionalArg: <param2>: "
  2344. "Example: "
  2345. "SPMP: both"
  2346. ///ScriptDocEnd
  2347. =============
  2348. */
  2349. get_links()
  2350. {
  2351. return strtok( self.script_linkTo, " " );
  2352. }
  2353.  
  2354.  
  2355.  
  2356. /*
  2357. =============
  2358. ///ScriptDocBegin
  2359. "Name: run_thread_on_targetname( <msg> , <func> , <param1> , <param2> , <param3> )"
  2360. "Summary: Runs the specified thread on any entity with that targetname"
  2361. "Module: Utility"
  2362. "MandatoryArg: <msg>: The targetname"
  2363. "MandatoryArg: <func>: The function"
  2364. "OptionalArg: <param1>: Optional argument"
  2365. "OptionalArg: <param2>: Optional argument"
  2366. "OptionalArg: <param3>: Optional argument"
  2367. "Example: run_thread_on_targetname( "chopper_guys", ::add_spawn_function, ::chopper_guys_land );"
  2368. "SPMP: both"
  2369. ///ScriptDocEnd
  2370. =============
  2371. */
  2372.  
  2373. run_thread_on_targetname( msg, func, param1, param2, param3 )
  2374. {
  2375. array = getentarray( msg, "targetname" );
  2376. array_thread( array, func, param1, param2, param3 );
  2377.  
  2378. array = getstructarray( msg, "targetname" );
  2379. array_thread( array, func, param1, param2, param3 );
  2380.  
  2381. array = call [[ level.getNodeArrayFunction ]]( msg, "targetname" );
  2382. array_thread( array, func, param1, param2, param3 );
  2383.  
  2384. array = getvehiclenodearray( msg, "targetname" );
  2385. array_thread( array, func, param1, param2, param3 );
  2386. }
  2387.  
  2388.  
  2389. /*
  2390. =============
  2391. ///ScriptDocBegin
  2392. "Name: run_thread_on_noteworthy( <msg> , <func> , <param1> , <param2> , <param3> )"
  2393. "Summary: Runs the specified thread on any entity with that noteworthy"
  2394. "Module: Utility"
  2395. "MandatoryArg: <msg>: The noteworthy"
  2396. "MandatoryArg: <func>: The function"
  2397. "OptionalArg: <param1>: Optional argument"
  2398. "OptionalArg: <param2>: Optional argument"
  2399. "OptionalArg: <param3>: Optional argument"
  2400. "Example: run_thread_on_noteworthy( "chopper_guys", ::add_spawn_function, ::chopper_guys_land );"
  2401. "SPMP: both"
  2402. ///ScriptDocEnd
  2403. =============
  2404. */
  2405.  
  2406.  
  2407. run_thread_on_noteworthy( msg, func, param1, param2, param3 )
  2408. {
  2409. array = getentarray( msg, "script_noteworthy" );
  2410. array_thread( array, func, param1, param2, param3 );
  2411.  
  2412. array = getstructarray( msg, "script_noteworthy" );
  2413. array_thread( array, func, param1, param2, param3 );
  2414.  
  2415. array = call [[ level.getNodeArrayFunction ]]( msg, "script_noteworthy" );
  2416. array_thread( array, func, param1, param2, param3 );
  2417.  
  2418. array = getvehiclenodearray( msg, "script_noteworthy" );
  2419. array_thread( array, func, param1, param2, param3 );
  2420. }
  2421.  
  2422.  
  2423. /*
  2424. =============
  2425. ///ScriptDocBegin
  2426. "Name: draw_arrow( <start> , <end> , <color> )"
  2427. "Summary: Draws an arrow pointing at < end > in the specified color for < duration > seconds."
  2428. "Module: Entity"
  2429. "CallOn: An entity"
  2430. "MandatoryArg: <start> : starting coordinate for the arrow"
  2431. "MandatoryArg: <end> : ending coordinate for the arrow"
  2432. "MandatoryArg: <color> :( r, g, b ) color array for the arrow"
  2433. "Example: draw_arrow( lasttarg.origin, targ.origin, ( 0, 0, 1 ));"
  2434. "SPMP: both"
  2435. ///ScriptDocEnd
  2436. =============
  2437. */
  2438.  
  2439. draw_arrow( start, end, color )
  2440. {
  2441. level endon( "newpath" );
  2442. pts = [];
  2443. angles = vectortoangles( start - end );
  2444. right = anglestoright( angles );
  2445. forward = anglestoforward( angles );
  2446.  
  2447. dist = distance( start, end );
  2448. arrow = [];
  2449. range = 0.05;
  2450. arrow[ 0 ] = start;
  2451. arrow[ 1 ] = start + vector_multiply( right, dist * ( range ) ) + vector_multiply( forward, dist * - 0.2 );
  2452. arrow[ 2 ] = end;
  2453. arrow[ 3 ] = start + vector_multiply( right, dist * ( -1 * range ) ) + vector_multiply( forward, dist * - 0.2 );
  2454.  
  2455. for ( p = 0;p < 4;p++ )
  2456. {
  2457. nextpoint = p + 1;
  2458. if ( nextpoint >= 4 )
  2459. nextpoint = 0;
  2460. line( arrow[ p ], arrow[ nextpoint ], color, 1.0 );
  2461. }
  2462. }
  2463.  
  2464. /*
  2465. =============
  2466. ///ScriptDocBegin
  2467. "Name: cap_value( value, minValue, maxValue )"
  2468. "Summary: Caps a number value within a range"
  2469. "Module: Utility"
  2470. "MandatoryArg: <value>: the int or float to cap"
  2471. "OptionalArg: <minValue>: minimum allowed value"
  2472. "OptionalArg: <maxValue>: maximum allowed value"
  2473. "Example: number = cap_value( number, 0.1, 2.0 );"
  2474. "SPMP: both"
  2475. ///ScriptDocEnd
  2476. =============
  2477. */
  2478. cap_value( value, minValue, maxValue )
  2479. {
  2480. assert( isdefined( value ) );
  2481.  
  2482. // handle a min value larger than a max value
  2483. if ( minValue > maxValue )
  2484. return cap_value( value, maxValue, minValue );
  2485.  
  2486. assert( minValue <= maxValue );
  2487.  
  2488. if ( isdefined( minValue ) && ( value < minValue ) )
  2489. return minValue;
  2490.  
  2491. if ( isdefined( maxValue ) && ( value > maxValue ) )
  2492. return maxValue;
  2493.  
  2494. return value;
  2495. }
  2496.  
  2497. /*
  2498. =============
  2499. ///ScriptDocBegin
  2500. "Name: getfx( <fx> )"
  2501. "Summary: Gets the associated level._effect"
  2502. "Module: Utility"
  2503. "MandatoryArg: <fx>: The effect"
  2504. "Example: playfx ( getfx( "heli_dust_default" ), eOrgFx.origin + offset ); "
  2505. "SPMP: both"
  2506. ///ScriptDocEnd
  2507. =============
  2508. */
  2509. getfx( fx )
  2510. {
  2511. assertEx( isdefined( level._effect[ fx ] ), "Fx " + fx + " is not defined in level._effect." );
  2512. return level._effect[ fx ];
  2513. }
  2514.  
  2515. /*
  2516. =============
  2517. ///ScriptDocBegin
  2518. "Name: fxExists( <fx> )"
  2519. "Summary: Returns whether or not an fx exists"
  2520. "Module: Utility"
  2521. "MandatoryArg: <fx>: The effect"
  2522. "Example: if ( fxExists( "blah" ) )"
  2523. "SPMP: both"
  2524. ///ScriptDocEnd
  2525. =============
  2526. */
  2527. fxExists( fx )
  2528. {
  2529. return isdefined( level._effect[ fx ] );
  2530. }
  2531.  
  2532. print_csv_asset( asset, type )
  2533. {
  2534. fileline = type + "," + asset;
  2535. if ( isdefined( level.csv_lines[ fileline ] ) )
  2536. return;
  2537. level.csv_lines[ fileline ] = true;
  2538. // fileprint_chk( level.fileprint, fileline );
  2539. }
  2540.  
  2541. fileprint_csv_start( file )
  2542. {
  2543. /#
  2544. file = "scriptgen/" + file + ".csv";
  2545. level.csv_lines = [];
  2546. #/
  2547. }
  2548.  
  2549. _loadfx( effect )
  2550. {
  2551. return loadfx( effect );
  2552. }
  2553.  
  2554.  
  2555.  
  2556. /*
  2557. =============
  2558. ///ScriptDocBegin
  2559. "Name: getLastWeapon( <getLastWeapon> )"
  2560. "Summary: "
  2561. "Module: Entity"
  2562. "CallOn: An entity"
  2563. "MandatoryArg: <param1>: "
  2564. "OptionalArg: <param2>: "
  2565. "Example: "
  2566. "SPMP: both"
  2567. ///ScriptDocEnd
  2568. =============
  2569. */
  2570. getLastWeapon()
  2571. {
  2572. assert( isDefined( self.saved_lastWeapon ) );
  2573.  
  2574. return self.saved_lastWeapon;
  2575. }
  2576.  
  2577.  
  2578. /*
  2579. =============
  2580. ///ScriptDocBegin
  2581. "Name: PlayerUnlimitedAmmoThread()"
  2582. "Summary: "
  2583. "Module: Entity"
  2584. "CallOn: An entity"
  2585. "Example: "
  2586. "SPMP: both"
  2587. ///ScriptDocEnd
  2588. =============
  2589. */
  2590. PlayerUnlimitedAmmoThread()
  2591. {
  2592. /#
  2593. if ( !isdefined( self ) || self == level || self.code_classname != "player" )
  2594. player = level.player;
  2595. else
  2596. player = self;
  2597.  
  2598. assert( isdefined( player ) );
  2599.  
  2600. while ( 1 )
  2601. {
  2602. wait .5;
  2603.  
  2604. if ( getdvar( "UnlimitedAmmoOff" ) == "1" )
  2605. continue;
  2606.  
  2607. currentWeapon = player getCurrentWeapon();
  2608. if ( currentWeapon != "none" )
  2609. {
  2610. currentAmmo = player GetFractionMaxAmmo( currentWeapon );
  2611. if ( currentAmmo < 0.2 )
  2612. player GiveMaxAmmo( currentWeapon );
  2613. }
  2614. currentoffhand = player GetCurrentOffhand();
  2615. if ( currentoffhand != "none" )
  2616. {
  2617. currentAmmo = player GetFractionMaxAmmo( currentoffhand );
  2618. if ( currentAmmo < 0.4 )
  2619. player GiveMaxAmmo( currentoffhand );
  2620. }
  2621. }
  2622. #/
  2623. }
  2624.  
  2625.  
  2626. isUsabilityEnabled()
  2627. {
  2628. return ( !self.disabledUsability );
  2629. }
  2630.  
  2631.  
  2632. _disableUsability()
  2633. {
  2634. self.disabledUsability++;
  2635. self DisableUsability();
  2636. }
  2637.  
  2638.  
  2639. _enableUsability()
  2640. {
  2641. self.disabledUsability--;
  2642.  
  2643. assert( self.disabledUsability >= 0 );
  2644.  
  2645. if ( !self.disabledUsability )
  2646. self EnableUsability();
  2647. }
  2648.  
  2649.  
  2650. resetUsability()
  2651. {
  2652. self.disabledUsability = 0;
  2653. self EnableUsability();
  2654. }
  2655.  
  2656.  
  2657. _disableWeapon()
  2658. {
  2659. self.disabledWeapon++;
  2660. self disableWeapons();
  2661. }
  2662.  
  2663. _enableWeapon()
  2664. {
  2665. self.disabledWeapon--;
  2666.  
  2667. assert( self.disabledWeapon >= 0 );
  2668.  
  2669. if ( !self.disabledWeapon )
  2670. self enableWeapons();
  2671. }
  2672.  
  2673. isWeaponEnabled()
  2674. {
  2675. return ( !self.disabledWeapon );
  2676. }
  2677.  
  2678.  
  2679. _disableWeaponSwitch()
  2680. {
  2681. self.disabledWeaponSwitch++;
  2682. self disableWeaponSwitch();
  2683. }
  2684.  
  2685. _enableWeaponSwitch()
  2686. {
  2687. self.disabledWeaponSwitch--;
  2688.  
  2689. assert( self.disabledWeaponSwitch >= 0 );
  2690.  
  2691. if ( !self.disabledWeaponSwitch )
  2692. self enableWeaponSwitch();
  2693. }
  2694.  
  2695. isWeaponSwitchEnabled()
  2696. {
  2697. return ( !self.disabledWeaponSwitch );
  2698. }
  2699.  
  2700.  
  2701. _disableOffhandWeapons()
  2702. {
  2703. self.disabledOffhandWeapons++;
  2704. self DisableOffhandWeapons();
  2705. }
  2706.  
  2707. _enableOffhandWeapons()
  2708. {
  2709. self.disabledOffhandWeapons--;
  2710.  
  2711. assert( self.disabledOffhandWeapons >= 0 );
  2712.  
  2713. if ( !self.disabledOffhandWeapons )
  2714. self EnableOffhandWeapons();
  2715. }
  2716.  
  2717. isOffhandWeaponEnabled()
  2718. {
  2719. return ( !self.disabledOffhandWeapons );
  2720. }
  2721.  
  2722.  
  2723. /*
  2724. =============
  2725. ///ScriptDocBegin
  2726. "Name: random( <array> )"
  2727. "Summary: chose a random element of an array"
  2728. "Module: Array"
  2729. "CallOn: Level"
  2730. "MandatoryArg: <param1>: "
  2731. "Example: select_spot = random( array );"
  2732. "SPMP: both"
  2733. ///ScriptDocEnd
  2734. =============
  2735. */
  2736. random( array )
  2737. {
  2738. // process the array so it'll work with any string index arrays and arrays with missing entries.
  2739. newarray = [];
  2740. foreach ( index, value in array )
  2741. {
  2742. newarray[ newarray.size ] = value;
  2743. }
  2744.  
  2745. if ( !newarray.size )
  2746. return undefined;
  2747.  
  2748. return newarray[ randomint( newarray.size ) ];
  2749. }
  2750.  
  2751.  
  2752. /*
  2753. =============
  2754. ///ScriptDocBegin
  2755. "Name: spawn_tag_origin()"
  2756. "Summary: Spawn a script model with tag_origin model"
  2757. "Module: Utility"
  2758. "Example: ent = spawn_tag_origin();"
  2759. "SPMP: both"
  2760. ///ScriptDocEnd
  2761. =============
  2762. */
  2763. spawn_tag_origin()
  2764. {
  2765. tag_origin = spawn( "script_model", ( 0, 0, 0 ) );
  2766. tag_origin setmodel( "tag_origin" );
  2767. tag_origin hide();
  2768. if ( isdefined( self.origin ) )
  2769. tag_origin.origin = self.origin;
  2770. if ( isdefined( self.angles ) )
  2771. tag_origin.angles = self.angles;
  2772.  
  2773. return tag_origin;
  2774. }
  2775.  
  2776.  
  2777. /*
  2778. =============
  2779. ///ScriptDocBegin
  2780. "Name: waittill_notify_or_timeout( <msg> , <timer> )"
  2781. "Summary: "
  2782. "Module: Entity"
  2783. "CallOn: An entity"
  2784. "MandatoryArg: <param1>: "
  2785. "OptionalArg: <param2>: "
  2786. "Example: "
  2787. "SPMP: both"
  2788. ///ScriptDocEnd
  2789. =============
  2790. */
  2791. waittill_notify_or_timeout( msg, timer )
  2792. {
  2793. self endon( msg );
  2794. wait( timer );
  2795. }
  2796.  
  2797. /*
  2798. =============
  2799. ///ScriptDocBegin
  2800. "Name: fileprint_launcher_start_file()"
  2801. "Summary: Tells Launcher to start storing text to a file. Use in conjunction with fileprint_launcher() and fileprint_launcher_end_file() to append to that file and then instruct launcher to write the file."
  2802. "Module: Print"
  2803. "CallOn: Level"
  2804. "Example: fileprint_launcher_start_file();"
  2805. "SPMP: both"
  2806. ///ScriptDocEnd
  2807. =============
  2808. */
  2809.  
  2810. fileprint_launcher_start_file()
  2811. {
  2812. AssertEx( ! isdefined( level.fileprint_launcher ), "Can't open more than one file at a time to print through launcher." );
  2813. level.fileprintlauncher_linecount = 0;
  2814. level.fileprint_launcher = true;
  2815. fileprint_launcher( "GAMEPRINTSTARTFILE:" );
  2816. }
  2817.  
  2818. /*
  2819. =============
  2820. ///ScriptDocBegin
  2821. "Name: fileprint_launcher( <string> )"
  2822. "Summary: Tell launcher to append text to current open file created by fileprint_launcher_start_file(), to be closed and written with fileprint_launcher_end_file() "
  2823. "Module: Print"
  2824. "CallOn: Level"
  2825. "MandatoryArg: <param1>: "
  2826. "Example: fileprint_launcher( "main()" );"
  2827. "SPMP: both"
  2828. ///ScriptDocEnd
  2829. =============
  2830. */
  2831.  
  2832. fileprint_launcher( string )
  2833. {
  2834. assert( isdefined( level.fileprintlauncher_linecount ) );
  2835. level.fileprintlauncher_linecount++;
  2836. if( level.fileprintlauncher_linecount > 200 )
  2837. {
  2838. wait .05;
  2839. level.fileprintlauncher_linecount = 0;
  2840. }
  2841. println( "LAUNCHERPRINTLN:" + string );
  2842. }
  2843.  
  2844.  
  2845. /*
  2846. =============
  2847. ///ScriptDocBegin
  2848. "Name: fileprint_launcher_end_file( <file_relative_to_game> , <bIsPerforceEnabled> )"
  2849. "Summary: Tell launcher to write out Text that has been started and appended to using fileprint_launcher_start_file() and fileprint_launcher(). you must end a file before you can start a new one."
  2850. "Module: Print"
  2851. "CallOn: Level"
  2852. "MandatoryArg: <param1>: "
  2853. "OptionalArg: <param2>: "
  2854. "Example: fileprint_launcher_end_file( "\\share\\raw\\maps\\createart\\" + level.script + "_art.gsc, true );"
  2855. "SPMP: both"
  2856. ///ScriptDocEnd
  2857. =============
  2858. */
  2859.  
  2860. fileprint_launcher_end_file( file_relative_to_game, bIsPerforceEnabled )
  2861. {
  2862. if( !isdefined( bIsPerforceEnabled ) )
  2863. bIsPerforceEnabled = false;
  2864.  
  2865. setDevDvarIfUninitialized("LAUNCHER_PRINT_FAIL", "0");
  2866. setDevDvarIfUninitialized("LAUNCHER_PRINT_SUCCESS", "0");
  2867.  
  2868. if( bIsPerforceEnabled )
  2869. fileprint_launcher( "GAMEPRINTENDFILE:GAMEPRINTP4ENABLED:"+file_relative_to_game );
  2870. else
  2871. fileprint_launcher( "GAMEPRINTENDFILE:"+file_relative_to_game );
  2872.  
  2873. // wait for launcher to tell us that it's done writing the file
  2874. TimeOut = gettime()+4000; // give launcher 4 seconds to print the file.
  2875. while( getdvarint( "LAUNCHER_PRINT_SUCCESS" ) == 0 && getdvar( "LAUNCHER_PRINT_FAIL" ) == "0" && gettime() < TimeOut )
  2876. wait .05;
  2877.  
  2878. if( ! ( gettime() < TimeOut ) )
  2879. {
  2880. iprintlnbold("LAUNCHER_PRINT_FAIL:( TIMEOUT ): launcherconflict? restart launcher and try again? " );
  2881. setdevdvar("LAUNCHER_PRINT_FAIL", "0");
  2882. level.fileprint_launcher = undefined;
  2883. return false;
  2884. }
  2885.  
  2886. failvar = getdvar("LAUNCHER_PRINT_FAIL");
  2887. if( failvar != "0" )
  2888. {
  2889. iprintlnbold("LAUNCHER_PRINT_FAIL:( "+ failvar + " ): launcherconflict? restart launcher and try again? " );
  2890. setdevdvar("LAUNCHER_PRINT_FAIL", "0");
  2891. level.fileprint_launcher = undefined;
  2892. return false;
  2893. }
  2894.  
  2895. setdevdvar("LAUNCHER_PRINT_FAIL", "0");
  2896. setdevdvar( "LAUNCHER_PRINT_SUCCESS", "0" );
  2897.  
  2898. level.fileprint_launcher = undefined;
  2899. return true;
  2900. }
  2901.  
  2902. /*
  2903. =============
  2904. ///ScriptDocBegin
  2905. "Name: launcher_write_clipboard( <str> )"
  2906. "Summary: send a string to your Connected PC's clipboard through launcher"
  2907. "Module: Print"
  2908. "CallOn: An entity"
  2909. "MandatoryArg: <param1>: "
  2910. "OptionalArg: <param2>: "
  2911. "Example: launcher_write_clipboard( Players_origin_string )"
  2912. "SPMP: both"
  2913. ///ScriptDocEnd
  2914. =============
  2915. */
  2916. launcher_write_clipboard( str )
  2917. {
  2918. level.fileprintlauncher_linecount = 0;
  2919. fileprint_launcher( "LAUNCHER_CLIP:" + str );
  2920. }
  2921.  
  2922. /*
  2923. =============
  2924. ///ScriptDocBegin
  2925. "Name: isDestructible()"
  2926. "Summary: returns true if self is a destructible"
  2927. "Module: Entity"
  2928. "CallOn: An entity"
  2929. "Example: if ( self isDestructible() )"
  2930. "SPMP: both"
  2931. ///ScriptDocEnd
  2932. =============
  2933. */
  2934. isDestructible()
  2935. {
  2936. if ( !isdefined( self ) )
  2937. return false;
  2938. return isdefined( self.destructible_type );
  2939. }
  2940.  
  2941. /*
  2942. =============
  2943. ///ScriptDocBegin
  2944. "Name: pauseEffect( <pauseEffect> )"
  2945. "Summary: "
  2946. "Module: Entity"
  2947. "CallOn: An entity"
  2948. "MandatoryArg: <param1>: "
  2949. "OptionalArg: <param2>: "
  2950. "Example: "
  2951. "SPMP: both"
  2952. ///ScriptDocEnd
  2953. =============
  2954. */
  2955. pauseEffect()
  2956. {
  2957. common_scripts\_createfx::stop_fx_looper();
  2958. }
  2959.  
  2960. /*
  2961. =============
  2962. ///ScriptDocBegin
  2963. "Name: activate_individual_exploder()"
  2964. "Summary: Activates an individual exploder, rather than all the exploders of a given number"
  2965. "Module: Utility"
  2966. "CallOn: An exploder"
  2967. "Example: exploder activate_individual_exploder();"
  2968. "SPMP: both"
  2969. ///ScriptDocEnd
  2970. =============
  2971. */
  2972. activate_individual_exploder()
  2973. {
  2974. if ( IsDefined( self.v[ "firefx" ] ) )
  2975. self thread fire_effect();
  2976.  
  2977. if ( IsDefined( self.v[ "fxid" ] ) && self.v[ "fxid" ] != "No FX" )
  2978. self thread cannon_effect();
  2979. else
  2980. if ( IsDefined( self.v[ "soundalias" ] ) && self.v[ "soundalias" ] != "nil" )
  2981. self thread sound_effect();
  2982.  
  2983. if ( IsDefined( self.v[ "loopsound" ] ) && self.v[ "loopsound" ] != "nil" )
  2984. self thread effect_loopsound();
  2985.  
  2986. if ( IsDefined( self.v[ "damage" ] ) )
  2987. self thread exploder_damage();
  2988.  
  2989. if ( IsDefined( self.v[ "earthquake" ] ) )
  2990. self thread exploder_earthquake();
  2991.  
  2992. if ( IsDefined( self.v[ "rumble" ] ) )
  2993. self thread exploder_rumble();
  2994.  
  2995. if ( self.v[ "exploder_type" ] == "exploder" )
  2996. self thread brush_show();
  2997. else
  2998. if ( ( self.v[ "exploder_type" ] == "exploderchunk" ) || ( self.v[ "exploder_type" ] == "exploderchunk visible" ) )
  2999. self thread brush_throw();
  3000. else
  3001. self thread brush_delete();
  3002. }
  3003.  
  3004. waitframe()
  3005. {
  3006. wait( 0.05 );
  3007. }
  3008.  
  3009. brush_delete()
  3010. {
  3011. // if( ent.v[ "exploder_type" ] != "normal" && !isdefined( ent.v[ "fxid" ] ) && !isdefined( ent.v[ "soundalias" ] ) )
  3012. // if( !isdefined( ent.script_fxid ) )
  3013.  
  3014. num = self.v[ "exploder" ];
  3015. if ( IsDefined( self.v[ "delay" ] ) )
  3016. wait( self.v[ "delay" ] );
  3017. else
  3018. wait( .05 );// so it disappears after the replacement appears
  3019.  
  3020. if ( !isdefined( self.model ) )
  3021. return;
  3022.  
  3023.  
  3024. Assert( IsDefined( self.model ) );
  3025.  
  3026. if ( isSP() && ( self.model.spawnflags & 1 ) )
  3027. self.model call [[ level.connectPathsFunction ]]();
  3028.  
  3029. if ( level.createFX_enabled )
  3030. {
  3031. if ( IsDefined( self.exploded ) )
  3032. return;
  3033.  
  3034. self.exploded = true;
  3035. self.model Hide();
  3036. self.model NotSolid();
  3037.  
  3038. wait( 3 );
  3039. self.exploded = undefined;
  3040. self.model Show();
  3041. self.model Solid();
  3042. return;
  3043. }
  3044.  
  3045. if ( !isdefined( self.v[ "fxid" ] ) || self.v[ "fxid" ] == "No FX" )
  3046. self.v[ "exploder" ] = undefined;
  3047.  
  3048. waittillframeend;// so it hides stuff after it shows the new stuff
  3049. self.model Delete();
  3050. }
  3051.  
  3052. brush_throw()
  3053. {
  3054. if ( IsDefined( self.v[ "delay" ] ) )
  3055. wait( self.v[ "delay" ] );
  3056.  
  3057. ent = undefined;
  3058. if ( IsDefined( self.v[ "target" ] ) )
  3059. ent = get_target_ent( self.v[ "target" ] );
  3060.  
  3061. if ( !isdefined( ent ) )
  3062. {
  3063. self.model Delete();
  3064. return;
  3065. }
  3066.  
  3067. self.model Show();
  3068.  
  3069. if ( IsDefined( self.v[ "delay_post" ] ) )
  3070. wait( self.v[ "delay_post" ] );
  3071.  
  3072. startorg = self.v[ "origin" ];
  3073. startang = self.v[ "angles" ];
  3074. org = ent.origin;
  3075.  
  3076. temp_vec = ( org - self.v[ "origin" ] );
  3077. x = temp_vec[ 0 ];
  3078. y = temp_vec[ 1 ];
  3079. z = temp_vec[ 2 ];
  3080.  
  3081. physics = IsDefined( self.v[ "physics" ] );
  3082. if ( physics )
  3083. {
  3084. target = undefined;
  3085. if ( IsDefined( ent.target ) )
  3086. target = ent get_target_ent();
  3087.  
  3088. if ( !isdefined( target ) )
  3089. {
  3090. contact_point = startorg;// no spin just push it.
  3091. throw_vec = ent.origin;
  3092. }
  3093. else
  3094. {
  3095. contact_point = ent.origin;
  3096. throw_vec = vector_multiply( target.origin - ent.origin, self.v[ "physics" ] );
  3097.  
  3098. }
  3099.  
  3100. // model = Spawn( "script_model", startorg );
  3101. // model.angles = startang;
  3102. // model PhysicsLaunchClient( model.origin, temp_vec );
  3103. self.model PhysicsLaunchClient( contact_point, throw_vec );
  3104. return;
  3105. }
  3106. else
  3107. {
  3108. self.model RotateVelocity( ( x, y, z ), 12 );
  3109. self.model MoveGravity( ( x, y, z ), 12 );
  3110. }
  3111.  
  3112. if ( level.createFX_enabled )
  3113. {
  3114. if ( IsDefined( self.exploded ) )
  3115. return;
  3116.  
  3117. self.exploded = true;
  3118. wait( 3 );
  3119. self.exploded = undefined;
  3120. self.v[ "origin" ] = startorg;
  3121. self.v[ "angles" ] = startang;
  3122. self.model Hide();
  3123. return;
  3124. }
  3125.  
  3126. self.v[ "exploder" ] = undefined;
  3127. wait( 6 );
  3128. self.model Delete();
  3129. // self Delete();
  3130. }
  3131.  
  3132. /*
  3133. =============
  3134. ///ScriptDocBegin
  3135. "Name: get_target_ent( <target> )"
  3136. "Summary: Returns whatever SINGLE ent is targetted, be it node, struct, or entity"
  3137. "Module: Utility"
  3138. "OptionalArg: <target>: Optional target override"
  3139. "Example: node = guy get_target_ent();"
  3140. "SPMP: both"
  3141. ///ScriptDocEnd
  3142. =============
  3143. */
  3144. get_target_ent( target )
  3145. {
  3146. if ( !isdefined( target ) )
  3147. target = self.target;
  3148.  
  3149. AssertEx( IsDefined( target ), "Self had no target!" );
  3150.  
  3151. ent = GetEnt( target, "targetname" );
  3152. if ( IsDefined( ent ) )
  3153. return ent;
  3154.  
  3155. if ( isSP() )
  3156. {
  3157. ent = call [[ level.getNodeFunction ]]( target, "targetname" );
  3158. if ( IsDefined( ent ) )
  3159. return ent;
  3160. }
  3161.  
  3162. ent = getstruct( target, "targetname" );
  3163. if ( IsDefined( ent ) )
  3164. return ent;
  3165.  
  3166. ent = GetVehicleNode( target, "targetname" );
  3167. if ( IsDefined( ent ) )
  3168. return ent;
  3169.  
  3170. AssertEx( "Tried to get ent, but there was no ent." );
  3171. }
  3172.  
  3173. brush_show()
  3174. {
  3175. if ( IsDefined( self.v[ "delay" ] ) )
  3176. wait( self.v[ "delay" ] );
  3177.  
  3178. Assert( IsDefined( self.model ) );
  3179.  
  3180. self.model Show();
  3181. self.model Solid();
  3182.  
  3183. self.brush_shown = true; // used for hiding an exploder.
  3184.  
  3185. if ( isSP() && ( self.model.spawnflags & 1 ) )
  3186. {
  3187. if ( !isdefined( self.model.disconnect_paths ) )
  3188. self.model call [[ level.connectPathsFunction ]]();
  3189. else
  3190. self.model call [[ level.disconnectPathsFunction ]]();
  3191. }
  3192.  
  3193. if ( level.createFX_enabled )
  3194. {
  3195. if ( IsDefined( self.exploded ) )
  3196. return;
  3197.  
  3198. self.exploded = true;
  3199. wait( 3 );
  3200. self.exploded = undefined;
  3201. self.model Hide();
  3202. self.model NotSolid();
  3203. }
  3204. }
  3205.  
  3206. exploder_earthquake()
  3207. {
  3208. self exploder_delay();
  3209. eq = level.earthquake[ self.v[ "earthquake" ] ];
  3210. Earthquake( eq[ "magnitude" ], eq[ "duration" ], self.v[ "origin" ], eq[ "radius" ] );
  3211. }
  3212.  
  3213. exploder_rumble()
  3214. {
  3215. if ( !isSP() )
  3216. return;
  3217.  
  3218. self exploder_delay();
  3219. level.player PlayRumbleOnEntity( self.v[ "rumble" ] );
  3220. }
  3221.  
  3222. exploder_delay()
  3223. {
  3224. if ( !isdefined( self.v[ "delay" ] ) )
  3225. self.v[ "delay" ] = 0;
  3226.  
  3227. min_delay = self.v[ "delay" ];
  3228. max_delay = self.v[ "delay" ] + 0.001;// cant randomfloatrange on the same #
  3229. if ( IsDefined( self.v[ "delay_min" ] ) )
  3230. min_delay = self.v[ "delay_min" ];
  3231.  
  3232. if ( IsDefined( self.v[ "delay_max" ] ) )
  3233. max_delay = self.v[ "delay_max" ];
  3234.  
  3235. if ( min_delay > 0 )
  3236. wait( RandomFloatRange( min_delay, max_delay ) );
  3237. }
  3238.  
  3239. exploder_damage()
  3240. {
  3241. if ( IsDefined( self.v[ "delay" ] ) )
  3242. delay = self.v[ "delay" ];
  3243. else
  3244. delay = 0;
  3245.  
  3246. if ( IsDefined( self.v[ "damage_radius" ] ) )
  3247. radius = self.v[ "damage_radius" ];
  3248. else
  3249. radius = 128;
  3250.  
  3251. damage = self.v[ "damage" ];
  3252. origin = self.v[ "origin" ];
  3253.  
  3254. wait( delay );
  3255. // Range, max damage, min damage
  3256. RadiusDamage( origin, radius, damage, damage );
  3257. }
  3258.  
  3259. effect_loopsound()
  3260. {
  3261. if ( IsDefined( self.loopsound_ent ) )
  3262. {
  3263. self.loopsound_ent Delete();
  3264. }
  3265. // save off this info in case we delete the effect
  3266. origin = self.v[ "origin" ];
  3267. alias = self.v[ "loopsound" ];
  3268. self exploder_delay();
  3269.  
  3270. self.loopsound_ent = play_loopsound_in_space( alias, origin );
  3271. }
  3272.  
  3273. /*
  3274. =============
  3275. ///ScriptDocBegin
  3276. "Name: play_loopsound_in_space( <alias> , <origin> , <master> )"
  3277. "Summary: Use the PlayLoopSound command at a position in space. Unrelated to caller."
  3278. "Module: Sound"
  3279. "CallOn: Level"
  3280. "MandatoryArg: <alias> : Sound alias to play"
  3281. "MandatoryArg: <origin> : Origin of the sound"
  3282. "Example: play_loopsound_in_space( "siren", level.speaker.origin );"
  3283. "SPMP: both"
  3284. ///ScriptDocEnd
  3285. =============
  3286. */
  3287. play_loopsound_in_space( alias, origin )
  3288. {
  3289. org = Spawn( "script_origin", ( 0, 0, 0 ) );
  3290. if ( !isdefined( origin ) )
  3291. origin = self.origin;
  3292.  
  3293. org.origin = origin;
  3294.  
  3295. org PlayLoopSound( alias, "sounddone" );
  3296. return org;
  3297. }
  3298.  
  3299. sound_effect()
  3300. {
  3301. self effect_soundalias();
  3302. }
  3303.  
  3304. effect_soundalias()
  3305. {
  3306. // save off this info in case we delete the effect
  3307. origin = self.v[ "origin" ];
  3308. alias = self.v[ "soundalias" ];
  3309. self exploder_delay();
  3310. play_sound_in_space( alias, origin );
  3311. }
  3312.  
  3313. /*
  3314. =============
  3315. ///ScriptDocBegin
  3316. "Name: play_sound_in_space( <alias> , <origin> , <master> )"
  3317. "Summary: Play a sound at an origin, unrelated to caller"
  3318. "Module: Sound"
  3319. "CallOn: Level"
  3320. "MandatoryArg: <alias> : Sound alias to play"
  3321. "MandatoryArg: <origin> : Origin of the sound"
  3322. "OptionalArg: <master> : Play this sound as a master sound. Defaults to false"
  3323. "Example: play_sound_in_space( "siren", level.speaker.origin );"
  3324. "SPMP: singleplayer"
  3325. ///ScriptDocEnd
  3326. =============
  3327. */
  3328. play_sound_in_space( alias, origin, master )
  3329. {
  3330. org = Spawn( "script_origin", ( 0, 0, 1 ) );
  3331. if ( !isdefined( origin ) )
  3332. origin = self.origin;
  3333. org.origin = origin;
  3334. if ( isSP() )
  3335. {
  3336. if ( IsDefined( master ) && master )
  3337. org PlaySoundAsMaster( alias, "sounddone" );
  3338. else
  3339. org PlaySound( alias, "sounddone" );
  3340. }
  3341. else
  3342. {
  3343. if ( IsDefined( master ) && master )
  3344. org PlaySoundAsMaster( alias );
  3345. else
  3346. org PlaySound( alias );
  3347. }
  3348. org waittill( "sounddone" );
  3349. org Delete();
  3350. }
  3351.  
  3352. cannon_effect()
  3353. {
  3354. if ( IsDefined( self.v[ "repeat" ] ) )
  3355. {
  3356. thread exploder_playSound();
  3357. for ( i = 0; i < self.v[ "repeat" ]; i++ )
  3358. {
  3359. PlayFX( level._effect[ self.v[ "fxid" ] ], self.v[ "origin" ], self.v[ "forward" ], self.v[ "up" ] );
  3360. self exploder_delay();
  3361. }
  3362. return;
  3363. }
  3364. self exploder_delay();
  3365.  
  3366. // PlayFX( level._effect[ self.v[ "fxid" ] ], self.v[ "origin" ], self.v[ "forward" ], self.v[ "up" ] );
  3367. if ( IsDefined( self.looper ) )
  3368. self.looper Delete();
  3369.  
  3370. self.looper = SpawnFx( getfx( self.v[ "fxid" ] ), self.v[ "origin" ], self.v[ "forward" ], self.v[ "up" ] );
  3371. TriggerFX( self.looper );
  3372. exploder_playSound();
  3373. }
  3374.  
  3375. exploder_playSound()
  3376. {
  3377. if ( !isdefined( self.v[ "soundalias" ] ) || self.v[ "soundalias" ] == "nil" )
  3378. return;
  3379.  
  3380. play_sound_in_space( self.v[ "soundalias" ], self.v[ "origin" ] );
  3381. }
  3382.  
  3383. fire_effect()
  3384. {
  3385. forward = self.v[ "forward" ];
  3386. up = self.v[ "up" ];
  3387.  
  3388. org = undefined;
  3389.  
  3390. firefxSound = self.v[ "firefxsound" ];
  3391. origin = self.v[ "origin" ];
  3392. firefx = self.v[ "firefx" ];
  3393. ender = self.v[ "ender" ];
  3394. if ( !isdefined( ender ) )
  3395. ender = "createfx_effectStopper";
  3396. timeout = self.v[ "firefxtimeout" ];
  3397.  
  3398. fireFxDelay = 0.5;
  3399. if ( IsDefined( self.v[ "firefxdelay" ] ) )
  3400. fireFxDelay = self.v[ "firefxdelay" ];
  3401.  
  3402. self exploder_delay();
  3403.  
  3404. if ( IsDefined( firefxSound ) )
  3405. level thread loop_fx_sound( firefxSound, origin, ender, timeout );
  3406.  
  3407. PlayFX( level._effect[ firefx ], self.v[ "origin" ], forward, up );
  3408.  
  3409. // loopfx( fxId, fxPos, waittime, fxPos2, fxStart, fxStop, timeout )
  3410. // maps\_fx::loopfx( firefx, origin, delay, org, undefined, ender, timeout );
  3411. }
  3412.  
  3413. /*
  3414. =============
  3415. ///ScriptDocBegin
  3416. "Name: loop_fx_sound( <alias> , <origin> , <ender> , <timeout> )"
  3417. "Summary: "
  3418. "Module: Entity"
  3419. "CallOn: An entity"
  3420. "MandatoryArg: <param1>: "
  3421. "OptionalArg: <param2>: "
  3422. "Example: "
  3423. "SPMP: both"
  3424. ///ScriptDocEnd
  3425. =============
  3426. */
  3427. loop_fx_sound( alias, origin, ender, timeout )
  3428. {
  3429. org = Spawn( "script_origin", ( 0, 0, 0 ) );
  3430. if ( IsDefined( ender ) )
  3431. {
  3432. thread loop_sound_delete( ender, org );
  3433. self endon( ender );
  3434. }
  3435. org.origin = origin;
  3436. org PlayLoopSound( alias );
  3437. if ( !isdefined( timeout ) )
  3438. {
  3439. org willNeverChange();
  3440. return;
  3441. }
  3442.  
  3443. wait( timeout );
  3444. // org Delete();
  3445. }
  3446.  
  3447. /*
  3448. =============
  3449. ///ScriptDocBegin
  3450. "Name: loop_sound_delete( <ender> , <ent> )"
  3451. "Summary: "
  3452. "Module: Entity"
  3453. "CallOn: An entity"
  3454. "MandatoryArg: <param1>: "
  3455. "OptionalArg: <param2>: "
  3456. "Example: "
  3457. "SPMP: both"
  3458. ///ScriptDocEnd
  3459. =============
  3460. */
  3461. loop_sound_delete( ender, ent )
  3462. {
  3463. ent endon( "death" );
  3464. self waittill( ender );
  3465. ent Delete();
  3466. }
  3467.  
  3468. exploder_before_load( num )
  3469. {
  3470. // gotta wait twice because the createfx_init function waits once then inits all exploders. This guarentees
  3471. // that if an exploder is run on the first frame, it happens after the fx are init.
  3472. waittillframeend;
  3473. waittillframeend;
  3474. activate_exploder( num );
  3475. }
  3476.  
  3477. exploder_after_load( num )
  3478. {
  3479. activate_exploder( num );
  3480. }
  3481.  
  3482. /*
  3483. =============
  3484. ///ScriptDocBegin
  3485. "Name: activate_exploder( <num> )"
  3486. "Summary: "
  3487. "Module: Entity"
  3488. "CallOn: An entity"
  3489. "MandatoryArg: <param1>: "
  3490. "OptionalArg: <param2>: "
  3491. "Example: "
  3492. "SPMP: both"
  3493. ///ScriptDocEnd
  3494. =============
  3495. */
  3496. activate_exploder( num )
  3497. {
  3498. num += "";
  3499.  
  3500. prof_begin( "activate_exploder" );
  3501.  
  3502. //here's a hook so you can know when a certain number of an exploder is going off
  3503. level notify( "exploding_" + num );
  3504.  
  3505. for ( i = 0;i < level.createFXent.size;i++ )
  3506. {
  3507. ent = level.createFXent[ i ];
  3508. if ( !isdefined( ent ) )
  3509. continue;
  3510.  
  3511. if ( ent.v[ "type" ] != "exploder" )
  3512. continue;
  3513.  
  3514. // make the exploder actually removed the array instead?
  3515. if ( !isdefined( ent.v[ "exploder" ] ) )
  3516. continue;
  3517.  
  3518. if ( ent.v[ "exploder" ] + "" != num )
  3519. continue;
  3520.  
  3521. ent activate_individual_exploder();
  3522. }
  3523. prof_end( "activate_exploder" );
  3524. }
  3525.  
  3526. /*
  3527. =============
  3528. ///ScriptDocBegin
  3529. "Name: createLoopEffect( <fxid> )"
  3530. "Summary: "
  3531. "Module: Entity"
  3532. "CallOn: An entity"
  3533. "MandatoryArg: <param1>: "
  3534. "OptionalArg: <param2>: "
  3535. "Example: "
  3536. "SPMP: both"
  3537. ///ScriptDocEnd
  3538. =============
  3539. */
  3540. createLoopEffect( fxid )
  3541. {
  3542. ent = common_scripts\_createfx::createEffect( "loopfx", fxid );
  3543. ent.v[ "delay" ] = 0.5;
  3544. return ent;
  3545. }
  3546.  
  3547. /*
  3548. =============
  3549. ///ScriptDocBegin
  3550. "Name: createOneshotEffect( <fxid> )"
  3551. "Summary: "
  3552. "Module: Entity"
  3553. "CallOn: An entity"
  3554. "MandatoryArg: <param1>: "
  3555. "OptionalArg: <param2>: "
  3556. "Example: "
  3557. "SPMP: both"
  3558. ///ScriptDocEnd
  3559. =============
  3560. */
  3561. createOneshotEffect( fxid )
  3562. {
  3563. // uses triggerfx
  3564. ent = common_scripts\_createfx::createEffect( "oneshotfx", fxid );
  3565. ent.v[ "delay" ] = -15;
  3566. return ent;
  3567. }
  3568.  
  3569. /*
  3570. =============
  3571. ///ScriptDocBegin
  3572. "Name: createExploder( <fxid> )"
  3573. "Summary: "
  3574. "Module: Entity"
  3575. "CallOn: An entity"
  3576. "MandatoryArg: <param1>: "
  3577. "OptionalArg: <param2>: "
  3578. "Example: "
  3579. "SPMP: both"
  3580. ///ScriptDocEnd
  3581. =============
  3582. */
  3583. createExploder( fxid )
  3584. {
  3585. ent = common_scripts\_createfx::createEffect( "exploder", fxid );
  3586. ent.v[ "delay" ] = 0;
  3587. ent.v[ "exploder_type" ] = "normal";
  3588. return ent;
  3589. }
  3590.  
  3591. /*
  3592. =============
  3593. ///ScriptDocBegin
  3594. "Name: alphabetize( <array> )"
  3595. "Summary: "
  3596. "Module: Entity"
  3597. "CallOn: An entity"
  3598. "MandatoryArg: <param1>: "
  3599. "OptionalArg: <param2>: "
  3600. "Example: "
  3601. "SPMP: both"
  3602. ///ScriptDocEnd
  3603. =============
  3604. */
  3605. alphabetize( array )
  3606. {
  3607. if ( array.size <= 1 )
  3608. return array;
  3609.  
  3610. addwaits = false;
  3611. if ( isSP() )
  3612. addwaits = true;
  3613.  
  3614. count = 0;
  3615. for ( ;; )
  3616. {
  3617. changed = false;
  3618. for ( i = 0; i < array.size - 1; i++ )
  3619. {
  3620. if ( is_later_in_alphabet( array[ i ], array[ i + 1 ] ) )
  3621. {
  3622. val = array[ i ];
  3623. array[ i ] = array[ i + 1 ];
  3624. array[ i + 1 ] = val;
  3625. changed = true;
  3626.  
  3627. if ( addwaits )
  3628. {
  3629. count++;
  3630. if ( count >= 10 )
  3631. {
  3632. count = 0;
  3633. waitframe();
  3634. }
  3635. }
  3636. }
  3637. }
  3638.  
  3639. if ( !changed )
  3640. return array;
  3641. }
  3642.  
  3643. return array;
  3644. }
  3645.  
  3646. is_later_in_alphabet( string1, string2 )
  3647. {
  3648. count = string1.size;
  3649. if ( count >= string2.size )
  3650. count = string2.size;
  3651.  
  3652. for ( i = 0; i < count; i++ )
  3653. {
  3654. val = alphabet_compare( string1[ i ], string2[ i ] );
  3655. if ( val == "1st" )
  3656. return true;
  3657. if ( val == "2nd" )
  3658. return false;
  3659. }
  3660.  
  3661. return string1.size > string2.size;
  3662. }
  3663.  
  3664. alphabet_compare( a, b )
  3665. {
  3666. list = [];
  3667. val = 1;
  3668. list[ "0" ] = val; val++;
  3669. list[ "1" ] = val; val++;
  3670. list[ "2" ] = val; val++;
  3671. list[ "3" ] = val; val++;
  3672. list[ "4" ] = val; val++;
  3673. list[ "5" ] = val; val++;
  3674. list[ "6" ] = val; val++;
  3675. list[ "7" ] = val; val++;
  3676. list[ "8" ] = val; val++;
  3677. list[ "9" ] = val; val++;
  3678. list[ "_" ] = val; val++;
  3679. list[ "a" ] = val; val++;
  3680. list[ "b" ] = val; val++;
  3681. list[ "c" ] = val; val++;
  3682. list[ "d" ] = val; val++;
  3683. list[ "e" ] = val; val++;
  3684. list[ "f" ] = val; val++;
  3685. list[ "g" ] = val; val++;
  3686. list[ "h" ] = val; val++;
  3687. list[ "i" ] = val; val++;
  3688. list[ "j" ] = val; val++;
  3689. list[ "k" ] = val; val++;
  3690. list[ "l" ] = val; val++;
  3691. list[ "m" ] = val; val++;
  3692. list[ "n" ] = val; val++;
  3693. list[ "o" ] = val; val++;
  3694. list[ "p" ] = val; val++;
  3695. list[ "q" ] = val; val++;
  3696. list[ "r" ] = val; val++;
  3697. list[ "s" ] = val; val++;
  3698. list[ "t" ] = val; val++;
  3699. list[ "u" ] = val; val++;
  3700. list[ "v" ] = val; val++;
  3701. list[ "w" ] = val; val++;
  3702. list[ "x" ] = val; val++;
  3703. list[ "y" ] = val; val++;
  3704. list[ "z" ] = val; val++;
  3705.  
  3706. a = ToLower( a );
  3707. b = ToLower( b );
  3708. val1 = 0;
  3709. if ( IsDefined( list[ a ] ) )
  3710. val1 = list[ a ];
  3711.  
  3712. val2 = 0;
  3713. if ( IsDefined( list[ b ] ) )
  3714. val2 = list[ b ];
  3715.  
  3716. if ( val1 > val2 )
  3717. return "1st";
  3718. if ( val1 < val2 )
  3719. return "2nd";
  3720. return "same";
  3721. }
  3722.  
  3723. /*
  3724. =============
  3725. ///ScriptDocBegin
  3726. "Name: play_loop_sound_on_entity( <alias> , <offset> )"
  3727. "Summary: Play loop sound alias on an entity"
  3728. "Module: Sound"
  3729. "CallOn: An entity"
  3730. "MandatoryArg: <alias> : Sound alias to loop"
  3731. "OptionalArg: <offset> : Offset for sound origin relative to the world from the models origin."
  3732. "Example: vehicle thread play_loop_sound_on_entity( "engine_belt_run" );"
  3733. "SPMP: both"
  3734. ///ScriptDocEnd
  3735. =============
  3736. */
  3737. play_loop_sound_on_entity( alias, offset )
  3738. {
  3739. org = Spawn( "script_origin", ( 0, 0, 0 ) );
  3740. org endon( "death" );
  3741. thread delete_on_death( org );
  3742.  
  3743. if ( IsDefined( offset ) )
  3744. {
  3745. org.origin = self.origin + offset;
  3746. org.angles = self.angles;
  3747. org LinkTo( self );
  3748. }
  3749. else
  3750. {
  3751. org.origin = self.origin;
  3752. org.angles = self.angles;
  3753. org LinkTo( self );
  3754. }
  3755.  
  3756. // org endon( "death" );
  3757. org PlayLoopSound( alias );
  3758. // PrintLn( "playing loop sound ", alias, " on entity at origin ", self.origin, " at ORIGIN ", org.origin );
  3759.  
  3760. self waittill( "stop sound" + alias );
  3761. org StopLoopSound( alias );
  3762. org Delete();
  3763. }
  3764.  
  3765. /*
  3766. =============
  3767. ///ScriptDocBegin
  3768. "Name: stop_loop_sound_on_entity( <alias> )"
  3769. "Summary: Stop playing the the loop sound alias on an entity"
  3770. "Module: Sound"
  3771. "CallOn: An entity"
  3772. "MandatoryArg: <alias> : Sound alias to stop looping"
  3773. "Example: vehicle thread stop_loop_sound_on_entity( "engine_belt_run" );"
  3774. "SPMP: both"
  3775. ///ScriptDocEnd
  3776. =============
  3777. */
  3778. stop_loop_sound_on_entity( alias )
  3779. {
  3780. self notify( "stop sound" + alias );
  3781. }
  3782.  
  3783. /*
  3784. =============
  3785. ///ScriptDocBegin
  3786. "Name: delete_on_death( <ent> )"
  3787. "Summary: Delete the entity when "self" dies."
  3788. "Module: Entity"
  3789. "CallOn: An entity"
  3790. "MandatoryArg: <param1>: "
  3791. "OptionalArg: <param2>: "
  3792. "Example: level.helicopter thread delete_on_death( someRandomScriptOriginThatISpawned );"
  3793. "SPMP: both"
  3794. ///ScriptDocEnd
  3795. =============
  3796. */
  3797. delete_on_death( ent )
  3798. {
  3799. //self ==> the entity you want to wait to die before deleting the ent
  3800. ent endon( "death" );
  3801. self waittill( "death" );
  3802. if ( IsDefined( ent ) )
  3803. ent Delete();
  3804. }
  3805.  
  3806. error( msg )
  3807. {
  3808. PrintLn( "^c * ERROR * ", msg );
  3809. waitframe();
  3810.  
  3811. /#
  3812. if ( GetDvar( "debug" ) != "1" )
  3813. AssertMsg( "This is a forced error - attach the log file. \n" + msg );
  3814. #/
  3815. }
  3816.  
  3817. /*
  3818. =============
  3819. ///ScriptDocBegin
  3820. "Name: exploder( <num> )"
  3821. "Summary: Sets off the desired exploder"
  3822. "Module: Utility"
  3823. "MandatoryArg: <num>: The exploder number"
  3824. "Example: exploder( 5 );"
  3825. "SPMP: both"
  3826. ///ScriptDocEnd
  3827. =============
  3828. */
  3829. exploder( num )
  3830. {
  3831. [[ level.exploderFunction ]]( num );
  3832. }
  3833.  
  3834.  
  3835. /*
  3836. =============
  3837. ///ScriptDocBegin
  3838. "Name: create_dvar( <var> , <val> )"
  3839. "Summary: Initialize a dvar with a given value"
  3840. "Module: Utility"
  3841. "MandatoryArg: <var>: Name of the dvar"
  3842. "MandatoryArg: <val>: Default value"
  3843. "Example: create_dvar( "fish", "on" );"
  3844. "SPMP: singleplayer"
  3845. ///ScriptDocEnd
  3846. =============
  3847. */
  3848. create_dvar( var, val )
  3849. {
  3850. SetDvarIfUninitialized( var, val );
  3851. }
  3852.  
  3853.  
  3854. void()
  3855. {
  3856. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement