Missile Stinger

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
agentmad007
Brigadier General
Posts: 570
Joined: Tue Feb 24, 2004 3:52 pm

Missile Stinger

Post by agentmad007 »

Hello , i ve made a search already , , have not found any post that match.

Do you think whe can make a stinger missile that would aim at a player reaching a certain area ?

I am using a script_model (static/v2.tik) ....There is no many comands allowing to do so.Most of the relevant comands are related to turretgun .

Any idea ?
Deadly and slient.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Possible... you could have a look at MW's heli script which also contains guided missiles :)
Image
agentmad007
Brigadier General
Posts: 570
Joined: Tue Feb 24, 2004 3:52 pm

Post by agentmad007 »

okay Thx Jv , i ll take a look .:D
Deadly and slient.
agentmad007
Brigadier General
Posts: 570
Joined: Tue Feb 24, 2004 3:52 pm

Post by agentmad007 »

uah this script is to clever for me to undertand it completely lol.There is some local.pilot conditions , wich i dont really need but if i take them out the script means nothing anymore.
Deadly and slient.
agentmad007
Brigadier General
Posts: 570
Joined: Tue Feb 24, 2004 3:52 pm

Post by agentmad007 »

Code: Select all

firerocket local.shooter:

	
	local.rok = spawn script_object model mw_projectiles/ffar.tik angles self.angles origin local.org
	local.rok playsound snd_ffar_fire
	local.rok physics_on
	
	// spawn the salvo smokers
	local.bsmoke = spawn mw_fx/ffarsmoke.tik origin (local.org - self.forwardvector * 60 + self.upvector * 4.0) angles (self.angles + (0 180 0))
	local.bsmoke commanddelay 0.25 anim start
	local.bsmoke commanddelay 2.25 remove
	
	// add rocket engine impulse
	local.rok physics_velocity (self.forwardvector * 2000)
	// add owner velocity
	local.rok physics_velocity self.speed
	
	local.rok thread rocketthink local.shooter self
	
	// guided or steerable
	if(level.helirocketmode == 0 || level.helirocketmode == 1)
		local.rok thread rocketsteer self
	else
	{
		local.rok gravity 0.25 // reduce gravity for unguided rockets
		
		// launch em a tad down
		local.velup = -1 * (80 + randomfloat 40)
		local.rok physics_velocity (0 0 local.velup)
	}
	
	if(level.helirocketmode == 2)
		// allow greater rof for unguided rockets
		wait 0.30
	else
		wait 0.50
		
	self.readytofirerocket = 1
end

getrockettarget local.heli:
	local.best = NULL
	
	if(level.helirocketmode == 0 && isAlive local.heli.pilot) // guided
	{
		// should be 1 of the players
		local.j = 0
		for(local.i = 1; local.i <= $player.size; local.i++)
		{
			local.p = $player[local.i]
			if(local.p.dmteam != spectator && (local.p.dmteam == "freeforall" || local.p.dmteam != local.heli.pilot.dmteam))
			{
				local.vectop = local.p.origin - self.origin
				local.dotvec = (vector_normalize local.vectop) * self.forwardvector
				
				if(local.dotvec > 0.70 && sighttrace self.origin (local.p.origin + (0 0 0)) 128)
				{
					// add this player to the posplayers array
					local.j ++
					local.posplayers[local.j] = local.p
					local.posplayersdotvec[local.j] = local.dotvec
				}
			}
		}
	
		local.highest = 0.0
		for(local.i = 1; local.i <= local.j; local.i++)
		{
			local.p = local.posplayers[local.j]
			local.sqdistvec = local.p.origin - self.origin
			local.sqdist = local.sqdistvec * local.sqdistvec
			local.dotvec = local.posplayersdotvec[local.j]
			local.fact = (100000 * local.dotvec) / local.sqdist
			if(local.fact >= local.highest)
			{
				local.best = local.p
				local.highest = local.fact	
			}
		}
	}
	if(local.best)
	{
		end local.best
	}
	else if (isAlive local.heli.pilot)
	{
		local.target = spawn listener
		local.vec = angles_toforward local.heli.pilot.viewangles
		local.end = local.heli.pilot.origin + local.vec * 8000.0
		local.trace = trace local.heli.pilot.origin local.end 128
		local.target.origin = local.trace
		local.target.removeme = 1
		end local.target
	}
end NULL

rocketsteer local.heli:
	local.burntime = 10.0

	local.aimvec = angles_toforward local.heli.pilot.viewangles
	
	local.starttime = level.time
	
	wait 0.25
	wait (randomfloat 0.50)

	if(self)
	{
		// random rocket quality :)
		local.steerability = (200 + (randomfloat 200)) * 2.0 // compensate for lower rate of update
	
		// grab a target
		local.target = waitthread getrockettarget local.heli
		
		if(local.target)
		{
			while(self && level.time - local.starttime <= local.burntime)
			{
				local.targetvec = vector_normalize (local.target.origin - self.origin)
				local.currentvec = self.forwardvector
				local.steervec = local.targetvec - local.currentvec
				self physics_velocity (local.steervec * local.steerability) // was 800
				self.angles = vector_toangles self.velocity
				wait 0.10 // test, reduce cpu load and network traffic
			}
			
			if(local.target.removeme == 1)
				local.target remove
		}
		else
		{
			wait local.burntime		
		}	
		if(self)
		{
			self anim nosmoke	
		}
	}
end

rocketthink local.shooter local.heli:
	self waittill touch
	
	if(parm.other != local.shooter)
		parm.other damage local.shooter 250 self (0 0 0) (0 0 0) (0 0 0) 0 1 rocket -1
	
	if(self isTouching $flyarea)
	{
		local.modelname = emitters/gren_exp.tik
		local.exp = spawn local.modelname origin (self.origin - self.forwardvector * 16) 
		local.exp anim start
	
		waitthread killnearbyplayers self.origin local.shooter self
	}
	
	self delete
	local.heli.rocketsinair--
	wait 2
	if(local.exp)
		local.exp remove
end

killnearbyplayers local.origin local.killer local.inflictor:
	local.maxsqdist = 200.0 * 200.0
	for(local.i = 1; local.i <= $player.size; local.i++)
	{
		local.p = $player[local.i]
		if(local.p != local.killer && isAlive local.p)
		{
			local.vec = local.p.origin - local.origin
			local.sqdist = local.vec * local.vec
			if(local.sqdist <= local.maxsqdist)
			{
				local.dmg_fact = 1 - local.sqdist / local.maxsqdist
				local.dmg = 150 * local.dmg_fact
				local.p damage local.killer local.dmg local.inflictor (0 0 0) (0 0 0) (0 0 0) 0 1 rocket -1
			}
		}
	}
end
Can't someone Help me to do it simplier ? Hehe

thx
Deadly and slient.
Post Reply