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

[HELP] Quest npc, whats wrong with this script? Rep+ for help. (script inside)

Falazen

New Member
Joined
Feb 18, 2008
Messages
82
Reaction score
2
Greetings once more, OtLand. I've got another issue. Im currently creating an NPC that will allow you to enter a mine (hunting area) for completing a simple quest for him. Below is the NPC I have, If someone could show me what I'm doing wrong, or make a new one that works, that would be wonderful.

What I want is to simply check if you have certain storage values, and if they are correct, he will reward you with access to his mines (another value.) You get the storage value from killing a troll king, which is added via an OnKill script i've made, so that is not needed.

The current issue is when I try to accept the quest by saying "join", no response is given, and likewise, no error is logged.

I'm using the latest TFS version (0.3.2?)

miner.lua
PHP:
local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end

local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v) == TRUE) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

local itemWindow = {
	{id=2553, subType=0, buy=2000, sell=0, name="Pickaxe"}
}

local items = {}
for _, item in ipairs(itemWindow) do
	items[item.id] = {buyPrice = item.buy, sellPrice = item.sell, subType = item.subType, realName = item.name}
end

local function getPlayerMoney(cid)
	return ((getPlayerItemCount(cid, 2160) * 10000) +
	(getPlayerItemCount(cid, 2152) * 100) +
	getPlayerItemCount(cid, 2148))
end

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. What this be? I not be buying this.", cid)
		return
	end

	if(getPlayerMoney(cid) >= amount * items[item].buyPrice) then
		local itemz, i = doNpcSellItem(cid, item, amount, subType, ignoreCap, inBackpacks)
		if(i < amount) then
			if(i == 0) then
				selfSay("Ye needs more strength. Ye cannot support any more weights.", cid)
			else
				selfSay("Here be what ye paid for, but ye lack the strength to carry no more weights.", cid)
				doPlayerRemoveMoney(cid, i * items[item].buyPrice)
			end
		else
			selfSay("Thank'e!", cid)
			doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
		end
	else
		selfSay("Ye lacks the funds to purchase mine goods.", cid)
	end
end

local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. What this be? I not be buying this.", cid)
	end

	if(subType < 1) then
		subType = -1
	end
	if(doPlayerRemoveItem(cid, item, amount, subType) == TRUE) then
		doPlayerAddMoney(cid, items[item].sellPrice * amount)
		selfSay("Here ye go.", cid)
	else
		selfSay("Lack item, not get the golds.", cid)
	end
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid) == TRUE) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end

function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, TRUE)
		selfSay("Interested in some mining? I can {trade} ye the picks and admit ye into the {Miners Society}.", cid)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "wares" or msg == "trade")) then
		selfSay("Is all me has.", cid)
		openShopWindow(cid, itemWindow, onBuy, onSell)
	elseif((isFocused(cid)) and (msg == "miners society" or msg == "society")) then
		queststatus = getPlayerStorageValue(cid,29999)
		if queststatus == -1 then
		selfSay("Yes. Ye needs to be one member of the Society in orders to be given access to the mines. Do ye wishes to {join}?", cid)
	elseif((isFocused(cid)) and (msg == "join" or msg == "yes")) then
   		setPlayerStorageValue(cid,29999,1)
		selfSay("Goods, goods. Ye will not be admitteds that easy, thoughs. Ye must bring me proof of ye loyalties...", cid)
		selfSay("Is easy task. Search the easts of the town, near the mountains. Searches for the troll king and bring me proofs of his death... ", cid)
		selfSay("He has stolen from mine treasurey for his last times. Ask me about the {troll king} when completes.", cid)
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Bye.", cid, TRUE)
		closeShopWindow(cid)
		removeFocus(cid)
	elseif((isFocused(cid)) and (msg == "troll" or msg == "quest")) then
		queststatus3 = getPlayerStorageValue(cid,30001,2)
		queststatus2 = getPlayerStorageValue(cid,30002,1)
		if queststatus3 == 1 then
		if queststatus2 == -1 then
   		setPlayerStorageValue(cid,30002,1)
		selfSay("Thank'e! Now mine treasures are safes. Ye are welcome to use mine mines from now on.", cid)
	end
end
end 
end
end

function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onPlayerEndTrade(cid)
	selfSay("Twas mine pleasure for thyne business.", cid)
end

function onThink()
	for i, focus in pairs(focuses) do
		if(isCreature(focus) == FALSE) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Hmph!")
				closeShopWindow(focus)
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end


Miner Mika.xml
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Miner Mike" script="data/npc/scripts/miner.lua" walkinterval="2000" floorchange="0" skull="green">
	<health now="150" max="150"/>
	<look type="139" head="132" body="79" legs="97" feet="132" corpse="2212"/>
</npc>
 
Back
Top