Scripts / Help me combine / add two behaviours (scripts) to an entity!

Author
Message
Bob Humid [2021]
Game Guru Backer
3
Years of Service
User Offline
Joined: 11th Jan 2021
Location: Cologne
Posted: 25th Feb 2023 05:08 Edited at: 25th Feb 2023 05:13
Ok, here´s a quick question for the experts to laugh off their behinds...

I want to give an object (actually a sci fi crate) the ability to be taken and carried around, at the same time this crate should emit binaural sound from a short distance ( Say 100 meters). So, that means I need two scripts to be in one script? Shoot me, I really don´t know.

I DO HAVE THE BOTH SCRIPTS NEEDED! Alas, but I need them both to be globally active ALL THE TIME.

I used the siwtchscript-thingy but I don´t know how to use it since there is no manual to it (The LUA-manual on Steam does not cover this topic, nor does Medinas Book - I bought it) and I ended up producing a very strange redundant / recursive loop-in-loop-in-loop nightmare ...

I really need help.

HOW TO COMBINE 2 SCRIPTS into the one mighty MAIN AI? The post answers I found in the forum are all kind of .. cryptical to say at least, because it seams that once you know how to use LUA and to properly script, it makes you forget how it is not to have that skill?

I have minor understanding of LUA and am only able to attach one script with ONE function to an entity via MAIN AI - or is there another way...?

smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 25th Feb 2023 10:32
combining scripts that do 2 jobs can be done by copying the code from each section into the same section in the other script
(don't take the init(), properties(), main() function lines - just the code that's inside them.
as long as you put the code inside the corresponding function only it should work as it did in the old script.

the easiest method is likely to put the code from sound script into the the carry script as i expect the carry script to be much larger
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Bob Humid [2021]
Game Guru Backer
3
Years of Service
User Offline
Joined: 11th Jan 2021
Location: Cologne
Posted: 25th Feb 2023 13:56
@smallg

Well, wam bam, Thank You, Sir! That sounds doable! Will report if I managed to do it! Thank you again!

Another small question:
Then what is function of "function", if one script needs it, but you cannot have 2 "function"-trees, than why does it have to be there? There is awlays a [function / end] in a script. Would that not be a cleaner code leaving out that semantics? Dont hit me, I am new to LUA.
Bob Humid [2021]
Game Guru Backer
3
Years of Service
User Offline
Joined: 11th Jan 2021
Location: Cologne
Posted: 25th Feb 2023 15:27
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
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Feb 2023 17:05 Edited at: 25th Feb 2023 17:07
Put:
realsound_cyan_flag = 0
At the top of the script.

Probably won't fix it but it should be there.
Been there, done that, got all the T-Shirts!
PM
Bob Humid [2021]
Game Guru Backer
3
Years of Service
User Offline
Joined: 11th Jan 2021
Location: Cologne
Posted: 26th Feb 2023 01:42 Edited at: 26th Feb 2023 02:09
Thanx @AmenMoses

But, should I MOVE "realsound_cyan_flag = 0" to top of the script, or place a copy of it there?

Also, I think you meant the top of the sound-script? It originally camein the script positioned BEFORE the function-command.

...

Done. Moved it up to be the first line in the sound-script. The sound keeps beeing erratic at best. Its suddenly there, fades not enough and suddenly cuts off.

I am going to use "soundbinau" now. Its the only sound-script that works on my level ... At least on another object in the same level.
Bob Humid [2021]
Game Guru Backer
3
Years of Service
User Offline
Joined: 11th Jan 2021
Location: Cologne
Posted: 26th Feb 2023 19:05
I succesfully placed "soundbinau" into "carry_object" and this way it works fine.

But now I seem not to be capable of adjusting the binaural-script to realistically fade out the volume over the distance when I move away from it. I can run for a mile and still hear the emitted sound. That is far from exponential or logarythmic, its nore like sinus-odial never quite reaching 0!

Hmm.

Login to post a reply

Server time is: 2024-12-22 06:24:37
Your offset time is: 2024-12-22 06:24:37