PDA

View Full Version : isThrowingGrenade function



Jeplaa
17th October 2013, 18:12
Hey guys,

I know there is a function called isThrowingGrenade() in CoD2 unfortunately for Singleplayer. I have tried recreate it in many ways but I failed.
Could someone point me how can I check if grenade (here could comes array of grenades) is throwing ?

Thanks in advance,
Jeplaa

serthy
17th October 2013, 18:32
iznogod made a working one. he checked every frame the players current offhand item against a custom grenade item.
do you need a isThrowingGrenade() function or is a hasThrownANade() already enough?

Tally
17th October 2013, 18:57
This monitors a grenade after a grenade is thrown:


// Called from Callback_StartGametype
{
level thread TrackGrenades()
}
/************************************
This function is snaffled from
the eXtreme+ mod for COD2
*************************************/
TrackGrenades()
{
for( ;; )
{
nades = getentarray( "grenade", "classname" );
if( isDefined( nades ) )
{
for( i = 0; i < nades.size; i++ )
{
nade = nades[i];
if( !isDefined( nade.monitored ) )
nade thread monitorNade();
}
}

wait( 0.05 );
}
}

/************************************
This function is snaffled from
the eXtreme+ mod for COD2
*************************************/
monitorNade()
{
self.monitored = true;

players = getentarray( "player", "classname" );
for( i = 0; i < players.size; i++ )
{
player = players[i];
if( self istouching( player ) )
self.nadeThrower = player;
}

if( !isDefined( self.nadeThrower ) ) return;

if( !isAlive( self.nadeThrower ) )
{
if( isDefined( self ) )
self delete();
return;
}

self.nadeType = self.nadeThrower getcurrentoffhand();
self.nadeThrower notify( "grenade_thrown", self, self.nadeType );
self.nadeThrower iprintlnbold( "throwing Grenade" );

}

Jeplaa
17th October 2013, 19:21
So, for first thanks for fast reply.
@serthy yup hasThrownANade() should be better because it is for jump mod to control grenade-explosion with timer.
@Tally thanks for this snip it's really clear and understandable, hope it will be usefull for me.

IzNoGoD
21st October 2013, 21:55
Shameless copy of myself @ modsonline:

IzNoGoD writes...
First: this tutorial is written only for the most experienced scripters in cod2. Others should steer clear of this explanation and hope someone writes them a proper implementation.


I got annoyed by all the non-working implementations of isthrowinggrenade() and decided to write my own function for it.

This was quite hard, as the cod2 engine has a lot(!) of limitations. Finally, all works :)

how it works:
As cod2 doesnt switch to the nadeweapon as cod1 does, we have to use the getcurrentoffhand() and switchtooffhand() to determine if the player is throwing a nade.
In essence, it is quite easy, but there are a lot of things you have to keep in mind.

First, if the player starts throwing a smokegrenade, getcurrentoffhand() will return the name of said nade, but the player will not switch back to any offhand. So we have to force it back to a grenade of our choice:


while(true)
{
self switchtooffhand("grenade");
wait 0.05;
}


This works fine, but it cannot detect any normal nadethrows, only the smokegrenade will show up.
If we force the player to the offhand smokegrenade, we can detect fraggrenades, but we lose the ability to detect any smokegrenades.

So what we need is a third offhand grenade. The weaponfile is pasted here:


WEAPONFILE\weaponType\grenade\weaponClass\grenade\ offhandClass\Frag Grenade\weaponSlot\none\displayName\WEAPON_M2FRAGG RENADE\AIOverlayDescription\\modeName\\playerAnimT ype\other\gunModel\viewmodel_mk2\handModel\viewmod el_hands_cloth\isHandModelOverridable\1\idleAnim\v iewmodel_mk2_idle\emptyIdleAnim\viewmodel_mk2_idle \fireAnim\viewmodel_mk2_throw\holdFireAnim\viewmod el_mk2_pullpin\lastShotAnim\viewmodel_mk2_throw\me leeAnim\viewmodel_mk2_idle\raiseAnim\viewmodel_mk2 _idle\dropAnim\viewmodel_mk2_idle\altRaiseAnim\vie wmodel_mk2_idle\altDropAnim\viewmodel_mk2_idle\aut oAimRange\1600\slowdownAimRange\50000\slowdownAimR angeAds\50000\lockonAimRange\50000\lockonAimRangeA ds\50000\moveSpeedScale\1\damage\0\meleeDamage\40\ fireDelay\0.1\meleeDelay\0.1\fireTime\0.3\holdFire Time\0.6\meleeTime\0.66\reloadTime\2\dropTime\0\ra iseTime\0\altDropTime\0\altRaiseTime\0\fuseTime\3. 5\clipOnly\1\hipIdleAmount\80\idleCrouchFactor\0.5 \idleProneFactor\0.15\parallelDefaultBounce\0.5\pa rallelBarkBounce\0.6\parallelBrickBounce\0.6\paral lelCarpetBounce\0.6\parallelClothBounce\0.2\parall elConcreteBounce\0.6\parallelDirtBounce\0.45\paral lelFleshBounce\0.2\parallelFoliageBounce\0.05\para llelGlassBounce\0.4\parallelGrassBounce\0.35\paral lelGravelBounce\0.5\parallelIceBounce\0.6\parallel MetalBounce\0.6\parallelMudBounce\0.2\parallelPape rBounce\0.2\parallelPlasterBounce\0.5\parallelRock Bounce\0.6\parallelSandBounce\0.3\parallelSnowBoun ce\0.2\parallelWaterBounce\0.2\parallelWoodBounce\ 0.6\parallelAsphaltBounce\0.6\perpendicularDefault Bounce\0.25\perpendicularBarkBounce\0.25\perpendic ularBrickBounce\0.25\perpendicularCarpetBounce\0.2 5\perpendicularClothBounce\0.2\perpendicularConcre teBounce\0.25\perpendicularDirtBounce\0.225\perpen dicularFleshBounce\0.2\perpendicularFoliageBounce\ 0.05\perpendicularGlassBounce\0.2\perpendicularGra ssBounce\0.15\perpendicularGravelBounce\0.25\perpe ndicularIceBounce\0.3\perpendicularMetalBounce\0.2 5\perpendicularMudBounce\0.1\perpendicularPaperBou nce\0.2\perpendicularPlasterBounce\0.25\perpendicu larRockBounce\0.25\perpendicularSandBounce\0.1\per pendicularSnowBounce\0.1\perpendicularWaterBounce\ 0.2\perpendicularWoodBounce\0.25\perpendicularAsph altBounce\0.25\swayMaxAngle\30\swayLerpSpeed\6\swa yPitchScale\0.1\swayYawScale\0.1\swayHorizScale\0. 1\swayVertScale\0.1\swayShellShockScale\5\worldMod el\xmodel/weapon_mk2fraggrenade\hudIcon\gfx/icons/hud@us_grenade.tga\modeIcon\\ammoName\idlenade\max Ammo\0\startAmmo\0\clipName\idlenade\clipSize\0\sh aredAmmoCapName\WEAPON_IDLENADE\sharedAmmoCap\0\dr opAmmoMin\0\dropAmmoMax\0\pickupSound\weap_pickup\ ammoPickupSound\\pullbackSound\weap_fraggrenade_pi n\fireSound\weap_fraggrenade_fire\lastShotSound\\r eloadSound\weap_fraggrenade_reload\altSwitchSound\ \raiseSound\\putawaySound\\noteTrackSoundA\\noteTr ackSoundB\\noteTrackSoundC\\noteTrackSoundD\\retic leCenter\gfx/reticle/center_cross.tga\reticleSide\\reticleCenterSize\32 \reticleSideSize\16\reticleMinOfs\4\altWeapon\\two Handed\0\cookOffHold\0\wideListIcon\0\killIcon\gfx/icons/hud@us_grenade.tga\wideKillIcon\0\flipKillIcon\1\s tandMoveF\0\standMoveR\1\standMoveU\-1.5\standRotP\0\standRotY\0\standRotR\0\duckedOfsF \-2\duckedOfsR\2\duckedOfsU\-0.2\duckedMoveF\0\duckedMoveR\1\duckedMoveU\-1.5\duckedRotP\0\duckedRotY\0\duckedRotR\0\proneOf sF\-6\proneOfsR\3.5\proneOfsU\0.8\proneMoveF\0\proneMo veR\1\proneMoveU\-1.5\proneRotP\0\proneRotY\0\proneRotR\0\posMoveRat e\4\posProneMoveRate\10\standMoveMinSpeed\110\duck edMoveMinSpeed\60\proneMoveMinSpeed\0\posRotRate\5 \posProneRotRate\10\standRotMinSpeed\110\duckedRot MinSpeed\60\proneRotMinSpeed\0\explosionRadius\256 \explosionInnerDamage\200\explosionOuterDamage\50\ projectileSpeed\940\projectileSpeedUp\120\projecti leModel\xmodel/projectile_mk2fraggrenade\projExplosionType\grenad e\projExplosionEffect\\projExplosionSound\\project ileTrail\none\projectileTrailTime\1\projectileTrai lRadius\32\projImpactExplode\0

as you can, or maybe cannot see, this nade has a max of 0 ammo, making it an addition to the player's loadout without any ammo. This is nice, because players will not have any additional nades.

We now need to put this code into a weaponfile, precache it and give it to all players on spawn. (warning: this WILL break the dropoffhand() function used to drop grenades. Write your own fix for this, like storing the last used grenade in a player var)

Now we can force the player to focus on this offhandtype, and catch any other offhands. I suggest you use something like this:



while(true)
{
self switchtooffhand("fraggrenade_idle_mp");
if(self getcurrentoffhand()!="fraggrenade_idle_mp")
{
//player is throwing a nade
}
wait 0.05;
}


And thats all.

Known bugs: If the smokegrenade is empty, but ppl press the smokegrenade button anyway, this system detects it as if a real nade is being thrown.