Scripts / Help with Script

Author
Message
Johno 15
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 25th Aug 2014
Location: Cork, Ireland
Posted: 21st Aug 2016 13:32
Hey all, Decided to try my hand at lua an try to write my first script. The idea of the script is simple enough. The player walks up to a door and if he has all 6 required parts a prompt appears saying press E to extend base. Upon pressing E a timer should start to count 10 minutes with a local prompt at the door displaying how long is left. When the timer reaches 0 the timer should stop,the if used field should be activated and the door should be destroyed. I wrote the following script myself and it works so far as the timer part, the timer doesn't stop when it gets to 0 it just keeps counting down in - numbers.
Any help is appreciated.



Thanks in advance: John
'Judge a man not by his answers. But by his questions.'
Nathan38
13
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 21st Aug 2016 15:26 Edited at: 21st Aug 2016 15:28
Have you tried setting the g_building = 1 back to 0 at the end of the script?


Johno 15
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 25th Aug 2014
Location: Cork, Ireland
Posted: 21st Aug 2016 15:59
Quote: "Have you tried setting the g_building = 1 back to 0 at the end of the script?

if g_timeleft == 0 then
    hide(e)
    ActivateIfUsed(e)
    PlaySound(e, 1)
    g_building = 0
    destroy(e)
    end
"


Did that and now it gets to 31 milliseconds. stops for about a second or two then the prompt disappears
'Judge a man not by his answers. But by his questions.'
Gtox
3D Media Maker
10
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 21st Aug 2016 18:40
Try this code -



I added a variable that determines whether or not the timer has been started, changed 'if timeleft == 0' to 'if timeleft < 0' (frame rate issues can cause GetTimer(e) to skip numbers), and capitalized Hide(e) and Destroy(e). I changed 'PromptLocal(e,"ECT: ".. g_timeleft.." milliseconds")' to 'PromptLocal(e,"ECT: "..math.floor(timeleft/1000).." seconds")' , because it looks neater (but that's just my opinion, so you can ignore it). Lastly, I had to remove the g_ prefix from your variables, because they were giving me error messages (I don't know why, because they were obviously working with you), so you can change them back if you want.
Johno 15
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 25th Aug 2014
Location: Cork, Ireland
Posted: 22nd Aug 2016 01:32
Thanks @Gtox, worked like a charm! I've a lot to learn yet with lua but happy enough for my first script
'Judge a man not by his answers. But by his questions.'

Login to post a reply

Server time is: 2025-01-05 06:32:15
Your offset time is: 2025-01-05 06:32:15