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

isInArray

PHP:
table = {"First", "Second", "Third"}
check = isInArray(table, "Second")
check2 = isInArray(table, "NotIn")
print(check, check2)

Try that piece of code :p
It simply returns 1 if that is in the array, but if it's not in the array, I think it returns -1, check the script and see by yourself...

Although, it doesn't take spaces, if you'd check like "Hello mr", I THINK it'd only check "Hello", or nothing at all, not sure. But you could make your own function for this:
PHP:
-- Function by Colandus
function isInArray(t, v, c)
	v = (c ~= nil and string.lower(v)) or v
	if type(t) == "table" and v ~= nil then
		for key, value in pairs(t) do
			value = (c ~= nil and string.lower(value)) or value
			if v == value then
				return 1
			end
		end
	end
	return -1
end

This one works exactly the same, but only that in NORMAL isInArray, it's case-sensetive, which means:
PHP:
table = {"First", "Second", "Third"}
check = isInArray(table, "Second")
check2 = isInArray(table, "THIRD")
print(check, check2)
Would print -1 -1, even though Third is in the array, but THIRD is not in. But my function, will allow incase-sensetivity if you just write something at the last parameter:
PHP:
-- Using my isInArray (in global.lua)
table = {"First", "Second", "Third", "4th Fourth"}
check = isInArray(table, "4th Fourth")
check2 = isInArray(table, "THIRD", true)
print(check, check2)
This will print 1 1, because spaces does work and incase-sensitivity was on at the second check.

Regards,
Colandus
 
Last edited:
this work?
Code:
tilex = {120, 121, 122, 123, 124, 125, 126, 127, 128, 129}
tiley = {32, 33, 34, 35, 36, 37, 38, 39}
tilez = {9}

if (isInArray(tilex, getPlayerPosition(cid).x) == TRUE) and (isInArray(tiley, getPlayerPosition(cid).y) == TRUE) and (isInArray(tilez, getPlayerPosition(cid).z) == TRUE) and getCreatureHealth(cid) < 1 then
arena = TRUE
else
arena = FALSE
end
 
Well... The isInArray part will work, but what's TRUE? Is it 1? Check in global.lua if it's 1 :p

Also, "and getCreatureHealth(cid) < 1", that's impossible, so it'll always return "FALSE" for the "arena" variable.

A slighter way would be to use a loop for this check instead.
PHP:
local position = {fromx=120, fromy=32, tox=129, toy=39, z=9}
 
function onUse(cid, item, frompos, item2, topos)
	for i = position.fromx, position.tox do
		for j = position.fromy, position.toy do
			local pos = {x=i, y=j, z=position.z, stackpos=253}
			local getThing = getThingfromPos(pos).uid
			if isPlayer(getThing) == 1 then
				//Player found, return a value to break the loop.
			end
		end
	end
	return FALSE
end
 
Last edited:
Back
Top