Scripts / How to use Timing?

Author
Message
shakyshawn8151
10
Years of Service
User Offline
Joined: 9th Nov 2013
Location: United States
Posted: 13th Jan 2015 00:48
I got a small script here, a few bits I did not add in, as I wanted to try to figure out how the timing worked, but I could not figure out, can someone explain it?


As you can see I am trying to start the timer, but the player wont be able to get the item to spawn until the timer number is reached, but I cannot figure it out.

CPU; Intel G850 2.9ghz GPU: Raedon HD 7750 1gb 4GB Ram

Windows 10 1TB HD 60GB HD
Gtox
3D Media Maker
9
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 13th Jan 2015 05:20
You should add Prompt(GetTimer(e)), so you can see what the timer is doing. Do you get the "xxxx Production Started" prompt?
Go Devils
11
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Phoenix Arizona USA
Posted: 13th Jan 2015 07:35
OK, seems to be a few issues here.
I'm not an expert in this but here is a modified code that may work




OK, First there is an issue with the placement of your "end" commands. Since there are some if/then statements that you only wish to operate once
so the placement of the end commands is important..
Second, I've used a different timer system establishing spawntimer1 and spawntimer2 as variables that will be used to control the timing of the spawn
In order to do this and limit the number of spawns you really need two timers.
Also, because the built-in timer functions in double precision, sometimes there's a problem with hitting a specific integer value.
Also, you only want the spawn function to happen one time (I assume) so spawntimer2 is used to trigger the spawn command just that one time when spawntimer2 equals 5.

Not sure about the final PromptDuration command ????

No guarantee, but this should work. (famous last words)
Good Luck

There is no Spoon...
tomjscott
User Banned
Posted: 13th Jan 2015 18:14
One thing to note is that it's a millisecond timer. So, if you're trying to do something for 5 seconds then your check needs to be for 5000, not 5. That might be the thing you are really not getting at this point.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
shakyshawn8151
10
Years of Service
User Offline
Joined: 9th Nov 2013
Location: United States
Posted: 13th Jan 2015 18:23
@tomjscott Alright, I never had a need before to use the timer function so I never put much thought into it, or learned anything about it, I have now come to realize how important a timer would be in advanced scripts.

CPU; Intel
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jan 2015 18:27
dont use starttimer(e) at all, it's pointless and causes lots of weird results - just offset your initial delay by gettimer(e) when you first call it.
also as go devils says you need to make sure your end statements are in the correct place - right now you are stuck with having to press e which also "starts" the timer and also checking that time against the delay while still pressing e... obviously this will never happen as the timer is always "starting"
and finally as tom said, timer is in milliseconds



life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
shakyshawn8151
10
Years of Service
User Offline
Joined: 9th Nov 2013
Location: United States
Posted: 13th Jan 2015 18:53
@smallg I tried the script out and got an error on line 5, attempt to compare a function with a number. Not sure why it is saying there is an error on line 5... There is no error there??

CPU; Intel G850 2.9ghz GPU: Raedon HD 7
tomjscott
User Banned
Posted: 13th Jan 2015 18:59
In smallg's script, GetPlayerDistance is supposed to be a distance function check. If that's a global function that already exists then it should be written as GetPlayerDistance(). If that function doesn't exist, then you'll need to create one. It's been a while, but I think that function actually does exist now in the global script.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
Go Devils
11
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Phoenix Arizona USA
Posted: 13th Jan 2015 19:01
Tom and smallg know their stuff...

In this code, won't the spawn(e) event happen over and over as soon as the timer is >=5000,
and the spawns will continue even if the player moves beyond the <=100 location?

It may be that multiple spawns are what ShakyShawn wants, but shouldn't there be some upper limit?

Go Devils

There is no Spoon...
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 13th Jan 2015 20:01
@shakeyshawn8151

I have placed some rems in your script... maybe they will help...


-- nano1.lua
--
-- author :- shakyshawn8151

-- timer tests trying to work out how they work
--
-- I want to start the timer , but player won't
PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 13th Jan 2015 20:04
!oops
Where did all those replies come from...
I must not of refreshed my browser... never saw the last 6 - so don't know if my post is still relevant..
Sorry...
PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 13th Jan 2015 20:09
I was busy writing a little example of how timers work...

not your script but something that may help you understand...

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jan 2015 21:39 Edited at: 13th Jan 2015 21:42
Quote: "In smallg's script, GetPlayerDistance is supposed to be a distance function check. If that's a global function that already exists then it should be written as GetPlayerDistance(). If that function doesn't exist, then you'll need to create one. It's been a while, but I think that function actually does exist now in the global script."


yep

as tom said change GetPlayerDistance to GetPlayerDistance(e) and it should work, i'm quite good at missing stuff like that (which is fine until i don't test my script as is the case here )



Quote: "It may be that multiple spawns are what ShakyShawn wants, but shouldn't there be some upper limit?"


possibly but spawn doesnt create an entity it simply spawns one that is hidden - once it is spawned there is no longer anything to spawn and so no reason to limit it (although it would be good practice)

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11

Login to post a reply

Server time is: 2024-05-07 19:37:03
Your offset time is: 2024-05-07 19:37:03