PDA

View Full Version : Picking up 'grenade' weapontypes [CoD4]



akuma2099
14th September 2015, 10:05
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)



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, :)

Tally
14th September 2015, 10:14
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.

akuma2099
14th September 2015, 10:44
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



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

Tally
14th September 2015, 11:13
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:


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.

akuma2099
15th September 2015, 10:44
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

Tally
15th September 2015, 11:14
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.

IzNoGoD
15th September 2015, 11:32
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

Tally
15th September 2015, 11:36
Try this:


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;
}



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.

akuma2099
15th September 2015, 12:34
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.

Tally
15th September 2015, 12:41
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?

akuma2099
15th September 2015, 12:46
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.



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



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;
}
}
}


and one with owner at the beginning of the thread



setMarker( origin, owner )
{

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;
}
}
}


If i don't put 'owner' at the beginning of the thread it causes a compile error as this part of the thread used in the beginning script

akuma2099
17th September 2015, 11:34
This makes the pickup trigger work, but the pickup trigger only spawns when the grenade is thrown from it's 'press g to throw back' action i.e when it has already been thrown, is idle on the floor, and gets thrown back.
Is there anything I can edit inside of _weapons.gsc or anywhere to change this/fix this, i've tried everything from editing owner/user permissions deleting script from _weapons in an attempt to remove the throwback notify from showing, using code from _disarmexplosives from OW SVN, but nothing seems to be working

Tally
17th September 2015, 13:45
This makes the pickup trigger work, but the pickup trigger only spawns when the grenade is thrown from it's 'press g to throw back' action i.e when it has already been thrown, is idle on the floor, and gets thrown back.
Is there anything I can edit inside of _weapons.gsc or anywhere to change this/fix this, i've tried everything from editing owner/user permissions deleting script from _weapons in an attempt to remove the throwback notify from showing, using code from _disarmexplosives from OW SVN, but nothing seems to be working

No idea what you are blathering on about. In fact, no idea what it is you are trying to do anymore. Talk about confusing posts, or what? I thought you were trying to find the origin of a THROWN grenade, but apparently not. if you don't want to find the origin of a thrown grenade, why not revert back to your original code? that will give you exactly what you seem to be asking for.

In which case, I will delete this entire thread as completely pointless and redundant garbage.

IzNoGoD
17th September 2015, 14:14
I also find it hard to identify your goal here. Are you trying to allow a player to pick up a thrown throwingknife to immediately throw it back, by trying to reuse nadethrowback code?

akuma2099
18th September 2015, 02:17
My goal is to make the throwingknife able to be picked and placed into the inventory of the player.

Your code is making the pickup trigger spawn only after the throwingknife has been thrown back (as it is a frag grenade weapontype the press g to throw back text spawns), sorry if my paragraph was hard to understand.

I'm trying to say that the pickup trigger will only spawn once the throwingknife has been idle and is being thrown back.
I'm trying to make the pickup trigger spawn once it has been idle in the first place.