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

data/lib/050-function.lua:2: attempt to call global 'type' (a string value)

ximmy

Member
Joined
Oct 31, 2009
Messages
374
Reaction score
6
console error:

Code:
[13:1:50.204] Description:
[13:1:50.204] data/lib/050-function.lua:2: attempt to call global 'type' (a string value)
[13:1:50.204] stack traceback:
[13:1:50.204]   data/lib/050-function.lua:2: in function 'isInArray'
[13:1:50.204]   [string "LuaInterface::loadBuffer"]:28: in function <[string "LuaInterface::loadBuffer"]:3>


function from 050-function.lua:

Code:
function isInArray(array, value, caseSensitive)
	if(caseSensitive == nil or caseSensitive == false) and type(value) == "string" then
		local lowerValue = value:lower()
		for _, _value in ipairs(array) do
			if type(_value) == "string" and lowerValue == _value:lower() then
				return true
			end
		end
	else
		for _, _value in ipairs(array) do
			if (value == _value) then return true end
		end
	end

	return false
end

Code fragment where function is use
Code:
			function onThink(cid, interval)
				if isInArray(daysOpen, os.date('%A')) then
					if isInArray(configRushEvent.days[os.date('%A')], os.date('%X', os.time())) then
						if getStorage(configRushEvent.storages.joining) ~= 1 then
							doStartCountingRushEvent(0)

							for _, pid in ipairs(getPlayersOnline()) do
								if tostring(getCreatureStorage(pid, configRushEvent.storages.player)) ~= '' then
									doCreatureSetStorage(pid, configRushEvent.storages.player, '')
									doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
									doRemoveCondition(pid, CONDITION_OUTFIT)
								end
							end

							doSetStorage(configRushEvent.storages.joining, 1)
							addEvent(doStartRushEvent, configRushEvent.delayTime * 60 * 1000)
						end
					end
				end

				return true
			end
Code:
function onStatsChange(cid, attacker, type, combat, value)
				if type == 1 and getCreatureHealth(cid) <= value then
					if isInRange(getThingPos(cid), configRushEvent.room.from, configRushEvent.room.to) then
						if isPlayer(cid) then
							local p = tostring(getCreatureStorage(cid, configRushEvent.storages.player))
							doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
							doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
							doTeleportThing(cid, p ~= 'blue' and configRushEvent.position.red or configRushEvent.position.blue)
							doCreatureSetNoMove(cid, true)
							addEvent(doCreatureSetNoMove, configRushEvent.waitTime * 1000, cid, false)

							if p ~= 'blue' then
								doSetStorage(configRushEvent.storages.b_score, math.max(getStorage(configRushEvent.storages.b_score), 0) + 1)
								if getStorage(configRushEvent.storages.b_score) == configRushEvent.fragLimit then
									doStopRushEvent()
								end
							else
								doSetStorage(configRushEvent.storages.r_score, math.max(getStorage(configRushEvent.storages.r_score), 0) + 1)
								if getStorage(configRushEvent.storages.r_score) == configRushEvent.fragLimit then
									doStopRushEvent()
								end
							end
							return false
						end
					end
				elseif isInArray({1,3}, type) and isPlayer(attacker) and isPlayer(cid) then
					if isInRange(getThingPos(cid), configRushEvent.room.from, configRushEvent.room.to) then
						if tostring(getCreatureStorage(cid, configRushEvent.storages.player)) == tostring(getCreatureStorage(attacker, configRushEvent.storages.player)) then
							return false
						end
					end
				end
				return true
			end

Someone can fix? :)
 
Last edited:
Code:
function isInArray(array, value, caseSensitive)
	if(caseSensitive == nil or caseSensitive == false) and type(value) == "string" then
		local lowerValue = value:lower()
		for _, _value in ipairs(array) do
			if type(_value) == "string" and lowerValue == _value:lower() then
				return true
			end
		end
	else
		for _, _value in ipairs(array) do
			if (value == _value) then return true end
		end
	end

	return false
end

function doPlayerGiveItem(cid, itemid, amount, subType)
	local item = 0
	if(isItemStackable(itemid)) then
		item = doCreateItemEx(itemid, amount)
		if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
			return false
		end
	else
		for i = 1, amount do
			item = doCreateItemEx(itemid, subType)
			if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
				return false
			end
		end
	end

	return true
end

function doPlayerGiveItemContainer(cid, containerid, itemid, amount, subType)
	for i = 1, amount do
		local container = doCreateItemEx(containerid, 1)
		for x = 1, getContainerCapById(containerid) do
			doAddContainerItem(container, itemid, subType)
		end

		if(doPlayerAddItemEx(cid, container, true) ~= RETURNVALUE_NOERROR) then
			return false
		end
	end

	return true
end

function doPlayerTakeItem(cid, itemid, amount)
	return getPlayerItemCount(cid, itemid) >= amount and doPlayerRemoveItem(cid, itemid, amount)
end

function doPlayerSellItem(cid, itemid, count, cost)
	if(not doPlayerTakeItem(cid, itemid, count)) then
		return false
	end

	if(not doPlayerAddMoney(cid, cost)) then
		error('[doPlayerSellItem] Could not add money to: ' .. getPlayerName(cid) .. ' (' .. cost .. 'gp).')
	end

	return true
end

function doPlayerWithdrawMoney(cid, amount)
	if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
		return false
	end

	local balance = getPlayerBalance(cid)
	if(amount > balance or not doPlayerAddMoney(cid, amount)) then
		return false
	end

	doPlayerSetBalance(cid, balance - amount)
	return true
end

function doPlayerDepositMoney(cid, amount)
	if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
		return false
	end

	if(not doPlayerRemoveMoney(cid, amount)) then
		return false
	end

	doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
	return true
end

function doPlayerAddStamina(cid, minutes)
	return doPlayerSetStamina(cid, getPlayerStamina(cid) + minutes)
end

function isPremium(cid)
	return (isPlayer(cid) and (getPlayerPremiumDays(cid) > 0 or getBooleanFromString(getConfigValue('freePremium'))))
end

function getMonthDayEnding(day)
	if(day == "01" or day == "21" or day == "31") then
		return "st"
	elseif(day == "02" or day == "22") then
		return "nd"
	elseif(day == "03" or day == "23") then
		return "rd"
	end

	return "th"
end

function getMonthString(m)
	return os.date("%B", os.time{year = 1970, month = m, day = 1})
end

function getArticle(str)
	return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
end

function doNumberFormat(i)
	local str, found = string.gsub(i, "(%d)(%d%d%d)$", "%1,%2", 1), 0
	repeat
		str, found = string.gsub(str, "(%d)(%d%d%d),", "%1,%2,", 1)
	until found == 0
	return str
end

function doPlayerAddAddons(cid, addon)
	for i = 0, table.maxn(maleOutfits) do
		doPlayerAddOutfit(cid, maleOutfits[i], addon)
	end

	for i = 0, table.maxn(femaleOutfits) do
		doPlayerAddOutfit(cid, femaleOutfits[i], addon)
	end
end

function getTibiaTime(num)
	local minutes, hours = getWorldTime(), 0
	while (minutes > 60) do
		hours = hours + 1
		minutes = minutes - 60
	end

	if(num) then
		return {hours = hours, minutes = minutes}
	end

	return {hours =  hours < 10 and '0' .. hours or '' .. hours, minutes = minutes < 10 and '0' .. minutes or '' .. minutes}
end

function doWriteLogFile(file, text)
	local f = io.open(file, "a+")
	if(not f) then
		return false
	end

	f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
	f:close()
	return true
end

function getExperienceForLevel(lv)
	lv = lv - 1
	return ((50 * lv * lv * lv) - (150 * lv * lv) + (400 * lv)) / 3
end

function doMutePlayer(cid, time)
	local condition = createConditionObject(CONDITION_MUTED, (time == -1 and time or time * 1000))
	return doAddCondition(cid, condition, false)

end

function doSummonCreature(name, pos)
	local cid = doCreateMonster(name, pos, false, false)
	if(not cid) then
		cid = doCreateNpc(name, pos)
	end

	return cid
end

function getPlayersOnlineEx()
	local players = {}
	for i, cid in ipairs(getPlayersOnline()) do
		table.insert(players, getCreatureName(cid))
	end

	return players
end

function getPlayerByName(name)
	local cid = getCreatureByName(name)
	return isPlayer(cid) and cid or nil
end

function isPlayer(cid)
	return isCreature(cid) and cid >= AUTOID_PLAYERS and cid < AUTOID_MONSTERS
end

function isPlayerGhost(cid)
	return isPlayer(cid) and (getCreatureCondition(cid, CONDITION_GAMEMASTER, GAMEMASTER_INVISIBLE, CONDITIONID_DEFAULT) or getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBESEEN))
end

function isMonster(cid)
	return isCreature(cid) and cid >= AUTOID_MONSTERS and cid < AUTOID_NPCS
end

function isNpc(cid)
	-- Npc IDs are over int32_t range (which is default for lua_pushnumber),
	-- therefore number is always a negative value.
	return isCreature(cid) and (cid < 0 or cid >= AUTOID_NPCS)
end

function isUnderWater(cid)
	return isInArray(underWater, getTileInfo(getCreaturePosition(cid)).itemid)
end

function doPlayerAddLevel(cid, amount, round)
	local experience, level, amount = 0, getPlayerLevel(cid), amount or 1
	if(amount > 0) then
		experience = getExperienceForLevel(level + amount) - (round and getPlayerExperience(cid) or getExperienceForLevel(level))
	else
		experience = -((round and getPlayerExperience(cid) or getExperienceForLevel(level)) - getExperienceForLevel(level + amount))
	end

	return doPlayerAddExperience(cid, experience)
end

function doPlayerAddMagLevel(cid, amount)
	local amount = amount or 1
	for i = 1, amount do
		doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true) + 1) - getPlayerSpentMana(cid), false)
	end

	return true
end

function doPlayerAddSkill(cid, skill, amount, round)
	local amount = amount or 1
	if(skill == SKILL__LEVEL) then
		return doPlayerAddLevel(cid, amount, round)
	elseif(skill == SKILL__MAGLEVEL) then
		return doPlayerAddMagLevel(cid, amount)
	end

	for i = 1, amount do
		doPlayerAddSkillTry(cid, skill, getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill), false)
	end

	return true
end

function isPrivateChannel(channelId)
	return channelId >= CHANNEL_PRIVATE
end

function doBroadcastMessage(text, class)
	local class = class or MESSAGE_STATUS_WARNING
	if(type(class) == 'string') then
		local className = MESSAGE_TYPES[class]
		if(className == nil) then
			return false
		end

		class = className
	elseif(class < MESSAGE_FIRST or class > MESSAGE_LAST) then
		return false
	end

	for _, pid in ipairs(getPlayersOnline()) do
		doPlayerSendTextMessage(pid, class, text)
	end

	print("> Broadcasted message: \"" .. text .. "\".")
	return true
end

function doPlayerBroadcastMessage(cid, text, class, checkFlag, ghost)
	local checkFlag, ghost, class = checkFlag or true, ghost or false, class or TALKTYPE_BROADCAST
	if(checkFlag and not getPlayerFlagValue(cid, PLAYERFLAG_CANBROADCAST)) then
		return false
	end

	if(type(class) == 'string') then
		local className = TALKTYPE_TYPES[class]
		if(className == nil) then
			return false
		end

		class = className
	elseif(class < TALKTYPE_FIRST or class > TALKTYPE_LAST) then
		return false
	end

	for _, pid in ipairs(getPlayersOnline()) do
		doCreatureSay(cid, text, class, ghost, pid)
	end

	print("> " .. getCreatureName(cid) .. " broadcasted message: \"" .. text .. "\".")
	return true
end

function doCopyItem(item, attributes)
	local attributes = ((type(attributes) == 'table') and attributes or { "aid" })

	local ret = doCreateItemEx(item.itemid, item.type)
	for _, key in ipairs(attributes) do
		local value = getItemAttribute(item.uid, key)
		if(value ~= nil) then
			doItemSetAttribute(ret, key, value)
		end
	end

	if(isContainer(item.uid)) then
		for i = (getContainerSize(item.uid) - 1), 0, -1 do
			local tmp = getContainerItem(item.uid, i)
			if(tmp.itemid > 0) then
				doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
			end
		end
	end

	return getThing(ret)
end

function doSetItemText(uid, text, writer, date)
	local thing = getThing(uid)
	if(thing.itemid < 100) then
		return false
	end

	doItemSetAttribute(uid, "text", text)
	if(writer ~= nil) then
		doItemSetAttribute(uid, "writer", tostring(writer))
		if(date ~= nil) then
			doItemSetAttribute(uid, "date", tonumber(date))
		end
	end

	return true
end

function getItemWeightById(itemid, count, precision)
	local item, count, precision = getItemInfo(itemid), count or 1, precision or false
	if(not item) then
		return false
	end

	if(count > 100) then
		-- print a warning, as its impossible to have more than 100 stackable items without "cheating" the count
		print('[Warning] getItemWeightById', 'Calculating weight for more than 100 items!')
	end

	local weight = item.weight * count
	return precission and weight or math.round(weight, 2)
end

function choose(...)
	local arg, ret = {...}

	if type(arg[1]) == 'table' then
		ret = arg[1][math.random(#arg[1])]
	else
		ret = arg[math.random(#arg)]
	end

	return ret
end

function doPlayerAddExpEx(cid, amount)
	if(not doPlayerAddExp(cid, amount)) then
		return false
	end

	local position = getThingPosition(cid)
	doPlayerSendTextMessage(cid, MESSAGE_EXPERIENCE, "You gained " .. amount .. " experience.", amount, COLOR_WHITE, position)

	local spectators, name = getSpectators(position, 7, 7), getCreatureName(cid)
	for _, pid in ipairs(spectators) do
		if(isPlayer(pid) and cid ~= pid) then
			doPlayerSendTextMessage(pid, MESSAGE_EXPERIENCE_OTHERS, name .. " gained " .. amount .. " experience.", amount, COLOR_WHITE, position)
		end
	end

	return true
end

function getItemTopParent(uid)
	local parent = getItemParent(uid)
	if(not parent or parent.uid == 0) then
		return nil
	end

	while(true) do
		local tmp = getItemParent(parent.uid)
		if(tmp and tmp.uid ~= 0) then
			parent = tmp
		else
			break
		end
	end

	return parent
end

function getItemHolder(uid)
	local parent = getItemParent(uid)
	if(not parent or parent.uid == 0) then
		return nil
	end

	local holder = nil
	while(true) do
		local tmp = getItemParent(parent.uid)
		if(tmp and tmp.uid ~= 0) then
			if(tmp.itemid == 1) then -- a creature
				holder = tmp
				break
			end

			parent = tmp
		else
			break
		end
	end

	return holder
end

function valid(f)
	return function(p, ...)
		if(isCreature(p)) then
			return f(p, ...)
		end
	end
end
 
Try this:
LUA:
function onStatsChange(cid, attacker, _type, combat, value)
				if _type == 1 and getCreatureHealth(cid) <= value then
					if isInRange(getThingPos(cid), configRushEvent.room.from, configRushEvent.room.to) then
						if isPlayer(cid) then
							local p = tostring(getCreatureStorage(cid, configRushEvent.storages.player))
							doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
							doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
							doTeleportThing(cid, p ~= 'blue' and configRushEvent.position.red or configRushEvent.position.blue)
							doCreatureSetNoMove(cid, true)
							addEvent(doCreatureSetNoMove, configRushEvent.waitTime * 1000, cid, false)

							if p ~= 'blue' then
								doSetStorage(configRushEvent.storages.b_score, math.max(getStorage(configRushEvent.storages.b_score), 0) + 1)
								if getStorage(configRushEvent.storages.b_score) == configRushEvent.fragLimit then
									doStopRushEvent()
								end
							else
								doSetStorage(configRushEvent.storages.r_score, math.max(getStorage(configRushEvent.storages.r_score), 0) + 1)
								if getStorage(configRushEvent.storages.r_score) == configRushEvent.fragLimit then
									doStopRushEvent()
								end
							end
							return false
						end
					end
				elseif isInArray({1,3}, _type) and isPlayer(attacker) and isPlayer(cid) then
					if isInRange(getThingPos(cid), configRushEvent.room.from, configRushEvent.room.to) then
						if tostring(getCreatureStorage(cid, configRushEvent.storages.player)) == tostring(getCreatureStorage(attacker, configRushEvent.storages.player)) then
							return false
						end
					end
				end
				return true
			end
 
the same

Code:
[20:58:09.597] [Error - CreatureScript Interface]
[20:58:09.597]                  domodlib("lib_rush_event")

[20:58:09.597]                  function onStatsChange(cid, attacker, _type, combat, value)
[20:58:09.597]                          if _type == 1 and getCreatureHealth(cid) <= value then
[20:58:09.597]                                  if isInRange(getThingPos(cid), configRushEvent.room.from, configRushEvent.room.to) then
[20:58:09.597]                                          if isPlayer(cid) then
[20:58:09.597]                                                  local p = tostring(getCreatureStorage(cid, configRushEvent.storages.player))
[20:58:09.597]                                                  doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
[20:58:09.597]                                                  doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
[20:58:09.597]                                                  doTeleportThing(cid, p ~= 'blue' and configRushEvent.position.red or configRushEvent.position.blue)
[20:58:09.597]                                                  doCreatureSetNoMove(cid, true)
[20:58:09.597]                                                  addEvent(doCreatureSetNoMove, configRushEvent.waitTime * 1000, cid, false)
[20:58:09.597]
[20:58:09.597]                                                  if p ~= 'blue' then
[20:58:09.598]                                                          doSetStorage(configRushEvent.storages.b_score, math.max(getStorage(configRushEvent.storages.b_score), 0) + 1)
[20:58:09.598]                                                          if getStorage(configRushEvent.storages.b_score) == configRushEvent.fragLimit then
[20:58:09.598]                                                                  doStopRushEvent()
[20:58:09.598]                                                          end
[20:58:09.598]                                                  else
[20:58:09.598]                                                          doSetStorage(configRushEvent.storages.r_score, math.max(getStorage(configRushEvent.storages.r_score), 0) + 1)
[20:58:09.598]                                                          if getStorage(configRushEvent.storages.r_score) == configRushEvent.fragLimit then
[20:58:09.598]                                                                  doStopRushEvent()
[20:58:09.598]                                                          end
[20:58:09.598]                                                  end
[20:58:09.598]                                                  return false
[20:58:09.598]                                          end
[20:58:09.598]                                  end
[20:58:09.598]                          elseif isInArray({1,3}, _type) and isPlayer(attacker) and isPlayer(cid) then
[20:58:09.598]                                  if isInRange(getThingPos(cid), configRushEvent.room.from, configRushEvent.room.to) then
[20:58:09.598]                                          if tostring(getCreatureStorage(cid, configRushEvent.storages.player)) == tostring(getCreatureStorage(attacker, configRushEvent.storages.player)) then
[20:58:09.598]                                                  return false
[20:58:09.598]                                          end
[20:58:09.598]                                  end
[20:58:09.598]                          end
[20:58:09.598]                          return true
[20:58:09.598]                  end
[20:58:09.598]          :onStatsChange
[20:58:09.598] Description:
[20:58:09.598] data/lib/050-function.lua:2: attempt to call global 'type' (a string value)
[20:58:09.598] stack traceback:
[20:58:09.598]  data/lib/050-function.lua:2: in function 'isInArray'
[20:58:09.598]  [string "LuaInterface::loadBuffer"]:28: in function <[string "LuaInterface::loadBuffer"]:3>
 
Back
Top