Scripts / [QUESTION] Sound when near an Entity

Author
Message
xSyndicate58
7
Years of Service
User Offline
Joined: 25th Feb 2017
Location:
Posted: 12th Apr 2017 19:27
Hello, so today I messed around trying to write script, which allows me to play a sound after an entity exploded



so basically what I want to do, as soon as somebody approaches the entity, it should explode, afterwards the player will be frozen, the music volume should be set to 0 and a sound will be played. During this sound (approx 126 seconds) the player will remain frozen. As soon as the sound ends the player should get unfrozen and the music volume should go up to 100 again.

But unfortunately almost none of the above mentioned works and idk why.. can anybody help me out pls?

greetings
PM
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 12th Apr 2017 21:04
music_set_volume doesn't exist

you probably want to use

SetGameMusicVolume(v)

where v is 0 to 100

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
UNIRD12B
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 2nd May 2014
Location: Canada
Posted: 3rd May 2017 17:08
Uhm Xsyndicate58 ,
you realize that 126 seconds is over 2 minutes long , right ?
isn't that a long time for the player to wait in the middle of a game
in order to move again ?

UNIRD12B
Let\'s actually make something happen with this one !
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 5th May 2017 18:58 Edited at: 5th May 2017 19:18
xSyndicate58 try these two scripts...

attach this control script to an always active dynamic entity..use ONLY ONE of this script in the level
script name is jc_player_freeze_music.lua



-- jc_player_freeze_music.lua
--
-- This is the music and player freeze control script
-- ONLY ONE used on level
-- attach script to an always active dynamic entity

-- these will be the explodable entities added to use with this script
local myent = {}
local mycnt = 0

-- the music trak to play
local mustrak = 2
local mon = 0

-- the explodable entitys state
local estate = {}
local ce = 0
-- delay used to freeeze player and music (change to your required value)
local tmdelay = 10000

-- Used by the destroy_too_near script to check if this control script is active
jc_player_freeze_music_set = 0

function jc_player_freeze_music_init(e)

end

function jc_player_freeze_music_main(e)

-- tell destroy_too_near script we are active
jc_player_freeze_music_set = 1

-- at startup start the music trak
-- if you have set the music to play already just rem out these lines
if mon == 0 then
music_play_cue(mustrak, 500)
music_set_volume(100,100)
mon = 1
end

-- if we have explodable entities added then do the for loop
if mycnt > 0 then
for ce = 1, mycnt do
-- if explodable entity has set trip (exploded)
if estate[ce] == "trip" then
-- we now freeze player and stop the music and reset the timer
FreezePlayer()
music_stop(10)
StartTimer(e)
-- set the state to tripped so we will control the next state logic
estate[ce] = "tripped"

elseif estate[ce] == "tripped" then
-- if we are tripped then check the time delay
if GetTimer(e) < tmdelay then
-- play sound while we wait
PlaySoundIfSilent(e,1)
else
-- time delay is up so unfreeze player stop the sound start the music
UnFreezePlayer()
StopSound(e,1)
music_play_instant(mustrak,10)
music_set_volume(100,100)
-- set the state to fin so we don't do this logic anymore
estate[ce] = "fin"
end
end
end
end
end

-- explodable entity adds its entity number to our list
function jc_player_freeze_music_add_me(ex)
if ex > 0 then
mycnt = mycnt + 1
myent[mycnt] = ex
estate[mycnt] = "setup"
end
return mycnt
end

-- explodable entity sets the trip state when it explodes
function jc_player_freeze_music_set_state(ec, st)
if ec > 0 and ec <= mycnt then
estate[mycnt] = st
end
end


and attach this one to your explode entity... add as many as you need
script name is destroy_too_near.lua



-- destroy_too_near.lua
--
-- Add this script to explodable entitys as many as you want

-- this is the external control script that will do most of the work
require "scriptbank\\myScripts\\jc_player_freeze_music"

-- will hold this expoldable entitys position in the above control scripts list of entitys
local ecnt = {}

-- player near distance check value
local neardist = 400 -- 220

function destroy_too_near_init(e)
-- make sure our ecnt[e] is set at zero at start
ecnt[e] = 0
end

function destroy_too_near_main(e)
-- check if we can see the external control script
if jc_player_freeze_music_set ~= nil then
if jc_player_freeze_music_set == 0 then
return
end
else
PromptLocal(e, "musicFreezeControl not setup")
end

-- we can see the external control script
-- so we can carry on
-- if our ecnt[e] has not been added yet then add our (e) to the control scripts list
if ecnt[e] == 0 then
ecnt[e] = jc_player_freeze_music_add_me(e)
elseif ecnt[e] > 0 then
-- we have been added to the control script
-- so check if player is near
if GetPlayerDistance(e) < neardist then
-- too near so explode
SetEntityHealth(e,0)
-- tell the control script we have exploded
-- using ecnt[e] our position in the control scrpts list
jc_player_freeze_music_set_state(ecnt[e], "trip")
end
end
end
[ /code ]

good luck..
I don't know why the script is not showing in the script box..?
PM

Login to post a reply

Server time is: 2024-03-29 07:03:50
Your offset time is: 2024-03-29 07:03:50