Scripts / [SOLVED] Modifying jump scare script for longer duration and not random

Author
Message
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 19th May 2022 18:37
I like the jump scare script but I've been trying to use it for different uses that require a longer time and not to change the object in random directions. It's also set to randomize how much time the object appears before disappearing. I managed to tweak it so it stopped turning the object in different directions and it would last for a longer time but I can't seem to remove the random time length without breaking the script. It has this line which controls if the item appears for 25% longer or shorter. I changed both these values to 1.00 but that didn't seem to work. Removing the line completely causes errors

fade_delay[e] = GetTimer(e) + math.random(fade_delay_init * 0.75,fade_delay_init * 1.25)

so what am I missing to make this work properly. I'm just trying to get the item to appear for three seconds/3000 ms and then disappear. Here's my tweaked version of the script



--DESCRIPTION:Jump-Scare by Smallg
--script by smallg
local appearances = {}
local fade_delay = {}
local hidden = {}
local fade_delay_init = 0


--set these to 0 if you dont want any movement from original location
--how far away from starting location entity can move in x axis
local movex_random = 0
--how far away from starting location entity can move in z axis
local movez_random = 0

function jumpscaretv_init(e)

--how many times entity will appear
appearances[e] = math.random(1,1)
--how long between appearances (and how long it will appear for)
--is randomed so can be 25% shorter or longer (see near end of script)
fade_delay[e] = 3000

---------------
hidden[e] = 1
CollisionOff(e)
fade_delay_init = fade_delay[e]
Hide(e)
end

function jumpscaretv_main(e)
CollisionOff(e)
if g_Entity[e]['activated'] == 1 then
if GetTimer(e) > fade_delay[e] then
if appearances[e] > 0 then
if hidden[e] == 1 then
PlaySound(e,1)
Show(e)
hidden[e] = 0
appearances[e] = appearances[e] - 1
else
Hide(e)
hidden[e] = 1
end
else
if hidden[e] == 0 then
Hide(e)
end
end
fade_delay[e] = GetTimer(e) + math.random(fade_delay_init * 0.99,fade_delay_init * 1.01)
end
end

end --main


function jumpscaretv_exit(e)

end

The author of this post has marked a post as an answer.

Go to answer
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th May 2022 21:00
This post has been marked by the post author as the answer.
you can remove the random by just adding the init_delay
i.e.
instead of
fade_delay[e] = GetTimer(e) + math.random(fade_delay_init * 0.99,fade_delay_init * 1.01)
put
fade_delay[e] = GetTimer(e) + fade_delay_init
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 19th May 2022 22:20 Edited at: 19th May 2022 23:00
Thanks smallG, I appreciate the help! I added the line and now it's doing the exact same timeframe each time is triggered. It does seem to be starting the item at different stages of its animation though which is what I'm trying to fix and I was figuring it had to do with a random time. What I have is a robed figure(only has one 3 second animation) that when triggered will appear and stand there and then turn around and walk away and then disappear. What its doing is starting the animation halfway through and then looping back around to the beginning and starting over for the last amount of time left. Is there something in the script I missing that randomizes the animation starting frame as well?

Edit: nevermind, I know what was going wrong. I had the model set to animate in the editor and it was just looping the animation even though the model wasn't seen. So every time it was activated I would get the animation starting at whatever point it was at when it was triggered. I just popped in this bit of code and turned animate in the editor off and it's working.

SetAnimation(0)
PlayAnimation(e)

Sometimes it takes me a bit to piece things together anyway, it works great now. Thank you for your help. Here's the modified script if it helps anybody. It has a timer of three seconds

Attachments

Login to view attachments
PM

Login to post a reply

Server time is: 2024-03-28 22:42:17
Your offset time is: 2024-03-28 22:42:17