Jump to content

Timer problems


blazeda59

Recommended Posts

Can someone please help me with my timer for the life of me I cant get it to work. The disabling of the player and the animations all work fine but only as soon as the player sits in the chair not after a 5 sec delay. Here's my code I've tried several different ways but none work.

 

float fTimer;
short doOnce


BEGIN GameMode

if (player.IsCurrentFurnitureRef seatREF)
		set fTimer to 5
	if ( fTimer == 0 )
   			if ( doOnce == 0 )
			doorREF.PlayGroup Backward 0
			DisablePlayerControls 1 1 1 0 0 1 1
			set doOnce to 1
		else
			set fTimer to fTimer + GetSecondsPassed
	endif
endif
endif

END

Link to comment
Share on other sites

Can someone please help me with my timer for the life of me I cant get it to work. The disabling of the player and the animations all work fine but only as soon as the player sits in the chair not after a 5 sec delay. Here's my code I've tried several different ways but none work.

 

float fTimer;
short doOnce


BEGIN GameMode

if (player.IsCurrentFurnitureRef seatREF)
		set fTimer to 5
	if ( fTimer == 0 )
   			if ( doOnce == 0 )
			doorREF.PlayGroup Backward 0
			DisablePlayerControls 1 1 1 0 0 1 1
			set doOnce to 1
		else
			set fTimer to fTimer + GetSecondsPassed
	endif
endif
endif

END

Could you please try to change this line:

set fTimer to fTimer + GetSecondsPassed

by this one:

set fTimer to fTimer - GetSecondsPassed

Link to comment
Share on other sites

Hi.

 

I am not sure if I understand exactly what you want. I assume it is this: Once the player sits down on seatREF for more than fife seconds you want some of his controls disabled and the door to animate? If he stands up again before the fife seconds are up nothing should happen. Is that it?

 

Then this snippet should do what you want:

 

Short doonce	;set to 1 once the timed event happened
Float fTimer	;timer to count up

Begin GameMode
If doonce == 0							;if the timed event was not yet triggered
	If Player.IsCurrentFurnitureRef seatREF			;if the player is sitting on the seat
		Set fTimer To fTimer + GetSecondsPassed		;increment the timer
		If fTimer >= 5					;if the timer ran for 5 seconds or more
			Set doonce To 1				;prevent the event form happening again
			doorREF.PlayGroup Backward 0		;start the door animation
			DisablePlayerControls 1 1 1 0 0 1 1	;disable some player controls
		EndIf
	Else							;otherwise the player is not sitting on the seat
		Set fTimer To 0					;reset timer to zero
	EndIf
EndIf
End

 

If it isn't, you should maybe explain what you want to happen in a few more words.

 

One word of general advice: If you work with floating point numbers, you should always avoid the == (equal) operator like the plaque and use >= (greater or equal) and <= (less or equal) instead. “fTimer == 0” would only be true if fTimer is really exactly 0 which is usually very unlikely with a floating point number modified by GetSecondsPassed (which is also a small float).

It could be 0.0021 on first pass, which is not == 0 and then -0.0033 on second pass which is also not == 0.

== (equal) and != (not equal) should usually only be used with integer numbers (short, long or int), never float.

 

I hope this helps you. Good luck.

Edited by Tefnacht
Link to comment
Share on other sites

dose anyone know how I would do it?

 

EDIT: nevermind I got it but one other thing I'd like to know is how to set the state of an object with a script not attached to it?

 

Name the reference of the object in the world. You can do this by opening the object in Render window and typing something in the ID area. Also make it persistent, I'm not sure if you need to make it persistent for all cases but do it anyway. Then in any script, simply call <refID>.enable or other commands as normal.

Link to comment
Share on other sites

that doesn't seem to work. this is my setup I have an object thats animating when triggered but unless I change its state from 0 to 1 using "set State to" it keeps triggering the same animation over and over. but I need the player to be able to trigger it again once a second animation plays which is from a second script. My problem is I need to be able to change the state back to 0 from the second script but "wallREF.set State to 0" wont work.
Link to comment
Share on other sites

that doesn't seem to work. this is my setup I have an object thats animating when triggered but unless I change its state from 0 to 1 using "set State to" it keeps triggering the same animation over and over. but I need the player to be able to trigger it again once a second animation plays which is from a second script. My problem is I need to be able to change the state back to 0 from the second script but "wallREF.set State to 0" wont work.

 

.setState to 0. No spaces.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...