if $trigger: show - else hide ?

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

if $trigger: show - else hide ?

Post by Kalti »

Well then, let me be the honest n00b for today...

I want to detect if there's a player in the room, so I've placed a trigger_multiple $room_occupied

If there is a player detected in the room I want to 'show' a certain element but if there isn't a player detected I want that element to 'hide'.

Anyways, I don't have the understanding to this all by myself so let me show you the mess I came up with... It is based on my lift script.

Code: Select all

//*** Room  ***
occupied_prep:
	level.occupied=0 // 0 is  not occupied, 1 is occupied
end

room_occupied:
   $room_occupied nottriggerable
   if (level.occupied==1)
   {
      $object show
      level.occupied=1
   }
   else
   {
      $object hide
      level.occupied=0
   }
   $room_occupied triggerable
end

//*** END - Room  ***
Obviously the above doesn't work and more obviously I don't seem to have any clue what I'm doing so please guys, treat me kindly and help me out here :D
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

This thread is launched by setthread, right? Well, I'd do it like this:

Code: Select all

room_occupied:
   self nottriggerable
   $object show
   local.occupied = 1
   while (local.occupied)
   {
      for (local.i = 1; local.i <= $player.size; local.i++)
      {
         if ($player[local.i] isTouching $room_occupied)
            break
         local.occupied = 0
         $object hide
      }
      waitframe
   }
   self triggerable
end
What this will do is to check for players touching the trigger (will also affect spectators). The for loop will break upon the first player touching it, therefore it won't reach the local.occupied = 0 part. But if there are no players touching it, it will set local.occupied to 0. Simple. ;)
Last edited by Rookie One.pl on Fri Jun 03, 2005 5:08 am, edited 1 time in total.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

Thank you...

Ehrm... setthread ?

And it shouldn't act on spectators if at all possible

I had a simple script working to the point where the object was 'hidden' and then got shown when a player was detected in the room... only problem was it remained shown after the player had left the room/trigger while no other players where present.
Image
User avatar
Axion
Major General
Posts: 683
Joined: Mon Sep 29, 2003 5:14 am
Location: Northern California
Contact:

Post by Axion »

With your original method, you would need two triggers- one inside the room and one outside. When you touch the inside trigger, the object would show, and when you touched the outside trigger, the object would hide. The problem with that is that if someone touches the outside trigger while someone is already in the room, the object would suddenly disappear.

Go with Rookie's method.
"The work of a thousand years is nothing but rubble."
- Dr. Carl Goerdeler (1943)
Visit my mapping site: http://www.freewebs.com/axion9
Image
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

Thanks guys...

It isn't worth the effort when it will also act on spectators, plain and simple.

I have thought of doing it with an entrance and exit trigger but soon came to the conclusion that it would cause problems with the more then one player.

Unless... I shouldn't allow more then one player at a time in the room... hmm
Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

Kalti wrote:Ehrm... setthread ?
Your trigger_multiple will have to have a key/value of setthread/room_occupied. This way the trigger, when touched, will execute the thread.

@Rookie One: U're sure, this would affect spectators?! The trigger_multiple would execute the thread when touched by a specator?
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

It should affect spectators, too.

But, look here. Imagine you were a spectator and flew into that room. A player enters the room and the object suddenly appears. He leaves and the object disappears. That'd be weird, huh? Anyway, this one will also check if the players are alive and not spectating:

Code: Select all

room_occupied:
   self nottriggerable
   $object show
   local.occupied = 1
   while (local.occupied)
   {
      for (local.i = 1; local.i <= $player.size; local.i++)
      {
         if (isAlive($player[local.i]) && $player[local.i].dmteam != spectator)
         {
            if ($player[local.i] isTouching $room_occupied)
               break
         }
         local.occupied = 0
         $object hide
      }
      waitframe
   }
   self triggerable
end
I've also arrived upon the conclusion that setting local.occupied to 1 before breaking the loop is quite pointless (it's already 1 since it hasn't been changed yet) so I omitted it here. ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

Wow... thanks all

And I can call that thread by thread room_occupied ?
Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

Rookie One.pl {sfx} wrote:It should affect spectators, too.
But, look here. Imagine you were a spectator and flew into that room. A player enters the room and the object suddenly appears. He leaves and the object disappears. That'd be weird, huh?
So, what u mean is, that a spectator would see the object show and hide when a player enters or leaves the room. But he wouldn't trigger the trigger_multiple himself. That's what I ment :wink:
And yes, Kalti. Ur trigger_multiple will need key/value: targetname/room_occupied (for Rookie's script, line 11) and setthread/room_occupied (to call this thread).
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

And is it possible to add more $objects then just the one ?

Like this ?

Code: Select all

room_occupied:
   self nottriggerable
   $object show
   $object1 show
   $object2 show
   local.occupied = 1
   while (local.occupied)
   {
      for (local.i = 1; local.i <= $player.size; local.i++)
      {
         if (isAlive($player[local.i]) && $player[local.i].dmteam != spectator)
         {
            if ($player[local.i] isTouching $room_occupied)
               break
         }
         local.occupied = 0
         $object hide
         $object1 hide
         $object2 hide
      }
      waitframe
   }
   self triggerable
end
and.. ehrm... it will still do the 'hide' thing even when a spectator is present ?
Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

Kalti wrote:And is it possible to add more $objects then just the one ?
and.. ehrm... it will still do the 'hide' thing even when a spectator is present ?
Yes and yes.
the if clause if (isAlive($player[local.i]) && $player[local.i].dmteam != spectator) is just true for an alive and not spectating player, so it wouldn't bother whether that player is touching the trigger, therefore wouldn't 'break', would set local.occupied to 0 and hide the objects.

Only thing bout ur script is, that u will still need the thread to hide the objec(s) at gamestart like

Code: Select all

occupied_prep:
$object hide
//and others if there were
end
which would have to be called by the main thread, but u surely know this :wink:
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

Thanks and thanks :D

Very kind all !

Will try it in a few hours from now :wink:
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Oops... Once again I was wrong... :oops: Local.occupied = 1 is necessary!

Code: Select all

room_occupied:
   self nottriggerable
   $object show
   $object1 show
   $object2 show
   local.occupied = 1
   while (local.occupied)
   {
      for (local.i = 1; local.i <= $player.size; local.i++)
      {
         if (isAlive($player[local.i]) && $player[local.i].dmteam != spectator)
         {
            if ($player[local.i] isTouching $room_occupied)
            {
               local.occupied = 0
               break
            }
         }
         local.occupied = 0
         $object hide
         $object1 hide
         $object2 hide
      }
      waitframe
   }
   self triggerable
end
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

Wacko galantly handed me an example map which I used to get it all implemented in my own map... thank you !

Showing you the working script:

Code: Select all

main:

//*** Scoreboard Messages And Image
setcvar "g_obj_alliedtext1" "" 
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" "" 
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" ""
setcvar "g_scoreboardpic" "none"

local.master = spawn ScriptMaster

//local.master aliascache [aliasname] [soundfile] soundparms [basevolume] [randvolume] [basepitch] [randpitch] [mindist] [maxdist] [channel] loaded maps "obj dm"

	// call additional stuff for playing this map round based is needed
	if(level.roundbased)
		thread roundbasedthread

	level waittill prespawn

//*** Precache Dm Stuff
	//exec maps/dm/yourmapnamehere_precache.scr

	exec global/door_locked.scr::lock
	level.script = maps/dm/creditroom.scr
	//exec global/weather.scr
	//exec global/shutter.scr

	level waittill spawn
	//$room_occupied thread room_occupied
	$speaker_room stopsound snd_room
	$$object hide
	$object1 hide
	$object2 hide

end

//*** Room ***
room_occupied:
   self nottriggerable
   $speaker_room loopsound snd_room
   $object show
   $object1 show
   $object2 show
   local.occupied = 1
   while (local.occupied)
   {
      for (local.i = 1; local.i <= $player.size; local.i++)
      {
         if (isAlive($player[local.i]) && $player[local.i].dmteam != spectator)
         {
            if ($player[local.i] isTouching $room_occupied)
               break
            }
         local.occupied = 0
         $speaker_room stopsound snd_room
	 $object hide
	 $object1 hide
	 $object2 hide
      }
      waitframe
   }
   self triggerable
end

//-----------------------------------------------------------------------------

roundbasedthread:

	// Can specify different scoreboard messages for round based games here.

	level waitTill prespawn

	level waittill spawn

	// set the parameters for this round based match
	level.dmrespawning = 0 // 1 or 0
	level.dmroundlimit = 5 // round time limit in minutes
	level.clockside = kills // set to axis, allies, kills, or draw

	level waittill roundstart

end
Now, 2 questions...

#1. Why does it work with //$room_occupied thread room_occupied commented out ?

#2. And I have placed:

Code: Select all

//$room_occupied thread room_occupied
$speaker_room stopsound snd_room
$$object hide
$object1 hide
$object2 hide
...below "level waittill spawn" is that correct or am I just lucky ?

*EDIT: I know I have not yet placed a sound alias :wink:
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Ad. 1. Because it's setthreaded.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply