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

Selfmade Annihilator, help me debug it! :)

Oxious

Amateur Mapper & Scripter
Joined
Jan 25, 2009
Messages
89
Reaction score
0
Location
Germany
Greetings everyone!

Today I started scripting my own annihilator. It took me quite a while to get this working halfway, haha.

This is what I have now:

I have a lever, if you pull it you get teleported to the annihilator room, 6 demons spawn aswell. You kill them and go through an exp door which sets off a timer to change a storageValue (the value handles that noone can pull the lever while another team is still inside). You pick your reward and leave. The timer will after a define ammount of time automatically reset the storageValue set by the exp door aswell as flipping back the switch.

The whole storageValue part works fine, noone can flip the lever unless someone of the team who's currently doing the quest walks through the exp door to set off the timer. Quest rewards and a playerStorage are scripted in a different file. I have scripted this whole thing so you can do the actual quest numerous times but only get a reward once. I also still have to add a timer to automatically reset the quest in case everyone on the team dies.

But there's some problems I am facing here:

All the if cases I defined at the start seem to be ignored or scripted wrongly (those don't give me an error in the console, though) because you can pull the lever no matter where you stand (supposed to be working only if you're standing on one of the 4 tiles making it impossible to reset the quest since noone can set off the exp door timer because the quest is activated but noone is teleported in) and you can flip the switch even if you are alone (it's supposed to be 4 players only; it's just giving me a "doTeleportThing: cannot find Thing" error message).
Furthermore, the doRemoveCreature lines don't seem to work either. They are supposed to remove demons players may not have killed (it's giving me a "doRemoveCreature: cannot find Creature" error message for ALL SIX creatures, even if I just kill the 2 in front).


Any help is greatly appreciated. With explanations if you can. I'll learn from it I hope. ^^


PHP:
local player1Pos     =	{x = 544, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}
local player2Pos     =	{x = 545, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}
local player3Pos     =	{x = 546, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}
local player4Pos     =	{x = 547, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}

local newPosition1   =	{x = 542, y = 714, z = 10, stackpos = 1}
local newPosition2   =	{x = 543, y = 714, z = 10, stackpos = 1}
local newPosition3   =	{x = 544, y = 714, z = 10, stackpos = 1}
local newPosition4   =	{x = 545, y = 714, z = 10, stackpos = 1}

local demon1Position =	{x = 542, y = 712, z = 10, stackpos = 1}
local demon2Position =	{x = 544, y = 712, z = 10, stackpos = 1}
local demon3Position =	{x = 543, y = 716, z = 10, stackpos = 1}
local demon4Position =	{x = 545, y = 716, z = 10, stackpos = 1}
local demon5Position = 	{x = 546, y = 714, z = 10, stackpos = 1}
local demon6Position =	{x = 547, y = 714, z = 10, stackpos = 1}

local leverPos	     =  {x = 548, y = 723, z = 10, stackpos = 1}

function onUse(cid, item, frompos, item2, topos)

local player1 	= getThingfromPos(player1Pos)
local player2 	= getThingfromPos(player2Pos)
local player3 	= getThingfromPos(player3Pos)
local player4 	= getThingfromPos(player4Pos)

local timer 	= 10



	if item.itemid == 1945 then

		if player1.itemid > 0 
		and player2.itemid > 0 
		and player3.itemid > 0 
		and player4.itemid > 0 then

			if isPlayer(player1.uid) == TRUE 
			and isPlayer(player2.uid) == TRUE 
			and isPlayer(player3.uid) == TRUE 
			and isPlayer(player4.uid) == TRUE then

				if getPlayerLevel(player1.uid) >= 100 
				and getPlayerLevel(player2.uid) >= 100
				and getPlayerLevel(player3.uid) >= 100
				and getPlayerLevel(player4.uid) >= 100 then

					setGlobalStorageValue(5000, 1)

				else

					setGlobalStorageValue(5000, 0)

				end

			end

		end

		if  getGlobalStorageValue(5000) == 1 then

			doSummonCreature("demon", demon1Position)
			doSummonCreature("demon", demon2Position)
			doSummonCreature("demon", demon3Position)
			doSummonCreature("demon", demon4Position)
			doSummonCreature("demon", demon5Position)
			doSummonCreature("demon", demon6Position)
			doSendMagicEffect(player1Pos, CONST_ME_POFF)
			doSendMagicEffect(player2Pos, CONST_ME_POFF)
			doSendMagicEffect(player3Pos, CONST_ME_POFF)
			doSendMagicEffect(player4Pos, CONST_ME_POFF)
			doTeleportThing(player1.uid, newPosition1, FALSE)
			doTeleportThing(player2.uid, newPosition2, FALSE)
			doTeleportThing(player3.uid, newPosition3, FALSE)
			doTeleportThing(player4.uid, newPosition4, FALSE)
			doSendMagicEffect(newPosition1, CONST_ME_ENERGYAREA)
			doSendMagicEffect(newPosition2, CONST_ME_ENERGYAREA)
			doSendMagicEffect(newPosition3, CONST_ME_ENERGYAREA)
			doSendMagicEffect(newPosition4, CONST_ME_ENERGYAREA)
			setGlobalStorageValue(5001, 1)

		elseif getGlobalStorageValue(5000) == 0 then

			doPlayerSendCancel(cid, "Sorry, not possible.")

		end

	elseif item.itemid == 1946 and getGlobalStorageValue(5001) == 1 then

		doPlayerSendCancel(cid, "Sorry, not possible.")
		doPlayerSendTextMessage(cid, 22, "There is already a team being annihilated! Please wait.")
		return 1

	elseif item.itemid == 8555 and getGlobalStorageValue(5001) == 1 then

		doPlayerSendTextMessage(cid, 22, "Congratulations! Enjoy your reward.")
		addEvent(resetLever, timer*1000)

	end

end

function resetLever()

local lever = getThingFromPos(leverPos)

	if getGlobalStorageValue(5001) == 1 then

		doRemoveCreature("demon", demon1Position)
		doRemoveCreature("demon", demon2Position)
		doRemoveCreature("demon", demon3Position)
		doRemoveCreature("demon", demon4Position)
		doRemoveCreature("demon", demon5Position)
		doRemoveCreature("demon", demon6Position)
		doTransformItem(lever.uid, 1945)
		setGlobalStorageValue(5001, 0)

	end

end
 
Why you are using stupid global storage value?

Simple checking for things in area:
Code:
for areax = 1041, 1052 do
	for areay = 985, 991 do
		areapos = {x=areax, y=areay, z=9, stackpos=253}
		areacreature = getThingfromPos(areapos)

		if areacreature.itemid > 0 then
			doPlayerSendCancel(cid,"Someone is in the area.")
			return 1
		end
	end
end
 
Ok, I sort of managed to fix it. Except it does not check which demons are left unkilled resulting in a

PHP:
[01/02/2009 16:39:10] Lua Script Error: [Action Interface] 
[01/02/2009 16:39:10] in a timer event called from: 
[01/02/2009 16:39:10] data/actions/scripts/quests/annihilator.lua:onUse

[01/02/2009 16:39:10] luaDoRemoveCreature(). Creature not found

error when the script is trying to remove a demon that has already been killed. However this does not have any negative side effects. I'm just to lazy right now to get into a checking routine like you described, Hermes. I might try to add this feature to the script another time. :)

This is how the script looks now:

PHP:
--- Annihilator script made by Oxious ---


local player1Pos	= {x = 544, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}
local player2Pos	= {x = 545, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}
local player3Pos	= {x = 546, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}
local player4Pos	= {x = 547, y = 723, z = 10, stackpos = STACKPOS_TOP_CREATURE}

local newPosition1	= {x = 542, y = 714, z = 10, stackpos = 1}
local newPosition2	= {x = 543, y = 714, z = 10, stackpos = 1}
local newPosition3	= {x = 544, y = 714, z = 10, stackpos = 1}
local newPosition4	= {x = 545, y = 714, z = 10, stackpos = 1}

local demon1Position	= {x = 542, y = 712, z = 10, stackpos = 1}
local demon2Position	= {x = 544, y = 712, z = 10, stackpos = 1}
local demon3Position	= {x = 543, y = 716, z = 10, stackpos = 1}
local demon4Position	= {x = 545, y = 716, z = 10, stackpos = 1}
local demon5Position	= {x = 546, y = 714, z = 10, stackpos = 1}
local demon6Position	= {x = 547, y = 714, z = 10, stackpos = 1}

local leverPos		= {x = 548, y = 723, z = 10, stackpos = 1}

local reqLevel		= 100   --- required level for the quest ---

function onUse(cid, item, frompos, item2, topos)

local player1     = getThingfromPos(player1Pos)
local player2     = getThingfromPos(player2Pos)
local player3     = getThingfromPos(player3Pos)
local player4     = getThingfromPos(player4Pos)

local timer     = 10   --- time to reset the quest in seconds ---



	if item.itemid == 1945 then

		if player1.itemid > 0 
		and player2.itemid > 0 
		and player3.itemid > 0 
		and player4.itemid > 0 then

			if isPlayer(player1.uid) == TRUE 
			and isPlayer(player2.uid) == TRUE 
			and isPlayer(player3.uid) == TRUE 
			and isPlayer(player4.uid) == TRUE then

				if getPlayerLevel(player1.uid) >= reqLevel 
				and getPlayerLevel(player2.uid) >= reqLevel
				and getPlayerLevel(player3.uid) >= reqLevel
				and getPlayerLevel(player4.uid) >= reqLevel then

					doSummonCreature("demon", demon1Position)
					doSummonCreature("demon", demon2Position)
					doSummonCreature("demon", demon3Position)
					doSummonCreature("demon", demon4Position)
					doSummonCreature("demon", demon5Position)
					doSummonCreature("demon", demon6Position)
					doSendMagicEffect(player1Pos, CONST_ME_POFF)
					doSendMagicEffect(player2Pos, CONST_ME_POFF)
					doSendMagicEffect(player3Pos, CONST_ME_POFF)
					doSendMagicEffect(player4Pos, CONST_ME_POFF)
					doTeleportThing(player1.uid, newPosition1, FALSE)
					doTeleportThing(player2.uid, newPosition2, FALSE)
					doTeleportThing(player3.uid, newPosition3, FALSE)
					doTeleportThing(player4.uid, newPosition4, FALSE)
					doSendMagicEffect(newPosition1, CONST_ME_ENERGYAREA)
					doSendMagicEffect(newPosition2, CONST_ME_ENERGYAREA)
					doSendMagicEffect(newPosition3, CONST_ME_ENERGYAREA)
					doSendMagicEffect(newPosition4, CONST_ME_ENERGYAREA)
					setGlobalStorageValue(5001, 1)

				else

					doPlayerSendCancel(cid, "Sorry, not possible.")
					return 1

				end

			else

				doPlayerSendCancel(cid, "Sorry, not possible.")
				return 1

			end

		else

			doPlayerSendCancel(cid, "Sorry, not possible.")
			return 1

		end


	elseif item.itemid == 1946 and getGlobalStorageValue(5001) == 1 then

		doPlayerSendCancel(cid, "Sorry, not possible.")
		doPlayerSendTextMessage(cid, 22, "There is already a team being annihilated! Please wait.")
		return 1

	elseif item.itemid == 8555 and getGlobalStorageValue(5001) == 1 then

		doPlayerSendTextMessage(cid, 22, "Congratulations! Enjoy your reward.")
		addEvent(resetLever, timer*1000)

	end

end

function resetLever()

local lever 	 = getThingFromPos(leverPos)
local demon1     = getThingfromPos(demon1Position)
local demon2     = getThingfromPos(demon2Position)
local demon3     = getThingfromPos(demon3Position)
local demon4     = getThingfromPos(demon4Position)
local demon5     = getThingfromPos(demon5Position)
local demon6     = getThingfromPos(demon6Position)

    if getGlobalStorageValue(5001) == 1 then


        doTransformItem(lever.uid, 1945)
        setGlobalStorageValue(5001, 0)
        doRemoveCreature(demon1.uid)
        doRemoveCreature(demon2.uid)
        doRemoveCreature(demon3.uid)
        doRemoveCreature(demon4.uid)
        doRemoveCreature(demon5.uid)
        doRemoveCreature(demon6.uid)

    end

end
 
Back
Top