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

NPC Request (Remove Rocks)

azzkaban

Monster Maker
Joined
Feb 23, 2010
Messages
1,101
Reaction score
194
Location
Iquique Chile
Hi! I need NPC.

Example:

Player: Hi.
NPC: Hello |PLAYERNAME|. I am the stronger Stone Golem and can {destroy} Rocks.

Player: destroy:
NPC: I can remove rock for 100gp

And NPC walk From Position: [X: 986] [Y: 197] [Z: 7]. to Position: [X: 992] [Y: 197] [Z: 7]. and remove rock:

rocks id:
1296
1297
1298
1299
remove rocks for 10 seconds and rocks back.
and NPC back to first position.

2ob.gif


Can you help me?
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
local config = {
	stone = {
		{id = 1296, pos = {x = 993, y = 196, z = 7}}, 
		{id = 1297, pos = {x = 994, y = 196, z = 7}},
		{id = 1298, pos = {x = 993, y = 197, z = 7}}, 
		{id = 1299, pos = {x = 994, y = 197, z = 7}} 
	},
	walkpos = {
		{x = 987, y = 197, z = 7},
		{x = 988, y = 197, z = 7},
		{x = 989, y = 197, z = 7},
		{x = 990, y = 197, z = 7},
		{x = 991, y = 197, z = 7},
		{x = 992, y = 197, z = 7}
	},
	walktime = 1, -- time in seconds for every step
	npcpos = {x = 986, y = 197, z = 7},
	stonebacktime = 10
}

local function removeStone()
	for s = 1, #config.stone do
		doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
	end
	return true
end

local function addStone()
	for s = 1, #config.stone do
		doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'destroy')) then
		if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
			selfSay('I can remove this rock for 100gp, do you want that?', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, there is no stone to remove.', cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100)) then
			selfSay('Ok, one moment.', cid)
			npcHandler:releaseFocus(cid)
			local time = 0
			for pos = 1, #config.walkpos do
				time = time + (config.walktime*1000)
				addEvent(doTeleportThing, time, getNpcId(), config.walkpos[pos])
			end
			local xtime = config.walktime*1000 + time
			addEvent(removeStone, xtime)
			addEvent(doTeleportThing, (config.stonebacktime * 1000) + xtime, getNpcId(), config.npcpos)
			addEvent(addStone, (config.stonebacktime * 1000) + xtime)
		else
			selfSay('You don\'t have enough money.', cid)
		end
                talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
local config = {
	stone = {
		{id = 1296, pos = {x = 993, y = 196, z = 7}}, 
		{id = 1297, pos = {x = 994, y = 196, z = 7}},
		{id = 1298, pos = {x = 993, y = 197, z = 7}}, 
		{id = 1299, pos = {x = 994, y = 197, z = 7}} 
	},
	walkpos = {
		{x = 987, y = 197, z = 7},
		{x = 988, y = 197, z = 7},
		{x = 989, y = 197, z = 7},
		{x = 990, y = 197, z = 7},
		{x = 991, y = 197, z = 7},
		{x = 992, y = 197, z = 7}
	},
	walktime = 1, -- time in seconds for every step
	npcpos = {x = 986, y = 197, z = 7},
	stonebacktime = 10
}

local function removeStone()
	for s = 1, #config.stone do
		doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
	end
	return true
end

local function addStone()
	for s = 1, #config.stone do
		doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'destroy')) then
		if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
			selfSay('I can remove this rock for 100gp, do you want that?', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, there is no stone to remove.', cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100)) then
			selfSay('Ok, one moment.', cid)
			npcHandler:releaseFocus(cid)
			local time = 0
			for pos = 1, #config.walkpos do
				time = time + (config.walktime*1000)
				addEvent(doTeleportThing, time, getNpcId(), config.walkpos[pos])
			end
			xtime = config.walktime*1000 + ((config.walktime*1000)*#config.walkpos)
			addEvent(removeStone, xtime)
			addEvent(doTeleportThing, (config.stonebacktime * 1000) + xtime, getNpcId(), config.npcpos)
			addEvent(addStone, (config.stonebacktime * 1000) + xtime)
		else
			selfSay('You don\'t have enough money.', cid)
		end
                talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Great
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
local config = {
	stone = {
		{id = 1296, pos = {x = 993, y = 196, z = 7}}, 
		{id = 1297, pos = {x = 994, y = 196, z = 7}},
		{id = 1298, pos = {x = 993, y = 197, z = 7}}, 
		{id = 1299, pos = {x = 994, y = 197, z = 7}} 
	},
	walkpos = {
		{x = 987, y = 197, z = 7},
		{x = 988, y = 197, z = 7},
		{x = 989, y = 197, z = 7},
		{x = 990, y = 197, z = 7},
		{x = 991, y = 197, z = 7},
		{x = 992, y = 197, z = 7}
	},
	walktime = 1, -- time in seconds for every step
	npcpos = {x = 986, y = 197, z = 7},
	stonebacktime = 10
}

local function removeStone()
	for s = 1, #config.stone do
		doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
	end
	return true
end

local function addStone()
	for s = 1, #config.stone do
		doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'destroy')) then
		if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
			selfSay('I can remove this rock for 100gp, do you want that?', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, there is no stone to remove.', cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100)) then
			selfSay('Ok, one moment.', cid)
			npcHandler:releaseFocus(cid)
			local time = 0
			for pos = 1, #config.walkpos do
				time = time + (config.walktime*1000)
				addEvent(doTeleportThing, time, getNpcId(), config.walkpos[pos])
			end
			local xtime = config.walktime*1000 + time
			addEvent(removeStone, xtime)
			addEvent(doTeleportThing, (config.stonebacktime * 1000) + xtime, getNpcId(), config.npcpos)
			addEvent(addStone, (config.stonebacktime * 1000) + xtime)
		else
			selfSay('You don\'t have enough money.', cid)
		end
                talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Testing:

- - - Updated - - -

AMAZING!!!!!
b90.gif

Is possible NPC back to "npcpos" but walking? and add effect groundshakers in stones?

Here script with every position:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
local config = {
	stone = {
		{id = 1296, pos = {x = 963, y = 175, z = 7}}, 
		{id = 1297, pos = {x = 964, y = 175, z = 7}},
		{id = 1298, pos = {x = 963, y = 176, z = 7}}, 
		{id = 1299, pos = {x = 964, y = 176, z = 7}} 
	},
	walkpos = {
		{x = 957, y = 176, z = 7},
		{x = 958, y = 176, z = 7},
		{x = 959, y = 176, z = 7},
		{x = 960, y = 176, z = 7},
		{x = 961, y = 176, z = 7},
		{x = 962, y = 176, z = 7}
	},
	walktime = 1, -- time in seconds for every step
	npcpos = {x = 956, y = 176, z = 7},
	stonebacktime = 10
}
 
local function removeStone()
	for s = 1, #config.stone do
		doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
	end
	return true
end
 
local function addStone()
	for s = 1, #config.stone do
		doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
	end
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'destruir')) then
		if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
			selfSay('Yo puedo remover las rocas por 100gp. Tu quieres?', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, there is no stone to remove.', cid)
		end
	elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100)) then
			selfSay('Ok, one moment.', cid)
			npcHandler:releaseFocus(cid)
			local time = 0
			for pos = 1, #config.walkpos do
				time = time + (config.walktime*1000)
				addEvent(doTeleportThing, time, getNpcId(), config.walkpos[pos])
			end
			local xtime = config.walktime*1000 + time
			addEvent(removeStone, xtime)
			addEvent(doTeleportThing, (config.stonebacktime * 1000) + xtime, getNpcId(), config.npcpos)
			addEvent(addStone, (config.stonebacktime * 1000) + xtime)
		else
			selfSay('You don\'t have enough money.', cid)
		end
                talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
local config = {
	stone = {
		{id = 1296, pos = {x = 963, y = 175, z = 7}}, 
		{id = 1297, pos = {x = 964, y = 175, z = 7}},
		{id = 1298, pos = {x = 963, y = 176, z = 7}}, 
		{id = 1299, pos = {x = 964, y = 176, z = 7}} 
	},
	walkpos = {
		{x = 957, y = 176, z = 7},
		{x = 958, y = 176, z = 7},
		{x = 959, y = 176, z = 7},
		{x = 960, y = 176, z = 7},
		{x = 961, y = 176, z = 7},
		{x = 962, y = 176, z = 7}
	},
	walktime = 1, -- time in seconds for every step
	npcpos = {x = 956, y = 176, z = 7},
	stonebacktime = 10
}

local function removeStone()
	for s = 1, #config.stone do
		doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
		doSendMagicEffect(config.stone[s].pos, CONST_ME_GROUNDSHAKER)
	end
	return true
end

local function addStone()
	for s = 1, #config.stone do
		doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
	end
	return true
end

local function npcBack(getNpc)
	local nbp = #config.walkpos
	local time = 0
	for pos = 1, #config.walkpos do
		if(nbp > 1) then
			nbp = nbp - 1
			time = time + (config.walktime*1000)
			addEvent(doTeleportThing, time, getNpc, config.walkpos[nbp])
		end
	end
	addEvent(doTeleportThing, (config.walktime*1000) + time, getNpc, config.npcpos)
	addEvent(doCreatureSetLookDirection, (config.walktime*1200) + time, getNpc, 2)
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'destruir')) then
		if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
			selfSay('Yo puedo remover las rocas por 100gp. Tu quieres?', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, there is no stone to remove.', cid)
			npcHandler:releaseFocus(cid)
		end
	elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100)) then
			selfSay('Ok, one moment.', cid)
			npcHandler:releaseFocus(cid)
			local time = 0
			for pos = 1, #config.walkpos do
				time = time + (config.walktime*1000)
				addEvent(doTeleportThing, time, getNpcId(), config.walkpos[pos])
			end
			local xtime = (config.walktime*1000) + time
			addEvent(removeStone, xtime)
			addEvent(npcBack, (config.stonebacktime * 1000) + xtime, getNpcId())
			addEvent(addStone, (config.stonebacktime * 1000) + xtime)
		else
			selfSay('You don\'t have enough money.', cid)
		end
		talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
@Limos
Good Job Limos, but I get an error, when the npc has to come back on his position, appears a random npc and walks to the config.npcpos, but the original npc who destroyed rock stays there.

Does someone happen the same as me?
 
Last edited:
Which server do you use?
Do you get an error in your console?

I tested it on TFS 0.3.6pl1 8.54 and worked fine for me.
 
Tfs 0.4 8.60

- - - Updated - - -

This script works, tested by Limos and Me :D
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
local config = {
	stone = {
		{id = 1296, pos = {x = 32379, y = 32214, z = 7}}, 
		{id = 1297, pos = {x = 32380, y = 32214, z = 7}},
		{id = 1298, pos = {x = 32379, y = 32215, z = 7}}, 
		{id = 1299, pos = {x = 32380, y = 32215, z = 7}} 
	},
	walkpos = {
		{x = 32375, y = 32215, z = 7},
		{x = 32376, y = 32215, z = 7},
		{x = 32377, y = 32215, z = 7},
		{x = 32378, y = 32215, z = 7}
	},
	walktime = 1, -- time in seconds for every step
	npcpos = {x = 32374, y = 32215, z = 7},
	stonebacktime = 10
}
 
local function removeStone()
	for s = 1, #config.stone do
		doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
		doSendMagicEffect(config.stone[s].pos, CONST_ME_GROUNDSHAKER)
	end
	return true
end
 
local function addStone()
	for s = 1, #config.stone do
		doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
	end
	return true
end
 
 
function creatureSayCallback(cid, type, msg)
local function npcBack(getNpc)
	local nbp = #config.walkpos
	local time = 0
	for pos = 1, #config.walkpos do
		if(nbp > 1) then
			nbp = nbp - 1
			time = time + (config.walktime*1000)
			addEvent(doTeleportThing, time, getNpc, config.walkpos[nbp])
		end
	end
	addEvent(doTeleportThing, (config.walktime*1000) + time, getNpc, config.npcpos)
	addEvent(doCreatureSetLookDirection, (config.walktime*1200) + time, getNpc, 2)
	return true
end
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'destruir')) then
		if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
			selfSay('Yo puedo remover las rocas por 100gp. Tu quieres?', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, there no stone to remove.', cid)
			npcHandler:releaseFocus(cid)
		end
	elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100)) then
			selfSay('Ok, one moment.', cid)
			npcHandler:releaseFocus(cid)
			local time = 0
			for pos = 1, #config.walkpos do
				time = time + (config.walktime*1000)
				addEvent(doTeleportThing, time, getNpcId(Rocker), config.walkpos[pos])
			end
			local xtime = (config.walktime*1000) + time
			addEvent(removeStone, xtime)
			addEvent(npcBack, (config.stonebacktime * 1000) + xtime, getNpcId(Rocker))
			addEvent(addStone, (config.stonebacktime * 1000) + xtime)
		else
			selfSay('You don\'t have enough money.', cid)
		end
		talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Why would you pay for scripting when Limos provides this kind of excellence for free?

Good work.

Cheers,
Yodot.
 
To make the animation look less glitchy - make the walk time 1.4 seconds. :)
 
Back
Top