Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 2ef0af3

Browse files
committed
Update npctalk() to check for NPCs in close range
Thanks to @Colandus for the idea and the code which I blatantly copied
1 parent 068d69e commit 2ef0af3

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/Events.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@
55
* original waitping() solution, passing `normalWait` as true.
66
*
77
* @since 0.1.0
8+
* @updated 1.2.0
89
*
910
* @param {string...} messages - Messages to be said
1011
* @param {boolean} [normalWait] - If waitping should be used as
1112
* waiting method; defaults to false
13+
*
14+
* @returns {boolean} - A value indicating whether all
15+
* messages were correctly said
1216
--]]
1317
function npctalk(...)
1418
local args = {...}
1519

20+
-- Checks for NPCs around
21+
-- Blatantly (almost) copied from @Colandus' lib
22+
local npcFound = false
23+
foreach creature c 'nfs' do
24+
if c.dist <= 3 then
25+
npcFound = true
26+
break
27+
end
28+
end
29+
30+
if not npcFound then
31+
return false
32+
end
33+
34+
1635
-- Checks for aditional parameters
1736
local normalWait = false
1837
if type(table.last(args)) == 'boolean' then
@@ -52,12 +71,13 @@ function npctalk(...)
5271
msgSuccess = waitFunction($name, v, 3000, true, MSG_SENT)
5372
if not msgSuccess then
5473
if not ischannel('NPCs') then
55-
npctalk(select(k, ...))
56-
return
74+
return npctalk(select(k, ...))
5775
end
5876
end
5977
end
6078
end
79+
80+
return true
6181
end
6282

6383
--[[

0 commit comments

Comments
 (0)