• 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!

onTile - NPC TALKS

Synergy

New Member
Joined
Nov 24, 2011
Messages
334
Reaction score
0
Ok.. This is complicated..

If anyone can make this, you f*cking rock.
rep++ and ALOT of thanks!!!


So..

YOU WALK ON A TILE AND A NEARBY NPC Says: "Hey adventurer!"


Thats all.. :P

Good luck
 
Here is some idea of getting a specific NPC from a position to say something.
Now that you know what to do, you can play around with it.

7lNTu.png


LUA:
function onStepIn(cid, item, position, fromPosition)
local npcPos = {x= 1014, y= 1029, z= 7, stackpos= 253}
local getPos = getThingFromPos(npcPos)

	doCreatureSay(getPos.uid, "Testing 123", 1)
	return false
end
 
if getCreatureByName("Soya") then
doCreatureSay(getCreatureByName("Soya"), "Hey I am Soya!", 1)
end

If the NPC on exists once otherwise by position..
 
Here is some idea of getting a specific NPC from a position to say something.
Now that you know what to do, you can play around with it.

7lNTu.png


LUA:
function onStepIn(cid, item, position, fromPosition)
local npcPos = {x= 1014, y= 1029, z= 7, stackpos= 253}
local getPos = getThingFromPos(npcPos)

	doCreatureSay(getPos.uid, "Testing 123", 1)
	return false
end



Ok first off, you rock!

Second, could you just give me what I put in movements.xml since I suck totally at scripting.

- - - Updated - - -

@Evan ERROR! :/

[09/08/2012 00:48:57] Lua Script Error: [MoveEvents Interface]
[09/08/2012 00:48:57] data/movements/scripts/npctalk.lua:onStepIn
[09/08/2012 00:48:57] data/movements/scripts/npctalk.lua:3: attempt to call global 'getThingFromPos' (a nil value)
[09/08/2012 00:48:57] stack traceback:
[09/08/2012 00:48:57] [C]: in function 'getThingFromPos'
[09/08/2012 00:48:57] data/movements/scripts/npctalk.lua:3: in function <data/movements/scripts/npctalk.lua:1>
 
The error says the function getThingFromPos(pos) does not exist in your server.
According to the LUA_FUNCTIONS file in the TFS SVN branch (0.2), the function exists.

Maybe you need to lower-case the 'f' in From?
LUA:
getThingfromPos(npcPos)
If not, then I have no idea, you should have the function.
 
Yes it's lowercase:
//getThingfromPos(pos)
lua_register(m_luaState, "getThingfromPos", LuaScriptInterface::luaGetThingfromPos);
 
It worked.

Thank you so much!


I really like this script.. It gives a rpg feeling since I use it when you enter shops they greet you before your in etc..


But It spams everytime you walk on the tile.. Isn't there a way to make it better with delay or something like that?
Any ideas?
 
Here, you can use this to add multiple NPC's without adding a lot of scripts, just mark the ACTION ID of the tiles in the map editor that will set the NPC's off
LUA:
local config = {
	[aid] = {'npc', 'text'},
	[aid] = {'npc', 'text'}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_SUBID, 1555)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 5000)

function onStepIn(cid, item, position, fromPosition)
	local current = config[item.actionid]
	if current then
		local npc = getCreatureByName(current[1])
		if not getCreatureCondition(cid, CONDITION_EXHAUST, 1555) and isPlayer(cid) and npc then
			doCreatureSay(npc, current[2], TALKTYPE_SAY)
			doAddCondition(cid, exhaust)
		end
	end
	return true
end
 
Here, you can use this to add multiple NPC's without adding a lot of scripts, just mark the ACTION ID of the tiles in the map editor that will set the NPC's off
LUA:
local config = {
	[aid] = {'npc', 'text'},
	[aid] = {'npc', 'text'}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_SUBID, 1555)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 5000)

function onStepIn(cid, item, position, fromPosition)
	local current = config[item.actionid]
	if current then
		local npc = getCreatureByName(current[1])
		if not getCreatureCondition(cid, CONDITION_EXHAUST, 1555) and isPlayer(cid) and npc then
			doCreatureSay(npc, current[2], TALKTYPE_SAY)
			doAddCondition(cid, exhaust)
		end
	end
	return true
end

Haha niceee!!

So I only change the 'npc' to npc name and text to the text I want? :)

- - - Updated - - -

Here, you can use this to add multiple NPC's without adding a lot of scripts, just mark the ACTION ID of the tiles in the map editor that will set the NPC's off
LUA:
local config = {
	[aid] = {'npc', 'text'},
	[aid] = {'npc', 'text'}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_SUBID, 1555)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 5000)

function onStepIn(cid, item, position, fromPosition)
	local current = config[item.actionid]
	if current then
		local npc = getCreatureByName(current[1])
		if not getCreatureCondition(cid, CONDITION_EXHAUST, 1555) and isPlayer(cid) and npc then
			doCreatureSay(npc, current[2], TALKTYPE_SAY)
			doAddCondition(cid, exhaust)
		end
	end
	return true
end



Error:
[09/08/2012 19:58:56] Lua Script Error: [Test Interface]
[09/08/2012 19:58:56] data/movements/scripts/npctalk.lua
[09/08/2012 19:58:56] data/movements/scripts/npctalk.lua:2: table index is nil
[09/08/2012 19:58:56] stack traceback:
[09/08/2012 19:58:56] [C]: in function '__newindex'
[09/08/2012 19:58:56] data/movements/scripts/npctalk.lua:2: in main chunk
[09/08/2012 19:58:56] Warning: [Event::checkScript] Can not load script. /scripts/npctalk.lua
 
Back
Top