• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua NPC help needed!

raver1234

New Member
Joined
Sep 7, 2012
Messages
12
Reaction score
0
Hello guys
I want some help with my NPCs, I want them to do two things:
First I want them not to say things right away, but to wait idk two seconds or so
Second I wanted them to advertise things on default chat.
As for the first problem, I'm using this function:
Code:
function delay_s(delay)
    local vb = "test.vbs"
  local f = assert(io.open(vb,"w"))
  f:write("WScript.Sleep(" .. (tonumber(delay) * 1000) .. ")\n")
  f:close()
  os.execute(vb)
end
before every selfSay, but the first message (after hi) and all the other "built in" responses aren't affected, also the server freezes during the delay.
i've found this function on my libs:
wait = coroutine.yield

Code:
function runThread(co)
	if(coroutine.status(co) ~= 'dead') then
		local _, delay = coroutine.resume(co)
		addEvent(continueThread, delay, co)
	end
end

function createThread(data)
	local dataType, func = type(data), nil
	if(dataType == 'string') then
		func = loadstring(data)
	elseif(dataType == 'function') then
		func = data
	end

	if(func ~= nil) then
		local co = coroutine.create(func)
		runThread(co)
	else
		print("[createThread]", "Invalid data specified.")
	end
end
but I don't know how yo use it
for the second problem, I have no idea about how to aproach it.
thanks for your time
 
Last edited:
Back
Top