Ok, I just tried all kind of combinations and now it seems to work, BUT: the sound deos not fades its volume up or down if I change my distance to the crate
... It just starts with a high volume andkeeps it there. It loops properly. I messed up something, didnt I?
Skript: carry_object_lua (with embedded realsound-part):
local nearest = nil
local nearest_dist = 80
local init_nearest_dist = nearest_dist
local cmode = 0
local new_y = 0
local prop_x = 0
local prop_z = 0
function carry_object_init(e)
cmode = 0
end
function carry_object_main(e)
if cmode == 0 then
if nearest == nil then
nearest_dist = init_nearest_dist
elseif GetPlayerDistance(nearest) > nearest_dist then
nearest_dist = init_nearest_dist
end
if GetPlayerDistance(e) < nearest_dist then
nearest_dist = GetPlayerDistance(e)
nearest = e
end
if (GetPlayerDistance(e) <= nearest_dist) then
Prompt("Press E to carry")
if g_KeyPressE == 1 then
cmode = 1
nearest = e
return
end
end
elseif (cmode == 1) then
new_y = math.rad(g_PlayerAngY)
prop_x = g_PlayerPosX + (math.sin(new_y) * 70)
prop_z = g_PlayerPosZ + (math.cos(new_y) * 70)
CollisionOff(nearest)
SetPosition(nearest , prop_x, g_PlayerPosY , prop_z)
RotateToCamera(nearest)
CollisionOn(nearest)
Prompt("Release E to drop")
if g_KeyPressE == 0 or GetPlayerDistance(nearest) > init_nearest_dist then
cmode = 0
CollisionOff(nearest)
SetPosition(nearest , prop_x , g_PlayerPosY , prop_z)
CollisionOn(nearest)
nearest_dist = init_nearest_dist
nearest = nil
end
end
PlayerDist_cyan = GetPlayerDistance(e)
if PlayerDist_cyan<500 then
if realsound_cyan_flag==0 then
LoopSound(e,0)
ActivateIfUsed(e)
realsound_cyan_flag = 1
else
SetSoundVolume(110-(PlayerDist_cyan/15))
end
else
StopSound(e)
realsound_cyan_flag = 0
end
end