Difference between revisions of "Script:Files:script/tools/defibrillator.script"
From Mod Wiki
Line 1: | Line 1: | ||
− | + | <span style="color:green">/***********************************************************************</span> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <span style="color:green">tool_defibrillator.script</span> | |
− | + | ||
− | + | <span style="color:green">***********************************************************************/</span> | |
− | + | ||
− | + | <span style="color:blue">object</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]] : [[ScriptClass:weapon_base|weapon_base]] { | |
− | + | ||
− | + | <span style="color:blue">void</span> init(); | |
− | + | <span style="color:blue">void</span> destroy(); | |
− | + | ||
− | + | <span style="color:blue">void</span> Raise(); | |
− | + | <span style="color:blue">void</span> Idle(); | |
− | + | <span style="color:blue">void</span> Attack(); | |
+ | <span style="color:blue">void</span> Shock(); | ||
+ | |||
+ | <span style="color:blue">boolean</span> DoRevive(); | ||
+ | |||
+ | <span style="color:blue">void</span> ToolTipThread_Raise(); | ||
+ | |||
+ | <span style="color:blue">float</span> meleeDistance; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::init() { | ||
+ | meleeDistance = [[ScriptEvent:getFloatKey|getFloatKey]]( <span style="color:brown">"melee_distance"</span> ); | ||
+ | |||
+ | <span style="color:blue">if</span> ( myPlayer.[[ScriptEvent:isLocalPlayer|isLocalPlayer]]() ) { | ||
+ | <span style="color:blue">thread</span> ToolTipThread_Raise(); | ||
+ | } | ||
+ | |||
+ | [[ScriptEvent:weaponState|weaponState]]( <span style="color:brown">"Raise"</span>, 0 ); | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::destroy() { | ||
+ | <span style="color:blue">if</span> ( myPlayer != <span style="color:blue">$null_entity</span> ) { | ||
+ | myPlayer.SetFireAnim( <span style="color:brown">""</span> ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::Raise() { | ||
+ | UpdateCharge(); | ||
+ | Base_Raise(); | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::Idle() { | ||
+ | [[ScriptEvent:weaponReady|weaponReady]](); | ||
+ | [[ScriptEvent:playCycle|playCycle]]( ANIMCHANNEL_ALL, <span style="color:brown">"idle"</span> ); | ||
+ | |||
+ | [[ScriptEvent:startSound|startSound]]( <span style="color:brown">"snd_charge"</span>, SND_WEAPON_FIRE ); | ||
+ | |||
+ | <span style="color:blue">while</span> ( true ) { | ||
+ | <span style="color:blue">if</span> ( WEAPON_LOWERWEAPON ) { | ||
+ | [[ScriptEvent:weaponState|weaponState]]( <span style="color:brown">"Lower"</span>, 4 ); | ||
+ | } | ||
+ | <span style="color:blue">if</span> ( WEAPON_ATTACK ) { | ||
+ | [[ScriptEvent:weaponState|weaponState]]( <span style="color:brown">"Attack"</span>, 0 ); | ||
+ | } | ||
+ | <span style="color:blue">if</span> ( WEAPON_ALTFIRE ) { | ||
+ | <span style="color:blue">if</span> ( myPlayer.[[ScriptEvent:getProficiency|getProficiency]]( g_proficiencyMedic ) >= 3 ) { | ||
+ | <span style="color:blue">if</span> ( !CanRemove( chargePerUse ) ) { | ||
+ | G_NotifyNoCharge( myPlayer ); | ||
+ | } <span style="color:blue">else</span> { | ||
+ | [[ScriptEvent:weaponState|weaponState]]( <span style="color:brown">"Shock"</span>, 0 ); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | UpdateCharge(); | ||
+ | |||
+ | sys.[[ScriptEvent:waitFrame|waitFrame]](); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">boolean</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::DoRevive() { | ||
+ | <span style="color:blue">if</span> ( sys.[[ScriptEvent:isClient|isClient]]() ) { | ||
+ | <span style="color:blue">return</span> false; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">entity</span> targetPlayer = myPlayer.[[ScriptEvent:getCrosshairEntity|getCrosshairEntity]](); | ||
+ | <span style="color:blue">if</span> ( myPlayer.[[ScriptEvent:getCrosshairDistance|getCrosshairDistance]]( true ) > meleeDistance ) { | ||
+ | <span style="color:blue">return</span> false; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">if</span> ( targetPlayer == <span style="color:blue">$null_entity</span> ) { | ||
+ | <span style="color:blue">return</span> false; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">if</span> ( !targetPlayer.vNeedsRevive( myPlayer ) ) { | ||
+ | <span style="color:blue">return</span> false; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">float</span> healthScale = 0.5f; | ||
+ | <span style="color:blue">if</span> ( myPlayer.[[ScriptEvent:getProficiency|getProficiency]]( g_proficiencyMedic ) >= 4 ) { | ||
+ | healthScale = 1.f; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">if</span> ( targetPlayer.vRevive( myPlayer, healthScale ) ) { | ||
+ | <span style="color:blue">return</span> true; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">return</span> false; | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::Shock() { | ||
+ | myPlayer.SetFireAnim( <span style="color:brown">"shock_self"</span> ); | ||
+ | |||
+ | Remove( chargePerUse ); | ||
+ | |||
+ | [[ScriptEvent:fired|fired]](); | ||
+ | [[ScriptEvent:playAnim|playAnim]]( ANIMCHANNEL_ALL, <span style="color:brown">"reload"</span> ); | ||
+ | |||
+ | sys.[[ScriptEvent:wait|wait]]( 1.0f ); | ||
+ | |||
+ | [[ScriptEvent:startSound|startSound]]( <span style="color:brown">"snd_shock"</span>, SND_WEAPON_FIRE2 ); | ||
+ | |||
+ | myPlayer.[[ScriptEvent:setHealth|setHealth]]( myPlayer.[[ScriptEvent:getHealth|getHealth]]() + 20.f ); <span style="color:green">// Gordon: this allows > maxhealth</span> | ||
+ | |||
+ | <span style="color:blue">while</span> ( ![[ScriptEvent:animDone|animDone]]( ANIMCHANNEL_ALL, 4 ) ) { | ||
+ | sys.[[ScriptEvent:waitFrame|waitFrame]](); | ||
+ | } | ||
+ | |||
+ | myPlayer.SetFireAnim( <span style="color:brown">""</span> ); | ||
+ | |||
+ | [[ScriptEvent:weaponState|weaponState]]( <span style="color:brown">"Idle"</span>, 1 ); | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::Attack() { | ||
+ | <span style="color:blue">string</span> fireAnim = <span style="color:brown">"fire"</span>; | ||
+ | <span style="color:blue">string</span> fireSnd = <span style="color:brown">"snd_fire"</span>; | ||
+ | <span style="color:blue">if</span> ( myPlayer.[[ScriptEvent:getProficiency|getProficiency]]( g_proficiencyMedic ) >= 4 ) { | ||
+ | fireAnim = <span style="color:brown">"fire_upgraded"</span>; | ||
+ | fireSnd = <span style="color:brown">"snd_fire_upgraded"</span>; | ||
+ | } | ||
+ | |||
+ | [[ScriptEvent:fired|fired]](); | ||
+ | [[ScriptEvent:playAnim|playAnim]]( ANIMCHANNEL_ALL, fireAnim ); | ||
+ | |||
+ | [[ScriptEvent:startSound|startSound]]( fireSnd, SND_WEAPON_FIRE ); | ||
+ | |||
+ | sys.[[ScriptEvent:wait|wait]]( 0.2f ); | ||
+ | |||
+ | <span style="color:blue">if</span> ( !DoRevive() ) { | ||
+ | [[ScriptEvent:melee|melee]]( MASK_SHOT_RENDERMODEL | CONTENTS_BODY | CONTENTS_SLIDEMOVER, meleeDistance, true, true ); | ||
+ | [[ScriptEvent:meleeAttack|meleeAttack]]( 1.f ); | ||
+ | myPlayer.AI_WEAPON_FIRED = false; <span style="color:green">// Gordon: melee attack will set this, but we've already triggered the animation anyway, so reset it</span> | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">while</span> ( ![[ScriptEvent:animDone|animDone]]( ANIMCHANNEL_ALL, 4 ) ) { | ||
+ | sys.[[ScriptEvent:waitFrame|waitFrame]](); | ||
+ | } | ||
+ | |||
+ | [[ScriptEvent:weaponState|weaponState]]( <span style="color:brown">"Idle"</span>, 1 ); | ||
+ | } | ||
+ | |||
+ | <span style="color:blue">void</span> [[ScriptClass:tool_defibrillator|tool_defibrillator]]::ToolTipThread_Raise() { | ||
+ | myPlayer.[[ScriptEvent:cancelToolTips|cancelToolTips]](); | ||
+ | sys.[[ScriptEvent:wait|wait]]( myPlayer.CalcTooltipWait() ); | ||
+ | |||
+ | WAIT_FOR_TOOLTIP; | ||
+ | myPlayer.[[ScriptEvent:sendToolTip|sendToolTip]]( GetToolTip( [[ScriptEvent:getKey|getKey]]( <span style="color:brown">"tt_intro_1"</span> ) ) ); | ||
+ | |||
+ | WAIT_FOR_TOOLTIP; | ||
+ | myPlayer.[[ScriptEvent:sendToolTip|sendToolTip]]( GetToolTip( [[ScriptEvent:getKey|getKey]]( <span style="color:brown">"tt_intro_2"</span> ) ) ); | ||
+ | |||
+ | <span style="color:blue">if</span> ( myPlayer.[[ScriptEvent:getProficiency|getProficiency]]( g_proficiencyMedic ) >= 3 ) { | ||
+ | WAIT_FOR_TOOLTIP; | ||
+ | myPlayer.[[ScriptEvent:sendToolTip|sendToolTip]]( GetToolTip( [[ScriptEvent:getKey|getKey]]( <span style="color:brown">"tt_intro_3"</span> ) ) ); | ||
+ | } | ||
+ | } |
Latest revision as of 18:14, 2 November 2007
/*********************************************************************** tool_defibrillator.script ***********************************************************************/ object tool_defibrillator : weapon_base { void init(); void destroy(); void Raise(); void Idle(); void Attack(); void Shock(); boolean DoRevive(); void ToolTipThread_Raise(); float meleeDistance; } void tool_defibrillator::init() { meleeDistance = getFloatKey( "melee_distance" ); if ( myPlayer.isLocalPlayer() ) { thread ToolTipThread_Raise(); } weaponState( "Raise", 0 ); } void tool_defibrillator::destroy() { if ( myPlayer != $null_entity ) { myPlayer.SetFireAnim( "" ); } } void tool_defibrillator::Raise() { UpdateCharge(); Base_Raise(); } void tool_defibrillator::Idle() { weaponReady(); playCycle( ANIMCHANNEL_ALL, "idle" ); startSound( "snd_charge", SND_WEAPON_FIRE ); while ( true ) { if ( WEAPON_LOWERWEAPON ) { weaponState( "Lower", 4 ); } if ( WEAPON_ATTACK ) { weaponState( "Attack", 0 ); } if ( WEAPON_ALTFIRE ) { if ( myPlayer.getProficiency( g_proficiencyMedic ) >= 3 ) { if ( !CanRemove( chargePerUse ) ) { G_NotifyNoCharge( myPlayer ); } else { weaponState( "Shock", 0 ); } } } UpdateCharge(); sys.waitFrame(); } } boolean tool_defibrillator::DoRevive() { if ( sys.isClient() ) { return false; } entity targetPlayer = myPlayer.getCrosshairEntity(); if ( myPlayer.getCrosshairDistance( true ) > meleeDistance ) { return false; } if ( targetPlayer == $null_entity ) { return false; } if ( !targetPlayer.vNeedsRevive( myPlayer ) ) { return false; } float healthScale = 0.5f; if ( myPlayer.getProficiency( g_proficiencyMedic ) >= 4 ) { healthScale = 1.f; } if ( targetPlayer.vRevive( myPlayer, healthScale ) ) { return true; } return false; } void tool_defibrillator::Shock() { myPlayer.SetFireAnim( "shock_self" ); Remove( chargePerUse ); fired(); playAnim( ANIMCHANNEL_ALL, "reload" ); sys.wait( 1.0f ); startSound( "snd_shock", SND_WEAPON_FIRE2 ); myPlayer.setHealth( myPlayer.getHealth() + 20.f ); // Gordon: this allows > maxhealth while ( !animDone( ANIMCHANNEL_ALL, 4 ) ) { sys.waitFrame(); } myPlayer.SetFireAnim( "" ); weaponState( "Idle", 1 ); } void tool_defibrillator::Attack() { string fireAnim = "fire"; string fireSnd = "snd_fire"; if ( myPlayer.getProficiency( g_proficiencyMedic ) >= 4 ) { fireAnim = "fire_upgraded"; fireSnd = "snd_fire_upgraded"; } fired(); playAnim( ANIMCHANNEL_ALL, fireAnim ); startSound( fireSnd, SND_WEAPON_FIRE ); sys.wait( 0.2f ); if ( !DoRevive() ) { melee( MASK_SHOT_RENDERMODEL | CONTENTS_BODY | CONTENTS_SLIDEMOVER, meleeDistance, true, true ); meleeAttack( 1.f ); myPlayer.AI_WEAPON_FIRED = false; // Gordon: melee attack will set this, but we've already triggered the animation anyway, so reset it } while ( !animDone( ANIMCHANNEL_ALL, 4 ) ) { sys.waitFrame(); } weaponState( "Idle", 1 ); } void tool_defibrillator::ToolTipThread_Raise() { myPlayer.cancelToolTips(); sys.wait( myPlayer.CalcTooltipWait() ); WAIT_FOR_TOOLTIP; myPlayer.sendToolTip( GetToolTip( getKey( "tt_intro_1" ) ) ); WAIT_FOR_TOOLTIP; myPlayer.sendToolTip( GetToolTip( getKey( "tt_intro_2" ) ) ); if ( myPlayer.getProficiency( g_proficiencyMedic ) >= 3 ) { WAIT_FOR_TOOLTIP; myPlayer.sendToolTip( GetToolTip( getKey( "tt_intro_3" ) ) ); } }