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

Effect on one of the monsters rep++

Niskafase

New Member
Joined
Jan 8, 2010
Messages
104
Reaction score
1
I'm having a hard time with this script, no idea how I can solve this so if someone can make it work I'll be Mr. Happy.

Information:
When a monster is 3 sqm away or closer to this item, a magic effect should show on the monster over and over again
(ONLY ONE OF THE MONSTERS THAT ARE IN THAT RANGE)
^ That's the problem.

When I use this script it shows the effect on all monsters in the range.
Lua:
function onThink(interval, lastExecution, thinkInterval)
	if getThingFromPos({x=111, y=111, z=7, stackpos=1}).itemid == 9999 then
		for x = item.x-3, item.x+3 do
			for y = item.y-3, item.y+3 do
				local monsterPos = {x=x, y=y, z=7, stackpos=253}
				local monster = getThingFromPos(monsterPos)
				if monster.itemid > 0 and isMonster(monster.uid) then
					doSendMagicEffect(monsterPos, 39)
				end
			end
		end
	end
return true
end

So what I would like you to figure out now is to make it only send the effect on one of the monsters in that range.

Thanks :)
 
Alright, it works fine with the if getSpectators(...) then function, but I can't figure out how I should use it with doSendMagicEffect(pos, ...) and doCreatureAddHealth(getSpec(?), ...)

So if someone can just change my script to one with the getSpectators function instead and also add doCreatureAddHealth function in it so it removes health from the monster in that area would be great.
 
Code:
function onThink(interval, lastExecution, thinkInterval)
	if getTileItemById({x=111, y=111, z=7}, 9999).uid > 0 then
		local monsters = getSpectators({x=111, y=111, z=7}, 3, 3, false)
		for i = 1, #monsters do
			if isMonster(monsters[i]) then
				doSendMagicEffect(getCreaturePosition(monsters[i]), 39)
				doCreatureAddHealth(monsters[i], 100)
				break -- break the loop once a monster is found
			end
		end
	end
	return true
end
 
Works perfect until the monster leaves the area, then I get this error:
[14/01/2010 21:28:22] [Error - GlobalEvent Interface]
[14/01/2010 21:28:22] data/globalevents/scripts/test.lua:eek:nThink
[14/01/2010 21:28:22] Description:
[14/01/2010 21:28:22] data/globalevents/scripts/test.lua:4: attempt to get length of local 'monsters' (a nil value)
[14/01/2010 21:28:22] stack traceback:
[14/01/2010 21:28:22] data/globalevents/scripts/test.lua:4: in function <data/globalevents/scripts/test.lua:1>
[14/01/2010 21:28:22] [Error - GlobalEvents::think] Couldn't execute event: test
 
Lua:
function onThink(interval, lastExecution, thinkInterval)
	if getTileItemById({x=111, y=111, z=7}, 9999).uid > 0 then
		local monsters = getSpectators({x=111, y=111, z=7}, 3, 3, false)
		if(#monsters > 0) then
			for i = 1, #monsters do
				if isMonster(monsters[i]) then
					doSendMagicEffect(getCreaturePosition(monsters[i]), 39)
					doCreatureAddHealth(monsters[i], 100)
					break -- break the loop once a monster is found
				end
			end
		end
	end
	return true
end
 
Same problem again ^^
data/globalevents/scripts/test.lua:7: attempt to get length of local 'monsters' (a nil value)

Line 7:
Lua:
if(#monsters > 0) then

EDIT:
Nvm, think I fixed it by using this instead:
Lua:
if(table.maxn(monsters) > 0) then

EDIT 2:
Omg, new error message... -.-

data/globalevents/scripts/test.lua:7: bad argument #1 to 'maxn' (table expected, got nil)
 
Last edited:
:D It returns false if no creatures are found so we have to check whether it returned false or true (table) before checking table length.

Code:
function onThink(interval, lastExecution, thinkInterval)
	if getTileItemById({x=111, y=111, z=7}, 9999).uid > 0 then
		local monsters = getSpectators({x=111, y=111, z=7}, 3, 3, false)
		if([B][COLOR="Red"]monsters and [/COLOR][/B]#monsters > 0) then
			for i = 1, #monsters do
				if isMonster(monsters[i]) then
					doSendMagicEffect(getCreaturePosition(monsters[i]), 39)
					doCreatureAddHealth(monsters[i], 100)
					break -- break the loop once a monster is found
				end
			end
		end
	end
	return true
end
 
Back
Top