Trigger use, for only axis...

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Trigger use, for only axis...

Post by chrisjbooth2001 »

how would i make a trigger use, so only axis could use it?

So far ive got this...

//------------------------------------------
axis_switch:
//------------------------------------------

$axis1 thread axisdoor

Jvmap told me this but i dunno how to incorporate it to the scripts...

if(parm.other.dmteam == axis)
dcoshea
Colour Sergeant
Posts: 94
Joined: Thu Mar 04, 2004 3:00 am
Location: Sydney, Australia
Contact:

Re: Trigger use, for only axis...

Post by dcoshea »

chrisjbooth2001 wrote:how would i make a trigger use, so only axis could use it?

So far ive got this...

//------------------------------------------
axis_switch:
//------------------------------------------

$axis1 thread axisdoor

Jvmap told me this but i dunno how to incorporate it to the scripts...

if(parm.other.dmteam == axis)
I assume the trigger_use has its 'setthread' property set to 'axis_switch' so that 'axis_switch' is called/executed when the trigger is USEd?

Anyway, assuming axis_switch is being called somehow, this will make it only call axisdoor when it's an Axis player who hit the "switch":

Code: Select all

//------------------------------------------
axis_switch:
//------------------------------------------
	if (parm.other.dmteam == "axis") {
		$axis1 thread axisdoor
	}
end
It of course is checking if parm.other (the Player who triggered the trigger) belongs to the Axis team, and only if they do is it calling the axisdoor thread.

Regards,
David
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Post by chrisjbooth2001 »

now if i didnt have the setthread, how would i do it?
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

chrisjbooth2001 wrote:now if i didnt have the setthread, how would i do it?
Add the setthread :P
Image
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Post by chrisjbooth2001 »

If i couldnt add one because i only had the bsp?
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Then add one by script :)
Image
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Post by chrisjbooth2001 »

I love the little comments lol,

How?
dcoshea
Colour Sergeant
Posts: 94
Joined: Thu Mar 04, 2004 3:00 am
Location: Sydney, Australia
Contact:

Post by dcoshea »

chrisjbooth2001 wrote:I love the little comments lol,

How?
Assuming the trigger's targetname is "bob", you'd use:

Code: Select all

$bob setthread axis_switch
When you use 'setthread', it's pretty much like doing this:

Code: Select all

$bob thread my_fake_setthread

my_fake_setthread:
	while (1) { // loop forever
		self waittill trigger // wait until the trigger is triggered
		self thread axis_switch // call the thread
	}
end
That's what 'setthread' does - call your thread when the trigger is triggered. The difference is that 'setthread' only allows one thread to be specified whereas with the 'my_fake_setthread' you could call a bunch of threads. Of course, the thread that 'setthread' calls could just call a bunch of threads itself.

Instead of using 'setthread', you could just use 'waittill trigger' in your code if you like.

Regards,
David
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Post by chrisjbooth2001 »

Thanks ill try it! :)
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Post by chrisjbooth2001 »

Ok, if i use the setthread method.. How would i make it so you trigger the thread, and once the thread finishes it allows ya to reuse it..

I think the command is waitthread ?
dcoshea
Colour Sergeant
Posts: 94
Joined: Thu Mar 04, 2004 3:00 am
Location: Sydney, Australia
Contact:

Post by dcoshea »

chrisjbooth2001 wrote:Ok, if i use the setthread method.. How would i make it so you trigger the thread, and once the thread finishes it allows ya to reuse it..

I think the command is waitthread ?
If you were using the "this is how setthread works" code I posted:

Code: Select all

$bob thread my_fake_setthread

my_fake_setthread:
   while (1) { // loop forever
      self waittill trigger // wait until the trigger is triggered
      self thread axis_switch // call the thread
   }
end
you could change 'thread' to 'waitthread' to prevent axis_switch from being called concurrently, i.e. it won't be called a second time until the first time has finished.

However, you asked about doing this with 'setthread'. 'waitthread' won't help you directly, although in your case since the axis_switch thread calls the axisdoor thread, it will be needed. The game will call the thread that 'setthread' points to every time the trigger is triggered (as far as I know), and it's up to you to prevent concurrent calls if you don't want them. Try something like this:

Code: Select all

axis_switch:
	if (level.axis_switch_thread_active) {
		// we are already running this thread, don't run it again
		end
	}
	level.axis_switch_thread_active = 1

	// call using waitthread instead of thread so that we know when it's done
	$axis1 waitthread] axisdoor

	// axisdoor is done, so we're done, and we can set the flag indicating we're active back to 0, allowing this thread to execute again
	level.axis_switch_thread_active = 0
end
[Edit: got rid of ignored bold tags]

Of course, if you think about it, if two copies of that thread were called simultaneously and executed in a truly parallel fashion, they could both check level.axis_switch_thread_active at the same time, both see it's not set, then both set it simultaneously, thus both running 'axisdoor' at the same time, but I don't believe the game really runs threads with that level of concurrency - I think it will only run another thread when the thread it is currently running gets to a 'wait' statement.

I'm thinking co-operative/non-pre-emptive multi-tasking, in case there's anyone who knows exactly what I'm thinking and happens to know that I'm wrong :)

Regards,
David
chrisjbooth2001
Colour Sergeant
Posts: 77
Joined: Thu Dec 18, 2003 12:57 am

Post by chrisjbooth2001 »

I will take a look at this thx
Post Reply