Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Picking up 'grenade' weapontypes [CoD4]

  1. #1
    Private
    Join Date
    Jul 2015
    Posts
    44
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Picking up 'grenade' weapontypes [CoD4]

    So i'm having a small issue, in the _weapons.gsc I added a little line that calls a seperate script gsc that allows the player to pick up frag grenades, this is called from watchthrowbacks and should allow the player to pick up files starting with throwingknife_ (throwingknife_mp is just an edited frag_grenade_mp, same weapontype and playeranimtype etc)

    Code:
    prepareTKPickup( owner )									// self = Throwingknife
    {
    	// self endon( "death" );
    		
    	self waitTillNotMoving();
    	
    	trigger = spawn( "trigger_radius", self.origin-(0,0,32), 0, 32, 64 );
    	
    	for(;;)
    	{
    		trigger waittill( "trigger", user );
    		
    		if( user canUse( user ) )
    			user.lowerMessage SetText( &"MPUI_PRESS_USE_TO_PICK_TK" );
    			user.lowerMessage.alpha = 1;
    			user.lowerMessage FadeOverTime( 0.05 );
    			user.lowerMessage.alpha = 0;
    
    		if( user usebuttonpressed() )
    		{
    			if( user == owner )
    			{
    				if( self deleteTK() )
    				{
    					tkammo = user getammocount( "throwingknife_mp" );
    					user setWeaponAmmoOverall( "throwingknife_mp", tkammo+1 );
    				}
    			}
    			else
    			{
    				return false;
    			}
    			break;
    		}
    	}
    }
    The code works although there's an issue, this waittillnotmoving() spawns the pickup trigger radius directly under the player, instead of wherever the idle knife lands, i'm pretty sure this is because, until the first person animation actually throws the throwingknife, the grenade throwing 3rd person animation will keep the throwingknife idle on the player and as it's idle, that is where the trigger radius is forced to spawn, I tried this with C4, C4 has it's own after-thrown, idle waittill, which is ( "activated" ) to tell the script it has landed and is idle on a surface, to which the script spawns the trigger radius around the c4 pack, I needed to know if there was a waittill for frag grenades - types so the script can waittill the throwingknife is actually idle on the ground and spawn the trigger radius instead of spawning the trigger radius when it's idle on the players body...

    something like waittill ( "landedonground" ) not that but you get the idea,

  2. #2
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    You need to show where and how you have threaded it. I am guessing that you have your entities mixed up, and that is why the trigger is being spawned under the player, and not the greande/knife.

    BTW - with world entities which have been created from a weapon file, you don't need to spawn a trigger. A trigger will automatically be spawned on them, and this is how you are able to pick up weapons in the game. You might want to play around with that method, rather than manually spawning a trigger_radius.

  3. #3
    Private
    Join Date
    Jul 2015
    Posts
    44
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Code:
    beginGrenadeTracking()
    {
    	self endon ( "death" );
    	self endon ( "disconnect" );
    	
    	startTime = getTime();
    	
    	self waittill ( "grenade_fire", grenade, weaponName );
    	
    	if ( (getTime() - startTime > 1000) )
    		grenade.isCooked = true;
    	
    	if ( weaponName == "frag_grenade_mp" || weaponName == "throwingknife_mp" )
    	{
    		grenade thread maps\mp\gametypes\_shellshock::grenade_earthQuake();
    		grenade.originalOwner = self;
    		grenade thread InfectedScript\mp\equipment\_tk::prepareTKPickup( self );
    	}
    		
    	self.throwingGrenade = false;
    }
    and

    Code:
    watchForThrowbacks()
    {
    	self endon ( "death" );
    	self endon ( "disconnect" );
    	
    	for ( ;; )
    	{
    		self waittill ( "grenade_fire", grenade, weapname );
    		if ( self.gotPullbackNotify )
    		{
    			self.gotPullbackNotify = false;
    			continue;
    		}
    		if ( !isSubStr( weapname, "frag_" ) || !isSubStr( weapname, "throwingknife_" ) )
    			continue;
    		
    		// no grenade_pullback notify! we must have picked it up off the ground.
    		grenade.threwBack = true;
    		grenade thread maps\mp\gametypes\_shellshock::grenade_earthQuake();
    		grenade.originalOwner = self;
    		grenade thread InfectedScript\mp\equipment\_tk::prepareTKPickup( self );
    	}
    }
    both in _weapons.gsc
    Last edited by akuma2099; 14th September 2015 at 10:46.

  4. #4
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    1. You don't need 2 threads to a function. Get rid of the one in throwbacks().

    2. I think your problem is very simple:

    Try this:

    Code:
    prepareTKPickup( owner )									// self = Throwingknife
    {
    	// self endon( "death" );
    		
    	waitTillNotMoving();
    	
    	self.trigger = spawn( "trigger_radius", self.origin-(0,0,32), 0, 32, 64 );
    	
    	for(;;)
    	{
    		self.trigger waittill( "trigger", user );
    		
    		if( user canUse( user ) )
    			user.lowerMessage SetText( &"MPUI_PRESS_USE_TO_PICK_TK" );
    			user.lowerMessage.alpha = 1;
    			user.lowerMessage FadeOverTime( 0.05 );
    			user.lowerMessage.alpha = 0;
    
    		if( user usebuttonpressed() )
    		{
    			if( user == owner )
    			{
    				if( self deleteTK() )
    				{
    					tkammo = user getammocount( "throwingknife_mp" );
    					user setWeaponAmmoOverall( "throwingknife_mp", tkammo+1 );
    				}
    			}
    			else
    			{
    				return false;
    			}
    			break;
    		}
    	}
    }
    I can't test any of this as I am encoding videos. And it takes a llllllooooooonnnnnnngggggggg time.

  5. #5
    Private
    Join Date
    Jul 2015
    Posts
    44
    Thanks
    7
    Thanked 2 Times in 2 Posts
    adding the 2 'self' to both the trigger lines still spawns the trigger radius under the player, and when picked up and thrown again, doesn't spawn it anymore
    Last edited by akuma2099; 15th September 2015 at 10:47.

  6. #6
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by akuma2099 View Post
    adding the 2 'self' to both the trigger lines still spawns the trigger radius under the player, and when picked up and thrown again, doesn't spawn it anymore
    Looks like you're going to have to play around with it then, doesn't it? These things don't get magically fixed. You have to try, try, and try again. I have sometimes spent a week just getting a code working.

    I would remove the waittillnotmoving() check and see where the origin of the grenade ends up.
    Last edited by Tally; 15th September 2015 at 11:18.

  7. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Im not seeing any trigger cleanups in your script. I hope you remember to delete() the trigger when done to prevent serv crashes due to too many entities
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  8. #8
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Try this:

    Code:
    beginGrenadeTracking()
    {
    	self endon ( "death" );
    	self endon ( "disconnect" );
    	
    	startTime = getTime();
    	
    	self waittill ( "grenade_fire", grenade, weaponName );
    	
    	if ( (getTime() - startTime > 1000) )
    		grenade.isCooked = true;
    	
    	if ( weaponName == "frag_grenade_mp" || weaponName == "throwingknife_mp" )
    	{
    		grenade thread maps\mp\gametypes\_shellshock::grenade_earthQuake();
    		grenade.originalOwner = self;
    		grenade thread InfectedScript\mp\equipment\_tk::Clearthrow( self );
    	}
    		
    	self.throwingGrenade = false;
    }
    Code:
    Clearthrow( player )
    {
    	ent = spawn( "script_model", self.origin );
    	ent.angles = ( 0,0,0 );
    	ent setmodel( "tag_origin" );
    	ent linkto( self );
    	
    	self findOrigin( player, ent );
    }
    
    findOrigin( player, ent )
    {
    	for( ;; )
    	{
    		if( !isdefined( self ) ) 
    		{
    			player thread setMarker( ent.origin );
    			ent delete();
    			break;
    		}
    		
    		wait 0.05;
    	}
    }
    
    setMarker( origin )
    {
    	
    	trigger = spawn( "trigger_radius", origin-(0,0,32), 0, 32, 64 );
    	
    	for(;;)
    	{
    		trigger waittill( "trigger", user );
    		
    		if( user canUse( user ) )
    			user.lowerMessage SetText( &"MPUI_PRESS_USE_TO_PICK_TK" );
    			user.lowerMessage.alpha = 1;
    			user.lowerMessage FadeOverTime( 0.05 );
    			user.lowerMessage.alpha = 0;
    
    		if( user usebuttonpressed() )
    		{
    			if( user == owner )
    			{
    				if( self deleteTK() )
    				{
    					tkammo = user getammocount( "throwingknife_mp" );
    					user setWeaponAmmoOverall( "throwingknife_mp", tkammo+1 );
    				}
    			}
    			else
    			{
    				return false;
    			}
    			break;
    		}
    	}
    }
    NB: Make sure "tag_origin" xmodel is precached.

    that basically waits for the grenade/knife entity to be auto deleted by the game, and for a "dummy" ent marker to take over finding the origin. To do that, you have to spawn the "dummy" ent on the grenade as soon as the game is notified a grenade has been "pulled", and then wait until the grenade/knife itself is auto deleted by the game before you find the "dummy" ent's origin.
    Last edited by Tally; 15th September 2015 at 11:50.

  9. #9
    Private
    Join Date
    Jul 2015
    Posts
    44
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Shouldn't I replace 'player' with 'owner' and since the value 'owner' is called from if( user usebuttonpressed() ), should I make setMarker( origin ) , setMarker( origin, owner )

    EDIT: I tried both, and neither worked, still trying to mess around and get it working.

  10. #10
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by akuma2099 View Post
    Shouldn't I replace 'player' with 'owner' and since the value 'owner' is called from if( user usebuttonpressed() ), should I make setMarker( origin ) , setMarker( origin, owner )

    EDIT: I tried both, and neither worked, still trying to mess around and get it working.
    Why would you replace "player" with "owner"? Where is "owner" defined? It isn't! But player is. So, I guess you should leave "player" as being the right entity.

    I tried both
    Both what? There is 1 script. What is the second one you are referring to?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •