question for bdbodger....

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

question for bdbodger....

Post by G3mInI »

I am using both your strafe script and spotlight script in a server side mod. What I would really like to do is make a new spotlight script which when activated by a setthread command at a specific node in the strafe.scr, would activate the spotlight(s) and stay fixed on the plane that is flying by. I have tried unsuccesfully to modify both spotlight and the strafe scripts. I was and am very close but errors fill up console. I do get the beam to target the plane and follow it but when the plane leaves the level they keep on a shining. I tried to put a variable in to shut them off but didnt work and dont know why. To accomplish targeting the plane, in the strafe script I gave level.plane[local.i] a targetname. Then in spotlight script I tried to trace the targetname. However I get all kinds of errors stating trace is applied to null entity and index 2 out of range. Even though the lights are shining on the plane and following it. Another thing was that the spotlights were blinking on and off. So I'm guessing when the lights were off is where it was finding the null entities. I guess what I am asking is how do I properly target the plane in strafe.scr in my level.script. And then how would I make a spotlight follow that target. I thought it was going to be easy but ...quite opposite. I get real confused in spotlight.scr when you start calculating the vectors.

My latest attempt is as follows and it is ugly in console. And now the lights don't even move. I just keep trying things and now I cant even get back to having the spotlights move. They just stay fixed and stay on.

Code: Select all

******************************************************************
while(1)
		{
		
		//local.range = 10240 //dont seem to need this but I bet its hurting me

		local.groundtarget.origin = trace $bomber1.origin  

		local.s_vec = ( local.groundtarget.origin - local.spot.origin)
		local.s_ang = vector_toangles(local.s_vec)

		local.s_ang[1] = (local.s_ang[1] - 180)

		local.s_ang[0] = (local.s_ang[0] * -1)


		local.spot.angles = local.s_ang

		local.spotlight.angles = ( 0 local.s_ang[1] 0 )

		local.light.origin = local.spot.origin + local.spot.forwardvector * -8 

		local.light show
		local.flare show
		local.beam show
		
		if(level.airstrike == 0)
			{
			wait 2
			local.beam hide
			local.light hide
			local.flare hide
			break
			}
		waitframe
		if(local.spot.destroyed == 1)
			break
	}

end
******************************************************************

And here is where I gave the plane a targetname in strafe.scr and placed a variable to let me know when the bomb hits the target. Which is also when I want the spotlights to stop shining.


Code: Select all

waitthread plane_init local.set 1 level.strafenode[local.set][1].planescale

		level.plane[local.set] show
		
		level.plane[local.set].targetname = bomber1 //added this line 

Here is where I added the variable to let me know when the bomb drops. Which does work for the other reason I needed to. It is accessible in my main level script.

Code: Select all

movedone:
	self.movedone = 0
	self waitmove
	self.movedone = 1
	level.airstrike = 0 // added this to help my main script out
end

Obviously probably to you this is not how to go about achieving this goal I have. But I wanted to give it a try. If you have any tips on how I can attain my goal I would appreciate it. And I fully understand if this is not something you want to dive into.

Peace,
G3mInI
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

When you set the setthread key on a node for the global/stafe2.scr it passes the set number and
node number to the thread

thread level.script::self.setthread self.set local.nodenum

so your thread can use that to determine what plane is flying

mythread local.set:

if your thread starts like that then local.set is the set number of the node that called the thread
and you can refer to the plane as level.strafeplane[local.set] and the thread can start the spotlights ,
the plane can fly as normal you don't need to change the strafe2.scr do so at your own risk .

What you need to do is make the spotlights think.You first need to understand vectors

Code: Select all


		local.fwd_vec = angles_toforward local.player.viewangles
		local.start = local.player gettagposition "Bip01 Head"

		local.range = 10240

		local.groundtarget.origin = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0
angles_toforward creates a vector 1 unit in the direction of the angles in other words how much you whould add from a
point like local.start in this example to the x y and z to give you those angles . angles converted to a direction 1 unit away

so starting from local.player gettagposition "Bip01 Head" it is 1 unit away in the directon of the angles .

(local.start + local.fwd_vec * 64) multiply that to get a point 64 units away from local.start along those angles

that is the first point for the trace

(local.start + local.fwd_vec * local.range ) a point 10240 units away from local.start along those angles

that is the second point for the trace

local.groundtarget.origin = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0

do a trace from the first point to the second point local.groundtarget.origin is the point that the trace hits something

For what you are doing you don't need that I just explained it so you can understand vectors a bit better

this is probably what you will need to use

Code: Select all

		local.s_vec = ( local.groundtarget.origin - local.spot.origin)
		local.s_ang = vector_toangles(local.s_vec)

		local.s_ang[1] = (local.s_ang[1] - 180)

		local.s_ang[0] = (local.s_ang[0] * -1)


		local.spot.angles = local.s_ang

		local.spotlight.angles = ( 0 local.s_ang[1] 0 )
for your code you will be useing level.strafeplane[local.set].origin not local.groundtarget.origin

local.s_vec = ( local.groundtarget.origin - local.spot.origin)

that will give you a vector , a change in the x y and z that gives you a direction

local.s_ang = vector_toangles(local.s_vec)

convert the vector that you got to angles this time instead of angles to vector like the first example

local.s_ang[1] = (local.s_ang[1] - 180)

The forward vector of the spotlight model is backwards if is away from the direction that the light faces so reverse it

local.s_ang[0] = (local.s_ang[0] * -1)

When the back of the light points up the front of the light points down so multiply by -1

local.spot.angles = local.s_ang

now that you have reversed the yaw of the angles and muliplied the pitch by -1 apply the angles to the spotlight

local.light.origin = local.spot.origin + local.spot.forwardvector * -8

that places the small corona inside the light to show that it is on. So by running that second code example in a loop the

spotlight will point to local.groundtarget.origin or for your code level.strafeplane[local.set].origin

the light at the end of the beam is this

local.flare = spawn script_model
local.flare model "fx/searchlight.tik"
local.flare notsolid
local.flare scale 5
local.flare.origin = local.groundtarget.origin
local.flare hide
local.flare light local.color
local.flare lightradius 250

and since the end of the beam is always level.strafeplane[local.set].origin that is where it will be in your code anyway

so run a thread that does those things as long as level.strafeplane[local.set] exists and when it does not delete local.flare and

if you have a beam deactivate it and stop the loop that points the light at the plane .
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

Thank you so much, I now have a much better understanding of vectors which is what I could not figure out at all. I really appreciate you taking the time to explain those statements. I am going to implement this now and give it a whirl. My omaha night mod is gonna rock! hehe.

Peace,

G3mInI
Post Reply