Helicopter problem

Discuss programming in the QuakeC language.
Post Reply
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Helicopter problem

Post by sniperz227 »

hey sniperz227, im having trouble coding a helicopter in for my mod. its not going to be controlled by the player or anything its sorta like the heli in cod where it comes and shoots just modified. i set up 2 enitities for the start and finish of the helicopter for now. What it'll do is go in a straight line from start enitity to the other and while its going in that line its will shoot a everything under in that line till the helicopter is gone. what im having trouble with is im not sure how i would make the helicopter move by itself like if it was triggered by the impulse and spawned how would it move if i set the velecoity etc.. and the other thing is i know for the W_Fire functions it is triggered by pressing the mouse on pc which is the +attack function which will fire the weapon but im not sure how i would get it to shoot by itself. Here's what i have so far. plus is there a more efficient way to do this etc.. without using an entity to chose what line it goes in?

Code: Select all

/*
===============
Helicopter Code
===============
*/

void() Heli_Anim =
{
local float end;
	while (end != 1)// while end isnt 1 so if it hasnt reached end point
	{
		if (self.weaponframe == 0)//check if weapon frame is 0
			self.weaponframe = self.weaponframe + 1; // increment by 1
		if (self.weaponframe >= 8)//end of animation
		return;
		self.nextthink = time + 0.1;
	}
	if(end == 0) // if it has reached end point
	{
		self.weaponframe == 0; // reset animation frame to first one and dont play anything
	}
		
}	
	
entity() item_unspawn =
{
	precache_model(self.model);
	setmodel (self,self.model);
	self.skin = 0;
}

entity() item_heli = 
{
	precache_model(self.model);
	setmodel (self,self.model);
	self.skin = 0;
}



void() heli_spawn =
{
entity spawn;
spawn = item_heli(); // setting spawn to where the helicopter spawns
}

void() Heli = 
{
self.classname = "helicopter";
self.health  = 500; // heli health
self.takedamage = DAMAGE_AIM;
self.solid = SOLID_NOT; // not solid so it can go thorugh map entity's and walls etc..
};

void() Heli_Move = 
{
vector start; // vector for startpoint of heli
vector end;	  // vector for endpoint of heli

heli_spawn(); // spawn heli
start = self.origin; 
end = v_forward*10; // not sure how i would make it go to the end entity
makevectors(self.v_angle);

// pseudo code for end because im not sure how to do it(if start (the point where the heli start) hits the end entity(item_unspawn) then end = 0 and remove model from map)
}
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Re: Helicopter problem

Post by r00k »

doesnt look like your copter will fly. maybe u should toss a super model at it and see what happens.
*bad joke kill me now
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Helicopter problem

Post by frag.machine »

sniperz227 wrote:

Code: Select all

/*
===============
Helicopter Code
===============
*/

void() Heli_Anim =
{
local float end;
	while (end != 1)// while end isnt 1 so if it hasnt reached end point
	{
		if (self.weaponframe == 0)//check if weapon frame is 0
			self.weaponframe = self.weaponframe + 1; // increment by 1
		if (self.weaponframe >= 8)//end of animation
		return;
		self.nextthink = time + 0.1;
	}
	if(end == 0) // if it has reached end point
	{
		self.weaponframe == 0; // reset animation frame to first one and dont play anything
	}
		
}	
Let's analyze this line first.

Code: Select all

local float end;
	while (end != 1)// while end isnt 1 so if it hasnt reached end point
So, let me ask you: what value does the "end" var is supposed to have ? Because you haven't initialized it, and it will be lost once you leave the function (because it's declared "local" to the current function), so I can state you hadn't set it elsewhere.

Second problem:

Code: Select all

	while (end != 1)// while end isnt 1 so if it hasnt reached end point
	{
		if (self.weaponframe == 0)//check if weapon frame is 0
			self.weaponframe = self.weaponframe + 1; // increment by 1
		if (self.weaponframe >= 8)//end of animation
		return;
		self.nextthink = time + 0.1;
	}
Assuming your while condition is true (even with the first problem I pointed above) and self.weaponframe value is 0 the first time the function is called, it then changes to 1. The next line checks if self.weaponframe is equals or greater than 8 and, if true, ends the function. However, self.weaponframe is 1, and thus we proceed to the next code line, which is... self.nextthink= time + 0.1. Ok, so we set this function to run again in 1 tenth of second, and because the end variable is unchanged, the while repeats and we go back to the "if (self.weaponframe == 0)" line, which now evaluates as false, so we jump to the next line, which again evaluates to false, and we again jump to the line setting self.nextthink to time + 0.1, and again the while break condition doesn't happens and so on... Your code now is running into an infinite loop, pretty much like Superman flying in loops around the Earth to travel back in time and save Lois Lane. Great Scott! Maybe you accidentally discovered a Quake engine based time traveling device! :shock: Doc Brown would be so proud...

Ok, seriously now: the simplest loop to animate the view weapon in Quake is like this:

Code: Select all

void Heli_Anim () =
{
  self.weaponframe = self.weaponframe + 1; // first, increment it
  if ((self.weaponframe < 0) || (self.weaponframe > 7)) // then, if it's out of our animation range we fix it
  {
    self.weaponframe = 0;
  }
  // NO NEED TO SET self.nextthink! the normal player code already takes care of the rest.
};
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Post Reply