• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC says something after we do any action. Possible?

Erevius

It Was A Good Day
Joined
Feb 12, 2010
Messages
157
Reaction score
7
Location
Poland/Olsztyn
Is it possible to make the NPC say something (one sentence), or do any action after we eg. push the lever? If yes please give me an example, or a little tutorial.
 
First method:
In NPC script [it can be in first line of .lua script) put something like:
LUA:
doSetStorage(12345, getNpcId())
It will execute while NPC (OTS) loading and save unique ID of that NPC in global storage.
In lever action script (funtion onUse...) put that line to say something as NPC:
LUA:
doCreatureSay(getStorage(12345), "TEXT THAT YOU WANT SHOW", SPEAK_SAY)
----------------
If you want make that text visible only for one player (if you set it 'cid' like in example, it will be visible only to guy who use lever):
LUA:
doCreatureSay(getStorage(12345), "TEXT THAT YOU WANT SHOW", SPEAK_SAY, false, cid)

Second method
Use getSpectators(centerPos, rangex, rangey) to get creatures in range in which should be NPC and find 'uid' of NPC.
This method does not need any code in NPC, only some code in lever script, BUT it uses much more CPU power!
getSpectators function with high (50x50, 100x100) rangex and rangey can LAG ALL PLAYERS ON OTS.
LUA:
local npcUID = 0
local creaturesList = getSpectators({x=123,y=234,z=7}, 7, 5)
if(creaturesList ~= nil) then
	for i, creatureUID in pairs(creaturesList) do
		if(isNpc(creatureUID) and getCreatureName(creatureUID) == "Npc Name, casesensitive!!") then
			npcUID = creatureUID
			break
		end
	end
end

if(npcUID ~= 0) then
	doCreatureSay(npcUID, "TEXT THAT YOU WANT SHOW", SPEAK_SAY)
else
	-- sorry, but NPC is not in range or you set wrong NPC Name
end
 
Last edited:
Back
Top