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

Encountered Problem with Npc

8408323

Hoster
Joined
Mar 6, 2009
Messages
432
Reaction score
26
Here's my problem:

[15/04/2012 23:19:54] [Error - LuaScriptInterface::loadFile] data/npc/scripts/shop.lua:37: '}' expected (to close '{' at line 34) near '{'
[15/04/2012 23:19:54] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/shop.lua
[15/04/2012 23:19:54] data/npc/scripts/shop.lua:37: '}' expected (to close '{' at line 34) near '{'
[15/04/2012 23:21:56] > Broadcasted message: "Full server save within 120 seconds, please mind it may freeze!".


LUA:
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)) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

local itemWindow = {
	{id=7958, subType=0, buy=1, sell=0, name="10sP", Bpoints = 10, Spoints = 5},
	{id=7958, subType=0, buy=0, sell=1, name="5sP", Bpoints = 10, Spoints = 5}
	{id=7426, subType=0, buy=1, sell=0, name="10ssP", Bpoints = 10, Spoints = 5},
	{id=7426, subType=0, buy=0, sell=1, name="5ssP", Bpoints = 10, Spoints = 5}
	{id=7435, subType=0, buy=1, sell=0, name="10aP", Bpoints = 10, Spoints = 5},
	{id=7435, subType=0, buy=0, sell=1, name="5aP", Bpoints = 10, Spoints = 5}
	{id=7416, subType=0, buy=1, sell=0, name="10dP", Bpoints = 10, Spoints = 5},
	{id=7416, subType=0, buy=0, sell=1, name="5dP", Bpoints = 10, Spoints = 5}
	{id=7461, subType=0, buy=1, sell=0, name="10fP", Bpoints = 10, Spoints = 5},
	{id=7461, subType=0, buy=0, sell=1, name="5fP", Bpoints = 10, Spoints = 5}
	{id=2507, subType=0, buy=1, sell=0, name="10gP", Bpoints = 10, Spoints = 5},
	{id=2507, subType=0, buy=0, sell=1, name="5gP", Bpoints = 10, Spoints = 5}
	{id=5907, subType=0, buy=1, sell=0, name="10hP", Bpoints = 10, Spoints = 5},
	{id=5907, subType=0, buy=0, sell=1, name="5hP", Bpoints = 10, Spoints = 5}
	{id=9932, subType=0, buy=1, sell=0, name="10jP", Bpoints = 10, Spoints = 5},
	{id=9932, subType=0, buy=0, sell=1, name="5jP", Bpoints = 10, Spoints = 5}
	}

--{id=5785, subType=0, buy=1, sell=0, name="10P", Bpoints = 10, Spoints = 5},
	--{id=5785, subType=0, buy=0, sell=1, name="5P", Bpoints = 10, Spoints = 5}

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

local function getPlayerMoney(cid)
	return getAccountPremiumPoints(cid)
end

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not selling it.", cid)
		return
	end

	if(getPlayerMoney(cid) >= amount * items[item].Bpoints) then
		if(getPlayerFreeCap(cid) >= getItemWeightById(item,amount)) then
			local new_item = doCreateItemEx(item, amount)
            local received_item = doPlayerAddItemEx(cid, new_item)
			if received_item == RETURNVALUE_NOERROR then
				selfSay("Thanks for the money!", cid)
				doAccountRemovePremiumPoints(cid, amount * items[item].Bpoints)
			else
				selfSay("You have no space for this item!", cid)
			end
		else
			selfSay("You can't carry this!", cid)
		end
	else
		selfSay("Buy more premium points at {www.goblinsfow.no-ip.org}", cid)
	end
end

local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not buying it.", cid)
	end

	if(subType < 1) then
		subType = -1
	end
	if(doPlayerRemoveItem(cid, item, amount, subType)) then
		doAccountAddPremiumPoints(cid, items[item].Spoints * amount)
		selfSay("Here you are.", cid)
	else
		selfSay("No item, no deal.", cid)
	end
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid)) 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("Do you want to see my {wares}?", cid)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "wares" or msg == "trade")) then
		selfSay("Pretty nice, right?", cid)
		openShopWindow(cid, itemWindow, onBuy, onSell)
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", cid, true)
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

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

function onPlayerEndTrade(cid)
	selfSay("It was a pleasure doing business with you.", cid)
end

function onThink()
	for i, focus in pairs(focuses) do
		if(not isCreature(focus)) 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

do anyone know how to fix it?
 
Last edited:
Back
Top