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

Removing creatures without errors

watkins577

As3, lua, xml scripter
Joined
Sep 20, 2008
Messages
130
Reaction score
0
Ok I made a script which resets a quest completely (even removes the creatures) but I cant work out how to do it so it gives no errors. Im just gonna post one of the removal scripts here (bcause its very repetitive)

Code:
local monster1 = {x=176, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
local mon1 = getThingfromPos(monster1)
if isMonster(mon1.uid) == TRUE then
	doRemoveCreature(mon1.uid)
end

When I use this (for the 11 spots that the demons could be on) it gives the error...

Code:
[22/05/2009 12:00:00] Lua Script Error: [CreatureScript Interface] 
[22/05/2009 12:00:00] data/creaturescripts/scripts/playerdeath.lua:onDeath

[22/05/2009 12:00:00] luaGetCreatureName(). Creature not found

However all the demons are removed...
 
@up
Post your fully playerdeath.lua.

or try this
Lua:
 local monPos = {x=176, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
local monster = getThingFromPos(monPos)
	if isCreature(monster.uid) == TRUE then
		doRemoveCreature(monster.uid)
	return TRUE
end
 
Ok, I changed it a little so its a lot shorter now, but I still get the errors:

Lua:
local config = {

	deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),

	sqlType = getConfigInfo('sqlType'),

	maxDeathRecords = getConfigInfo('maxDeathRecords')
,
	fPos = {x=175, y=128, z=8},
	tPos = {x=186, y=128, z=8}
}



function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)

	if isInArea(getCreaturePosition(cid), config.fPos, config.tPos) then
		reset1()
	end
	if getPlayerItemCount(cid, 2173) >= 1 then
		doPlayerRemoveItem(cid, 2173, 1)
	end
	if(config.deathListEnabled == TRUE) then

		local hitKillerName = "field item"

		local damageKillerName = ""

		if(lastHitKiller ~= FALSE) then

			if(isPlayer(lastHitKiller) == TRUE) then

				hitKillerName = getPlayerGUID(lastHitKiller)

			else

				hitKillerName = getCreatureName(lastHitKiller)

			end


			if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then

				if(isPlayer(mostDamageKiller) == TRUE) then

					damageKillerName = getPlayerGUID(mostDamageKiller)

				else

					damageKillerName = getCreatureName(mostDamageKiller)

				end

			end

		end


		db.executeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

		local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")

		if(rows:getID() ~= -1) then

			local amount = rows:getRows(true) - config.maxDeathRecords

			if(amount > 0) then

				if(config.sqlType == "sqlite") then

					for i = 1, amount do

						db.executeQuery("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")

					end

				else

					db.executeQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")

				end

			end

		end

	end

end

local monsterArea = {
    fromPos = {x=176, y=128, z=8},
    toPos = {x=186, y=128, z=8}
}

local removeWalls = {
    {x=174, y=128, z=8, stackpos=1},
    {x=188, y=128, z=8, stackpos=1},
    {x=173, y=128, z=8, stackpos=1}
}

local itemId = 1304
local createWalls = {
    {x=175, y=128, z=8},
    {x=186, y=128, z=8},
    {x=187, y=128, z=8}
}
function reset1()
    for _, pos in ipairs(removeWalls) do
        local thing = getThingfromPos(pos)
        if(thing.uid > 0) then
            doRemoveItem(thing.uid)
        end
    end
    for _, pos in ipairs(createWalls) do
        doCreateItem(itemId, 1, pos)
    end
    for _, thing in mapArea(monsterArea.fromPos, monsterArea.toPos, STACKPOS_TOP_CREATURE) do
        if(isMonster(thing.uid) == TRUE)then
            doRemoveCreature(thing.uid)
        end
    end
    return TRUE
end
function mapArea(fromPos, toPos, stack)
    -- Area iterator by Colandus @ OTFans.net
    local pos = {x=fromPos.x, y=fromPos.y-1, z=fromPos.z}
    return function()
        if (pos.y < toPos.y) then
            pos.y = pos.y+1
        elseif (pos.x <= toPos.x) then
            pos.y = fromPos.y
            pos.x = pos.x+1
        else
            pos.x = fromPos.x
            pos.y = fromPos.y
            pos.z = pos.z+1
        end
        if (pos.x <= toPos.x and pos.y <= toPos.y or pos.z < toPos.z) then
            if (stack == nil) then
                return pos
            else
                pos.stackpos = stack
                return pos, getThingfromPos(pos)
            end
        end
    end
end

I told you it was big...
 
@up
I just tried it and it doesnt remove the demons

Edit: I think it might have just been me being stupid... hold on lemme retry... Nvm it just gives the errors, and the demons aren't removed.

Edit2: Ok it removes 1 demon...
 
Last edited:
Ok, here they are...
Lua:
	local monster1 = {x=176, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster2 = {x=177, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster3 = {x=178, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster4 = {x=179, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster5 = {x=180, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster6 = {x=181, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster7 = {x=182, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster8 = {x=183, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster9 = {x=184, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
	local monster10 = {x=185, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}
 
Lua:
local creaturePositions =
{

{x=176, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=177, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=178, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=179, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=180, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=181, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=182, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=183, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=184, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=185, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}

}
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
    for i = 1, 10 do
        local monster = getThingFromPos(creaturePositions[i])

        if isCreature(monster.uid) == TRUE then
            doRemoveCreature(monster.uid)
	end	 
    end
   return TRUE
end
 
Woops... I just realised my errors aren't coming from there, but these lines...

Lua:
if(isPlayer(lastHitKiller) == TRUE) then
   hitKillerName = getPlayerGUID(lastHitKiller)
else
   hitKillerName = getCreatureName(lastHitKiller)
end
if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
   if(isPlayer(mostDamageKiller) == TRUE) then
      damageKillerName = getPlayerGUID(mostDamageKiller)
   else
      damageKillerName = getCreatureName(mostDamageKiller)
   end
end

Yep.. I just checked phpmyadmin and the results in last deaths are messed up.
 
Lua:
local creaturePositions =
{

{x=176, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=177, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=178, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=179, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=180, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=181, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=182, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=183, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=184, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE},
{x=185, y=128, z=8, stackpos=STACKPOS_TOP_CREATURE}

}
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
for i = 1, table.maxn(creaturePositions) do

local monster = getThingFromPos(i)
        if isCreature(monster.uid) == TRUE then
                doRemoveCreature(monster.uid)
		end
	end
		return TRUE
end
positions taken from josejunior :)

Just make a new script for this.
 
As he said that's not the error.

You don't need to try to shorten it, as it's already shorten: OpenTibia Fans - View Single Post - Want your script shortened?

And clearly the error is not in that script as there is no getCreatureName!

Lua:
if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
   if(isPlayer(mostDamageKiller) == TRUE) then
      damageKillerName = getPlayerGUID(mostDamageKiller)
   else
      damageKillerName = getCreatureName(mostDamageKiller)
   end
end

You have to put a if isCreature(...) check there. Sometimes the killer ain't a creature, or there's no mostDamageKiller at all!
 
@up -- I did that yesterday lol, and it works perfectly (after I did some minor adjustments in playerdeath which did not involve your script)
 
Back
Top