pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

dim3 private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Bink on Sun 13 Jul 19:52
report abuse | download | new post

  1. // ***********************************************************
  2.  
  3. //
  4. // Player Script
  5.  
  6. //
  7.  
  8. // This script runs the player's object.
  9.  
  10. //
  11.  
  12. // ***********************************************************
  13.  
  14.  
  15.  
  16. //
  17.  
  18. // This code setups a object that will contain information about a single weapon
  19.  
  20. // that the player owns.  An array of these objects will be created, one for each
  21.  
  22. // weapon.  This array will be used to install the weapons (in the construct) and
  23.  
  24. // run the HUD.
  25.  
  26. //
  27.  
  28. // All this information could just be hard-code within the script, but this
  29.  
  30. // way is more "object-oriented", easy to change and easy to read.
  31.  
  32. //
  33.  
  34. // Note that there is one additional weapon that is hard coded into the script.  This
  35.  
  36. // is the throwable grenade.  This weapon is special as it is not selectable, but
  37.  
  38. // instead auto-fired by a player message.
  39.  
  40. //
  41.  
  42.  
  43.  
  44. function playerWeapon(name,displayName,bitmapName,meshName,hasClip,hasAmmo)
  45.  
  46. {
  47.  
  48.         this.name=name;                                 // name of weapon
  49.  
  50.         this.displayName=displayName;   // display name of weapon
  51.  
  52.         this.bitmapName=bitmapName;             // name of bitmap in hud that represents this weapon
  53.  
  54.         this.meshName=meshName;                 // name of mesh in player model that represents this weapon
  55.  
  56.         this.hasClip=hasClip;                   // if this weapon uses clips
  57.  
  58.         this.hasAmmo=hasAmmo;                   // if this weapon has ammo
  59.  
  60. }
  61.  
  62.  
  63.  
  64. //
  65.  
  66. // Now we create an array of these definitions.  These arrays will be used to construct
  67.  
  68. // the weapons in the rest of the script.
  69.  
  70. //
  71.  
  72.  
  73.  
  74. var weapons=new Array(7);
  75.  
  76. weapons[0]=new playerWeapon('Hammer','Hammer','Hammer Icon','Hammer',false,false);
  77.  
  78. weapons[1]=new playerWeapon('Pistol','Pistol','Pistol Icon','Pistol',true,true);
  79.  
  80. weapons[2]=new playerWeapon('Machine Gun','AR14','Machine Gun Icon','Machine Gun',true,true);
  81.  
  82. weapons[3]=new playerWeapon('Ray Gun','Ray Gun','Ray Gun Icon','Ray Gun',false,true);
  83.  
  84. weapons[4]=new playerWeapon('Missile Launcher','Missile Launcher','Missile Icon','Missile Launcher',false,true);
  85.  
  86. weapons[5]=new playerWeapon('Mine','Mines','Mine Icon','Mine',false,true);
  87.  
  88. weapons[6]=new playerWeapon('Shock Launcher','Shock Gun','Shock Cube Icon','Shock Launcher',false,true);
  89.  
  90.  
  91.  
  92. //
  93.  
  94. // variables
  95.  
  96. //
  97.  
  98.  
  99.  
  100. var stopableAnimation=false;
  101.  
  102. var canRespawn=false;
  103.  
  104. var dying=false;
  105.  
  106. var dieFlipCount=0;
  107.  
  108. var lastHit=0;
  109.  
  110.  
  111.  
  112. //
  113.  
  114. // timer IDs
  115.  
  116. //
  117.  
  118.  
  119.  
  120. const PLAYER_DIE_FALL_OVER_ID=1;
  121.  
  122.  
  123.  
  124. //
  125.  
  126. // player script constructor
  127.  
  128. //
  129.  
  130.  
  131.  
  132. function playerConstruct(obj)
  133.  
  134. {
  135.  
  136.         var             i;
  137.  
  138.  
  139.  
  140.                 // setup player model
  141.  
  142.                
  143.  
  144.         obj.model.on=true;
  145.  
  146.         obj.model.name='Player';
  147.  
  148.         obj.model.lit=DIM3_MODEL_LIT_VERTEX;
  149.  
  150.         obj.model.shadow.on=true;
  151.  
  152.        
  153.  
  154.                 // setup player settings
  155.  
  156.                
  157.  
  158.         obj.setting.damage=true;
  159.  
  160.         obj.setting.crushable=true;
  161.  
  162.         obj.setting.bumpUp=true;
  163.  
  164.  
  165.  
  166.         obj.size.x=1730;
  167.  
  168.         obj.size.z=1730;
  169.  
  170.         obj.size.y=2200;
  171.  
  172.         obj.size.eyeOffset=-2100;
  173.  
  174.         obj.size.weight=250;
  175.  
  176.  
  177.  
  178.         obj.turnSpeed.facingWalk=4;
  179.  
  180.         obj.turnSpeed.motionWalk=4;
  181.  
  182.         obj.turnSpeed.facingRun=4.2;
  183.  
  184.         obj.turnSpeed.motionRun=4.2;
  185.  
  186.         obj.turnSpeed.facingCrawl=3;
  187.  
  188.         obj.turnSpeed.motionCrawl=3;
  189.  
  190.         obj.turnSpeed.facingAir=3;
  191.  
  192.         obj.turnSpeed.motionAir=3;
  193.  
  194.        
  195.  
  196.         obj.forwardSpeed.walk=95;
  197.  
  198.         obj.forwardSpeed.run=155;
  199.  
  200.         obj.forwardSpeed.crawl=50;
  201.  
  202.         obj.forwardSpeed.air=80;
  203.  
  204.         obj.forwardSpeed.acceleration=4;
  205.  
  206.         obj.forwardSpeed.deceleration=8;
  207.  
  208.         obj.forwardSpeed.accelerationAir=1.0;
  209.  
  210.         obj.forwardSpeed.decelerationAir=0.5;
  211.  
  212.        
  213.  
  214.         obj.sideSpeed.walk=60;
  215.  
  216.         obj.sideSpeed.run=120;
  217.  
  218.         obj.sideSpeed.crawl=30;
  219.  
  220.         obj.sideSpeed.air=50;
  221.  
  222.         obj.sideSpeed.acceleration=4;
  223.  
  224.         obj.sideSpeed.deceleration=8;
  225.  
  226.         obj.sideSpeed.accelerationAir=1.0;
  227.  
  228.         obj.sideSpeed.decelerationAir=0.5;
  229.  
  230.  
  231.  
  232.         obj.verticalSpeed.normal=50;
  233.  
  234.         obj.verticalSpeed.acceleration=10;
  235.  
  236.         obj.verticalSpeed.deceleration=20;
  237.  
  238.        
  239.  
  240.         obj.objectSpeed.jumpHeight=48;
  241.  
  242.         obj.objectSpeed.bumpHeight=300;
  243.  
  244.         obj.objectSpeed.duckAdd=32;
  245.  
  246.         obj.objectSpeed.duckChange=800;
  247.  
  248.        
  249.  
  250.         obj.look.upAngle=80;
  251.  
  252.         obj.look.downAngle=90;
  253.  
  254.        
  255.  
  256.         if (map.setting.multiplayer) {          // different health for network games
  257.  
  258.                 obj.health.maximum=100;
  259.  
  260.                 obj.health.start=100;
  261.  
  262.         }
  263.  
  264.         else {
  265.  
  266.                 obj.health.maximum=200;
  267.  
  268.                 obj.health.start=200;
  269.  
  270.         }
  271.  
  272.  
  273.  
  274.         obj.health.fallDamageMinimumHeight=4000;
  275.  
  276.         obj.health.fallDamageFactor=0.01;
  277.  
  278.        
  279.  
  280.         obj.click.crosshairUp='click_up';
  281.  
  282.         obj.click.crosshairDown='click_down';
  283.  
  284.        
  285.  
  286.                 // setup weapons from the array
  287.  
  288.        
  289.  
  290.         for (i=0;i!=weapons.length;i++) obj.weapon.add(weapons[i].name);
  291.  
  292.  
  293.  
  294.                 // add the special grenade throw weapon
  295.  
  296.                 // hide it so it's not selectable
  297.  
  298.  
  299.  
  300.         obj.weapon.add('Grenade Throw');
  301.  
  302.         obj.weapon.hideSingle('Grenade Throw');
  303.  
  304.        
  305.  
  306.         obj.radar.on=true;
  307.  
  308.         obj.radar.icon='player';
  309.  
  310. }
  311.  
  312.  
  313.  
  314. //
  315.  
  316. // player spawing
  317.  
  318. //
  319.  
  320.  
  321.  
  322. function playerSpawn(obj)
  323.  
  324. {
  325.  
  326.                 // select the hammer
  327.  
  328.        
  329.  
  330.         obj.weapon.setSelect(weapons[0].name);
  331.  
  332.        
  333.  
  334.                 // if in network play, hide all weapons
  335.  
  336.                 // pickup weapons
  337.  
  338.                
  339.  
  340.         if (map.setting.multiplayer) {
  341.  
  342.                 obj.weapon.hideSingle('Ray Gun',true);
  343.  
  344.                 obj.weapon.hideSingle('Missile Launcher',true);
  345.  
  346.                 obj.weapon.hideSingle('Mine',true);
  347.  
  348.                 obj.weapon.hideSingle('Shock Launcher',true);
  349.  
  350.         }
  351.  
  352.        
  353.  
  354.                 // redraw the weapon display
  355.  
  356.        
  357.  
  358.         redrawWeaponDisplay(obj);
  359.  
  360.        
  361.  
  362.         stopableAnimation=false;
  363.  
  364.        
  365.  
  366.                 // setup health
  367.  
  368.        
  369.  
  370.         lastHit=0;
  371.  
  372.        
  373.  
  374.                 // show hammer with model
  375.  
  376.                
  377.  
  378.         obj.model.mesh.showOnlyMesh('Default');
  379.  
  380.         obj.model.mesh.showMesh(weapons[0].meshName);
  381.  
  382.        
  383.  
  384.                 // not dead
  385.  
  386.                        
  387.  
  388.         canRespawn=false;
  389.  
  390.         dying=false;
  391.  
  392.        
  393.  
  394.         obj.event.startTimer(1,0);
  395.  
  396. }
  397.  
  398.  
  399.  
  400. //
  401.  
  402. // player in liquids
  403.  
  404. //
  405.  
  406.        
  407.  
  408. function playerLiquid(obj)
  409.  
  410. {
  411.  
  412.         sound.play("Splash",obj.position.x,obj.position.z,obj.position.y,1);
  413.  
  414. }
  415.  
  416.  
  417.  
  418. //
  419.  
  420. // Player ANIMATION changes
  421.  
  422. //
  423.  
  424.  
  425.  
  426. function playerAnimation(obj,subEvent)
  427.  
  428. {
  429.  
  430.         var                     model;
  431.  
  432.        
  433.  
  434.                 // can't change animation if dying
  435.  
  436.                
  437.  
  438.         if (dying) return;
  439.  
  440.        
  441.  
  442.                 // pick new animations
  443.  
  444.        
  445.  
  446.         model=obj.model;
  447.  
  448.        
  449.  
  450.         switch (subEvent) {
  451.  
  452.        
  453.  
  454.                 case DIM3_EVENT_ANIMATION_OBJECT_STOP:
  455.  
  456.                         if (stopableAnimation) model.animation.stop();
  457.  
  458.                         if (obj.status.stand!=DIM3_STAND_DUCKING)
  459.  
  460.                                 model.animation.change('Idle')
  461.  
  462.                         else
  463.  
  464.                                 model.animation.change('Idle Crawl');
  465.  
  466.                         stopableAnimation=true;
  467.  
  468.                         return;
  469.  
  470.  
  471.  
  472.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK:
  473.  
  474.                         if (stopableAnimation) model.animation.stop();
  475.  
  476.                         model.animation.change('Walk');
  477.  
  478.                         stopableAnimation=true;
  479.  
  480.                         return;
  481.  
  482.  
  483.  
  484.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN:
  485.  
  486.                         if (stopableAnimation) model.animation.stop();
  487.  
  488.                         model.animation.change('Run');
  489.  
  490.                         stopableAnimation=true;
  491.  
  492.                         return;
  493.  
  494.                        
  495.  
  496.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_BACK:
  497.  
  498.                         if (stopableAnimation) model.animation.stop();
  499.  
  500.                         model.animation.change('WalkBack');
  501.  
  502.                         stopableAnimation=true;
  503.  
  504.                         return;
  505.  
  506.  
  507.  
  508.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_BACK:
  509.  
  510.                         if (stopableAnimation) model.animation.stop();
  511.  
  512.                         model.animation.change('RunBack');
  513.  
  514.                         stopableAnimation=true;
  515.  
  516.                         return;
  517.  
  518.                        
  519.  
  520.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_LEFT:
  521.  
  522.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_LEFT_FORWARD:
  523.  
  524.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_LEFT_BACK:
  525.  
  526.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_LEFT:
  527.  
  528.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_LEFT_FORWARD:
  529.  
  530.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_LEFT_BACK:
  531.  
  532.                         if (stopableAnimation) model.animation.stop();
  533.  
  534.                         model.animation.change('WalkSideLeft');
  535.  
  536.                         stopableAnimation=true;
  537.  
  538.                         return;
  539.  
  540.                        
  541.  
  542.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_RIGHT:
  543.  
  544.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_RIGHT_FORWARD:
  545.  
  546.                 case DIM3_EVENT_ANIMATION_OBJECT_WALK_RIGHT_BACK:
  547.  
  548.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_RIGHT:
  549.  
  550.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_RIGHT_FORWARD:
  551.  
  552.                 case DIM3_EVENT_ANIMATION_OBJECT_RUN_RIGHT_BACK:
  553.  
  554.                         if (stopableAnimation) model.animation.stop();
  555.  
  556.                         model.animation.change('WalkSideRight');
  557.  
  558.                         stopableAnimation=true;
  559.  
  560.                         return;
  561.  
  562.                        
  563.  
  564.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL:
  565.  
  566.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_BACK:
  567.  
  568.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_LEFT:
  569.  
  570.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_LEFT_FORWARD:
  571.  
  572.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_LEFT_BACK:
  573.  
  574.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_RIGHT:
  575.  
  576.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_RIGHT_FORWARD:
  577.  
  578.                 case DIM3_EVENT_ANIMATION_OBJECT_CRAWL_RIGHT_BACK:
  579.  
  580.                         if (stopableAnimation) model.animation.stop();
  581.  
  582.                         model.animation.change('Crawl');
  583.  
  584.                         stopableAnimation=true;
  585.  
  586.                         return;
  587.  
  588.  
  589.  
  590.                 case DIM3_EVENT_ANIMATION_OBJECT_JUMP:
  591.  
  592.                         model.animation.start('Jump');
  593.  
  594.                         stopableAnimation=false;
  595.  
  596.                         return;
  597.  
  598.                        
  599.  
  600.                 case DIM3_EVENT_ANIMATION_OBJECT_LAND:
  601.  
  602.                         obj.motionVector.alterSpeed(0.7);
  603.  
  604.                         model.animation.start('Land');
  605.  
  606.                         stopableAnimation=false;
  607.  
  608.                         return;
  609.  
  610.        
  611.  
  612.                 case DIM3_EVENT_ANIMATION_OBJECT_DUCK_DOWN:
  613.  
  614.                         model.animation.start('Squat');
  615.  
  616.                         stopableAnimation=false;
  617.  
  618.                         return;
  619.  
  620.  
  621.  
  622.                 case DIM3_EVENT_ANIMATION_OBJECT_STAND_UP:
  623.  
  624.                         model.animation.start('Standup');
  625.  
  626.                         stopableAnimation=false;
  627.  
  628.                         return;
  629.  
  630.                        
  631.  
  632.         }
  633.  
  634. }
  635.  
  636.  
  637.  
  638. //
  639.  
  640. // player health
  641.  
  642. //
  643.  
  644.  
  645.  
  646. function playerDamage(obj,tick)
  647.  
  648. {
  649.  
  650.                 // tint the view and update health bar
  651.  
  652.                
  653.  
  654.         obj.status.tintView(1,0,0,0.5,500,300,1000);
  655.  
  656.        
  657.  
  658.                 // scream
  659.  
  660.                
  661.  
  662.         if (lastHit<tick) {
  663.  
  664.                 lastHit=tick+600;               // don't overplay scream effect
  665.  
  666.                 sound.play("Scream",obj.position.x,obj.position.z,obj.position.y,utility.random.getFloat(0.75,1.0));
  667.  
  668.         }
  669.  
  670. }
  671.  
  672.  
  673.  
  674. function playerHealthDraw(obj)
  675.  
  676. {
  677.  
  678.  
  679.  
  680. }
  681.  
  682.  
  683.  
  684. //
  685.  
  686. // player item pickup
  687.  
  688. //
  689.  
  690.  
  691.  
  692. function playerItemPickup(obj)
  693.  
  694. {
  695.  
  696.     obj.status.tintView(0.5,0.5,0.5,0.5,300,300,300);           // flash gray on item pickup
  697.  
  698.     redrawWeaponDisplay(obj);
  699.  
  700. }
  701.  
  702.  
  703.  
  704. //
  705.  
  706. // player dying
  707.  
  708. //
  709.  
  710.  
  711.  
  712. function playerDie(obj)
  713.  
  714. {
  715.  
  716.                 // hide weapon and health bar
  717.  
  718.                
  719.  
  720.         obj.weapon.hide(true);
  721.  
  722.  
  723.  
  724.        
  725.  
  726.                 // freeze all input and lock off player
  727.  
  728.                
  729.  
  730.         obj.setting.damage=false;
  731.  
  732.         obj.model.shadow.on=false;
  733.  
  734.        
  735.  
  736.         obj.motionVector.stop();
  737.  
  738.         obj.motionAngle.turnStop();
  739.  
  740.        
  741.  
  742.         obj.status.freezeInput(true);
  743.  
  744.        
  745.  
  746.                 // death scream
  747.  
  748.                
  749.  
  750.         sound.play("Scream",obj.position.x,obj.position.z,obj.position.y,utility.random.getFloat(0.4,0.5));
  751.  
  752.        
  753.  
  754.                 // drop to floor
  755.  
  756.                
  757.  
  758.         dying=true;
  759.  
  760.         dieFlipCount=0;
  761.  
  762.        
  763.  
  764.         obj.model.animation.start('Die');
  765.  
  766.         obj.event.startTimer(1,PLAYER_DIE_FALL_OVER_ID);
  767.  
  768. }
  769.  
  770.  
  771.  
  772. function playerFallOver(obj)
  773.  
  774. {
  775.  
  776.                 // turn and drop
  777.  
  778.                
  779.  
  780.     dieFlipCount+=(1+(dieFlipCount*0.25));                      // accelerated fall over
  781.  
  782.                
  783.  
  784.                 // only slant camera if in fpp
  785.  
  786.  
  787.  
  788.     if (camera.setting.type==DIM3_CAMERA_TYPE_FPP) {
  789.  
  790.           camera.angle.z=dieFlipCount;
  791.  
  792.           obj.size.eyeOffset+=90;
  793.  
  794.         }
  795.  
  796.        
  797.  
  798.                 // time to stop?
  799.  
  800.                
  801.  
  802.         if (dieFlipCount<=90) return;
  803.  
  804.        
  805.  
  806.         camera.angle.z=90;
  807.  
  808.        
  809.  
  810.                 // clear timer and mark OK to respawn
  811.  
  812.                
  813.  
  814.         canRespawn=true;
  815.  
  816.        
  817.  
  818.         obj.setting.contact=false;
  819.  
  820.        
  821.  
  822.         obj.event.clearTimer();
  823.  
  824. }
  825.  
  826.  
  827.  
  828. //
  829.  
  830. // player telefragging
  831.  
  832. //
  833.  
  834.  
  835.  
  836. function playerTelefrag(obj)
  837.  
  838. {
  839.  
  840.         var                     x,y,z,yadd;
  841.  
  842.        
  843.  
  844.         obj.setting.hidden=true;
  845.  
  846.         obj.setting.contact=false;
  847.  
  848.        
  849.  
  850.         yadd=obj.size.y/4;
  851.  
  852.        
  853.  
  854.         x=obj.position.x;
  855.  
  856.         z=obj.position.z;
  857.  
  858.         y=obj.position.y-yadd;
  859.  
  860.        
  861.  
  862.         spawn.particle(x,z,y,'Telefrag Blood');
  863.  
  864.        
  865.  
  866.         y-=yadd;
  867.  
  868.         spawn.particle(x,z,y,'Telefrag Blood');
  869.  
  870.        
  871.  
  872.         y-=yadd;
  873.  
  874.         spawn.particle(x,z,y,'Telefrag Blood');
  875.  
  876.        
  877.  
  878.         sound.play('Splash',x,z,y,0.4);
  879.  
  880. }
  881.  
  882.  
  883.  
  884. //
  885.  
  886. // change ammo read-outs
  887.  
  888. //
  889.  
  890.  
  891.  
  892. function make2DigitString(k)
  893.  
  894. {
  895.  
  896.         if (k<10) return('0'+k);
  897.  
  898.         return(k);
  899.  
  900. }
  901.  
  902.  
  903.  
  904. function make3DigitString(k)
  905.  
  906. {
  907.  
  908.         if (k<10) return('00'+k);
  909.  
  910.         if (k<100) return('0'+k);
  911.  
  912.         return(k);
  913.  
  914. }
  915.  
  916.  
  917.  
  918. function getAmmoString(obj,name)
  919.  
  920. {
  921.  
  922.         var             k,str;
  923.  
  924.        
  925.  
  926.         str=make2DigitString(obj.weapon.getAmmoCount(name));
  927.  
  928.         str=str+'/';
  929.  
  930.         str=str+make2DigitString(obj.weapon.getMaxAmmoCount(name));
  931.  
  932.  
  933.  
  934.         return(str);
  935.  
  936. }
  937.  
  938.        
  939.  
  940. function redrawWeaponDisplay(obj)
  941.  
  942. {
  943.  
  944.  
  945. }
  946.  
  947.  
  948.  
  949. //
  950.  
  951. // player fires
  952.  
  953. //
  954.  
  955.  
  956.  
  957. function playerFire(obj)
  958.  
  959. {
  960.  
  961.         obj.model.animation.interrupt('Fire');
  962.  
  963. }
  964.  
  965.  
  966.  
  967. //
  968.  
  969. // player commands
  970.  
  971. //
  972.  
  973.  
  974.  
  975. function playerRespawn(obj)
  976.  
  977. {
  978.  
  979.                 // fix changes when dead
  980.  
  981.                
  982.  
  983.         camera.angle.z=0;
  984.  
  985.         obj.size.eyeOffset=-2100;
  986.  
  987.        
  988.  
  989.         obj.status.freezeInput(false);
  990.  
  991.         obj.weapon.hide(false);
  992.  
  993.        
  994.  
  995.         obj.setting.damage=true;
  996.  
  997.         obj.model.shadow.on=true;
  998.  
  999.        
  1000.  
  1001.         obj.setting.hidden=false;
  1002.  
  1003.         obj.setting.contact=true;
  1004.  
  1005.        
  1006.  
  1007.                 // reset health
  1008.  
  1009.                
  1010.  
  1011.         obj.health.reset();
  1012.  
  1013.         obj.weapon.reset();
  1014.  
  1015.        
  1016.  
  1017.                 // call spawn to set some other items
  1018.  
  1019.                 // spawn only gets called when player starts, so we have
  1020.  
  1021.                 // to call it ourselves here
  1022.  
  1023.                
  1024.  
  1025.         playerSpawn(obj);
  1026.  
  1027.        
  1028.  
  1029.                 // restart differently depending on
  1030.  
  1031.                 // if we are in a network game or not
  1032.  
  1033.                 //
  1034.  
  1035.                 // if not networking, then restart the map
  1036.  
  1037.                 // from the last save point.  If no last
  1038.  
  1039.                 // save, then map automatically restarts
  1040.  
  1041.                 // from the beginning
  1042.  
  1043.                 //
  1044.  
  1045.                 // if networking, then move the player
  1046.  
  1047.                 // to any spot valid in the game rules
  1048.  
  1049.                
  1050.  
  1051.         if (!map.setting.multiplayer)
  1052.  
  1053.                 map.action.restartMapFromSave()
  1054.  
  1055.         else
  1056.  
  1057.                 obj.position.placeNetworkSpot();
  1058.  
  1059. }
  1060.  
  1061.  
  1062.  
  1063. function playerMessage(obj,subEvent,id)
  1064.  
  1065. {
  1066.  
  1067.                 // we are only checking for player_X key
  1068.  
  1069.                 // message here, we can ignore all others
  1070.  
  1071.  
  1072.  
  1073.         if (subEvent!=DIM3_EVENT_MESSAGE_FROM_KEY_DOWN) return;
  1074.  
  1075.  
  1076.  
  1077.                 // check messages
  1078.  
  1079.  
  1080.  
  1081.         switch (id) {
  1082.  
  1083.                
  1084.  
  1085.                 case 0:         // grenade throw is player_0
  1086.  
  1087.                         obj.weapon.fire('Grenade Throw',3);
  1088.  
  1089.                         redrawWeaponDisplay(obj);
  1090.  
  1091.                         return;
  1092.  
  1093.  
  1094.  
  1095.                 case 1:         // respawn is player_1
  1096.  
  1097.                         if (canRespawn) playerRespawn(obj);
  1098.  
  1099.                         return;
  1100.  
  1101.  
  1102.  
  1103.                 case 2:         // flying mode is player_2
  1104.  
  1105.                         if (!obj.setting.fly) {
  1106.  
  1107.                                 obj.setting.fly=true;
  1108.  
  1109.                                 obj.setting.inputMode=DIM3_INPUT_MODE_FLY;
  1110.  
  1111.                                 obj.motionVector.alterGravity(0);       // reset gravity because now in flying
  1112.  
  1113.                                 iface.console.write('Fly Mode On');
  1114.  
  1115.                         }
  1116.  
  1117.                         else {
  1118.  
  1119.                                 obj.setting.fly=false;
  1120.  
  1121.                                 obj.setting.inputMode=DIM3_INPUT_MODE_FPP;
  1122.  
  1123.                                 iface.console.write('Fly Mode Off');
  1124.  
  1125.                         }
  1126.  
  1127.                         return;
  1128.  
  1129.  
  1130.  
  1131.                 case 3:         // camera mode is player_3
  1132.  
  1133.                         if (camera.setting.type!=DIM3_CAMERA_TYPE_FPP) {
  1134.  
  1135.                                 camera.setting.type=DIM3_CAMERA_TYPE_FPP;
  1136.  
  1137.                                 obj.look.upAngle=80;
  1138.  
  1139.                                 obj.look.downAngle=35;
  1140.  
  1141.                                 obj.look.effectWeapons=true;
  1142.  
  1143.                                 iface.console.write('Camera Mode FPP');
  1144.  
  1145.                         }
  1146.  
  1147.                         else {
  1148.  
  1149.                                 camera.setting.type=DIM3_CAMERA_TYPE_CHASE;
  1150.  
  1151.                                 camera.chase.distance=4000;
  1152.  
  1153.                                 obj.look.upAngle=10;
  1154.  
  1155.                                 obj.look.downAngle=30;
  1156.  
  1157.                                 obj.look.effectWeapons=false;
  1158.  
  1159.                                 iface.console.write('Camera Mode Chase');
  1160.  
  1161.                         }
  1162.  
  1163.                         return;
  1164.  
  1165.                
  1166.  
  1167.         }
  1168.  
  1169. }
  1170.  
  1171.  
  1172.  
  1173. //
  1174.  
  1175. // player timers
  1176.  
  1177. //
  1178.  
  1179.  
  1180.  
  1181. function playerTimer(obj,id)
  1182.  
  1183. {
  1184.  
  1185.         switch (id) {
  1186.  
  1187.        
  1188.  
  1189.                 case PLAYER_DIE_FALL_OVER_ID:
  1190.  
  1191.                         playerFallOver(obj);
  1192.  
  1193.                         return;
  1194.  
  1195.                        
  1196.  
  1197.         }
  1198.  
  1199. }
  1200.  
  1201.  
  1202.  
  1203. //
  1204.  
  1205. // player state
  1206.  
  1207. // use these messages to persist or recover global variables when saving/loading
  1208.  
  1209. //
  1210.  
  1211.  
  1212.  
  1213. function playerState(obj,subEvent)
  1214.  
  1215. {
  1216.  
  1217.     switch (subEvent) {
  1218.  
  1219.  
  1220.  
  1221.                 case DIM3_EVENT_STATE_SAVE:
  1222.  
  1223.                 data.addScriptSpecific('stopableAnimation',stopableAnimation);
  1224.  
  1225.                 data.addScriptSpecific('canRespawn',canRespawn);
  1226.  
  1227.                 data.addScriptSpecific('dying',dying);
  1228.  
  1229.                 return;
  1230.  
  1231.            
  1232.  
  1233.                 case DIM3_EVENT_STATE_LOAD:
  1234.  
  1235.                         stopableAnimation=data.getScriptSpecific('stopableAnimation');
  1236.  
  1237.                 canRespawn=data.getScriptSpecific('canRespawn');
  1238.  
  1239.                 dying=data.getScriptSpecific('dying');
  1240.  
  1241.                 return;
  1242.  
  1243.            
  1244.  
  1245.     }
  1246.  
  1247. }
  1248.  
  1249.  
  1250.  
  1251. //
  1252.  
  1253. // player messages
  1254.  
  1255. //
  1256.  
  1257.  
  1258.  
  1259. function event(obj,mainEvent,subEvent,id,tick)
  1260.  
  1261. {
  1262.  
  1263.         switch (mainEvent) {
  1264.  
  1265.  
  1266.  
  1267.                 case DIM3_EVENT_CONSTRUCT:
  1268.  
  1269.                         playerConstruct(obj);
  1270.  
  1271.                         return;
  1272.  
  1273.                        
  1274.  
  1275.                 case DIM3_EVENT_SPAWN:
  1276.  
  1277.                         playerSpawn(obj);
  1278.  
  1279.                         return;
  1280.  
  1281.  
  1282.  
  1283.                 case DIM3_EVENT_LIQUID:
  1284.  
  1285.                         playerLiquid(obj);
  1286.  
  1287.                         return;
  1288.  
  1289.                        
  1290.  
  1291.                 case DIM3_EVENT_ANIMATION_OBJECT:
  1292.  
  1293.                         playerAnimation(obj,subEvent);
  1294.  
  1295.                         return;
  1296.  
  1297.        
  1298.  
  1299.                 case DIM3_EVENT_DAMAGE:
  1300.  
  1301.                         playerDamage(obj,tick);
  1302.  
  1303.                         return;
  1304.  
  1305.                        
  1306.  
  1307.                 case DIM3_EVENT_HEALTH:
  1308.  
  1309.                         playerHealthDraw(obj);
  1310.  
  1311.                         return;
  1312.  
  1313.                        
  1314.  
  1315.                 case DIM3_EVENT_CRUSH:
  1316.  
  1317.                 case DIM3_EVENT_DIE:
  1318.  
  1319.                         playerDie(obj);
  1320.  
  1321.                         return;
  1322.  
  1323.  
  1324.  
  1325.                 case DIM3_EVENT_TELEFRAG:
  1326.  
  1327.                         playerTelefrag(obj);
  1328.  
  1329.                         return;
  1330.  
  1331.                        
  1332.  
  1333.                 case DIM3_EVENT_PICKUP:
  1334.  
  1335.                         playerItemPickup(obj);
  1336.  
  1337.                         return;
  1338.  
  1339.                    
  1340.  
  1341.                 case DIM3_EVENT_WEAPON_SELECT:
  1342.  
  1343.                         redrawWeaponDisplay(obj);
  1344.  
  1345.                         return;
  1346.  
  1347.                        
  1348.  
  1349.                 case DIM3_EVENT_WEAPON_FIRE:
  1350.  
  1351.                         playerFire(obj);
  1352.  
  1353.                         redrawWeaponDisplay(obj);
  1354.  
  1355.                         return;
  1356.  
  1357.                        
  1358.  
  1359.                 case DIM3_EVENT_MESSAGE:
  1360.  
  1361.                         playerMessage(obj,subEvent,id);
  1362.  
  1363.                         return;
  1364.  
  1365.                        
  1366.  
  1367.                 case DIM3_EVENT_TIMER:
  1368.  
  1369.                         playerTimer(obj,id);
  1370.  
  1371.                         return;
  1372.  
  1373.                        
  1374.  
  1375.                 case DIM3_EVENT_STATE:
  1376.  
  1377.                         playerState(obj,subEvent);
  1378.  
  1379.                         return;
  1380.  
  1381.  
  1382.  
  1383.         }
  1384.  
  1385. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post