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

Lua Monster Lever Script, doRemoveCreature.

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
I'm sick of this script lol, everything about it works fine except for the doRemoveCreature, and I'm not sure how to make it remove random creatures in a 1x1 area, for example "exori gran". I tried a lot of stuff, nothing wants to work.. 0.3.1pl2. If possible, can the tiles be cleaned too on 1945? If there is a function I must add to do so, let me know, thanks in advance, any advice is appreciated!
PHP:
local t = {
	[{1, 14}] = "Rotworm",
	[{15, 39}] = "Dragon",
	[{40, 79}] = "Dragon Lord",
	[{80, 179}] = "Demon",
	[{180, 3000}] = "Bog Spider"
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z}
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z}
	if(item.itemid == 1946) then
		for k, v in pairs(t) do
			if(getPlayerLevel(cid) >= k[1] and getPlayerLevel(cid) <= k[2]) then
				doSummonCreature(v, getPlayerPosition(cid))
				doSummonCreature(v, getPlayerPosition(cid))
			end
		end
	elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then
		doPlayerSendCancel(cid, "Sorry, not possible.")
		doRemoveCreature(isMonster(isInArea(fromPos, toPos)))
		doRemoveCreature(isMonster(isInArea(fromPos, toPos)))
	end
return true
end

Forgot the error;
PHP:
[16/06/2012 07:56:09] data/lib/function.lua:258: attempt to index local 'toPos' (a nil value)
[16/06/2012 07:56:09] stack traceback:
[16/06/2012 07:56:09] 	data/lib/function.lua:258: in function 'isInArea'
[16/06/2012 07:56:09] 	data/actions/scripts/other/monster_lever.lua:21: in function <data/actions/scripts/other/monster_lever.lua:9>

Edit; here is the function in lib/function.lua:
PHP:
function isInArea(pos, fromPos, toPos)
	if(pos.x >= fromPos.x and pos.x <= toPos.x) then
		if(pos.y >= fromPos.y and pos.y <= toPos.y) then
			if(pos.z >= fromPos.z and pos.z <= toPos.z) then
				return TRUE
			end
		end
	end

	return FALSE
end
-------------------------------------------------------------------------------------------------------------------------------------
Sorry for all these edits, but here is what I got to after reviewing that function. If this one is closer you can use it, if it isn't then use the above one.
PHP:
local t = {
	[{1, 14}] = "Rotworm",
	[{15, 39}] = "Dragon",
	[{40, 79}] = "Dragon Lord",
	[{80, 179}] = "Demon",
	[{180, 3000}] = "Bog Spider"
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z}
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z}
	if(item.itemid == 1946) then
		for k, v in pairs(t) do
			if(getPlayerLevel(cid) >= k[1] and getPlayerLevel(cid) <= k[2]) then
				doSummonCreature(v, getPlayerPosition(cid))
				doSummonCreature(v, getPlayerPosition(cid))
			end
		end
	elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then
		doPlayerSendCancel(cid, "Sorry, not possible.")
		doRemoveCreature(isMonster(isInArea(getCreaturePosition(cid), fromPos, toPos)))
		doRemoveCreature(isMonster(isInArea(getCreaturePosition(cid), fromPos, toPos)))
	end
return true
end
Code:
[16/06/2012 09:18:57] luaDoRemoveCreature(). Creature not found
 
Last edited:
is a pretty rare problem, but try with this

Code:
local t = {
    [{1, 14}] = "Rotworm",
    [{15, 39}] = "Dragon",
    [{40, 79}] = "Dragon Lord",
    [{80, 179}] = "Demon",
    [{180, 3000}] = "Bog Spider"
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z}
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z}
    if(item.itemid == 1946) then
        for k, v in pairs(t) do
            if(getPlayerLevel(cid) >= k[1] and getPlayerLevel(cid) <= k[2]) then
                doSummonCreature(v, getPlayerPosition(cid))
                doSummonCreature(v, getPlayerPosition(cid))
            end
        end
    elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then
        doPlayerSendCancel(cid, "Sorry, not possible.")
        doRemoveCreature(isMonster(isInArea(getCreaturePosition(cid), fromPosition, toPosition)))
        doRemoveCreature(isMonster(isInArea(getCreaturePosition(cid), fromPosition, toPosition)))
    end
return true
end
 
Code:
[18/06/2012 17:51:05] luaDoRemoveCreature(). Creature not found
and for some reason once i use the switch just keeps going back and forth and summoning, but not deleting.
 
try

LUA:
local t = { 
    [{1, 14}] = "Rotworm", 
    [{15, 39}] = "Dragon", 
    [{40, 79}] = "Dragon Lord", 
    [{80, 179}] = "Demon", 
    [{180, 3000}] = "Bog Spider" 
} 

function onUse(cid, item, fromPosition, itemEx, toPosition) 
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z} 
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z} 
    if(item.itemid == 1946) then 
        for k, v in pairs(t) do 
            if(getPlayerLevel(cid) >= k[1] and getPlayerLevel(cid) <= k[2]) then 
                doSummonCreature(v, getPlayerPosition(cid)) 
                doSummonCreature(v, getPlayerPosition(cid)) 
            end 
        end 
    elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then 
        doPlayerSendCancel(cid, "Sorry, not possible.") 
	for _, var in ipairs(getCreatureSummons(cid)) do
	doRemoveCreature(var)
	end
    end 
return true 
end
 
not removing, but i'm not getting any errors.
EDIT; when i summon a monster using utevo res or /s, it removes it. but not the monsters that summon from the switch. is there a way to give the creatures a storage when they are made then it removes monsters with that storage? or like i was thinking doRemoveCreature(isMonster)) in an area 1x1.
 
It's removing your summoned monster because of this:

LUA:
for _, var in ipairs(getCreatureSummons(cid)) do

You'll see what I mean. (hint: cid)
 
Just need to use a for loop to get all the creatures (isMonster) in the area and use that to determine their summons (if any).
 
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z}
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z}
elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then
doPlayerSendCancel(cid, "Sorry, not possible.")
doRemoveCreature(isMonster(isInArea(cid, fromPos, toPos)))
end
- something like this?
 
I have a similar thing in one of my quests, you can look at this, it might help. This works fine for me:

Code:
function deSpawn()

    TOP_LEFT_CORNER = {x=1154, y=978, z=10, stackpos=253}
    BOTTOM_RIGHT_CORNER = {x=1167, y=990, z=10, stackpos=253}

        for Py = TOP_LEFT_CORNER.y, BOTTOM_RIGHT_CORNER.y do
    
    for Px = TOP_LEFT_CORNER.x, BOTTOM_RIGHT_CORNER.x do
        creature = getThingfromPos({x=Px, y=Py, z=10, stackpos=253})
        if isMonster(creature.uid) then
        if getCreatureName(creature.uid) == "Ghoul" then
                            doRemoveCreature(creature.uid)
                        doSendMagicEffect({x=Px, y=Py, z=10}, 65)
                        end
                end
            end
    end
    return TRUE
end
 
LUA:
local t = { 
    [{1, 14}] = "Rotworm", 
    [{15, 39}] = "Dragon", 
    [{40, 79}] = "Dragon Lord", 
    [{80, 179}] = "Demon", 
    [{180, 3000}] = "Bog Spider" 
} 
 
function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers, showSummons)
	local creaturesList = {}
	for x = -radiusx, radiusx do
		for y = -radiusy, radiusy do
			if not (x == 0 and y == 0) then
				creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z, stackpos = 253})
				if (creature.type == 1 and showPlayers == TRUE) or (creature.type == 2 and showMonsters == TRUE and (showSummons == FALSE or (showSummons == TRUE and getCreatureMaster(creature.uid) == (creature.uid)))) then
					table.insert(creaturesList, creature.uid)
				end
			end
		end
	end
 
	local creature = getTopCreature(position)
	if (creature.type == 1 and showPlayers == TRUE) or (creature.type == 2 and showMonsters == TRUE and (showSummons == FALSE or (showSummons == TRUE and getCreatureMaster(creature.uid) == (creature.uid)))) then
		if not(table.find(creaturesList, creature.uid)) then
			table.insert(creaturesList, creature.uid)
		end
	end
    return creaturesList
end

function onUse(cid, item, fromPosition, itemEx, toPosition) 
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z} 
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z} 
    if(item.itemid == 1946) then 
        for k, v in pairs(t) do 
            if(getPlayerLevel(cid) >= k[1] and getPlayerLevel(cid) <= k[2]) then 
                doSummonCreature(v, getPlayerPosition(cid)) 
                doSummonCreature(v, getPlayerPosition(cid)) 
            end 
        end 
    elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then 
        doPlayerSendCancel(cid, "Sorry, not possible.") 
	local creatures = getCreaturesInRange(getPlayerPosition(cid), 1, 1, FALSE, FALSE, TRUE)
		for i = 1, #creatures do
			doRemoveCreature(creatures)
	end
    end 
return true 
end

A very sketchy copy and paste of a function from another script. If it gives a bunch of errors, don't be alarmed.
I'm assuming it works, if it doesn't we can work on it from here.

The real problem is I don't even know what your script is supposed to do haha, I just know you want to remove summoned creatures in an area.
 
That's not removing the monsters either, it also isn't giving any errors. What the script does is when you are in the Monster Lever Room, you use the switch and it creates 2 monsters, depending on your level. If you don't kill them and keep spamming the lever, it spams the console and probably creates lag. What I'm trying to do is make it so that when it is on 1945 and you use it, it removes the monsters in the area. The area looks something like this ( I'll make it in spell form. ) Key: 0 = nothing, protection tile. 1 = where the monster would go, 2 = switch, 3 = player.
[1, 0, 0],
[2, 3, 0],
[1, 0, 0]

Understandable?
 
Oh... I thought you only wanted to remove summons.

LUA:
local t = { 
    [{1, 14}] = "Rotworm", 
    [{15, 39}] = "Dragon", 
    [{40, 79}] = "Dragon Lord", 
    [{80, 179}] = "Demon", 
    [{180, 3000}] = "Bog Spider" 
} 
 
function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers, showSummons)
	local creaturesList = {}
	for x = -radiusx, radiusx do
		for y = -radiusy, radiusy do
			if not (x == 0 and y == 0) then
				creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z, stackpos = 253})
				if (creature.type == 1 and showPlayers == TRUE) or (creature.type == 2 and showMonsters == TRUE and (showSummons == FALSE or (showSummons == TRUE and getCreatureMaster(creature.uid) == (creature.uid)))) then
					table.insert(creaturesList, creature.uid)
				end
			end
		end
	end
 
	local creature = getTopCreature(position)
	if (creature.type == 1 and showPlayers == TRUE) or (creature.type == 2 and showMonsters == TRUE and (showSummons == FALSE or (showSummons == TRUE and getCreatureMaster(creature.uid) == (creature.uid)))) then
		if not(table.find(creaturesList, creature.uid)) then
			table.insert(creaturesList, creature.uid)
		end
	end
    return creaturesList
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition) 
local fromPos = {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z} 
local toPos = {x=toPosition.x,y=toPosition.y-1,z=toPosition.z} 
    if(item.itemid == 1946) then 
        for k, v in pairs(t) do 
            if(getPlayerLevel(cid) >= k[1] and getPlayerLevel(cid) <= k[2]) then 
                doSummonCreature(v, getPlayerPosition(cid)) 
                doSummonCreature(v, getPlayerPosition(cid)) 
            end 
        end 
    elseif(item.itemid == 1945 or getPlayerLevel(cid) > k[2]) then 
        doPlayerSendCancel(cid, "Sorry, not possible.") 
	local creatures = getCreaturesInRange(getPlayerPosition(cid), 1, 1, TRUE, FALSE, TRUE)
		for i = 1, #creatures do
			doRemoveCreature(creatures)
	end
    end 
return true 
end

Changed showMonster from FALSE to TRUE
 
Code:
[29/07/2012 19:53:17] Lua Script Error: [Action Interface] 
[29/07/2012 19:53:17] data/actions/scripts/other/monster_lever.lua:onUse

[29/07/2012 19:53:17] luaDoRemoveCreature(). Creature not found

[29/07/2012 19:53:17] Lua Script Error: [Action Interface] 
[29/07/2012 19:53:17] data/actions/scripts/other/monster_lever.lua:onUse

[29/07/2012 19:53:17] luaDoRemoveCreature(). Creature not found
It says it for every moster in the area, so it obviously counts the monsters.
 
Back
Top