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

Solved 011-string.lua problem!

Snooczek

New Member
Joined
Apr 29, 2011
Messages
15
Reaction score
0
Location
Poland
Hello, after compiling 9.6 sources everything ran well but when I tried to open doors, use GM and GOD commands problems started to appear!

Code:
[Error - TalkAction Interface]
data/talkactions/script/teleporttown.lua:onSay
Description:
data/lib/011-string.lua:11: attempt to call global 'isInArray' <a
nil value>
stack traceback:
data/lib/011-string.lua:11: in function 'explode'
data/talkaction/scripts/teleporttown.lua:15: in function <data/
talkactions/scripts/teleporttown.lua:1>


Code:
[Error - TalkAction Interface]
data/talkactions/scripts/createitem.lua:onSay
Description:
data/lib/011-string.lua:11: attempt to call global 'isInArray' <a
nil value>
stack traceback:
data/lib/011-string.lua:11: in fuction 'explode'
data/talkactions/scripts/createitem.lua:7: in function <data/tal
kactions/scripts/createitem.lua:1
 
Last edited:
Test this

Talkactions / teleporttown
Code:
function onSay(cid, words, param, channel)
	local master = false
	if(words == '/t') then
		master = true
	elseif(param == '') then
		local str = ""
		for i, town in ipairs(getTownList()) do
			str = str .. town.name .. "\n"
		end

		doShowTextDialog(cid, ITEM_ACTION_BOOK, str)
		return true
	end

	local tid, t = cid, string.explode(param, ",")
	if(t[(master and 1 or 2)]) then
		tid = getPlayerByNameWildcard(t[(master and 1 or 2)])
		if(not tid or (isPlayerGhost(tid) and getPlayerAccess(tid) > getPlayerAccess(cid))) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. t[(master and 1 or 2)] .. " not found.")
			return true
		end
	end

	local tmp = getPlayerTown(tid)
	if(not master) then
		tmp = t[1]
		if(not tonumber(tmp)) then
			tmp = getTownId(tmp)
			if(not tmp) then
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Town " .. t[1] .. " does not exists.")
				return true
			end
		end
	end

	local pos = getTownTemplePosition(tmp)
	if(type(pos) ~= 'table' or isInArray({pos.x, pos.y}, 0)) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Town " .. t[1] .. " does not exists or has invalid temple position.")
		return true
	end

	pos = getClosestFreeTile(tid, pos)
	if(type(pos) ~= 'table' or isInArray({pos.x, pos.y}, 0)) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Destination not reachable.")
		return true
	end

	tmp = getCreaturePosition(tid)
	if(doTeleportThing(tid, pos) and not isPlayerGhost(tid)) then
		doSendMagicEffect(tmp, CONST_ME_POFF)
		doSendMagicEffect(pos, CONST_ME_TELEPORT)
	end

	return true
end

Talkactions / createitem
Code:
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local t = string.explode(param, ",")
	local ret = RETURNVALUE_NOERROR
	local pos = getCreaturePosition(cid)

	local id = tonumber(t[1])
	if(not id) then
		errors(false)
		id = getItemIdByName(t[1])
		errors(true)

		if(not id) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
			return true
		end
	end

	local amount = 100
	if(t[2]) then
		amount = t[2]
	end

	local item = doCreateItemEx(id, amount)
	if(t[3] and getBooleanFromString(t[3])) then
		if(t[4] and getBooleanFromString(t[4])) then
			pos = getCreatureLookPosition(cid)
		end

		ret = doTileAddItemEx(pos, item)
	else
		ret = doPlayerAddItemEx(cid, item, true)
	end

	if(ret ~= RETURNVALUE_NOERROR) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Couldn't add item: " .. t[1])
		return true
	end

	doDecayItem(item)
	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(pos, CONST_ME_MAGIC_RED)
	end

	return true
end

Lib
Code:
string.split = function (str)
	local t = {}
	return not str:gsub("%w+", function(s) table.insert(t, s) return "" end):find("%S") and t or {}
end

string.trim = function (str)
	return str:gsub("^%s*(.-)%s*$", "%1")
end

string.explode = function (str, sep, limit)
	if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
		return {}
	end

	local i, pos, tmp, t = 0, 1, "", {}
	for s, e in function() return string.find(str, sep, pos) end do
		tmp = str:sub(pos, s - 1):trim()
		table.insert(t, tmp)
		pos = e + 1

		i = i + 1
		if(limit ~= nil and i == limit) then
			break
		end
	end

	tmp = str:sub(pos):trim()
	table.insert(t, tmp)
	return t
end

string.expand = function (str)
	return string.gsub(str, "$(%w+)", function(n) return _G[n] end)
end

string.diff = function (diff)
	local format = {
		{"week", diff / 60 / 60 / 24 / 7},
		{"day", diff / 60 / 60 / 24 % 7},
		{"hour", diff / 60 / 60 % 24},
		{"minute", diff / 60 % 60},
		{"second", diff % 60}
	}

	local t = {}
	for k, v in ipairs(format) do
		local d, tmp = math.floor(v[2]), ""
		if(d > 0) then
			tmp = (k < table.maxn(format) and (table.maxn(t) > 0 and ", " or "") or " and ") .. d .. " " .. v[1] .. (d ~= 1 and "s" or "")
			table.insert(t, tmp)
		end
	end

	return t
end
string.timediff = string.diff

string.boolean = function (input)
	local tmp = type(input)
	if(tmp == 'boolean') then
		return input
	end

	if(tmp == 'number') then
		return input > 0
	end

	local str = string.lower(tostring(input))
	return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
end
getBooleanFromString = string.boolean

test and post
 
Thank you djtuca but I don't need it anymore. I just found an solution with changing lib folders to newer ones! It worked! Thank you anyway for you help :)
 
Back
Top