Trigger multiple and more than 1 player....

Post your scripting questions / solutions here

Moderator: Moderators

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

Trigger multiple and more than 1 player....

Post by G3mInI »

I am tying to do a server side mod which if a player enters the trigger multiple and is there for 30 seconds or more another thread is activated.

trig1_loop:

while(1)
{
$trigger1 waittill trigger
for(local.i=1;local.i<=$player.size;local.i++)
{
$player[local.i] waitthread action $trigger_area1
}
waitframe
}
end



action local.name:


after a 30 second timer operation and player still in trigger is checked

then do this blah blah blah

end


My problem is when the first person enters the trigger all is fine. In 30 seconds the action is performed. However if a second person enters the trigger, the action or the timer does not start until the first persons time is up. etc. etc. How can I set up a trigger multiple so that it can keep track of each player entering and do a 30 second timer on each player depending on when that person entered. I thought the for statement I had would accomplish this but it does not. In the action thread all commands to the player are referred to as self. Example self playsound, self wait, etc. etc. I dont know how to pass the $player[local.i] variable down to the action thread. Everytime I use some debugging, the $player[local.i] variable is always equal to player. I was hoping it would equal player[1] and player[2] and so on and so on.

Anyone ?

G3mInI
Splaetos
Major General
Posts: 730
Joined: Tue Jan 20, 2004 2:55 pm
Contact:

Post by Splaetos »

I could be wrong but....


the loop pick up the local player after its triggered then it send that player into another thread as local.name.... BUT its not a thread, its a waitthread so wont the loop not finish until it finishes what its doing with the first player?

course i could be way off just guessing and my knowledge could certainly be flawed here. I never understood the waitframe command myself, what exactly does it do? hehe ive used it several times based on other scripts.

But I dont see how it would be available to pick up another player while its waiting for one to finish?
When I am king, you will be first against the wall~
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

You know I first set up this trigger just to test with 1 player in mind and then realized more than 1 can be in trigger at same time. I never even looked at the waitthread statement!!! Man I am going to see if that is whats causing this.. and if so... a big DOH! to me, as usual.

G3mInI
Splaetos
Major General
Posts: 730
Joined: Tue Jan 20, 2004 2:55 pm
Contact:

Post by Splaetos »

hope thats all it was...


so out of curiosity... waitframe jsut pauses a loop until its parameter changes right?

like

test:
while level.whatever
waitframe
thread somestufftodo
end

that would hold in the loop till level.whatever becomes untrue and then execute the thread? Just to clarify for my own piece of mind =)
When I am king, you will be first against the wall~
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

My understanding of waitframe is this.

Lets take this thread from boldgers fire a flak script....

Code: Select all

get_ready_to_fire:

local.player = parm.other

while(local.player istouching self)
{
	if(local.player.fireheld == 1)
	{

	local.shot_org = local.player thread find_spot

	self.target waitthread fire_cannon local.shot_org

	local.shot_org immediateremove

	wait 2

	}

waitframe

}

end
First statement sets the local player to parm.other

Next is the while loop. Which will repeat over and over as long as the player is touching self, which in this case would be the flak trigger.

Now it checks to see if the player is holding the use key. If not then it will skip all the statements in the brackets under the If statement. And the next line the while loop reads is waitframe. That will make the game wait 1 frame before starting this loop over again to check if the player (while standing in the trigger) is holding the fire button. 1 frame of mohaa is real fast, something like .02 seconds or so Im not sure. If that waitframe statement was not there then this loop would repeat as fast as code can be executed which is REAL FAST and would cause and Infinite loop or Buffer Overflow error and the script would crash. The idea behind the waitframe command is make a looping thread wait at least 1 frame before continuing onto the next loop.

You will see in scripts made by the developers that a lot of times they used wait .1 instead of waitframe which in my opinion basically accomplishes the same thing, it keeps the while loop from crashing.

That is my understanding of waitframe.

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

Post by bdbodger »

Instead of trigger waittill trigger you need to use the setthread key on the trigger . What setthread does is start a new thread everytime the trigger is triggered . For every new thread that is run parm.other will not be the same and for example if 3 players trigger the trigger then there will be 3 copies of the same thread running at the same time and in each parm.other will be the player who triggered the trigger . You may actually want to also set a variable so that the trigger does not fire for the same player more than once while that player is touching the trigger like this

Make a trigger with key: setthread value:trigger_thread

trigger_thread:

local.player = parm.other

if(local.player.intrigger != 1) // != not equall( if statement starts here)
{

local.player.intrigger = 1
local.timmer = 0

while(local.player istouching self && local.timmer < 30) // self being the trigger in this case
{
wait 1
local.timmer++
}

local.player.intrigger = 0 // reset the variable

if(local.timmer == 30) // if the timmer reached 30
{
local.player thread myother_thread
}

/* self in new thread will be player or use thread myother_thread local.player then in the other thread do : myother_thread local.player: put local.player after the name of the new thread and before the : so that local.player mean the same in the new thread
*/

} // if(local.player.intrigger != 1) ends here

end
Image
Splaetos
Major General
Posts: 730
Joined: Tue Jan 20, 2004 2:55 pm
Contact:

Post by Splaetos »

thats basicaly what I thought at first, cept I got all muddled while typing it. I had no clue how long a frame was though =)

I get all confuseded in me head in the wee hours of the morning.
When I am king, you will be first against the wall~
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

Ahh bodger thanks very much. I never knew that setthread would run mulitple copies of same thread. Man you just simplified my 50 lines of script down to 20 or so.... :) and sorry for misspelling your name up there in previous post :oops:

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

Post by G3mInI »

OK I am just totally stuck now. What I am trying to do is anti camper type mod. I have taken parts from Elgan's anti camper script and tried to incorporate it into a server side mod Im doing. In Elgans script he had an anticamper bomb plant on anyone who camped for 30 seconds or more. What I want to do is make specific areas that if people are camping for 30 seconds or more then they get hurt (10 health at a time). This is for Remagen on the beam area inside the axis schoolhouse. I am having a major problem. If the person camping gets shot while the bomb is ticking then when they go into spectate they still hear the tick sound until the round ends. And with bolgers advice previously in this thread I think I have now really messed up my script. Here is what I have as it is now... can one of ya's help me make this work? I would like to set up other triggers too in this map which I/we consider campsites. So I need this code to work for multiple triggers throughout the map and for multiple players in the trigger at same time... THANKS for any help I may receive....

Code: Select all

camper_setups:
	local.trig1 = spawn trigger_multiple origin ( 4636.00 -3256.00 232.00 )
	local.trig1 setsize ( -140.00 -320.00 -0.00 ) ( 140.00 320.00 176.00 )
	local.trig1.targetname = schoolhouse_beam_trigger
	local.trig1 triggerable
	
	
end
	
	
camper_trig_loop:
	
	while(1)
	{
	$schoolhouse_beam_trigger waittill trigger
	for(local.i=1;local.i<=$player.size;local.i++)
		{
		$player[local.i] thread camper_triggers $schoolhouse_beam_trigger
		}
	waitframe
	}	
end	
	
camper_triggers local.name:

	local.camper_silent = 0
	local.camper_box = local.trig_size
	local.camper_time = 30
	local.camper_ticktime = 10

	if(self.trigger!=1)
	{
		self.trigger=1
	}
	else
	{
		end
	}
	
	local.camper_time = int local.camper_time

	for(local.timer=0;local.timer<local.camper_time;local.timer++)
		{
		if!(self isTouching local.name)
			{	
			self.trigger=0
			end
			}
		wait 1
		}

	self.trigger=0

	local.mine = spawn script_model 
	local.mine model "items/explosive.tik"
	local.mine.origin = ( self gettagposition "Bip01 R Forearm")//local.player.origin//
	local.mine notsolid

	self iprintln "You Were Camping And That Will Cost You 10 Health!"

	local.mine attach self "Bip01 R Forearm" 
	
	local.camper_ticktime  = int local.camper_ticktime 

	self stopwatch local.camper_ticktime 

	local.camper_silent  = int local.camper_silent 
	
	if(local.camper_silent==0)
	{
		self loopsound bombtick1
	}

	local.timer=0
	while(Isalive self)
		{
		wait 1
		local.timer++
			if(local.timer == local.camper_ticktime)
				{
				self stoploopsound bombtick1
				local.Exp2 = spawn "animate/fx_explosion_mine.tik"
				local.Exp2.origin = local.mine.origin
				local.Exp2 anim start
				radiusdamage local.mine.origin 10 5
				local.mine remove 
				wait 1
				local.Exp2 remove
				self.trigger=0
				if(self.dmteam == "spectator")
					{
					self stoploopsound bombtick1
					local.mine remove
					self.trigger=0
					}	
				break
				}
		}
		
end


That is how it is now...and I know it is terrible but I am trying :?

Oh and btw no message prints either and have no idea why.

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

Post by bdbodger »

If you are going to have more than 1 trigger then maybe do it this way have the triggers start the same thread . Who is bolger ?

Code: Select all

camper_setups:
   local.trig1 = spawn trigger_multiple origin ( 4636.00 -3256.00 232.00 )
   local.trig1 setsize ( -140.00 -320.00 -0.00 ) ( 140.00 320.00 176.00 )
   local.trig1.targetname = schoolhouse_beam_trigger
   local.trig1 thread camper_trig_loop
   
   
end
   
   
camper_trig_loop:
   
	while(1)
	{
	 self waittill trigger // thread waits here so you don't need a waitframe

	local.player = parm.other // the guy who triggered the trigger

	local.player thread camper_triggers self // self becomes local.trigger in the next thread and local.player becomes self

	}   
end   
   
camper_triggers local.trigger:

	local.camper_silent = 0
	local.camper_time = 30
	local.camper_ticktime = 10

	if(self.trigger!=1)
	{
		self.trigger=1
	}
	else
	{
		end
	}
   

	for(local.timer=0;local.timer<local.camper_time;local.timer++)
	{
		if!(self istouching local.trigger)
		{   
		self.trigger = 0
		end
		}
	wait 1

	}

	local.mine = spawn script_model model "items/explosive.tik" spawnflags 1 // spawnflags 1 = notsolid

	local.mine.origin = ( self gettagposition "Bip01 R Forearm")

	self iprint "You Were Camping And That Will Cost You 10 Health!"

	local.mine attach self "Bip01 R Forearm"
   
	self stopwatch local.camper_ticktime
   
	if(local.camper_silent==0) // don't know the reason for this maybe make it a key on the trigger??
	{
	self loopsound bombtick1
	}

	local.team = self.dmteam // maybe use this to test for player going to spectator or changeing teams

	local.timer = 0

	while(self.team == local.team && self.health > 0 )
	{
	wait 1
	local.timer++

	if(local.timer == local.camper_ticktime)
	{
		local.Exp2 = spawn "animate/fx_explosion_mine.tik"
		local.Exp2.origin = local.mine.origin
		local.Exp2 anim start
		radiusdamage local.mine.origin 10 5

		wait 1
		local.Exp2 remove
		break
	}
	}
		self stopwatch 0
		self.trigger = 0
		local.mine remove
		self stoploopsound
      
end
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

LMAO>.. I just cant get your name right !!! ... Thanks for the advice here... I am going to study this and make it work. Thanks again.

bdbodger
bdbodger
bdbodger
bdbodger
bdbodger
bdbodger

:D 8-)


There! according to a Harvard University study done in 1982 they determined that if you repeat something six times in your mind you will most likely never forget it. Let's see if they were right !


Peace,

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

Post by G3mInI »

Worked just as I wanted it to bdbodger ! I did have to change one thing though,

Code: Select all

while(self.team == local.team && self.health > 0 )
Had to be,

Code: Select all

while(self.dmteam == local.team && self.health > 0 )
When I did some debugging to see why the stopwatch was not displaying it kept returning self.team = american and local.team = axis or ally depending

so when I changed it to self.dmteam all was good. They both equalled the same, and if a person went to spectate or changed teams the script broke as it is suppose to and the loopsound and stopwatch both left the players screen..... THANK YOU VERY MUCH!!!!!! It was exactly what I was looking for.

I say we all give bdbodger an "attaboy" and a high five! For all his time and effort he brings to this community...

Peace,

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

Post by bdbodger »

oops yes dmteam is what I ment to put there glad you where able to spot that I guess that proves you are not just a cut and paste scripter :)
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

Nope.. although I do cut and paste to my text editor. From there though I study study study. I am determined to teach myself scripting. Very close it seems to C++. I am also about to begin a course in C++ at my local college here, along with a Securities Certificate course and A+ Certification course. I am determined to get a job in the computer field, would love to be part of a team developing games, but that is just a dream. It's about time I do something like this anyhow, at age 38 I'm tired of the low paying jobs which I can't seem to stay at for more than a year or 2. I am all about computers, my dad was a programmer and we have had a pc in the home since '79 (actually not a pc back then :) ).

Thanks again for the info, someday I hope to be as good as you or jv or bjarne even tltrude..... someday.

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

Post by bdbodger »

Well if you do well you will probably be a lot better than us . Well maybe not better than JV he is a natural .
Image
Post Reply