Community Forum

PlaySample Help

Forum Overview >> Scripting

CategoryScripting
Created19.01.2011 22:06


Frederik Jørgensen (Unknown) 19.01.2011 22:07
Hello..

I need help with this

playSample
Description

Play sample object


Definition

function playSample(integer objectId, integer loops, float volume, float offset)


Arguments

integer objectId id of sample object
integer loops number of loops [0,n] 0 = endless looping
float volume volume [0,1]
float offset offset in milliseconds

how should i use it in a LUA script for Farming Simulator.

I want it to play the sound xxxx.wav but what should i exactly code in the LUA file.
Lets start from the beginning please ;) I am kinda new to this LUA languange ;)

Stefan Geiger - GIANTS Software 21.01.2011 09:44
You first need to create and load a sample, using createSample and loadSample. Then you can play whenever it is needed.

Maybe you want to have a look at the honk specialization which loads a single sample for the honk of a vehicle.
http://ls-mods.de/scriptDocumentation.php?lua_file=vehicles/specializations/Honk

Frederik Jørgensen (Unknown) 21.01.2011 18:27
Thanks.
:)
ill try work it out..

Btw which file types does it support ?

Frederik Jørgensen (Unknown) 21.01.2011 18:38
Hellom again.

Ive looked at it.

will this one work if i put it in a LUA script and add the lua script to the xml file ?
[code]
10 Radio = {};
11
12
13 function Radio.prerequisitesPresent(specializations)
14 return SpecializationUtil.hasSpecialization(Steerable, specializations);
15 end;
16
17 function Radio:load(xmlFile)
18
19 self.playRadio = SpecializationUtil.callSpecializationsFunction("playRadio");
20
21 local radioSoundFile = getXMLString(xmlFile, "vehicle.RadioSound#file");
22 local clientRadioSoundFile = getXMLString(xmlFile, "vehicle.RadioSound#client");
23 if radioSoundFile ~= nil and clientRadioSoundFile ~= nil then
24 radioSoundFile = Utils.getFilename(radioSoundFile, self.baseDirectory);
25 clientRadioSoundFile = Utils.getFilename(clientRadioSoundFile, self.baseDirectory);
26 self.radioSoundId = createSample("radioSound");
27 loadSample(self.radioSoundId, radioSoundFile, false);
28 self.radioSoundVolume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.radioSound#volume"), 1.0);
29 self.radioSoundRadius = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.radioSound#radius"), 50);
30 self.radioSoundInnerRadius = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.radioSound#innerRadius"), 10);
31 self.clientRadioSound = createAudioSource("clientRadioSound", clientRadioSoundFile, self.radioSoundRadius, self.radioSoundInnerRadius, self.radioSoundVolume, 0);
32 link(self.components[1].node, self.clientRadioSound);
33 setVisibility(self.clientRadioSound, false);
34 self.RadioPlaying = false; (this one should be true right instred of false?)
35 end;
36 end;

(Is the last codes here needed?)
37
38 function Honk:delete()
39 if self.honkSoundId ~= nil then
40 delete(self.honkSoundId);
41 self.honkSoundId = nil;
42 end;
43 end;
44
45 function Honk:readStream(streamId, connection)
46 end;
47
48 function Honk:writeStream(streamId, connection)
49 end;
[/code]

Thomas H. (Patar) 23.02.2011 10:56
I think you should learn lua before you work with it in LS11. You only load your sample. But where do you play it? It cannot work without the function playSample. And where do you switch your radio on and out?

EDIT: Oh, I see, you use a sound which is bound on an transformGroup. Why? If you make a radio, you shouldn`t bound it on an transformGroup.


Note: Log in to post. Create a new account here.