• 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 and tiles[Solved]

Shinmaru

エロルアー Scripter!
Joined
Aug 20, 2007
Messages
1,988
Reaction score
88
Location
Puerto Rico
Is there a way to get and NPC to say something when you step on a certain tile?
 
Last edited:
onStepIn -> Either npc = getCreatureByName("NPCNAME") (if you use the npc only once) or check the tiles where the npc could be at the moment and npc = getThingFromPos(tile).uid
doCreatureSay(npc, "Something)
 
OK here is my script:
Lua:
local cfg = {
	[7] = {x = 1295, y = 1689, z = 7, stackpos = 253},
	[5] = {x = 1296, y = 1691, z = 5, stackpos = 253}
	}
local function getNPCs(cid)
	local pos = cfg[getCreaturePosition(cid).z]
	local NpCid = getThingFromPos(pos.x, pos.y, pos.z, pos.stackpos)
	if isNpc(NpCid) == true then
		return NpCid
	else
		return print('[Error:Not a Npc.]'..NpCid)
	end
end	

local function doNPCSay(NpCid, msg, rndm)
	if rndm == true then
		return doCreatureSay(NpCid, math.random(#msg), TALKTYPE_SAY)
	end
	return doCreatureSay(NpCid, msg, TALKTYPE_SAY)
end	
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
local npc = getNPCs(cid)
	if getCreatureStorage(cid, 1500) == 0 then
		doCreatureSetStorage(cid, 1500, 1)
		doNPCSay(npc, {'Go on through I can see you are strong enough!', 'Head on '..getCreatureName(cid)..' the king awaits!'}, true)
	elseif getCreatureStorage(cid, 1500) == 1 then
		doTeleportThing(cid, fromPosition, true)
		doNPCSay(npc, 'You have nothing else to do here!')
	else
		doTeleportThing(cid, fromPosition, true)
		doNPCSay(npc, 'You\'re still too weak to venture forward in this path.')
	end
return true
end
and here is my error:
Code:
[18:33:13.259] [Error - MoveEvents Interface]
[18:33:13.259] data/movements/scripts/NuubiaNoobtile.lua:onStepIn
[18:33:13.260] Description:
[18:33:13.260] attempt to index a number value
[18:33:13.260] stack traceback:
[18:33:13.261]  [C]: in function 'getThingFromPos'
[18:33:13.261]  data/movements/scripts/NuubiaNoobtile.lua:7: in function 'getNPC
s'
[18:33:13.261]  data/movements/scripts/NuubiaNoobtile.lua:22: in function <data/
movements/scripts/NuubiaNoobtile.lua:21>
Now what could be the problem?
 
you have to make it like that:
Code:
getThingFromPos([b][color="red"]{[/color][/b][b][color="red"]x=pos.x[/color][/b], [b][color="red"]y=pos.y[/color][/b], [b][color="red"]y=pos.z[/color][/b], [b][color="red"]stackpos=pos.stackpos[/color][/b][b][color="red"]}[/color][/b])
also use getTopCreature() like Cykotitan said
 
Back
Top