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

function onThink(cid, interval), remove creatures when X players in area.

Status
Not open for further replies.

richux

Tibera.org
Joined
Aug 18, 2008
Messages
3,666
Reaction score
26
Location
---------
Hello! Could someone help me to finish this script, I fail do it doing it myself?

error:

Code:
[22:21:35.698] [Error - GlobalEvent Interface]
[22:21:35.698] data/globalevents/scripts/deadlyArena.lua:onThink
[22:21:35.698] Description:
[22:21:35.698] (luaGetThingPosition) Thing not found

[22:21:35.698] [Error - GlobalEvent Interface]
[22:21:35.698] data/globalevents/scripts/deadlyArena.lua:onThink
[22:21:35.698] Description:
[22:21:35.698] data/lib/032-position.lua:2: attempt to index local 'position' (a boolean value)
[22:21:35.698] stack traceback:
[22:21:35.698]  data/lib/032-position.lua:2: in function 'isInRange'
[22:21:35.698]  data/globalevents/scripts/deadlyArena.lua:10: in function <data/globalevents/scripts/deadlyArena.lua:8>
[22:21:35.698] [Error - GlobalEvents::think] Couldn't execute event: deadlyArena


script:
LUA:
local config = {
		ghleftarena = {
			frompos = {x = 3041, y = 2986, z =9},
			topos = {x = 3052, y = 2991, z=9}
		}
}

function onThink(cid, interval)

if (isInRange(getCreaturePosition(cid), config.ghleftarena.frompos, config.ghleftarena.topos)) then
		local monsters = getMonstersfromArea(config.ghleftarena.frompos, config.ghleftarena.topos)
		local players = getPlayersfromArea(config.ghleftarena.frompos, config.ghleftarena.topos)
	   if #players  < 1 then
		for _, monster in ipairs(monsters) do
			doRemoveCreature(monster)
		end
	end

end
return true
end

WATAFAKA!@?
 
to get monsters in range try with this but idk how to call it tho, gl:
LUA:
function getCreatureInRange(type, fromPos, toPos, toGet, itemid)
local type1 = {
	["monster"] = isMonster
}
local tmp = {}
local type = type1[type]
	if not type then
		return false
	end
	local thing = nil
	for x = fromPos.x, toPos.x do
		for y = fromPos.y, toPos.y do
			for z = fromPos.z, toPos.z do
				for s = 1, 253 do
					local position = {x = x, y = y, z = z, stackpos = s}
					thing = getTileThingByPos(position)
					if(type(thing.uid) == true) then
						table.insert(tmp, thing.uid)
					end
				end
			end
		end
	end
	if(toGet == "count") then
		return table.maxn(tmp)
	elseif(toGet == "name") then
		return tmp
	else
		print('[getCreatureInRange]>> Unknow creature to get')
		return false
	end
	return true
end

also wtf is function onThink(cid, interval) ?? lol
 
Last edited:
to get monsters in range try with this but idk how to call it tho, gl:
LUA:
function getCreatureInRange(type, fromPos, toPos, toGet, itemid)
local type1 = {
	["monster"] = isMonster
}
local tmp = {}
local type = type1[type]
	if not type then
		return false
	end
	local thing = nil
	for x = fromPos.x, toPos.x do
		for y = fromPos.y, toPos.y do
			for z = fromPos.z, toPos.z do
				for s = 1, 253 do
					local position = {x = x, y = y, z = z, stackpos = s}
					thing = getTileThingByPos(position)
					if(type(thing.uid) == true) then
						table.insert(tmp, thing.uid)
					end
				end
			end
		end
	end
	if(toGet == "count") then
		return table.maxn(tmp)
	elseif(toGet == "name") then
		return tmp
	else
		print('[getCreatureInRange]>> Unknow creature to get')
		return false
	end
	return true
end

also wtf is function onThink(cid, interval) ?? lol

thx for the function, gona try to figure something out.

@onThink(cid, interval)
one of tfs developers told me to add "cid", but it didn't help anyways.
 
thx for the function, gona try to figure something out.

@onThink(cid, interval)
one of tfs developers told me to add "cid", but it didn't help anyways.

You cant use 'cid' in globalevent, so he probably meant to create creature event onThink, but this way all online players would 'think' ^^
 
Code:
[22:21:35.698] data/lib/[COLOR="Red"]032-position.lua[/COLOR]:[COLOR="Blue"]2[/COLOR]: attempt to index local '[B]position[/B]' (a [COLOR="Green"]boolean[/COLOR] value)
As far as I know 'boolean' is for 'true' or 'false', isn't it?

Then, why that error? :confused:!

So, it returns getCreaturePosition(cid) as a boolean value??
 
Code:
[22:21:35.698] data/lib/[COLOR=Red]032-position.lua[/COLOR]:[COLOR=Blue]2[/COLOR]: attempt to index local '[B]position[/B]' (a [COLOR=Green]boolean[/COLOR] value)
As far as I know 'boolean' is for 'true' or 'false', isn't it?

Then, why that error? :confused:!

So, it returns getCreaturePosition(cid) as a boolean value??

No, its returning "nil" because cid does not exist.
 
lol, I need it to get player count in specific area.

Code:
local players = {}

for x, cid in ipairs(getPlayersOnline()) do
	if(isInRage(cid, {x = , y = , z = })) then
		table.insert(players, cid)
	end
end

print(#players .." in event area.")
 
Code:
local config = {
	ghleftarena = {
		frompos = {x = 3041, y = 2986, z =9},
		topos = {x = 3052, y = 2991, z=9}
	}
}
function onThink(interval, lastExecution, thinkInterval)
	if #getPlayersfromArea(config.ghleftarena.frompos, config.ghleftarena.topos) < 1 then
		local monsters = getMonstersfromArea(config.ghleftarena.frompos, config.ghleftarena.topos)
		for _, monster in ipairs(monsters) do
			doRemoveCreature(monster)
		end
	end
	return true
end
 
Code:
local config = {
	ghleftarena = {
		frompos = {x = 3041, y = 2986, z =9},
		topos = {x = 3052, y = 2991, z=9}
	}
}
function onThink(interval, lastExecution, thinkInterval)
	if #getPlayersfromArea(config.ghleftarena.frompos, config.ghleftarena.topos) < 1 then
		local monsters = getMonstersfromArea(config.ghleftarena.frompos, config.ghleftarena.topos)
		for _, monster in ipairs(monsters) do
			doRemoveCreature(monster)
		end
	end
	return true
end

I fucking love you :) problem solved&thread closed.
 
Status
Not open for further replies.
Back
Top