@@ -12,13 +12,13 @@ local type = type
1212local GetEntityCoords = GetEntityCoords
1313local vector3 = vector3
1414local PlayAmbientSpeechFromPositionNative = PlayAmbientSpeechFromPositionNative
15+ local exports = exports
1516
1617-- Local Variables ----------------------------------------------
1718local resourceName = GetCurrentResourceName ()
1819
1920-- Functions --------------------------------------------------------
2021--- Resolve location for speech playback
21- --- @alias LocationInput nil | vector3 | number | string |{ x : number,y : number,z : number }| number[]
2222--- @param location ? LocationInput Location to resolve
2323--- @return vector3 coords Resolved world coordinates
2424local function resolveLocation (location )
@@ -137,36 +137,36 @@ end
137137--- @param speechName string Base speech name
138138--- @param character CharacterName Character voice to use
139139--- @param addressal Addressal Player ' s addressal preference
140- --- @param location ? vector3 | string | table Optional location for speech
141- local function playSpeech (speechName , character , addressal , location )
142- assert (type (speechName ) == ' string' , ' speechName must be a string' )
143- assert (type (character ) == ' string' , ' character must be a string' )
144- assert (constants .isValidCharacter (character ), ' invalid character name: ' .. tostring (character ))
145- assert (type (addressal ) == ' string' , ' addressal must be a string' )
146- assert (constants .isValidAddressal (addressal ), ' invalid addressal: ' .. tostring (addressal ))
147-
140+ --- @param isNetworked boolean Whether to play for nearby players
141+ --- @param location ? LocationInput Optional location for speech playback
142+ local function playSpeech (speechName , character , addressal , isNetworked , location )
148143 local baseName = getBaseSpeechName (speechName )
149144 local finalName = resolveSpeechName (baseName , addressal )
150145 local voiceName = constants .getVoiceName (character )
151146 local finalLocation = resolveLocation (location )
152147
153- -- this client
154148 PlayAmbientSpeechFromPositionNative (finalName , voiceName , finalLocation .x , finalLocation .y , finalLocation .z , constants .speechParams .default )
149+ lib .print .debug (format (' Playing Speech: "%s" | Location: %s | Voice: "%s"' , finalName , tostring (finalLocation ), voiceName ))
150+
151+ if isNetworked == nil then
152+ isNetworked = true
153+ end
154+
155+ if not isNetworked then
156+ return
157+ end
155158
156- -- nearby clients
157159 TriggerServerEvent (resourceName .. ' :server:playSpeech' , {
158160 speechName = finalName ,
159161 voiceName = voiceName ,
160162 location = finalLocation ,
161163 speechParams = constants .speechParams .default ,
162164 })
163-
164- lib .print .debug (format (' Playing Speech: "%s" | Location: %s | Voice: "%s"' , finalName , tostring (finalLocation ), voiceName ))
165165end
166166
167167--- Play voice response for an intent/topic
168- --- @param data table Data containing speechName , topic , location
169- local function playResponse (data )
168+ --- @param data SpeechData
169+ local function playResponse (data , message )
170170 if not data .speechName then
171171 return
172172 end
@@ -183,7 +183,7 @@ local function playResponse(data)
183183 ' AI: "%s" | Responding to: "%s" | Message: "%s" | Topic: "%s"' ,
184184 utils .capital (currentCharacter ),
185185 utils .capital (currentAddressal ),
186- data . message ,
186+ message or ' no message ' ,
187187 utils .capital (data .topic )
188188 )
189189 )
@@ -198,26 +198,27 @@ local function playResponse(data)
198198 duration = sharedConfig .notify .duration ,
199199 })
200200
201- playSpeech (data .speechName , currentCharacter , currentAddressal , data .location )
201+ playSpeech (data .speechName , currentCharacter , currentAddressal , data .isNetworked , data . location )
202202end
203203
204204--- Send a message to the AI and get a voice response (routes to server NLP processing)
205205--- @param message string The message to send to the AI
206+ --- @param isNetworked boolean Whether to play for nearby players
206207--- @param location ? LocationInput Optional location for speech playback (defaults to player ped )
207208--- @return boolean success Whether the request was successful
208- local function talk (message , location )
209+ local function talk (message , isNetworked , location )
209210 if not message or type (message ) ~= ' string' or # message == 0 then
210211 lib .print .warn (' talk: Invalid message' )
211212 return false
212213 end
213214
214- local success = lib .callback .await (resourceName .. ' :server:talk' , false , message , location )
215+ local success = lib .callback .await (resourceName .. ' :server:talk' , false , message , isNetworked , location )
215216
216217 return success or false
217218end
218219
219220--- Plays a random voice line
220- local function playRandomLine (location )
221+ local function playRandomLine (isNetworked , location )
221222 local speechName = lib .callback .await (resourceName .. ' :server:getRandomLine' , false )
222223 if not speechName then
223224 lib .print .warn (' Failed to get random line' )
@@ -227,7 +228,7 @@ local function playRandomLine(location)
227228 local currentCharacter = state .getCharacter ()
228229 local currentAddressal = state .getAddressal ()
229230
230- playSpeech (speechName , currentCharacter , currentAddressal , location )
231+ playSpeech (speechName , currentCharacter , currentAddressal , isNetworked , location )
231232end
232233
233234-- Exports -----------------------------------------------------------
0 commit comments