Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Troubles making a simple timer


ub3rman123
 Share

Recommended Posts

Scripting has never been my forte, but this scene is somewhat integral.

First: Some exposition. What happens in this scene is when the player passes a triggerbox, the controls are disabled and a sound plays (I'll make the sound later), as well as some enemies with their own Truncheons of Submission. The player stays there for about 8 seconds getting whacked with these clubs until a script timer runs out and the player is warped to another area as though they've gone unconscious. The problem I have is with that 8 second timer.

Okay, the player passes through a triggerbox that sets the stage to 55. The stage 55 has a result script:

set wsmainquest.timersapper to getsecondspassed + 8
Then on the quest script (With some other unrelated bits) is
if getsecondspassed > timersapper && Timersapper != 0

setstage wsmainquest 60

endif

In theory, it should set the stage to 60 after 8 seconds, but it doesn't do anything to indicate that the stage has advanced or the timer has worked.

Link to comment
Share on other sites

Don't put you're timer in the quest script as by default they're only updated every 5 seconds. You could use the script you put on you're trigger zone to handle the timer and both quest advancemants. Off the top of my head something like this should work.


scn MyScriptName

Short Tripped
Float Timer


Begin OnTrigger

If GetActionRef == Player && Tripped == 0
SetStage wsmainquest 55
DisablePlayerControls
Enable.MyBadguyParent
Set Timer to 8
Set Tripped to 1
Endif

End


Begin GameMode

If Tripped == 1
If Timer <= 0
EnablePlayercontrols
SetStage wsmainquest 60
Set Tripped to 2
Player.MoveTo MyXmarker
Endif
Endif

If Timer > 0
Set Timer to Timer - GetSecondsPassed
Endif

End
[/code]

WT

Link to comment
Share on other sites

Is there a benefit to subtracting the getsecondspassed from the timer as opposed to adding them together and waiting for it to be larger?

I noticed a few more bugs. In the original, I accidentally misspelled one of the variables, though it compiled, as well as not including GetActionRef player. Wouldn't using Begin OnTrigger Player remove the necessity of the GetActionRef part?

Link to comment
Share on other sites

1) Is there a benefit to subtracting the getsecondspassed from the timer as opposed to adding them together and waiting for it to be larger?

2) I noticed a few more bugs. In the original, I accidentally misspelled one of the variables, though it compiled,

3) as well as not including GetActionRef player. Wouldn't using Begin OnTrigger Player remove the necessity of the GetActionRef part?

1) Personal preference. I prefer to 'count down' than to 'count up'. That way I can use the same timer for multiple timer checks.

float timer
short myS
begin ontrigger player
set timer to 5
set myS to 1
end
begin gamemode
if myS > 0
if timer >= 0
set timer to timer - GetSecondsPassed
else
if myS == 1
;do stuff part 1
set myS to 2
set timer to 20
elseif myS == 2
;do stuff part 2
set myS to 3
set timer to 10[/code]

etc..

2) as long as its mispelled everywhere, the compiler does not care.

3) Triggers are funny. Sometimes the 'ontrigger player' does not work. So its best to use the GetActionRef to make sure its the player triggering the script.

Link to comment
Share on other sites

Okay, I've combined the scripting so its all on the triggerbox. Here's what I have:

scn WSSapperSquadTriggerSCRIPT


short triggered

ref target

ref mySelf

float timersapper


begin onTrigger player


	if triggered == 0

		set triggered to 1

WSSapperSquad.enable

WSSapperSquad.startcombat player

playsound NPCGOblinAware

setstage wsmainquest 55

set timersapper to getsecondspassed + 8

endif

end

begin gamemode

if getsecondspassed > timersapper && timersapper != 0

setstage wsmainquest 60

player.messagebox "IT WORKED"

endif

endif

end

Still, I don't get the message after 8 seconds. Am I missing something painfully obvious here?

Link to comment
Share on other sites

You can't use GetSecondsPassed that way. It returns "the number of seconds passed since the last frame in which the current script was processed" which in anything but a quest script will always be a fraction of a second. That's why you have to use a float (shorts only hold whole numbers). You setup a timer in the GameMode block so it continuosly adds to or subtracts from your variable. So GetSecondsPassed will never be greater than 8, it will always be somewhere around 0.016 depending on the speed of your PC and what's going on in the scene. If you want to count up for example you'd say

If TimerSapper < 8
Set TimerSapper to TimerSapper + GetSecondsPassed
Else
SetStage WSMainQuest 60
MessageBox "IT WORKED"
Endif[/code]

So on the first pass it will see that TimerSapper is 0, which is less than 8 and add the fraction of a second to it.

On the second pass it will see that TimerSapper is 0.016 (or similar) and add to it again.

It will keep doing this untill TimerSapper is NOT less than 8, then it will process your instructions after the Else.

On a side note that's why you never use == in a timer script, you may jump from 7.99 to 8.02 and never be exactly equal to 8.

WT

Link to comment
Share on other sites

That'd be my problem. I was under the impression GetSecondsPassed worked like GameDaysPassed, where it is the total number of seconds played. Although on reconsideration that seems like a ludicrously large number. I'll try putting in that form of it instead. It also explains why none of my second-based timers worked...

Edit: It works now! Here's the final script. I had to add in a few more variable checks so it doesn't fire off at the wrong time.

scn WSSapperSquadTriggerSCRIPT


short triggered

ref target

ref mySelf

short actiondone

float timersapper


begin onTrigger player


	if triggered == 0

		set triggered to 1

WSSapperSquad.enable

WSSapperSquad.startcombat player

playsound NPCGOblinAware

setstage wsmainquest 55

endif

end

begin gamemode

If TimerSapper < 8 && triggered == 1 && actiondone == 0

    Set TimerSapper to TimerSapper + GetSecondsPassed

Elseif actiondone == 0 && triggered == 1 && timersapper >= 8

    SetStage WSMainQuest 60

    MessageBox "IT WORKED"

set actiondone to 1

Endif

endif

endif

end

Time to set the next scene. I love scripting so much. One typo and it explodes..

Edited by ub3rman123
Link to comment
Share on other sites

Your script has errors. You have way more 'endif' statements than you have 'if' statements. Its a one for one on those.

The variables 'target' and 'mySelf' are not used and can be deleted.

And you really do not need the variable "actiondone" in your script. You can use the already available 'triggered' variable.

Its also recommended to use the TAB key to space out your 'IF/ENDIF' commands.

scn WSSapperSquadTriggerSCRIPT
short triggered
float timersapper

begin onTrigger player
if triggered == 0
set triggered to 1
WSSapperSquad.enable
WSSapperSquad.startcombat player
playsound NPCGOblinAware
setstage wsmainquest 55
endif
end

begin gamemode
If TimerSapper < 8 && triggered == 1
Set TimerSapper to TimerSapper + GetSecondsPassed
Elseif timersapper >= 8 && triggered == 1
SetStage WSMainQuest 60
MessageBox "IT WORKED"
set triggered to 2
Endif
end[/code]

Link to comment
Share on other sites

Works even better, thanks!

Next bit.. I've read that using MoveTo on the player acts as a return. Where do I put it into the result section so it'll cause the least bugging up?

Well, since it does an 'exit' on your script, you should make it the last thing the script needs to do.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...