Script problem....


(Flippy) #1

hey all

ive got a problem with my map / script…

i have this door/energyfield, moving up and down by a button, which is a script_mover
(it works)

i also have a generator (simulated by a button at the moment)

when the generator is blown up (press button) i want the door to dissapear (“remove”)
this works too…

but now, when i press the button again (generator constrcuted again) i want the door to come back alive, and this is where the problem starts…

it comes with an error “G_scripting: alertentity, targetname cannot be found: door_1” (or something like that, it says it cant find the targetname “door_1”

my script is like this:


gen1   // The button which simulates the generator
{
	spawn
	{
		globalaccum 0 set 1		//0 = Gen destr, 1 = Gen constr        
		accum 2 set 1
		wait 500
		trigger gen1 main
	}
	trigger main
	{
		trigger gen1 on
		trigger gen1 off
	}
	trigger on
	{	
		accum 2 abort_if_not_equal 1
		resetscript
		wm_announce "The Main Generator has been constructed, Energy Field on."
		trigger door_1 revive
		globalaccum 0 set 1
		accum 2 set 0
	}
	trigger off
	{
		accum 2 abort_if_not_equal 0
		resetscript
		wm_announce "The Main Generator has been destroyed, Energy Field off."
		trigger door_1 kill
		globalaccum 0 set 0
		accum 2 set 1
	}
}

door_1
{
	spawn
	{
	}

	trigger open
	{
		wait 500
		gotomarker door_pos2 35 wait
	}

	trigger close
	{
		wait 500
		gotomarker door_pos1 35 wait
	}
	
	trigger kill
	{
		wait 20
		remove
	}
	
	trigger revive
	{
		wait 20
		alertentity door_1
	}
}

The “trigger open” and “trigger close” commands are triggered from the door1_trigger (another button), but because the moving works i didnt see any reason to put them in…

The entity:


// entity 23
{
"health" "0"
"target" "door_1"
"scriptname" "door_1"
"targetname" "door_1"
"spawnflags" "10"
"classname" "script_mover"

Insert a couple of brushes here...
}

And the error again, it cant find “targetname - door_1”
and the script_mover has a targetname of door_1… so i dont get it :???:


(]UBC[ McNite) #2

afaik the command “remove” really removes the scriptblock.
If you want something to disappear and re-appear, you should use “setstate puttargetnamehere invisible” and “setstate puttargetnamehere default”.
Here is an example of how to use setstate:

bellropeinfo 
{
	spawn
	{
		wait 400
		setstate bellropeinfo default // makes it appear right from the start
	}
	trigger on
	{
		setstate bellropeinfo default // you get it back with this
	}
	trigger off
	{
		setstate bellropeinfo invisible // makes it disappear
	}
}

(Flippy) #3

yeah i know… but the reason im using remove and alertentity is because the setstate command will not work when the door is moving…
i posted this a while back and i got asked to use remove and alertentity…

setstate works pefectly, as long as the script_mover is not moving while the setstate command is issued… this is a major problem now, because when the generator gets destroyed when somebody just pressed the button to move the script_mover it does not go away and stays on, making the generator useless…

(it doesnt go away even after it stopped moving, the setstate command seems to be totally ignored when the script_mover is moving…)

so is there really no way to do it? :???:


(psyco_mario) #4

Could you have it so when its moving, keep calling the setstate command? so when it stops it goes? … im not sure myself, sorry


(]UBC[ McNite) #5

Well you could work around this but it needs a bit of scripting. Since remove is not a solution, you need the setstates.

The idea is: delay the setstate command while the door is moving with an accum. Also make sure nobody can keep pressing the button all the time, to make sure there will be a timegap after the moving in which the setstate can take effect. I think you only need to change the door_1 block for this:

door_1
{
   spawn
   {
	wait 200
	accum 1 set 0 // door is not moving
   }

   trigger open
   {
	accum 1 set 1 // door is moving
      wait 500
      gotomarker door_pos2 35 wait
	wait 50
	accum 1 set 0 // door finished moving
   }

   trigger close
   {
	accum 1 set 1 // door is moving
      wait 500
      gotomarker door_pos1 35 wait
	wait 50
	accum 1 set 0 // door finished moving
   }

	trigger kill // fires both setstate scripts
	{
		accum 1 abort_if_equal 2 // 
		// I d keep the button working, with sound too, only there s just no door when its destroyed
		trigger door_1 killnotmoving
		trigger door_1 killmoving
	}
   
   trigger killnotmoving
   {
	accum 1 abort_if_not_equal 0 // only works when door is not moving
	accum 1 set 2 // door is destroyed
	setstate door_1 invisible
	wait 50 // works like resetscript
   }

   trigger killmoving
   {
	accum 1 abort_if_not_equal 1 // only works when door is moving
	wait 700 // needed waittime: as long as the moving takes = 500+50+35 a bit
	// the idea is: make sure the setstate executes after finishing the moving
	accum 2 set 2 // door is destroyed
	setstate door_1 invisible
	wait 50 // works like resetscript
   }
   
   trigger revive
   {
      wait 20
      //alertentity door_1
	setstate door_1 default
	accum 2 set 0 // door is rebuilt, not moving
   }
}

For the button, which probably gets started with a trigger_multiple or something similiar. In there you need a delay or wait of about 1-2 secs, so a user can’t fire the movement continuously. Make the wait/delay a little bit longer than the sound the button makes.

This should work, only it could look odd when the door disappears about 0.5 secs after the actual explosion…

Edit: Just an idea… why does the door disappear when the generator has been blown up? I d rather have it go open then, and stay open, until the generator is repaired again. I don’t see the connection between a destroyed generator and a disappearing door.


(Flippy) #6

hey thxn for that :smiley:
but could you tell me if you used a new accum value in your modified version so i can change it again if i had this number already (avoiding duplicate accum values)

and the button is simply a func_button, and has a delay time of 5 seconds already

and the door dissapears when gen is destroyed because it is an energyfield, not really a door (but its called door in the scrtip i used from a tut so i called it door)
the energyfield needs power ofcourse, and destroying the generator stops the power which disables the energyfield

(think of the fields in starwars where obi wan does the “NOOOOOOOOOOOOOOOOO!!” :smiley: )


(]UBC[ McNite) #7

Check the thread on max accums for that. If i understand it right, you can use accum 1 in every scriptblock again. Only the globalaccums need different numbers.


(Flippy) #8

Heh, i was just wondering if that was possible :smiley: you answered it without me even asking :clap:

so, i can use any accum number up to 7 per 1 scriptblock…
so:


scriptblock1
{
spawn
{
accum 1 set 1
}
}

scriptblock 2
{
spawn
{
accum 1 set 0
}
}

The 2 scriptblocks will NOT interfere having the same accum values?

thats cool :clap:
I will try your code now… will post if it works in a minute


(Flippy) #9

OK, same problem i guess… but thanks anyway cos half of it is working now :slight_smile:

Everything works like it should, EXCEPT the “door” (energyfield) dissappearing!

the field can NOT be moved anymore after the generator is broken but its still there!
so the only problem is the setstate command not working; i get this error when the generator is destroyed/repaired:

Warning: setstate called and no entities found

I guess this is basically the same problem as we started with… BUT its working in the way that it cannot move anymore after the generator is destroyed! so thnx for that :slight_smile:


(BigBadWolf) #10

maybe try something like this

I dont know if this would work, but it might because the gen1 will always remain in the script eaven if door_1 is removed. So im thinking if you throw the alertentity part inside gen1, and removing the trigger revive block out of door_1 entirley, it may work. But again im not for sure.

gen1   // The button which simulates the generator 
{ 
   spawn 
   { 
      globalaccum 0 set 1      //0 = Gen destr, 1 = Gen constr        
      accum 2 set 1 
      wait 500 
      trigger gen1 main 
   } 
   trigger main 
   { 
      trigger gen1 on 
      trigger gen1 off 
   } 
   trigger on 
   {    
      accum 2 abort_if_not_equal 1 
      resetscript 
      wm_announce "The Main Generator has been constructed, Energy Field on." 

      // Adding the wait and alertentity here instead of calling it in another scriptblock
      wait 20
      alertentity door_1
      globalaccum 0 set 1 
      accum 2 set 0 
   } 
   trigger off 
   { 
      accum 2 abort_if_not_equal 0 
      resetscript 
      wm_announce "The Main Generator has been destroyed, Energy Field off." 
      trigger door_1 kill 
      globalaccum 0 set 0 
      accum 2 set 1 
   } 
} 

door_1 
{ 
   spawn 
   { 
   } 

   trigger open 
   { 
      wait 500 
      gotomarker door_pos2 35 wait 
   } 

   trigger close 
   { 
      wait 500 
      gotomarker door_pos1 35 wait 
   } 
    
   trigger kill 
   { 
      wait 20 
      remove 
   } 
   
   // Removing this block of code
   //trigger revive 
   //{ 
   //   wait 20 
   //   alertentity door_1 
   //} 
} 


(Flippy) #11

Hey,

thnx for trying to help :slight_smile: I thought your code should work! but when i tried it it gives me the same error as in the original first post… :bored:

When i kill the “door” it goes away and doesnt move anymore…
when i press the button (gen_1) again the game freezes and goes back to the main menu with this error:

G_Scripting: alertentity cannot find targetname: “door_1”

WTF?!


(Flippy) #12

Ok… i made a little test map with EXACTLY the same things in it (except the door cannot move in this one)

the error is in this map too…

i uploaded it so if anyone would be so kind to take a look at it and tell me what STUPID mistake i made? :moo:

Alertentitytest.rar

http://www.fragland.org/nick/alertentitytest.rar
RAR-file (inside is pk3)
5.72 kb

Thnx in advance :slight_smile:


(BigBadWolf) #13

An easier way to do this instead of removing and trying to make it reappear through the script is to just use another path_corner thats in the void (unseeable) and tell it to go to that path corner at a speed of like 9000. Shouldn’t eaven be able to tell a difference than if it was removed.


(Flippy) #14

Hey thnx!
I tried it like this before but i couldnt get it working with the accums… but now i tried it again and it works now :smiley:

tho i dont make another path_corner, i just make it go to the same, but faster…
thnx alot, its working correctly now :clap: