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

Need a script to get closer creature in the screen!

Exedion

Active Member
Joined
Jun 11, 2007
Messages
628
Reaction score
30
need a function to get closer creature in the screen, check if have a storage value, if not have, do the function, but if the closer creature have the storage, is ignored and get the second closer creature and so it continues according to the number of repetitions to be configured in the script
 
Last edited:
iterating twice with getArea(pos, x, y) you can search for uid of players with storage
 
Something like this perhaps?

Code:
function f(position, key)
	local area, creatures = getArea(position, 5, 7), {}
	for i = 1, #area do
		local creature = getTopCreature(area[i]).uid
		if creature > 0 and getCreatureStorage(creature, key) ~= -1 then
			table.insert(creatures, creature)
		end
	end

	table.sort(creatures,
		function(a, b)
			return getDistanceBetween(getThingPosition(a), position) < getDistanceBetween(getThingPosition(b), position)
		end
	)

	return #creatures > 0 and creatures[1] or nil
end
 
This function will iterate through positions table, check if there's a creature on given position, add found creatures to table, sort table by proximity to the center position and return the closest creature or nil, you call it with center position and storage key that you want to check creatures for.
 
example if the most closer creature have a storage, this return nil? or return the other second most closer creature without storage?

ANOTHER QUESTION: storage value can be set in monsters?
 
Last edited:
sorry for my bad english, if the closer creature has storage, the script return "nil" or return second closer creature without storage?

storage values [setCreatureStorage(cid, key, value)] can be set in monsters?
 
Back
Top