Scripts / Timer?

Author
Message
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 2nd Mar 2015 05:04 Edited at: 6th Mar 2015 23:02
I found a script someone had posted about an on screen timer for an explosion. I am looking for a timer that I can trigger each level that will begin a countdown on the screen. If the player hasn't finished the level by the time expiration, it is automatic game over. Do we have access to that already, or is this something I need to research on scripting?
Devcore35
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 5th Aug 2014
Location: Rouen (76) - France
Posted: 2nd Mar 2015 11:25
Hello,

It's a great idea!
Unfortunately I do not know how to do this. Maybe you can help you create other scripts already on this board? There are certain scripts (such as day / night) that uses a timer I think ... By modifying a can you should get there.
I'll look still on my side: if I find I would put available here.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Mar 2015 13:35
you just need to change the value for the winzone and the delay to match your game settings

Quote: "--change to entity number of winzone
local zonenumber = 3
--change to time limit before gameover
local delay = 60
local time1 = 0
local time2 = g_Time
local timepassed = time2 - time1

function self_destruct_init(e)

end

function self_destruct_main(e)

if g_Entity[zonenumber] ~= nil then
if g_Entity[zonenumber]['plrinzone'] == 0 then
if time1 == 0 then
time1 = g_Time
end
time2 = g_Time
timepassed = (time2 - time1) / 1000
if timepassed >= delay - 0.5 then
SetPlayerLives(e,0)
HurtPlayer(e,g_PlayerHealth)
else
Prompt("Time til self destruct: " .. math.floor(delay - timepassed) .. "s")
end
end
end

end"


if you want to remove the onscreen prompt then remove the line 'Prompt("Time til self destruct: " .. math.floor(delay - timepassed) .. "s")'
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 3rd Mar 2015 04:32 Edited at: 6th Mar 2015 23:03
@smallg that is actually almost perfect! Thank you! That gives me something to start with. The main issue I have with it is that the further away from the start area you get, the prompt leaves the screen (Though the time is still running). I am working on it to get the script to keep the prompt up all the time. Here is the script with the few minor changes from your original:

Quote: "--change to entity number of winzone
local zonenumber = 155

--change to time limit before gameover
local delay = 1200
local time1 = 0
local time2 = g_Time
local timepassed = time2 - time1

function countdown_init()
end

function countdown_main()
if g_Entity[zonenumber] ~= nil then
if g_Entity[zonenumber]['plrinzone'] == 0 then
if time1 == 0 then
time1 = g_Time
end
time2 = g_Time
timepassed = (time2 - time1) / 1000
if timepassed >= delay - 0.5 then
SetPlayerLives(e,0)
HurtPlayer(e,g_PlayerHealth)
else
Prompt("Time until fail: " .. math.floor(delay - timepassed) .. "s")
end
end
end

end"


I thought the issue may be here:



But I tried to comment it out and had the same result. Time to dig into the code bank
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 3rd Mar 2015 05:14 Edited at: 6th Mar 2015 23:03
Well I fixed one part of the script. The main "End" part of the script had the player die, then reset and die again. It was a loop that didn't end. I fixed it to where it gives a Game Over:

Quote: "--change to entity number of winzone
local zonenumber = 155

--change to time limit before gameover
local delay = 1200
local time1 = 0
local time2 = g_Time
local timepassed = time2 - time1

function countdown_init()
end

function countdown_main()
if g_Entity[zonenumber] ~= nil then
if g_Entity[zonenumber]['plrinzone'] == 0 then
if time1 == 0 then
time1 = g_Time
end
time2 = g_Time
timepassed = (time2 - time1) / 1000
if timepassed >= delay - 0.5 then
FinishLevel()
else
Prompt("Time until fail: " .. math.floor(delay - timepassed) .. "s")
end
end
end

end"
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Mar 2015 10:27 Edited at: 3rd Mar 2015 10:32
ah didnt know there was a finishlevel command now, would still work as it was in the standalone as dying with no lives returns you to the menu, only get the loop issue in test mode

as for the range issue you need to make it always active in the entity properties - i highly suggest checking the guide on steam for the lua menu options
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 3rd Mar 2015 15:01 Edited at: 6th Mar 2015 23:03
@smallg thank you for all your responses. I figured it out, it really wasn't much of a scripting issue as an attachment issue. I was attaching the script to a trigger zone, which is not what is needed. Instead, it has to be attached to an entity, set to always run, and the entity has to be made not static. So I made a few more tweaks, and the timer script works perfect now... counting down until game over. Anyone who wants to use it, please feel free to

Quote: "--This is the number of the Winzone
zonenumber = 155

--change to time limit before gameover
delay = 1200
time1 = 0
time2 = g_Time
timepassed = time2 - time1

function countdown_init()
end

function countdown_main()
if g_Entity[zonenumber] ~= nil then
if g_Entity[zonenumber]['plrinzone'] == 0 then
if time1 == 0 then
time1 = g_Time
end
time2 = g_Time
timepassed = (time2 - time1) / 1000
if timepassed >= delay - 0.5 then
FinishLevel()
else
Prompt("Time until fail: " .. math.floor(delay - timepassed) .. "s")
end
end
end

end"

Login to post a reply

Server time is: 2024-12-21 14:59:27
Your offset time is: 2024-12-21 14:59:27