Page 1 of 1

How to make a person move in direction of a grenade?

Posted: February 25th, 2010, 8:37 am
by xeno
How do you make a person move in the same way/direction a grenade would if they threw it; if necessary, how to make a special weapon file / grenade that when used it causes them to be attached to the nade or whatever.

Re: How to make a person move in direction of a grenade?

Posted: February 25th, 2010, 11:36 am
by matt101harris
xeno wrote:How do you make a person move in the same way/direction a grenade would if they threw it; if necessary, how to make a special weapon file / grenade that when used it causes them to be attached to the nade or whatever.
Im not quite sure what you mean, but in promod there is a little "ready up" period, where u can have a certain mod called "warm up" mode or something, there you can follow your nade in mid air to see where it is going.

Re: How to make a person move in direction of a grenade?

Posted: February 25th, 2010, 6:29 pm
by xeno
Well I want to be able to make a person move like a grenade being thrown. How it has the arch motion and such. By attaching/linking the player to the nade or some other method.

Re: How to make a person move in direction of a grenade?

Posted: February 25th, 2010, 7:14 pm
by matt101harris
xeno wrote:Well I want to be able to make a person move like a grenade being thrown. How it has the arch motion and such. By attaching/linking the player to the nade or some other method.
Yes for that do the thing as i said above, ill try and find you a link on the mod, 1 second.

http://www.filefront.com/9469714/AM4PAM ... dmiralMOD/

here is a mod you can download, haven't tested it, but im sure it will work.

Re: How to make a person move in direction of a grenade?

Posted: February 26th, 2010, 12:10 am
by xeno
Well, it's for cod1. Not cod4, so don't know if that will work.

Re: How to make a person move in direction of a grenade?

Posted: February 26th, 2010, 1:00 am
by waywaaaard
xeno wrote:Well, it's for cod1. Not cod4, so don't know if that will work.
Get the script and just try it out. I guess it could work most likely.

Re: How to make a person move in direction of a grenade?

Posted: February 26th, 2010, 8:26 pm
by Drofder2004
The script was actually quite easy when I created a private test mod, but I cannot find my scripting for it :/

The idea is very simple:

Create a loop to detect grenades being thrown.
when the frag is found, create a new loop to monitor the origin of the frag (I created a quick array that basically stored all the values of the frag origin)
Then just force the player origin to follow the frag using a little maths to detect direction. (anglestoup and anglestoforward, I think)
Then force those angles upon the player.

I may try recreate the code, it didnt take me long last time...

Re: How to make a person move in direction of a grenade?

Posted: February 26th, 2010, 10:43 pm
by Drofder2004
Nades are tracked differently in vCoD, they are tracked as basic entities

Code: Select all

getentarray("grenade","classname");
That will create a list of all the current grenades been thrown, it is slightly more complicated to keep track of multiple nades, and I cannot remember how (if possible) you track who threw which...

But this is how it looks for CoD4.
This will give you the exact view the nade gets. Unlike Nade Training in promod, this will automatically realign the camera to follow the trajectory of the nade.

With a little cross-threading you can easily access the recorded data as it is being recorded, allowing you to watch the nade in the air...

the movement however is alot jerkier, but this is due to single origins being processed every 0.05 seconds (giving the illusion of 20 fps).

Do as you wish with it, I was on the verge of relasing a tactics mod several years back in CoD2, but I didn't bother bringing it forward any further as the interest in setnades dropped.

(you must call the checkForNades() function on a player, not on the level entity).

Code: Select all

checkForNades()
{
	for(;;)
	{
		self waittill ( "grenade_fire", grenade);
		grenade tracknade(self);
	}
}

tracknade(player)
{
	org = [];
	ang = [];
	
	while(isDefined(self))
	{
		org[org.size] = self getOrigin();
		ang[ang.size] = self.angles;
		
		wait 0.05;
	}
	
	for(i=1;i<org.size;i++)
	{
		player setPlayerangles(vectortoangles(org[i] - org[i-1]));
		player setOrigin(org[i-1]);
		wait 0.05;
	}
}
(For smoothness set your sv_fps to 125, although this does do some strange other things, but works well for smoothness :P)

Re: How to make a person move in direction of a grenade?

Posted: February 27th, 2010, 7:06 am
by xeno
This?

Code: Select all

checkForNades()
{
	iprintln("IN checkForNades");
	for(;;)
	{
		//self waittill ( "grenade_fire", grenade);
		grenadesthrown = getentarray("mpweapon_fraggrenade", "classname");
		if(grenadesthrown.size>0)
		{
			iprintln("IN if statement");
			grenadesthrown[0] tracknade(self);
		}
	}
}

tracknade(player)
{
	iprintln("IN tracknade");
   org = [];
   ang = [];
   
   while(isDefined(self))
   {
      org[org.size] = self getOrigin();
      ang[ang.size] = self.angles;
      
      wait 0.05;
   }
   
   for(i=1;i<org.size;i++)
   {
      player setPlayerangles(vectortoangles(org[i] - org[i-1]));
      player setOrigin(org[i-1]);
      wait 0.05;
   }
}

Re: How to make a person move in direction of a grenade?

Posted: February 28th, 2010, 12:56 am
by Drofder2004
Not exactly

1. do not use "weapon_..." just simply "grenade"
2. you for(;;) is infinite, it needs a wait statement
3. your code should work but it is not very friendly. This would not work as a mod in its current form as it only detects the one nade. (also, if you are the only person using it, there is no need for the array. I have code here for how to track multiple nades using a tag system, if you cannot get this too work.