Scripts / Timer problem.

Author
Message
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 14th Mar 2016 12:32
I created a doorswitch which is working good, the problem is to activate the switch working with a timer so you have amount of time to open the door. I created this script , but the timer function is not working so I need some help , what is wrong? Thanks.


local timer = 0
function timerswitch_init(e)
Door_Switch2 = 0
SwitchActivated2 = 0
end

function timerswitch_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 100 and g_PlayerHealth > 0 then
if SwitchActivated2 == 0 then
Prompt("Press E key to activate switch")
if g_KeyPressE == 1 and timer == 0 then
Door_Switch2 = 1
PromptDuration("Doorswitch activated" ,3000)
SwitchActivated2 = 1
timer = 1
StartTimer(e)
if timer == 1 and GetTimer(e) > 20000 then
PromptDuration("timer " .. GetTimer(e))
Door_Switch2 = 0
end
end
end
end
end
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 14th Mar 2016 15:49
GG timer does not work fine lately.
Try this one:




hth

3com


Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 14th Mar 2016 19:36
Thanks for your help 3com, I only put Door_Switch2 in the script, this is the action in my door script.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 14th Mar 2016 19:50
you are welcome.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 15th Mar 2016 10:25 Edited at: 15th Mar 2016 10:33
Hi 3com,

I tested this script but the script is working till the timer, I can open the door but the timer is not working, the DoorTimerSwitch is the action to let open and close the door. Thanks.


local timer = {}

function timerswitch_init(e
TimeSwitchActivated = 0
DoorTimerSwitch = 0
timer[e] = 0
end

function timerswitch_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 100 and g_PlayerHealth > 0 then
if TimeSwitchActivated == 0 then
Prompt("Press E key to activate switch")
if g_KeyPressE == 1 then
timer[e] = os.time()
DoorTimerSwitch = 1
PromptDuration("Doorswitch activated" ,3000)
TimeSwitchActivated = 1
end
end

(not working)
if DoorTimerSwitch == 1 then
if os.time() > timer[e] + 1000 then -- increase/decrease this value to fit yours needs
PromptDuration("os.time1: " ..os.time() .." - timer1[e]: " ..timer[e],3000)
DoorTimerSwitch = 0
end
end

end
end
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 15th Mar 2016 14:30
Taking a quick look it seems ok but OS.time() works in seconds so that script would require you to stay in range of the door for 1000s before it resets
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 15th Mar 2016 14:56
Yes, this is the script of the switch I found out leaving the switch the timer stops, maybe a global timer not depended of the switch will work.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 15th Mar 2016 18:20 Edited at: 15th Mar 2016 21:51
this should work for you
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 15th Mar 2016 21:09
Cool smallg!
Aside note, you has to change this one:

Quote: "function timerswitch_init(e"


And it works quite well.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 15th Mar 2016 21:51
thanks, i copied the code he posted and didn't notice it
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 16th Mar 2016 18:50
Hi Smallg, 3com,

Timerswitch is working correct, only it is strange when showing the timer on screen you cannot open the door.
Thanks for the help.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 16th Mar 2016 19:12
well you would need a script for the door like this
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 17th Mar 2016 07:27
Hi Smallg,

Thanks, is it interesting to put the timer- and door switch in your " some sample scripts for ideas" ?
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Mar 2016 13:47
Quote: "Hi Smallg,

Thanks, is it interesting to put the timer- and door switch in your " some sample scripts for ideas" ?"

sure, added an improved version to my collection
https://forum.game-guru.com/thread/207801?page=14#msg2544393
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 17th Mar 2016 15:44
Good suggestion! and nice addiction!. thanks guys.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 24th Mar 2016 23:34
I've made some improvements to the timer code for V1.13 so hopefully we can see if this fixes it during the beta testing.
PC SPECS: Windows 8.1 Pro 64-bit, Intel Core i7-5930K (PASSMARK:13645), NVIDIA Geforce GTX 980 GPU (PASSMARK:9762) , 32GB RAM

Login to post a reply

Server time is: 2024-12-22 15:25:37
Your offset time is: 2024-12-22 15:25:37